OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/views/html_dialog_view.h" | 5 #include "chrome/browser/ui/views/html_dialog_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/ui/browser_dialogs.h" | 9 #include "chrome/browser/ui/browser_dialogs.h" |
10 #include "chrome/browser/ui/views/window.h" | 10 #include "chrome/browser/ui/views/window.h" |
11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
12 #include "content/common/native_web_keyboard_event.h" | 12 #include "content/common/native_web_keyboard_event.h" |
13 #include "content/common/notification_details.h" | |
14 #include "content/common/notification_source.h" | |
15 #include "content/common/notification_type.h" | |
13 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
14 #include "views/events/event.h" | 17 #include "views/events/event.h" |
15 #include "views/widget/root_view.h" | 18 #include "views/widget/root_view.h" |
16 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
17 #include "views/window/window.h" | 20 #include "views/window/window.h" |
18 | 21 |
19 #if defined(TOOLKIT_USES_GTK) | 22 #if defined(TOOLKIT_USES_GTK) |
20 #include "views/window/native_window_gtk.h" | 23 #include "views/window/native_window_gtk.h" |
21 #endif | 24 #endif |
22 | 25 |
26 class RenderWidgetHost; | |
27 | |
23 namespace browser { | 28 namespace browser { |
24 | 29 |
25 // Declared in browser_dialogs.h so that others don't need to depend on our .h. | 30 // Declared in browser_dialogs.h so that others don't need to depend on our .h. |
26 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, Profile* profile, | 31 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, Profile* profile, |
27 HtmlDialogUIDelegate* delegate) { | 32 HtmlDialogUIDelegate* delegate) { |
28 HtmlDialogView* html_view = | 33 HtmlDialogView* html_view = |
29 new HtmlDialogView(profile, delegate); | 34 new HtmlDialogView(profile, delegate); |
30 browser::CreateViewsWindow(parent, gfx::Rect(), html_view); | 35 browser::CreateViewsWindow(parent, gfx::Rect(), html_view); |
31 html_view->InitDialog(); | 36 html_view->InitDialog(); |
32 html_view->window()->Show(); | 37 html_view->window()->Show(); |
33 return html_view->window()->GetNativeWindow(); | 38 return html_view->window()->GetNativeWindow(); |
34 } | 39 } |
35 | 40 |
36 } // namespace browser | 41 } // namespace browser |
37 | 42 |
38 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
39 // HtmlDialogView, public: | 44 // HtmlDialogView, public: |
40 | 45 |
41 HtmlDialogView::HtmlDialogView(Profile* profile, | 46 HtmlDialogView::HtmlDialogView(Profile* profile, |
42 HtmlDialogUIDelegate* delegate) | 47 HtmlDialogUIDelegate* delegate) |
43 : DOMView(), | 48 : DOMView(), |
44 HtmlDialogTabContentsDelegate(profile), | 49 HtmlDialogTabContentsDelegate(profile), |
50 state_(NONE), | |
45 delegate_(delegate) { | 51 delegate_(delegate) { |
46 } | 52 } |
47 | 53 |
48 HtmlDialogView::~HtmlDialogView() { | 54 HtmlDialogView::~HtmlDialogView() { |
49 } | 55 } |
50 | 56 |
51 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
52 // HtmlDialogView, views::View implementation: | 58 // HtmlDialogView, views::View implementation: |
53 | 59 |
54 gfx::Size HtmlDialogView::GetPreferredSize() { | 60 gfx::Size HtmlDialogView::GetPreferredSize() { |
55 gfx::Size out; | 61 gfx::Size out; |
56 if (delegate_) | 62 if (delegate_) |
57 delegate_->GetDialogSize(&out); | 63 delegate_->GetDialogSize(&out); |
58 return out; | 64 return out; |
59 } | 65 } |
60 | 66 |
61 bool HtmlDialogView::AcceleratorPressed(const views::Accelerator& accelerator) { | 67 bool HtmlDialogView::AcceleratorPressed(const views::Accelerator& accelerator) { |
62 // Pressing ESC closes the dialog. | 68 // Pressing ESC closes the dialog. |
63 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 69 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
64 OnWindowClosed(); | 70 OnWindowClosed(); |
65 OnDialogClosed(std::string()); | 71 OnDialogClosed(std::string()); |
66 return true; | 72 return true; |
67 } | 73 } |
68 | 74 |
75 void HtmlDialogView::ViewHierarchyChanged( | |
76 bool is_add, View* parent, View* child) { | |
77 DOMView::ViewHierarchyChanged(is_add, parent, child); | |
78 if (is_add && GetWidget() && state_ == NONE) { | |
79 state_ = INITIALIZED; | |
80 #if defined(OS_CHROMEOS) | |
sky
2011/06/07 15:41:17
Should the ifdefs be OS_LINUX?
oshima
2011/06/07 19:08:58
This make sense only with chromeos wm. Note that t
| |
81 CHECK( | |
82 static_cast<views::NativeWidgetGtk*>( | |
83 GetWidget()->native_widget())->SuppressFreezeUpdates()); | |
84 #endif | |
85 RegisterDialogAccelerators(); | |
86 } | |
87 } | |
88 | |
69 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
70 // HtmlDialogView, views::WindowDelegate implementation: | 90 // HtmlDialogView, views::WindowDelegate implementation: |
71 | 91 |
72 bool HtmlDialogView::CanResize() const { | 92 bool HtmlDialogView::CanResize() const { |
73 return true; | 93 return true; |
74 } | 94 } |
75 | 95 |
76 bool HtmlDialogView::IsModal() const { | 96 bool HtmlDialogView::IsModal() const { |
77 if (delegate_) | 97 if (delegate_) |
78 return delegate_->IsDialogModal(); | 98 return delegate_->IsDialogModal(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 void HtmlDialogView::InitDialog() { | 235 void HtmlDialogView::InitDialog() { |
216 // Now Init the DOMView. This view runs in its own process to render the html. | 236 // Now Init the DOMView. This view runs in its own process to render the html. |
217 DOMView::Init(profile(), NULL); | 237 DOMView::Init(profile(), NULL); |
218 | 238 |
219 tab_contents_->set_delegate(this); | 239 tab_contents_->set_delegate(this); |
220 | 240 |
221 // Set the delegate. This must be done before loading the page. See | 241 // Set the delegate. This must be done before loading the page. See |
222 // the comment above HtmlDialogUI in its header file for why. | 242 // the comment above HtmlDialogUI in its header file for why. |
223 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(), | 243 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(), |
224 this); | 244 this); |
225 | 245 notification_registrar_.Add( |
226 // Pressing the ESC key will close the dialog. | 246 this, |
227 AddAccelerator(views::Accelerator(ui::VKEY_ESCAPE, false, false, false)); | 247 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
248 Source<TabContents>(tab_contents())); | |
249 notification_registrar_.Add( | |
250 this, | |
251 NotificationType::LOAD_COMPLETED_MAIN_FRAME, | |
252 Source<TabContents>(tab_contents())); | |
228 | 253 |
229 DOMView::LoadURL(GetDialogContentURL()); | 254 DOMView::LoadURL(GetDialogContentURL()); |
230 } | 255 } |
256 | |
257 void HtmlDialogView::Observe(NotificationType type, | |
258 const NotificationSource& source, | |
259 const NotificationDetails& details) { | |
260 if (type == NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB) { | |
sky
2011/06/07 15:41:17
nit: a switch would be more readable here.
oshima
2011/06/07 19:08:58
Done.
| |
261 RenderWidgetHost* rwh = Details<RenderWidgetHost>(details).ptr(); | |
262 notification_registrar_.Add( | |
263 this, | |
264 NotificationType::RENDER_WIDGET_HOST_DID_PAINT, | |
265 Source<RenderWidgetHost>(rwh)); | |
266 return; | |
267 } | |
268 | |
269 if (type == NotificationType::LOAD_COMPLETED_MAIN_FRAME && | |
270 state_ == INITIALIZED) { | |
271 state_ = LOADED; | |
272 } else if (type == NotificationType::RENDER_WIDGET_HOST_DID_PAINT && | |
273 state_ == LOADED) { | |
274 state_ = PAINTED; | |
275 #if defined(OS_CHROMEOS) | |
276 views::NativeWidgetGtk::UpdateFreezeUpdatesProperty( | |
277 GTK_WINDOW(GetWidget()->GetNativeView()), false); | |
278 #endif | |
279 } | |
280 } | |
281 | |
282 void HtmlDialogView::RegisterDialogAccelerators() { | |
283 // Pressing the ESC key will close the dialog. | |
284 AddAccelerator(views::Accelerator(ui::VKEY_ESCAPE, false, false, false)); | |
285 } | |
OLD | NEW |