Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/ui/gtk/constrained_web_dialog_delegate_gtk.cc

Issue 231733005: Delete the GTK+ port of Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remerge to ToT Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
6
7 #include <gdk/gdk.h>
8 #include <gtk/gtk.h>
9
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"
21
22 using content::WebContents;
23 using ui::WebDialogDelegate;
24 using ui::WebDialogWebContentsDelegate;
25 using web_modal::WebContentsModalDialogManager;
26
27 namespace {
28
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) {}
39
40 // WebDialogWebContentsDelegate interface.
41 virtual void CloseContents(WebContents* source) OVERRIDE {
42 gtk_widget_destroy(window_);
43 }
44
45 void set_window(GtkWidget* window) { window_ = window; }
46 GtkWidget* window() const { return window_; }
47
48 private:
49 GtkWidget* window_;
50
51 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateGtk);
52 };
53
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);
58 }
59
60 } // namespace
61
62 class ConstrainedWebDialogDelegateViewGtk
63 : public ConstrainedWebDialogDelegate {
64 public:
65 ConstrainedWebDialogDelegateViewGtk(
66 content::BrowserContext* browser_context,
67 WebDialogDelegate* delegate,
68 WebDialogWebContentsDelegate* tab_delegate);
69
70 virtual ~ConstrainedWebDialogDelegateViewGtk() {}
71
72 // ConstrainedWebDialogDelegate interface
73 virtual const WebDialogDelegate*
74 GetWebDialogDelegate() const OVERRIDE {
75 return impl_->GetWebDialogDelegate();
76 }
77 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE {
78 return impl_->GetWebDialogDelegate();
79 }
80 virtual void OnDialogCloseFromWebUI() OVERRIDE {
81 return impl_->OnDialogCloseFromWebUI();
82 }
83 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE {
84 return impl_->ReleaseWebContentsOnDialogClose();
85 }
86 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() OVERRIDE {
87 return impl_->window();
88 }
89 virtual WebContents* GetWebContents() OVERRIDE {
90 return impl_->GetWebContents();
91 }
92
93 void SetWindow(GtkWidget* window) {
94 impl_->set_window(window);
95 }
96
97 GtkWidget* GetWindow() {
98 return impl_->window();
99 }
100
101 private:
102 CHROMEGTK_CALLBACK_0(ConstrainedWebDialogDelegateViewGtk, void, OnDestroy);
103
104 scoped_ptr<ConstrainedWebDialogDelegateGtk> impl_;
105
106 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewGtk);
107 };
108
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());
124
125 gtk_widget_show_all(contents);
126
127 g_signal_connect(contents, "destroy", G_CALLBACK(OnDestroyThunk), this);
128 }
129
130 void ConstrainedWebDialogDelegateViewGtk::OnDestroy(GtkWidget* widget) {
131 if (!impl_->closed_via_webui())
132 GetWebDialogDelegate()->OnDialogClosed(std::string());
133 delete this;
134 }
135
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);
151
152 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
153 WebContentsModalDialogManager::FromWebContents(web_contents);
154 web_contents_modal_dialog_manager->ShowDialog(window);
155
156 return constrained_delegate;
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698