| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/dom_ui/constrained_html_ui.h" | |
| 6 | |
| 7 #include "chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h" | |
| 8 #include "chrome/browser/dom_ui/html_dialog_ui.h" | |
| 9 #include "chrome/browser/gtk/constrained_window_gtk.h" | |
| 10 #include "chrome/browser/gtk/gtk_util.h" | |
| 11 #include "chrome/browser/gtk/tab_contents_container_gtk.h" | |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 14 #include "chrome/common/notification_source.h" | |
| 15 #include "gfx/rect.h" | |
| 16 #include "ipc/ipc_message.h" | |
| 17 | |
| 18 class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, | |
| 19 public HtmlDialogTabContentsDelegate, | |
| 20 public ConstrainedHtmlUIDelegate { | |
| 21 public: | |
| 22 ConstrainedHtmlDelegateGtk(Profile* profile, | |
| 23 HtmlDialogUIDelegate* delegate); | |
| 24 | |
| 25 virtual ~ConstrainedHtmlDelegateGtk(); | |
| 26 | |
| 27 // ConstrainedWindowGtkDelegate ---------------------------------------------- | |
| 28 virtual GtkWidget* GetWidgetRoot() { | |
| 29 return tab_contents_container_.widget(); | |
| 30 } | |
| 31 virtual void DeleteDelegate() { | |
| 32 html_delegate_->OnDialogClosed(""); | |
| 33 delete this; | |
| 34 } | |
| 35 | |
| 36 // ConstrainedHtmlDelegate --------------------------------------------- | |
| 37 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate(); | |
| 38 virtual void OnDialogClose(); | |
| 39 virtual bool GetBackgroundColor(GdkColor* color) { | |
| 40 *color = gtk_util::kGdkWhite; | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 // HtmlDialogTabContentsDelegate --------------------------------------------- | |
| 45 void MoveContents(TabContents* source, const gfx::Rect& pos) {} | |
| 46 void ToolbarSizeChanged(TabContents* source, bool is_animating) {} | |
| 47 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | |
| 48 | |
| 49 void set_window(ConstrainedWindow* window) { | |
| 50 window_ = window; | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 TabContents tab_contents_; | |
| 55 TabContentsContainerGtk tab_contents_container_; | |
| 56 HtmlDialogUIDelegate* html_delegate_; | |
| 57 | |
| 58 // The constrained window that owns |this|. It's saved here because it needs | |
| 59 // to be closed in response to the DOMUI OnDialogClose callback. | |
| 60 ConstrainedWindow* window_; | |
| 61 }; | |
| 62 | |
| 63 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( | |
| 64 Profile* profile, | |
| 65 HtmlDialogUIDelegate* delegate) | |
| 66 : HtmlDialogTabContentsDelegate(profile), | |
| 67 tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), | |
| 68 tab_contents_container_(NULL), | |
| 69 html_delegate_(delegate), | |
| 70 window_(NULL) { | |
| 71 tab_contents_.set_delegate(this); | |
| 72 | |
| 73 // Set |this| as a property on the tab contents so that the ConstrainedHtmlUI | |
| 74 // can get a reference to |this|. | |
| 75 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( | |
| 76 tab_contents_.property_bag(), this); | |
| 77 | |
| 78 tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), | |
| 79 GURL(), PageTransition::START_PAGE); | |
| 80 tab_contents_container_.SetTabContents(&tab_contents_); | |
| 81 | |
| 82 gfx::Size dialog_size; | |
| 83 delegate->GetDialogSize(&dialog_size); | |
| 84 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_.widget()), | |
| 85 dialog_size.width(), | |
| 86 dialog_size.height()); | |
| 87 | |
| 88 gtk_widget_show_all(GetWidgetRoot()); | |
| 89 } | |
| 90 | |
| 91 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { | |
| 92 } | |
| 93 | |
| 94 HtmlDialogUIDelegate* | |
| 95 ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { | |
| 96 return html_delegate_; | |
| 97 } | |
| 98 | |
| 99 void ConstrainedHtmlDelegateGtk::OnDialogClose() { | |
| 100 window_->CloseConstrainedWindow(); | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 void ConstrainedHtmlUI::CreateConstrainedHtmlDialog( | |
| 105 Profile* profile, | |
| 106 HtmlDialogUIDelegate* delegate, | |
| 107 TabContents* overshadowed) { | |
| 108 ConstrainedHtmlDelegateGtk* constrained_delegate = | |
| 109 new ConstrainedHtmlDelegateGtk(profile, delegate); | |
| 110 ConstrainedWindow* constrained_window = | |
| 111 overshadowed->CreateConstrainedDialog(constrained_delegate); | |
| 112 constrained_delegate->set_window(constrained_window); | |
| 113 } | |
| OLD | NEW |