From 2a30775a7ffa8558399bcc8131a39e0ae1600b60 Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Mon, 18 Oct 2010 19:42:22 +0000 Subject: Use TabContents for Constrained HTML dialogs. This makes constrained html windows match HtmlDialogUI more closely. The main reason for wanting to do this is that TabContents{View} has a lot of functionality that we need, but miss out on if we use RenderViewHost directly. This isn't hooked up to anything yet, but can be tested using sync setup. BUG=58022 TEST=manual Review URL: http://codereview.chromium.org/3846002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62961 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/constrained_html_dialog_gtk.cc | 89 +++++++++++++++-------- 1 file changed, 58 insertions(+), 31 deletions(-) (limited to 'chrome/browser/gtk') diff --git a/chrome/browser/gtk/constrained_html_dialog_gtk.cc b/chrome/browser/gtk/constrained_html_dialog_gtk.cc index 6fd36f1..5f65b2a 100644 --- a/chrome/browser/gtk/constrained_html_dialog_gtk.cc +++ b/chrome/browser/gtk/constrained_html_dialog_gtk.cc @@ -2,59 +2,77 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/dom_ui/constrained_html_dialog.h" +#include "chrome/browser/dom_ui/constrained_html_ui.h" #include "gfx/rect.h" #include "chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/gtk/constrained_window_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" +#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_source.h" #include "ipc/ipc_message.h" -class ConstrainedHtmlDialogGtk : public ConstrainedHtmlDialog, - public ConstrainedWindowGtkDelegate, - public HtmlDialogTabContentsDelegate { +class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, + public HtmlDialogTabContentsDelegate, + public ConstrainedHtmlUIDelegate { public: - ConstrainedHtmlDialogGtk(Profile* profile, + ConstrainedHtmlDelegateGtk(Profile* profile, HtmlDialogUIDelegate* delegate); - virtual ~ConstrainedHtmlDialogGtk(); - - // ConstrainedHtmlDialog ----------------------------------------------------- - virtual ConstrainedWindowDelegate* GetConstrainedWindowDelegate() { - return this; - } + virtual ~ConstrainedHtmlDelegateGtk(); // ConstrainedWindowGtkDelegate ---------------------------------------------- virtual GtkWidget* GetWidgetRoot() { return tab_contents_container_.widget(); } - virtual void DeleteDelegate() { delete this; } + // ConstrainedHtmlDelegate --------------------------------------------- + virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate(); + virtual void OnDialogClose(); + // HtmlDialogTabContentsDelegate --------------------------------------------- void MoveContents(TabContents* source, const gfx::Rect& pos) {} void ToolbarSizeChanged(TabContents* source, bool is_animating) {} void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} + void set_window(ConstrainedWindow* window) { + window_ = window; + } + private: + TabContents tab_contents_; TabContentsContainerGtk tab_contents_container_; + HtmlDialogUIDelegate* html_delegate_; + + // The constrained window that owns |this|. It's saved here because it needs + // to be closed in response to the DOMUI OnDialogClose callback. + ConstrainedWindow* window_; }; -ConstrainedHtmlDialogGtk::ConstrainedHtmlDialogGtk( +ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( Profile* profile, HtmlDialogUIDelegate* delegate) - : ConstrainedHtmlDialog(profile, delegate), - HtmlDialogTabContentsDelegate(profile), - tab_contents_container_(NULL) { - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); - tab_contents_->set_delegate(this); - tab_contents_->controller().LoadURL(delegate->GetDialogContentURL(), - GURL(), PageTransition::START_PAGE); - tab_contents_container_.SetTabContents(tab_contents_); + : HtmlDialogTabContentsDelegate(profile), + tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), + tab_contents_container_(NULL), + html_delegate_(delegate), + window_(NULL) { + tab_contents_.set_delegate(this); + + // Set |this| as a property on the tab contents so that the ConstrainedHtmlUI + // can get a reference to |this|. + ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( + tab_contents_.property_bag(), this); + + tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), + GURL(), PageTransition::START_PAGE); + tab_contents_container_.SetTabContents(&tab_contents_); gfx::Size dialog_size; delegate->GetDialogSize(&dialog_size); @@ -62,20 +80,29 @@ ConstrainedHtmlDialogGtk::ConstrainedHtmlDialogGtk( dialog_size.width(), dialog_size.height()); - InitializeDOMUI(tab_contents_->render_view_host()); - gtk_widget_show_all(GetWidgetRoot()); } -ConstrainedHtmlDialogGtk::~ConstrainedHtmlDialogGtk() { - delete tab_contents_; - // Prevent other accesses to |tab_contents_| (during superclass destruction, - // for example). - tab_contents_ = NULL; +ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { +} + +HtmlDialogUIDelegate* + ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { + return html_delegate_; +} + +void ConstrainedHtmlDelegateGtk::OnDialogClose() { + window_->CloseConstrainedWindow(); } // static -ConstrainedHtmlDialog* ConstrainedHtmlDialog::CreateConstrainedHTMLDialog( - Profile* profile, HtmlDialogUIDelegate* delegate) { - return new ConstrainedHtmlDialogGtk(profile, delegate); +void ConstrainedHtmlUI::CreateConstrainedHtmlDialog( + Profile* profile, + HtmlDialogUIDelegate* delegate, + TabContents* overshadowed) { + ConstrainedHtmlDelegateGtk* constrained_delegate = + new ConstrainedHtmlDelegateGtk(profile, delegate); + ConstrainedWindow* constrained_window = + overshadowed->CreateConstrainedDialog(constrained_delegate); + constrained_delegate->set_window(constrained_window); } -- cgit v1.1