OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/gtk/html_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/web_dialog_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/property_bag.h" | 9 #include "base/property_bag.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/browser_dialogs.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/gtk/gtk_util.h" | 15 #include "chrome/browser/ui/gtk/gtk_util.h" |
16 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" | 16 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/browser/ui/webui/html_dialog_controller.h" | 18 #include "chrome/browser/ui/webui/web_dialog_controller.h" |
19 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 19 #include "chrome/browser/ui/webui/web_dialog_ui.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/native_web_keyboard_event.h" | 21 #include "content/public/browser/native_web_keyboard_event.h" |
22 | 22 |
23 using content::WebContents; | 23 using content::WebContents; |
24 using content::WebUIMessageHandler; | 24 using content::WebUIMessageHandler; |
25 | 25 |
26 namespace browser { | 26 namespace browser { |
27 | 27 |
28 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, | 28 gfx::NativeWindow ShowWebDialog(gfx::NativeWindow parent, |
29 Profile* profile, | 29 Profile* profile, |
30 Browser* browser, | 30 Browser* browser, |
31 HtmlDialogUIDelegate* delegate, | 31 WebDialogDelegate* delegate, |
32 DialogStyle style) { | 32 DialogStyle style) { |
33 // Ignore style for now. The style parameter only used in the implementation | 33 // Ignore style for now. The style parameter only used in the implementation |
34 // in html_dialog_view.cc file. | 34 // in web_dialog_view.cc file. |
35 // TODO (bshe): Add style parameter to HtmlDialogGtk. | 35 // TODO (bshe): Add style parameter to WebDialogGtk. |
36 HtmlDialogGtk* html_dialog = | 36 WebDialogGtk* web_dialog = |
37 new HtmlDialogGtk(profile, browser, delegate, parent); | 37 new WebDialogGtk(profile, browser, delegate, parent); |
38 return html_dialog->InitDialog(); | 38 return web_dialog->InitDialog(); |
39 } | 39 } |
40 | 40 |
41 void CloseHtmlDialog(gfx::NativeWindow window) { | 41 void CloseWebDialog(gfx::NativeWindow window) { |
42 gtk_dialog_response(GTK_DIALOG(window), GTK_RESPONSE_CLOSE); | 42 gtk_dialog_response(GTK_DIALOG(window), GTK_RESPONSE_CLOSE); |
43 } | 43 } |
44 | 44 |
45 } // namespace browser | 45 } // namespace browser |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 void SetDialogStyle() { | 49 void SetDialogStyle() { |
50 static bool style_was_set = false; | 50 static bool style_was_set = false; |
51 | 51 |
52 if (style_was_set) | 52 if (style_was_set) |
53 return; | 53 return; |
54 style_was_set = true; | 54 style_was_set = true; |
55 | 55 |
56 gtk_rc_parse_string( | 56 gtk_rc_parse_string( |
57 "style \"chrome-html-dialog\" {\n" | 57 "style \"chrome-html-dialog\" {\n" |
58 " GtkDialog::action-area-border = 0\n" | 58 " GtkDialog::action-area-border = 0\n" |
59 " GtkDialog::content-area-border = 0\n" | 59 " GtkDialog::content-area-border = 0\n" |
60 " GtkDialog::content-area-spacing = 0\n" | 60 " GtkDialog::content-area-spacing = 0\n" |
61 "}\n" | 61 "}\n" |
62 "widget \"*chrome-html-dialog\" style \"chrome-html-dialog\""); | 62 "widget \"*chrome-html-dialog\" style \"chrome-html-dialog\""); |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
68 // HtmlDialogGtk, public: | 68 // WebDialogGtk, public: |
69 | 69 |
70 HtmlDialogGtk::HtmlDialogGtk(Profile* profile, | 70 WebDialogGtk::WebDialogGtk(Profile* profile, |
71 Browser* browser, | 71 Browser* browser, |
72 HtmlDialogUIDelegate* delegate, | 72 WebDialogDelegate* delegate, |
73 gfx::NativeWindow parent_window) | 73 gfx::NativeWindow parent_window) |
74 : HtmlDialogTabContentsDelegate(profile), | 74 : WebDialogWebContentsDelegate(profile), |
75 delegate_(delegate), | 75 delegate_(delegate), |
76 parent_window_(parent_window), | 76 parent_window_(parent_window), |
77 dialog_(NULL), | 77 dialog_(NULL), |
78 dialog_controller_(new HtmlDialogController(this, profile, browser)) { | 78 dialog_controller_(new WebDialogController(this, profile, browser)) { |
79 } | 79 } |
80 | 80 |
81 HtmlDialogGtk::~HtmlDialogGtk() { | 81 WebDialogGtk::~WebDialogGtk() { |
82 } | 82 } |
83 | 83 |
84 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
85 // HtmlDialogUIDelegate implementation: | 85 // WebDialogDelegate implementation: |
86 | 86 |
87 ui::ModalType HtmlDialogGtk::GetDialogModalType() const { | 87 ui::ModalType WebDialogGtk::GetDialogModalType() const { |
88 return delegate_ ? delegate_->GetDialogModalType() : ui::MODAL_TYPE_NONE; | 88 return delegate_ ? delegate_->GetDialogModalType() : ui::MODAL_TYPE_NONE; |
89 } | 89 } |
90 | 90 |
91 string16 HtmlDialogGtk::GetDialogTitle() const { | 91 string16 WebDialogGtk::GetDialogTitle() const { |
92 return delegate_ ? delegate_->GetDialogTitle() : string16(); | 92 return delegate_ ? delegate_->GetDialogTitle() : string16(); |
93 } | 93 } |
94 | 94 |
95 GURL HtmlDialogGtk::GetDialogContentURL() const { | 95 GURL WebDialogGtk::GetDialogContentURL() const { |
96 if (delegate_) | 96 if (delegate_) |
97 return delegate_->GetDialogContentURL(); | 97 return delegate_->GetDialogContentURL(); |
98 else | 98 else |
99 return GURL(); | 99 return GURL(); |
100 } | 100 } |
101 | 101 |
102 void HtmlDialogGtk::GetWebUIMessageHandlers( | 102 void WebDialogGtk::GetWebUIMessageHandlers( |
103 std::vector<WebUIMessageHandler*>* handlers) const { | 103 std::vector<WebUIMessageHandler*>* handlers) const { |
104 if (delegate_) | 104 if (delegate_) |
105 delegate_->GetWebUIMessageHandlers(handlers); | 105 delegate_->GetWebUIMessageHandlers(handlers); |
106 else | 106 else |
107 handlers->clear(); | 107 handlers->clear(); |
108 } | 108 } |
109 | 109 |
110 void HtmlDialogGtk::GetDialogSize(gfx::Size* size) const { | 110 void WebDialogGtk::GetDialogSize(gfx::Size* size) const { |
111 if (delegate_) | 111 if (delegate_) |
112 delegate_->GetDialogSize(size); | 112 delegate_->GetDialogSize(size); |
113 else | 113 else |
114 *size = gfx::Size(); | 114 *size = gfx::Size(); |
115 } | 115 } |
116 | 116 |
117 void HtmlDialogGtk::GetMinimumDialogSize(gfx::Size* size) const { | 117 void WebDialogGtk::GetMinimumDialogSize(gfx::Size* size) const { |
118 if (delegate_) | 118 if (delegate_) |
119 delegate_->GetMinimumDialogSize(size); | 119 delegate_->GetMinimumDialogSize(size); |
120 else | 120 else |
121 *size = gfx::Size(); | 121 *size = gfx::Size(); |
122 } | 122 } |
123 | 123 |
124 std::string HtmlDialogGtk::GetDialogArgs() const { | 124 std::string WebDialogGtk::GetDialogArgs() const { |
125 if (delegate_) | 125 if (delegate_) |
126 return delegate_->GetDialogArgs(); | 126 return delegate_->GetDialogArgs(); |
127 else | 127 else |
128 return std::string(); | 128 return std::string(); |
129 } | 129 } |
130 | 130 |
131 void HtmlDialogGtk::OnDialogClosed(const std::string& json_retval) { | 131 void WebDialogGtk::OnDialogClosed(const std::string& json_retval) { |
132 DCHECK(dialog_); | 132 DCHECK(dialog_); |
133 | 133 |
134 Detach(); | 134 Detach(); |
135 if (delegate_) { | 135 if (delegate_) { |
136 HtmlDialogUIDelegate* dialog_delegate = delegate_; | 136 WebDialogDelegate* dialog_delegate = delegate_; |
137 delegate_ = NULL; // We will not communicate further with the delegate. | 137 delegate_ = NULL; // We will not communicate further with the delegate. |
138 | 138 |
139 // Store the dialog bounds. | 139 // Store the dialog bounds. |
140 gfx::Rect dialog_bounds = gtk_util::GetDialogBounds(GTK_WIDGET(dialog_)); | 140 gfx::Rect dialog_bounds = gtk_util::GetDialogBounds(GTK_WIDGET(dialog_)); |
141 dialog_delegate->StoreDialogSize(dialog_bounds.size()); | 141 dialog_delegate->StoreDialogSize(dialog_bounds.size()); |
142 | 142 |
143 dialog_delegate->OnDialogClosed(json_retval); | 143 dialog_delegate->OnDialogClosed(json_retval); |
144 } | 144 } |
145 | 145 |
146 gtk_widget_destroy(dialog_); | 146 gtk_widget_destroy(dialog_); |
147 delete this; | 147 delete this; |
148 } | 148 } |
149 | 149 |
150 void HtmlDialogGtk::OnCloseContents(WebContents* source, | 150 void WebDialogGtk::OnCloseContents(WebContents* source, |
151 bool* out_close_dialog) { | 151 bool* out_close_dialog) { |
152 if (delegate_) | 152 if (delegate_) |
153 delegate_->OnCloseContents(source, out_close_dialog); | 153 delegate_->OnCloseContents(source, out_close_dialog); |
154 } | 154 } |
155 | 155 |
156 void HtmlDialogGtk::CloseContents(WebContents* source) { | 156 void WebDialogGtk::CloseContents(WebContents* source) { |
157 DCHECK(dialog_); | 157 DCHECK(dialog_); |
158 | 158 |
159 bool close_dialog = false; | 159 bool close_dialog = false; |
160 OnCloseContents(source, &close_dialog); | 160 OnCloseContents(source, &close_dialog); |
161 if (close_dialog) | 161 if (close_dialog) |
162 OnDialogClosed(std::string()); | 162 OnDialogClosed(std::string()); |
163 } | 163 } |
164 | 164 |
165 content::WebContents* HtmlDialogGtk::OpenURLFromTab( | 165 content::WebContents* WebDialogGtk::OpenURLFromTab( |
166 content::WebContents* source, | 166 content::WebContents* source, |
167 const content::OpenURLParams& params) { | 167 const content::OpenURLParams& params) { |
168 content::WebContents* new_contents = NULL; | 168 content::WebContents* new_contents = NULL; |
169 if (delegate_ && | 169 if (delegate_ && |
170 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { | 170 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { |
171 return new_contents; | 171 return new_contents; |
172 } | 172 } |
173 return HtmlDialogTabContentsDelegate::OpenURLFromTab(source, params); | 173 return WebDialogWebContentsDelegate::OpenURLFromTab(source, params); |
174 } | 174 } |
175 | 175 |
176 void HtmlDialogGtk::AddNewContents(content::WebContents* source, | 176 void WebDialogGtk::AddNewContents(content::WebContents* source, |
177 content::WebContents* new_contents, | 177 content::WebContents* new_contents, |
178 WindowOpenDisposition disposition, | 178 WindowOpenDisposition disposition, |
179 const gfx::Rect& initial_pos, | 179 const gfx::Rect& initial_pos, |
180 bool user_gesture) { | 180 bool user_gesture) { |
181 if (delegate_ && delegate_->HandleAddNewContents( | 181 if (delegate_ && delegate_->HandleAddNewContents( |
182 source, new_contents, disposition, initial_pos, user_gesture)) { | 182 source, new_contents, disposition, initial_pos, user_gesture)) { |
183 return; | 183 return; |
184 } | 184 } |
185 HtmlDialogTabContentsDelegate::AddNewContents( | 185 WebDialogWebContentsDelegate::AddNewContents( |
186 source, new_contents, disposition, initial_pos, user_gesture); | 186 source, new_contents, disposition, initial_pos, user_gesture); |
187 } | 187 } |
188 | 188 |
189 void HtmlDialogGtk::LoadingStateChanged(content::WebContents* source) { | 189 void WebDialogGtk::LoadingStateChanged(content::WebContents* source) { |
190 if (delegate_) | 190 if (delegate_) |
191 delegate_->OnLoadingStateChanged(source); | 191 delegate_->OnLoadingStateChanged(source); |
192 } | 192 } |
193 | 193 |
194 bool HtmlDialogGtk::ShouldShowDialogTitle() const { | 194 bool WebDialogGtk::ShouldShowDialogTitle() const { |
195 return true; | 195 return true; |
196 } | 196 } |
197 | 197 |
198 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
199 // content::WebContentsDelegate implementation: | 199 // content::WebContentsDelegate implementation: |
200 | 200 |
201 // A simplified version of BrowserWindowGtk::HandleKeyboardEvent(). | 201 // A simplified version of BrowserWindowGtk::HandleKeyboardEvent(). |
202 // We don't handle global keyboard shortcuts here, but that's fine since | 202 // We don't handle global keyboard shortcuts here, but that's fine since |
203 // they're all browser-specific. (This may change in the future.) | 203 // they're all browser-specific. (This may change in the future.) |
204 void HtmlDialogGtk::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 204 void WebDialogGtk::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
205 GdkEventKey* os_event = &event.os_event->key; | 205 GdkEventKey* os_event = &event.os_event->key; |
206 if (!os_event || event.type == WebKit::WebInputEvent::Char) | 206 if (!os_event || event.type == WebKit::WebInputEvent::Char) |
207 return; | 207 return; |
208 | 208 |
209 // To make sure the default key bindings can still work, such as Escape to | 209 // To make sure the default key bindings can still work, such as Escape to |
210 // close the dialog. | 210 // close the dialog. |
211 gtk_bindings_activate_event(GTK_OBJECT(dialog_), os_event); | 211 gtk_bindings_activate_event(GTK_OBJECT(dialog_), os_event); |
212 } | 212 } |
213 | 213 |
214 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
215 // HtmlDialogGtk: | 215 // WebDialogGtk: |
216 | 216 |
217 gfx::NativeWindow HtmlDialogGtk::InitDialog() { | 217 gfx::NativeWindow WebDialogGtk::InitDialog() { |
218 tab_.reset(new TabContentsWrapper( | 218 tab_.reset(new TabContentsWrapper( |
219 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); | 219 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); |
220 tab_->web_contents()->SetDelegate(this); | 220 tab_->web_contents()->SetDelegate(this); |
221 | 221 |
222 // This must be done before loading the page; see the comments in | 222 // This must be done before loading the page; see the comments in |
223 // HtmlDialogUI. | 223 // WebDialogUI. |
224 HtmlDialogUI::GetPropertyAccessor().SetProperty( | 224 WebDialogUI::GetPropertyAccessor().SetProperty( |
225 tab_->web_contents()->GetPropertyBag(), this); | 225 tab_->web_contents()->GetPropertyBag(), this); |
226 | 226 |
227 tab_->web_contents()->GetController().LoadURL( | 227 tab_->web_contents()->GetController().LoadURL( |
228 GetDialogContentURL(), | 228 GetDialogContentURL(), |
229 content::Referrer(), | 229 content::Referrer(), |
230 content::PAGE_TRANSITION_START_PAGE, | 230 content::PAGE_TRANSITION_START_PAGE, |
231 std::string()); | 231 std::string()); |
232 GtkDialogFlags flags = GTK_DIALOG_NO_SEPARATOR; | 232 GtkDialogFlags flags = GTK_DIALOG_NO_SEPARATOR; |
233 if (delegate_->GetDialogModalType() != ui::MODAL_TYPE_NONE) | 233 if (delegate_->GetDialogModalType() != ui::MODAL_TYPE_NONE) |
234 flags = static_cast<GtkDialogFlags>(flags | GTK_DIALOG_MODAL); | 234 flags = static_cast<GtkDialogFlags>(flags | GTK_DIALOG_MODAL); |
(...skipping 28 matching lines...) Expand all Loading... |
263 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_->widget()), | 263 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_->widget()), |
264 minimum_dialog_size.width(), | 264 minimum_dialog_size.width(), |
265 minimum_dialog_size.height()); | 265 minimum_dialog_size.height()); |
266 } | 266 } |
267 | 267 |
268 gtk_widget_show_all(dialog_); | 268 gtk_widget_show_all(dialog_); |
269 | 269 |
270 return GTK_WINDOW(dialog_); | 270 return GTK_WINDOW(dialog_); |
271 } | 271 } |
272 | 272 |
273 void HtmlDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { | 273 void WebDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { |
274 OnDialogClosed(std::string()); | 274 OnDialogClosed(std::string()); |
275 } | 275 } |
OLD | NEW |