| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" | 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | 7 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" |
| 8 #include "content/public/browser/notification_source.h" | 8 #include "content/public/browser/notification_source.h" |
| 9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/browser/web_contents_view.h" | 11 #include "content/public/browser/web_contents_view.h" |
| 12 #include "ui/base/gtk/gtk_hig_constants.h" | 12 #include "ui/base/gtk/gtk_hig_constants.h" |
| 13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 14 #include "ui/web_dialogs/web_dialog_delegate.h" | 14 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 15 #include "ui/web_dialogs/web_dialog_ui.h" | 15 #include "ui/web_dialogs/web_dialog_ui.h" |
| 16 | 16 |
| 17 using content::WebContents; | 17 using content::WebContents; |
| 18 using ui::WebDialogDelegate; | 18 using ui::WebDialogDelegate; |
| 19 using ui::WebDialogWebContentsDelegate; | 19 using ui::WebDialogWebContentsDelegate; |
| 20 | 20 |
| 21 class ConstrainedWebDialogDelegateGtk : public ConstrainedWindowGtkDelegate, | 21 namespace { |
| 22 public ConstrainedWebDialogDelegate { | 22 |
| 23 class ConstrainedWebDialogDelegateGtk |
| 24 : public ConstrainedWebDialogDelegateBase { |
| 23 public: | 25 public: |
| 24 ConstrainedWebDialogDelegateGtk( | 26 ConstrainedWebDialogDelegateGtk( |
| 25 content::BrowserContext* browser_context, | 27 content::BrowserContext* browser_context, |
| 26 WebDialogDelegate* delegate, | 28 WebDialogDelegate* delegate, |
| 29 WebDialogWebContentsDelegate* tab_delegate) |
| 30 : ConstrainedWebDialogDelegateBase( |
| 31 browser_context, delegate, tab_delegate) {} |
| 32 |
| 33 // WebDialogWebContentsDelegate interface. |
| 34 virtual void CloseContents(WebContents* source) OVERRIDE { |
| 35 window_->CloseWebContentsModalDialog(); |
| 36 } |
| 37 |
| 38 void set_window(ConstrainedWindowGtk* window) { window_ = window; } |
| 39 ConstrainedWindowGtk* window() const { return window_; } |
| 40 |
| 41 private: |
| 42 ConstrainedWindowGtk* window_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk); |
| 45 }; |
| 46 |
| 47 } // namespace |
| 48 |
| 49 class ConstrainedWebDialogDelegateViewGtk |
| 50 : public ConstrainedWindowGtkDelegate, |
| 51 public ConstrainedWebDialogDelegate { |
| 52 public: |
| 53 ConstrainedWebDialogDelegateViewGtk( |
| 54 content::BrowserContext* browser_context, |
| 55 WebDialogDelegate* delegate, |
| 27 WebDialogWebContentsDelegate* tab_delegate); | 56 WebDialogWebContentsDelegate* tab_delegate); |
| 28 | 57 |
| 29 virtual ~ConstrainedWebDialogDelegateGtk() {} | 58 virtual ~ConstrainedWebDialogDelegateViewGtk() {} |
| 30 | |
| 31 void set_window(WebContentsModalDialog* dialog) { | |
| 32 return impl_->set_window(dialog); | |
| 33 } | |
| 34 | 59 |
| 35 // ConstrainedWebDialogDelegate interface | 60 // ConstrainedWebDialogDelegate interface |
| 36 virtual const WebDialogDelegate* | 61 virtual const WebDialogDelegate* |
| 37 GetWebDialogDelegate() const OVERRIDE { | 62 GetWebDialogDelegate() const OVERRIDE { |
| 38 return impl_->GetWebDialogDelegate(); | 63 return impl_->GetWebDialogDelegate(); |
| 39 } | 64 } |
| 40 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { | 65 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { |
| 41 return impl_->GetWebDialogDelegate(); | 66 return impl_->GetWebDialogDelegate(); |
| 42 } | 67 } |
| 43 virtual void OnDialogCloseFromWebUI() OVERRIDE { | 68 virtual void OnDialogCloseFromWebUI() OVERRIDE { |
| 44 return impl_->OnDialogCloseFromWebUI(); | 69 return impl_->OnDialogCloseFromWebUI(); |
| 45 } | 70 } |
| 46 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { | 71 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { |
| 47 return impl_->ReleaseWebContentsOnDialogClose(); | 72 return impl_->ReleaseWebContentsOnDialogClose(); |
| 48 } | 73 } |
| 49 virtual WebContentsModalDialog* GetWindow() OVERRIDE { | 74 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { |
| 50 return impl_->GetWindow(); | 75 return impl_->window()->GetNativeDialog(); |
| 51 } | 76 } |
| 52 virtual WebContents* GetWebContents() OVERRIDE { | 77 virtual WebContents* GetWebContents() OVERRIDE { |
| 53 return impl_->GetWebContents(); | 78 return impl_->GetWebContents(); |
| 54 } | 79 } |
| 55 | 80 |
| 56 // ConstrainedWindowGtkDelegate interface | 81 // ConstrainedWindowGtkDelegate interface |
| 57 virtual GtkWidget* GetWidgetRoot() OVERRIDE { | 82 virtual GtkWidget* GetWidgetRoot() OVERRIDE { |
| 58 return GetWebContents()->GetView()->GetNativeView(); | 83 return GetWebContents()->GetView()->GetNativeView(); |
| 59 } | 84 } |
| 60 virtual GtkWidget* GetFocusWidget() OVERRIDE { | 85 virtual GtkWidget* GetFocusWidget() OVERRIDE { |
| 61 return GetWebContents()->GetContentNativeView(); | 86 return GetWebContents()->GetContentNativeView(); |
| 62 } | 87 } |
| 63 virtual void DeleteDelegate() OVERRIDE { | 88 virtual void DeleteDelegate() OVERRIDE { |
| 64 if (!impl_->closed_via_webui()) | 89 if (!impl_->closed_via_webui()) |
| 65 GetWebDialogDelegate()->OnDialogClosed(""); | 90 GetWebDialogDelegate()->OnDialogClosed(""); |
| 66 delete this; | 91 delete this; |
| 67 } | 92 } |
| 68 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { | 93 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { |
| 69 *color = ui::kGdkWhite; | 94 *color = ui::kGdkWhite; |
| 70 return true; | 95 return true; |
| 71 } | 96 } |
| 72 | 97 |
| 98 void SetWindow(ConstrainedWindowGtk* window) { |
| 99 impl_->set_window(window); |
| 100 } |
| 101 |
| 102 ConstrainedWindowGtk* GetWindow() { |
| 103 return impl_->window(); |
| 104 } |
| 105 |
| 73 private: | 106 private: |
| 74 scoped_ptr<ConstrainedWebDialogDelegateBase> impl_; | 107 scoped_ptr<ConstrainedWebDialogDelegateGtk> impl_; |
| 75 | 108 |
| 76 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk); | 109 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewGtk); |
| 77 }; | 110 }; |
| 78 | 111 |
| 79 ConstrainedWebDialogDelegateGtk::ConstrainedWebDialogDelegateGtk( | 112 ConstrainedWebDialogDelegateViewGtk::ConstrainedWebDialogDelegateViewGtk( |
| 80 content::BrowserContext* browser_context, | 113 content::BrowserContext* browser_context, |
| 81 WebDialogDelegate* delegate, | 114 WebDialogDelegate* delegate, |
| 82 WebDialogWebContentsDelegate* tab_delegate) | 115 WebDialogWebContentsDelegate* tab_delegate) |
| 83 : impl_(new ConstrainedWebDialogDelegateBase( | 116 : impl_(new ConstrainedWebDialogDelegateGtk( |
| 84 browser_context, delegate, tab_delegate)) { | 117 browser_context, |
| 118 delegate, |
| 119 tab_delegate)) { |
| 85 gfx::Size dialog_size; | 120 gfx::Size dialog_size; |
| 86 delegate->GetDialogSize(&dialog_size); | 121 delegate->GetDialogSize(&dialog_size); |
| 87 gtk_widget_set_size_request(GTK_WIDGET(GetWidgetRoot()), | 122 gtk_widget_set_size_request(GTK_WIDGET(GetWidgetRoot()), |
| 88 dialog_size.width(), | 123 dialog_size.width(), |
| 89 dialog_size.height()); | 124 dialog_size.height()); |
| 90 | 125 |
| 91 gtk_widget_show_all(GetWidgetRoot()); | 126 gtk_widget_show_all(GetWidgetRoot()); |
| 92 } | 127 } |
| 93 | 128 |
| 94 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 129 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| 95 content::BrowserContext* browser_context, | 130 content::BrowserContext* browser_context, |
| 96 WebDialogDelegate* delegate, | 131 WebDialogDelegate* delegate, |
| 97 WebDialogWebContentsDelegate* tab_delegate, | 132 WebDialogWebContentsDelegate* tab_delegate, |
| 98 content::WebContents* web_contents) { | 133 content::WebContents* web_contents) { |
| 99 ConstrainedWebDialogDelegateGtk* constrained_delegate = | 134 ConstrainedWebDialogDelegateViewGtk* constrained_delegate = |
| 100 new ConstrainedWebDialogDelegateGtk( | 135 new ConstrainedWebDialogDelegateViewGtk( |
| 101 browser_context, delegate, tab_delegate); | 136 browser_context, delegate, tab_delegate); |
| 102 WebContentsModalDialog* web_contents_modal_dialog = | 137 ConstrainedWindowGtk* window = |
| 103 new ConstrainedWindowGtk(web_contents, constrained_delegate); | 138 new ConstrainedWindowGtk(web_contents, constrained_delegate); |
| 104 constrained_delegate->set_window(web_contents_modal_dialog); | 139 constrained_delegate->SetWindow(window); |
| 105 return constrained_delegate; | 140 return constrained_delegate; |
| 106 } | 141 } |
| OLD | NEW |