diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 20:28:13 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 20:28:13 +0000 |
commit | 97c22ee2f0123d1d4dbdb705809d97d0f1d9f65a (patch) | |
tree | 4b6501ca599fb8d884381f56e4435a9b4244d7a2 /chrome/browser/gtk/constrained_html_delegate_gtk.cc | |
parent | b104b50ddb1d70d95ff9ace7a6fb30ec3b1aeb17 (diff) | |
download | chromium_src-97c22ee2f0123d1d4dbdb705809d97d0f1d9f65a.zip chromium_src-97c22ee2f0123d1d4dbdb705809d97d0f1d9f65a.tar.gz chromium_src-97c22ee2f0123d1d4dbdb705809d97d0f1d9f65a.tar.bz2 |
[Gtk] add facility for constrained window delegate to control background color.
This makes modal html dialogs blend better (rather than having a white HTML background and a theme-colored border).
BUG=none
TEST=manual
Review URL: http://codereview.chromium.org/3784006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/constrained_html_delegate_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/constrained_html_delegate_gtk.cc | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/chrome/browser/gtk/constrained_html_delegate_gtk.cc b/chrome/browser/gtk/constrained_html_delegate_gtk.cc new file mode 100644 index 0000000..f23c82d --- /dev/null +++ b/chrome/browser/gtk/constrained_html_delegate_gtk.cc @@ -0,0 +1,113 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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_ui.h" + +#include "gfx/gtk_util.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 ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, + public HtmlDialogTabContentsDelegate, + public ConstrainedHtmlUIDelegate { + public: + ConstrainedHtmlDelegateGtk(Profile* profile, + HtmlDialogUIDelegate* delegate); + + virtual ~ConstrainedHtmlDelegateGtk(); + + // ConstrainedWindowGtkDelegate ---------------------------------------------- + virtual GtkWidget* GetWidgetRoot() { + return tab_contents_container_.widget(); + } + virtual void DeleteDelegate() { + delete this; + } + + // ConstrainedHtmlDelegate --------------------------------------------- + virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate(); + virtual void OnDialogClose(); + virtual bool GetBackgroundColor(GdkColor* color) { + *color = gfx::kGdkWhite; + return true; + } + + // 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_; +}; + +ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( + Profile* profile, + HtmlDialogUIDelegate* delegate) + : 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); + gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_.widget()), + dialog_size.width(), + dialog_size.height()); + + gtk_widget_show_all(GetWidgetRoot()); +} + +ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { +} + +HtmlDialogUIDelegate* + ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { + return html_delegate_; +} + +void ConstrainedHtmlDelegateGtk::OnDialogClose() { + window_->CloseConstrainedWindow(); +} + +// static +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); +} |