Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / constrained_web_dialog_delegate_gtk.cc
blobc58ed62ffde7ef034414e5b7039b09e48d0a5893
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
7 #include <gdk/gdk.h>
8 #include <gtk/gtk.h>
10 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_view.h"
16 #include "ui/base/gtk/gtk_hig_constants.h"
17 #include "ui/base/gtk/gtk_signal.h"
18 #include "ui/gfx/size.h"
19 #include "ui/web_dialogs/web_dialog_delegate.h"
20 #include "ui/web_dialogs/web_dialog_ui.h"
22 using content::WebContents;
23 using ui::WebDialogDelegate;
24 using ui::WebDialogWebContentsDelegate;
25 using web_modal::WebContentsModalDialogManager;
27 namespace {
29 class ConstrainedWebDialogDelegateGtk
30 : public ConstrainedWebDialogDelegateBase {
31 public:
32 ConstrainedWebDialogDelegateGtk(
33 content::BrowserContext* browser_context,
34 WebDialogDelegate* delegate,
35 WebDialogWebContentsDelegate* tab_delegate)
36 : ConstrainedWebDialogDelegateBase(
37 browser_context, delegate, tab_delegate),
38 window_(NULL) {}
40 // WebDialogWebContentsDelegate interface.
41 virtual void CloseContents(WebContents* source) OVERRIDE {
42 gtk_widget_destroy(window_);
45 void set_window(GtkWidget* window) { window_ = window; }
46 GtkWidget* window() const { return window_; }
48 private:
49 GtkWidget* window_;
51 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk);
54 void SetBackgroundColor(GtkWidget* widget, const GdkColor &color) {
55 gtk_widget_modify_base(widget, GTK_STATE_NORMAL, &color);
56 gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color);
57 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
60 } // namespace
62 class ConstrainedWebDialogDelegateViewGtk
63 : public ConstrainedWebDialogDelegate {
64 public:
65 ConstrainedWebDialogDelegateViewGtk(
66 content::BrowserContext* browser_context,
67 WebDialogDelegate* delegate,
68 WebDialogWebContentsDelegate* tab_delegate);
70 virtual ~ConstrainedWebDialogDelegateViewGtk() {}
72 // ConstrainedWebDialogDelegate interface
73 virtual const WebDialogDelegate*
74 GetWebDialogDelegate() const OVERRIDE {
75 return impl_->GetWebDialogDelegate();
77 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE {
78 return impl_->GetWebDialogDelegate();
80 virtual void OnDialogCloseFromWebUI() OVERRIDE {
81 return impl_->OnDialogCloseFromWebUI();
83 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE {
84 return impl_->ReleaseWebContentsOnDialogClose();
86 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() OVERRIDE {
87 return impl_->window();
89 virtual WebContents* GetWebContents() OVERRIDE {
90 return impl_->GetWebContents();
93 void SetWindow(GtkWidget* window) {
94 impl_->set_window(window);
97 GtkWidget* GetWindow() {
98 return impl_->window();
101 private:
102 CHROMEGTK_CALLBACK_0(ConstrainedWebDialogDelegateViewGtk, void, OnDestroy);
104 scoped_ptr<ConstrainedWebDialogDelegateGtk> impl_;
106 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewGtk);
109 ConstrainedWebDialogDelegateViewGtk::ConstrainedWebDialogDelegateViewGtk(
110 content::BrowserContext* browser_context,
111 WebDialogDelegate* delegate,
112 WebDialogWebContentsDelegate* tab_delegate)
113 : impl_(new ConstrainedWebDialogDelegateGtk(
114 browser_context,
115 delegate,
116 tab_delegate)) {
117 gfx::Size dialog_size;
118 delegate->GetDialogSize(&dialog_size);
119 GtkWidget* contents =
120 GTK_WIDGET(GetWebContents()->GetView()->GetNativeView());
121 gtk_widget_set_size_request(contents,
122 dialog_size.width(),
123 dialog_size.height());
125 gtk_widget_show_all(contents);
127 g_signal_connect(contents, "destroy", G_CALLBACK(OnDestroyThunk), this);
130 void ConstrainedWebDialogDelegateViewGtk::OnDestroy(GtkWidget* widget) {
131 if (!impl_->closed_via_webui())
132 GetWebDialogDelegate()->OnDialogClosed(std::string());
133 delete this;
136 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog(
137 content::BrowserContext* browser_context,
138 WebDialogDelegate* delegate,
139 WebDialogWebContentsDelegate* tab_delegate,
140 content::WebContents* web_contents) {
141 ConstrainedWebDialogDelegateViewGtk* constrained_delegate =
142 new ConstrainedWebDialogDelegateViewGtk(
143 browser_context, delegate, tab_delegate);
144 GtkWidget* window =
145 CreateWebContentsModalDialogGtk(
146 constrained_delegate->GetWebContents()->GetView()->GetNativeView(),
147 constrained_delegate->GetWebContents()->GetView()->
148 GetContentNativeView());
149 SetBackgroundColor(window, ui::kGdkWhite);
150 constrained_delegate->SetWindow(window);
152 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
153 WebContentsModalDialogManager::FromWebContents(web_contents);
154 web_contents_modal_dialog_manager->ShowDialog(window);
156 return constrained_delegate;