| 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 "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 8 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 9 #include "content/public/browser/notification_source.h" | 9 #include "content/public/browser/notification_source.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void set_window(GtkWidget* window) { window_ = window; } | 39 void set_window(GtkWidget* window) { window_ = window; } |
| 40 GtkWidget* window() const { return window_; } | 40 GtkWidget* window() const { return window_; } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 GtkWidget* window_; | 43 GtkWidget* window_; |
| 44 | 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk); | 45 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 void SetBackgroundColor(GtkWidget* widget, const GdkColor &color) { |
| 49 gtk_widget_modify_base(widget, GTK_STATE_NORMAL, &color); |
| 50 gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color); |
| 51 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color); |
| 52 } |
| 53 |
| 48 } // namespace | 54 } // namespace |
| 49 | 55 |
| 50 class ConstrainedWebDialogDelegateViewGtk | 56 class ConstrainedWebDialogDelegateViewGtk |
| 51 : public ConstrainedWindowGtkDelegate, | 57 : public ConstrainedWebDialogDelegate { |
| 52 public ConstrainedWebDialogDelegate { | |
| 53 public: | 58 public: |
| 54 ConstrainedWebDialogDelegateViewGtk( | 59 ConstrainedWebDialogDelegateViewGtk( |
| 55 content::BrowserContext* browser_context, | 60 content::BrowserContext* browser_context, |
| 56 WebDialogDelegate* delegate, | 61 WebDialogDelegate* delegate, |
| 57 WebDialogWebContentsDelegate* tab_delegate); | 62 WebDialogWebContentsDelegate* tab_delegate); |
| 58 | 63 |
| 59 virtual ~ConstrainedWebDialogDelegateViewGtk() {} | 64 virtual ~ConstrainedWebDialogDelegateViewGtk() {} |
| 60 | 65 |
| 61 // ConstrainedWebDialogDelegate interface | 66 // ConstrainedWebDialogDelegate interface |
| 62 virtual const WebDialogDelegate* | 67 virtual const WebDialogDelegate* |
| 63 GetWebDialogDelegate() const OVERRIDE { | 68 GetWebDialogDelegate() const OVERRIDE { |
| 64 return impl_->GetWebDialogDelegate(); | 69 return impl_->GetWebDialogDelegate(); |
| 65 } | 70 } |
| 66 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { | 71 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { |
| 67 return impl_->GetWebDialogDelegate(); | 72 return impl_->GetWebDialogDelegate(); |
| 68 } | 73 } |
| 69 virtual void OnDialogCloseFromWebUI() OVERRIDE { | 74 virtual void OnDialogCloseFromWebUI() OVERRIDE { |
| 70 return impl_->OnDialogCloseFromWebUI(); | 75 return impl_->OnDialogCloseFromWebUI(); |
| 71 } | 76 } |
| 72 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { | 77 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { |
| 73 return impl_->ReleaseWebContentsOnDialogClose(); | 78 return impl_->ReleaseWebContentsOnDialogClose(); |
| 74 } | 79 } |
| 75 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { | 80 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { |
| 76 return impl_->window(); | 81 return impl_->window(); |
| 77 } | 82 } |
| 78 virtual WebContents* GetWebContents() OVERRIDE { | 83 virtual WebContents* GetWebContents() OVERRIDE { |
| 79 return impl_->GetWebContents(); | 84 return impl_->GetWebContents(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 // ConstrainedWindowGtkDelegate interface | |
| 83 virtual GtkWidget* GetWidgetRoot() OVERRIDE { | |
| 84 return GetWebContents()->GetView()->GetNativeView(); | |
| 85 } | |
| 86 virtual GtkWidget* GetFocusWidget() OVERRIDE { | |
| 87 return GetWebContents()->GetView()->GetContentNativeView(); | |
| 88 } | |
| 89 virtual void DeleteDelegate() OVERRIDE { | |
| 90 if (!impl_->closed_via_webui()) | |
| 91 GetWebDialogDelegate()->OnDialogClosed(""); | |
| 92 delete this; | |
| 93 } | |
| 94 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { | |
| 95 *color = ui::kGdkWhite; | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 void SetWindow(GtkWidget* window) { | 87 void SetWindow(GtkWidget* window) { |
| 100 impl_->set_window(window); | 88 impl_->set_window(window); |
| 101 } | 89 } |
| 102 | 90 |
| 103 GtkWidget* GetWindow() { | 91 GtkWidget* GetWindow() { |
| 104 return impl_->window(); | 92 return impl_->window(); |
| 105 } | 93 } |
| 106 | 94 |
| 107 private: | 95 private: |
| 96 CHROMEGTK_CALLBACK_0(ConstrainedWebDialogDelegateViewGtk, void, OnDestroy); |
| 97 |
| 108 scoped_ptr<ConstrainedWebDialogDelegateGtk> impl_; | 98 scoped_ptr<ConstrainedWebDialogDelegateGtk> impl_; |
| 109 | 99 |
| 110 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewGtk); | 100 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewGtk); |
| 111 }; | 101 }; |
| 112 | 102 |
| 113 ConstrainedWebDialogDelegateViewGtk::ConstrainedWebDialogDelegateViewGtk( | 103 ConstrainedWebDialogDelegateViewGtk::ConstrainedWebDialogDelegateViewGtk( |
| 114 content::BrowserContext* browser_context, | 104 content::BrowserContext* browser_context, |
| 115 WebDialogDelegate* delegate, | 105 WebDialogDelegate* delegate, |
| 116 WebDialogWebContentsDelegate* tab_delegate) | 106 WebDialogWebContentsDelegate* tab_delegate) |
| 117 : impl_(new ConstrainedWebDialogDelegateGtk( | 107 : impl_(new ConstrainedWebDialogDelegateGtk( |
| 118 browser_context, | 108 browser_context, |
| 119 delegate, | 109 delegate, |
| 120 tab_delegate)) { | 110 tab_delegate)) { |
| 121 gfx::Size dialog_size; | 111 gfx::Size dialog_size; |
| 122 delegate->GetDialogSize(&dialog_size); | 112 delegate->GetDialogSize(&dialog_size); |
| 123 gtk_widget_set_size_request(GTK_WIDGET(GetWidgetRoot()), | 113 GtkWidget* contents = |
| 114 GTK_WIDGET(GetWebContents()->GetView()->GetNativeView()); |
| 115 gtk_widget_set_size_request(contents, |
| 124 dialog_size.width(), | 116 dialog_size.width(), |
| 125 dialog_size.height()); | 117 dialog_size.height()); |
| 126 | 118 |
| 127 gtk_widget_show_all(GetWidgetRoot()); | 119 gtk_widget_show_all(contents); |
| 120 |
| 121 g_signal_connect(contents, "destroy", G_CALLBACK(OnDestroyThunk), this); |
| 122 } |
| 123 |
| 124 void ConstrainedWebDialogDelegateViewGtk::OnDestroy(GtkWidget* widget) { |
| 125 if (!impl_->closed_via_webui()) |
| 126 GetWebDialogDelegate()->OnDialogClosed(""); |
| 127 delete this; |
| 128 } | 128 } |
| 129 | 129 |
| 130 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 130 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| 131 content::BrowserContext* browser_context, | 131 content::BrowserContext* browser_context, |
| 132 WebDialogDelegate* delegate, | 132 WebDialogDelegate* delegate, |
| 133 WebDialogWebContentsDelegate* tab_delegate, | 133 WebDialogWebContentsDelegate* tab_delegate, |
| 134 content::WebContents* web_contents) { | 134 content::WebContents* web_contents) { |
| 135 ConstrainedWebDialogDelegateViewGtk* constrained_delegate = | 135 ConstrainedWebDialogDelegateViewGtk* constrained_delegate = |
| 136 new ConstrainedWebDialogDelegateViewGtk( | 136 new ConstrainedWebDialogDelegateViewGtk( |
| 137 browser_context, delegate, tab_delegate); | 137 browser_context, delegate, tab_delegate); |
| 138 GtkWidget* window = | 138 GtkWidget* window = |
| 139 CreateWebContentsModalDialogGtk(web_contents, constrained_delegate); | 139 CreateWebContentsModalDialogGtk( |
| 140 web_contents, |
| 141 constrained_delegate->GetWebContents()->GetView()->GetNativeView(), |
| 142 constrained_delegate->GetWebContents()->GetView()-> |
| 143 GetContentNativeView()); |
| 144 SetBackgroundColor(window, ui::kGdkWhite); |
| 140 constrained_delegate->SetWindow(window); | 145 constrained_delegate->SetWindow(window); |
| 141 | 146 |
| 142 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 147 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 143 WebContentsModalDialogManager::FromWebContents(web_contents); | 148 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 144 web_contents_modal_dialog_manager->ShowDialog(window); | 149 web_contents_modal_dialog_manager->ShowDialog(window); |
| 145 | 150 |
| 146 return constrained_delegate; | 151 return constrained_delegate; |
| 147 } | 152 } |
| OLD | NEW |