| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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/ui/webui/constrained_html_ui_delegate_impl.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | |
| 8 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" | |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 10 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
| 11 #include "content/public/browser/notification_source.h" | |
| 12 #include "content/public/browser/render_view_host.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "ui/base/gtk/gtk_hig_constants.h" | |
| 15 #include "ui/gfx/size.h" | |
| 16 | |
| 17 using content::WebContents; | |
| 18 | |
| 19 class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, | |
| 20 public ConstrainedHtmlUIDelegate { | |
| 21 public: | |
| 22 ConstrainedHtmlDelegateGtk(Profile* profile, | |
| 23 HtmlDialogUIDelegate* delegate, | |
| 24 HtmlDialogTabContentsDelegate* tab_delegate); | |
| 25 | |
| 26 virtual ~ConstrainedHtmlDelegateGtk() {} | |
| 27 | |
| 28 void set_window(ConstrainedWindow* window) { | |
| 29 return impl_->set_window(window); | |
| 30 } | |
| 31 | |
| 32 // ConstrainedHtmlUIDelegate interface | |
| 33 virtual const HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() const OVERRIDE { | |
| 34 return impl_->GetHtmlDialogUIDelegate(); | |
| 35 } | |
| 36 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE { | |
| 37 return impl_->GetHtmlDialogUIDelegate(); | |
| 38 } | |
| 39 virtual void OnDialogCloseFromWebUI() OVERRIDE { | |
| 40 return impl_->OnDialogCloseFromWebUI(); | |
| 41 } | |
| 42 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE { | |
| 43 return impl_->ReleaseTabContentsOnDialogClose(); | |
| 44 } | |
| 45 virtual ConstrainedWindow* window() OVERRIDE { | |
| 46 return impl_->window(); | |
| 47 } | |
| 48 virtual TabContentsWrapper* tab() OVERRIDE { | |
| 49 return impl_->tab(); | |
| 50 } | |
| 51 | |
| 52 // ConstrainedWindowGtkDelegate interface | |
| 53 virtual GtkWidget* GetWidgetRoot() OVERRIDE { | |
| 54 return tab_contents_container_.widget(); | |
| 55 } | |
| 56 virtual GtkWidget* GetFocusWidget() OVERRIDE { | |
| 57 return tab()->web_contents()->GetContentNativeView(); | |
| 58 } | |
| 59 virtual void DeleteDelegate() OVERRIDE { | |
| 60 if (!impl_->closed_via_webui()) | |
| 61 GetHtmlDialogUIDelegate()->OnDialogClosed(""); | |
| 62 delete this; | |
| 63 } | |
| 64 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { | |
| 65 *color = ui::kGdkWhite; | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 scoped_ptr<ConstrainedHtmlUIDelegateImpl> impl_; | |
| 71 | |
| 72 TabContentsContainerGtk tab_contents_container_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlDelegateGtk); | |
| 75 }; | |
| 76 | |
| 77 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( | |
| 78 Profile* profile, | |
| 79 HtmlDialogUIDelegate* delegate, | |
| 80 HtmlDialogTabContentsDelegate* tab_delegate) | |
| 81 : impl_(new ConstrainedHtmlUIDelegateImpl(profile, delegate, tab_delegate)), | |
| 82 tab_contents_container_(NULL) { | |
| 83 tab_contents_container_.SetTab(tab()); | |
| 84 | |
| 85 gfx::Size dialog_size; | |
| 86 delegate->GetDialogSize(&dialog_size); | |
| 87 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_.widget()), | |
| 88 dialog_size.width(), | |
| 89 dialog_size.height()); | |
| 90 | |
| 91 gtk_widget_show_all(GetWidgetRoot()); | |
| 92 } | |
| 93 | |
| 94 // static | |
| 95 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( | |
| 96 Profile* profile, | |
| 97 HtmlDialogUIDelegate* delegate, | |
| 98 HtmlDialogTabContentsDelegate* tab_delegate, | |
| 99 TabContentsWrapper* overshadowed) { | |
| 100 ConstrainedHtmlDelegateGtk* constrained_delegate = | |
| 101 new ConstrainedHtmlDelegateGtk(profile, delegate, tab_delegate); | |
| 102 ConstrainedWindow* constrained_window = | |
| 103 new ConstrainedWindowGtk(overshadowed, constrained_delegate); | |
| 104 constrained_delegate->set_window(constrained_window); | |
| 105 return constrained_delegate; | |
| 106 } | |
| OLD | NEW |