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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 } // namespace browser | 41 } // namespace browser |
42 | 42 |
43 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
44 // HtmlDialogView, public: | 44 // HtmlDialogView, public: |
45 | 45 |
46 HtmlDialogView::HtmlDialogView(Profile* profile, | 46 HtmlDialogView::HtmlDialogView(Profile* profile, |
47 HtmlDialogUIDelegate* delegate) | 47 HtmlDialogUIDelegate* delegate) |
48 : DOMView(), | 48 : DOMView(), |
49 HtmlDialogTabContentsDelegate(profile), | 49 HtmlDialogTabContentsDelegate(profile), |
50 state_(NONE), | 50 initialized_(false), |
51 delegate_(delegate) { | 51 delegate_(delegate) { |
52 } | 52 } |
53 | 53 |
54 HtmlDialogView::~HtmlDialogView() { | 54 HtmlDialogView::~HtmlDialogView() { |
55 } | 55 } |
56 | 56 |
57 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
58 // HtmlDialogView, views::View implementation: | 58 // HtmlDialogView, views::View implementation: |
59 | 59 |
60 gfx::Size HtmlDialogView::GetPreferredSize() { | 60 gfx::Size HtmlDialogView::GetPreferredSize() { |
61 gfx::Size out; | 61 gfx::Size out; |
62 if (delegate_) | 62 if (delegate_) |
63 delegate_->GetDialogSize(&out); | 63 delegate_->GetDialogSize(&out); |
64 return out; | 64 return out; |
65 } | 65 } |
66 | 66 |
67 bool HtmlDialogView::AcceleratorPressed(const views::Accelerator& accelerator) { | 67 bool HtmlDialogView::AcceleratorPressed(const views::Accelerator& accelerator) { |
68 // Pressing ESC closes the dialog. | 68 // Pressing ESC closes the dialog. |
69 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 69 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
70 OnDialogClosed(std::string()); | 70 OnDialogClosed(std::string()); |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 void HtmlDialogView::ViewHierarchyChanged( | 74 void HtmlDialogView::ViewHierarchyChanged( |
75 bool is_add, View* parent, View* child) { | 75 bool is_add, View* parent, View* child) { |
76 DOMView::ViewHierarchyChanged(is_add, parent, child); | 76 DOMView::ViewHierarchyChanged(is_add, parent, child); |
77 if (is_add && GetWidget() && state_ == NONE) { | 77 if (is_add && GetWidget() && !initialized_) { |
78 state_ = INITIALIZED; | 78 initialized_ = true; |
79 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) | 79 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) |
80 CHECK( | 80 CHECK( |
81 static_cast<views::NativeWidgetGtk*>( | 81 static_cast<views::NativeWidgetGtk*>( |
82 GetWidget()->native_widget())->SuppressFreezeUpdates()); | 82 GetWidget()->native_widget())->SuppressFreezeUpdates()); |
83 #endif | 83 #endif |
84 RegisterDialogAccelerators(); | 84 RegisterDialogAccelerators(); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
235 // HtmlDialogView: | 235 // HtmlDialogView: |
236 | 236 |
237 void HtmlDialogView::InitDialog() { | 237 void HtmlDialogView::InitDialog() { |
238 // Now Init the DOMView. This view runs in its own process to render the html. | 238 // Now Init the DOMView. This view runs in its own process to render the html. |
239 DOMView::Init(profile(), NULL); | 239 DOMView::Init(profile(), NULL); |
240 | 240 |
241 TabContents* tab_contents = dom_contents_->tab_contents(); | 241 TabContents* tab_contents = dom_contents_->tab_contents(); |
242 tab_contents->set_delegate(this); | 242 tab_contents->set_delegate(this); |
243 | 243 |
244 // Set the delegate. This must be done before loading the page. See | |
245 // the comment above HtmlDialogUI in its header file for why. | |
246 HtmlDialogUI::GetPropertyAccessor().SetProperty( | |
247 tab_contents->property_bag(), this); | |
248 notification_registrar_.Add( | |
249 this, | |
250 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | |
251 content::Source<TabContents>(tab_contents)); | |
252 notification_registrar_.Add( | |
253 this, | |
254 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
255 content::Source<TabContents>(tab_contents)); | |
256 | |
257 DOMView::LoadURL(GetDialogContentURL()); | 244 DOMView::LoadURL(GetDialogContentURL()); |
258 } | 245 } |
259 | 246 |
260 void HtmlDialogView::Observe(int type, | 247 void HtmlDialogView::OnTabMainFrameFirstRender() { |
261 const content::NotificationSource& source, | |
262 const content::NotificationDetails& details) { | |
263 switch (type) { | |
264 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | |
265 RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr(); | |
266 notification_registrar_.Add( | |
267 this, | |
268 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | |
269 content::Source<RenderWidgetHost>(rwh)); | |
270 break; | |
271 } | |
272 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | |
273 if (state_ == INITIALIZED) | |
274 state_ = LOADED; | |
275 break; | |
276 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: | |
277 if (state_ == LOADED) { | |
278 state_ = PAINTED; | |
279 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) | 248 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) |
280 views::NativeWidgetGtk::UpdateFreezeUpdatesProperty( | 249 if (initialized_) { |
281 GTK_WINDOW(GetWidget()->GetNativeView()), false); | 250 views::NativeWidgetGtk::UpdateFreezeUpdatesProperty( |
251 GTK_WINDOW(GetWidget()->GetNativeView()), false); | |
252 } | |
282 #endif | 253 #endif |
283 } | |
284 break; | |
285 default: | |
286 NOTREACHED() << "unknown type" << type; | |
287 } | |
288 } | 254 } |
289 | 255 |
oshima
2011/10/27 20:49:30
nit: remove empty line
xiyuan
2011/10/27 21:48:07
Done.
| |
256 | |
290 void HtmlDialogView::RegisterDialogAccelerators() { | 257 void HtmlDialogView::RegisterDialogAccelerators() { |
291 // Pressing the ESC key will close the dialog. | 258 // Pressing the ESC key will close the dialog. |
292 AddAccelerator(views::Accelerator(ui::VKEY_ESCAPE, false, false, false)); | 259 AddAccelerator(views::Accelerator(ui::VKEY_ESCAPE, false, false, false)); |
293 } | 260 } |
OLD | NEW |