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

Side by Side Diff: chrome/browser/ui/views/html_dialog_view.cc

Issue 10204002: Revert 133467 - Convert the last users of DOMView to WebView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
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/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/property_bag.h"
10 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser_dialogs.h" 11 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/browser/ui/webui/html_dialog_controller.h" 12 #include "chrome/browser/ui/webui/html_dialog_controller.h"
14 #include "content/public/browser/native_web_keyboard_event.h" 13 #include "content/public/browser/native_web_keyboard_event.h"
15 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
19 #include "ui/base/keycodes/keyboard_codes.h" 18 #include "ui/base/keycodes/keyboard_codes.h"
20 #include "ui/views/controls/webview/webview.h"
21 #include "ui/views/events/event.h" 19 #include "ui/views/events/event.h"
22 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/root_view.h" 20 #include "ui/views/widget/root_view.h"
24 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
25 22
26 #if defined(USE_AURA) 23 #if defined(USE_AURA)
27 #include "ui/aura/event.h" 24 #include "ui/aura/event.h"
28 #include "ui/views/widget/native_widget_aura.h" 25 #include "ui/views/widget/native_widget_aura.h"
29 #endif 26 #endif
30 27
31 using content::WebContents; 28 using content::WebContents;
32 using content::WebUIMessageHandler; 29 using content::WebUIMessageHandler;
33 30
34 namespace browser { 31 namespace browser {
35 32
36 // Declared in browser_dialogs.h so that others don't need to depend on our .h. 33 // Declared in browser_dialogs.h so that others don't need to depend on our .h.
37 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, 34 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent,
38 Profile* profile, 35 Profile* profile,
39 Browser* browser, 36 Browser* browser,
40 HtmlDialogUIDelegate* delegate, 37 HtmlDialogUIDelegate* delegate,
41 DialogStyle style) { 38 DialogStyle style) {
42 views::Widget* widget = views::Widget::CreateWindowWithParent( 39 HtmlDialogView* html_view = new HtmlDialogView(profile, browser, delegate);
43 new HtmlDialogView(profile, browser, delegate), 40 views::Widget::CreateWindowWithParent(html_view, parent);
44 parent); 41 html_view->InitDialog();
45 widget->Show(); 42 html_view->GetWidget()->Show();
46 return widget->GetNativeWindow(); 43 return html_view->GetWidget()->GetNativeWindow();
47 } 44 }
48 45
49 void CloseHtmlDialog(gfx::NativeWindow window) { 46 void CloseHtmlDialog(gfx::NativeWindow window) {
50 views::Widget::GetWidgetForNativeWindow(window)->Close(); 47 views::Widget::GetWidgetForNativeWindow(window)->Close();
51 } 48 }
52 49
53 } // namespace browser 50 } // namespace browser
54 51
55 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
56 // HtmlDialogView, public: 53 // HtmlDialogView, public:
57 54
58 HtmlDialogView::HtmlDialogView(Profile* profile, 55 HtmlDialogView::HtmlDialogView(Profile* profile,
59 Browser* browser, 56 Browser* browser,
60 HtmlDialogUIDelegate* delegate) 57 HtmlDialogUIDelegate* delegate)
61 : HtmlDialogTabContentsDelegate(profile), 58 : DOMView(),
59 HtmlDialogTabContentsDelegate(profile),
62 initialized_(false), 60 initialized_(false),
63 delegate_(delegate), 61 delegate_(delegate),
64 dialog_controller_(new HtmlDialogController(this, profile, browser)), 62 dialog_controller_(new HtmlDialogController(this, profile, browser)) {
65 web_view_(new views::WebView(profile)) {
66 AddChildView(web_view_);
67 SetLayoutManager(new views::FillLayout);
68 // Pressing the ESC key will close the dialog.
69 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false));
70 } 63 }
71 64
72 HtmlDialogView::~HtmlDialogView() { 65 HtmlDialogView::~HtmlDialogView() {
73 } 66 }
74 67
75 content::WebContents* HtmlDialogView::web_contents() {
76 return web_view_->web_contents();
77 }
78
79 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
80 // HtmlDialogView, views::View implementation: 69 // HtmlDialogView, views::View implementation:
81 70
82 gfx::Size HtmlDialogView::GetPreferredSize() { 71 gfx::Size HtmlDialogView::GetPreferredSize() {
83 gfx::Size out; 72 gfx::Size out;
84 if (delegate_) 73 if (delegate_)
85 delegate_->GetMinimumDialogSize(&out); 74 delegate_->GetMinimumDialogSize(&out);
86 return out; 75 return out;
87 } 76 }
88 77
89 bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { 78 bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) {
90 // Pressing ESC closes the dialog. 79 // Pressing ESC closes the dialog.
91 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 80 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
92 OnDialogClosed(std::string()); 81 OnDialogClosed(std::string());
93 return true; 82 return true;
94 } 83 }
95 84
96 void HtmlDialogView::ViewHierarchyChanged(bool is_add, 85 void HtmlDialogView::ViewHierarchyChanged(
97 views::View* parent, 86 bool is_add, View* parent, View* child) {
98 views::View* child) { 87 DOMView::ViewHierarchyChanged(is_add, parent, child);
99 if (is_add && GetWidget()) 88 if (is_add && GetWidget() && !initialized_) {
100 InitDialog(); 89 initialized_ = true;
90 RegisterDialogAccelerators();
91 }
101 } 92 }
102 93
103 //////////////////////////////////////////////////////////////////////////////// 94 ////////////////////////////////////////////////////////////////////////////////
104 // HtmlDialogView, views::WidgetDelegate implementation: 95 // HtmlDialogView, views::WidgetDelegate implementation:
105 96
106 bool HtmlDialogView::CanResize() const { 97 bool HtmlDialogView::CanResize() const {
107 return true; 98 return true;
108 } 99 }
109 100
110 ui::ModalType HtmlDialogView::GetModalType() const { 101 ui::ModalType HtmlDialogView::GetModalType() const {
(...skipping 18 matching lines...) Expand all
129 // dialog. 120 // dialog.
130 if (delegate_) 121 if (delegate_)
131 OnDialogClosed(""); 122 OnDialogClosed("");
132 } 123 }
133 124
134 views::View* HtmlDialogView::GetContentsView() { 125 views::View* HtmlDialogView::GetContentsView() {
135 return this; 126 return this;
136 } 127 }
137 128
138 views::View* HtmlDialogView::GetInitiallyFocusedView() { 129 views::View* HtmlDialogView::GetInitiallyFocusedView() {
139 return web_view_; 130 return this;
140 } 131 }
141 132
142 bool HtmlDialogView::ShouldShowWindowTitle() const { 133 bool HtmlDialogView::ShouldShowWindowTitle() const {
143 return ShouldShowDialogTitle(); 134 return ShouldShowDialogTitle();
144 } 135 }
145 136
146 views::Widget* HtmlDialogView::GetWidget() { 137 views::Widget* HtmlDialogView::GetWidget() {
147 return View::GetWidget(); 138 return View::GetWidget();
148 } 139 }
149 140
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 HtmlDialogTabContentsDelegate::AddNewContents( 274 HtmlDialogTabContentsDelegate::AddNewContents(
284 source, new_contents, disposition, initial_pos, user_gesture); 275 source, new_contents, disposition, initial_pos, user_gesture);
285 } 276 }
286 277
287 void HtmlDialogView::LoadingStateChanged(content::WebContents* source) { 278 void HtmlDialogView::LoadingStateChanged(content::WebContents* source) {
288 if (delegate_) 279 if (delegate_)
289 delegate_->OnLoadingStateChanged(source); 280 delegate_->OnLoadingStateChanged(source);
290 } 281 }
291 282
292 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
293 // HtmlDialogView, TabRenderWatcher::Delegate implementation: 284 // HtmlDialogView:
294
295 void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) {
296 }
297
298 void HtmlDialogView::OnTabMainFrameLoaded() {
299 }
300
301 void HtmlDialogView::OnTabMainFrameRender() {
302 tab_watcher_.reset();
303 }
304
305 ////////////////////////////////////////////////////////////////////////////////
306 // HtmlDialogView, private:
307 285
308 void HtmlDialogView::InitDialog() { 286 void HtmlDialogView::InitDialog() {
309 content::WebContents* web_contents = web_view_->GetWebContents(); 287 // Now Init the DOMView. This view runs in its own process to render the html.
310 if (web_contents->GetDelegate() == this) 288 DOMView::Init(profile(), NULL);
311 return;
312 289
290 WebContents* web_contents = dom_contents_->web_contents();
313 web_contents->SetDelegate(this); 291 web_contents->SetDelegate(this);
314 292
315 // Set the delegate. This must be done before loading the page. See 293 // Set the delegate. This must be done before loading the page. See
316 // the comment above HtmlDialogUI in its header file for why. 294 // the comment above HtmlDialogUI in its header file for why.
317 HtmlDialogUI::GetPropertyAccessor().SetProperty( 295 HtmlDialogUI::GetPropertyAccessor().SetProperty(
318 web_contents->GetPropertyBag(), this); 296 web_contents->GetPropertyBag(), this);
319 tab_watcher_.reset(new TabRenderWatcher(web_contents, this)); 297 tab_watcher_.reset(new TabRenderWatcher(web_contents, this));
320 298
321 if (delegate_) { 299 if (delegate_) {
322 gfx::Size out; 300 gfx::Size out;
323 delegate_->GetDialogSize(&out); 301 delegate_->GetDialogSize(&out);
324 if (!out.IsEmpty() && GetWidget()) 302 if (!out.IsEmpty() && GetWidget())
325 GetWidget()->CenterWindow(out); 303 GetWidget()->CenterWindow(out);
326 } 304 }
327 305
328 web_view_->LoadInitialURL(GetDialogContentURL()); 306 DOMView::LoadURL(GetDialogContentURL());
329 } 307 }
308
309 void HtmlDialogView::RegisterDialogAccelerators() {
310 // Pressing the ESC key will close the dialog.
311 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false));
312 }
313
314 void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) {
315 }
316
317 void HtmlDialogView::OnTabMainFrameLoaded() {
318 }
319
320 void HtmlDialogView::OnTabMainFrameRender() {
321 tab_watcher_.reset();
322 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/html_dialog_view.h ('k') | chrome/browser/ui/views/html_dialog_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698