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/webui/constrained_web_dialog_delegate_base.h" | 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/constrained_window_views.h" | |
9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 8 #include "components/web_modal/web_contents_modal_dialog_host.h" |
10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
12 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
14 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
15 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 14 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
16 #include "ui/views/controls/webview/webview.h" | 15 #include "ui/views/controls/webview/webview.h" |
17 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
19 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
20 #include "ui/views/window/dialog_delegate.h" | 19 #include "ui/views/window/dialog_delegate.h" |
21 #include "ui/web_dialogs/web_dialog_delegate.h" | 20 #include "ui/web_dialogs/web_dialog_delegate.h" |
22 #include "ui/web_dialogs/web_dialog_ui.h" | 21 #include "ui/web_dialogs/web_dialog_ui.h" |
23 | 22 |
24 using content::WebContents; | 23 using content::WebContents; |
25 using ui::WebDialogDelegate; | 24 using ui::WebDialogDelegate; |
26 using ui::WebDialogWebContentsDelegate; | 25 using ui::WebDialogWebContentsDelegate; |
27 using web_modal::NativeWebContentsModalDialog; | 26 using web_modal::NativeWebContentsModalDialog; |
28 using web_modal::WebContentsModalDialogManager; | 27 using web_modal::WebContentsModalDialogManager; |
29 using web_modal::WebContentsModalDialogManagerDelegate; | 28 using web_modal::WebContentsModalDialogManagerDelegate; |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 class ConstrainedWebDialogDelegateViews | 32 class ConstrainedWebDialogDelegateViews |
34 : public ConstrainedWebDialogDelegateBase { | 33 : public ConstrainedWebDialogDelegateBase { |
35 public: | 34 public: |
36 ConstrainedWebDialogDelegateViews( | 35 ConstrainedWebDialogDelegateViews(content::BrowserContext* browser_context, |
37 content::BrowserContext* browser_context, | 36 WebDialogDelegate* delegate, |
38 WebDialogDelegate* delegate, | 37 WebDialogWebContentsDelegate* tab_delegate, |
39 WebDialogWebContentsDelegate* tab_delegate, | 38 views::WebView* view) |
40 views::WebView* view) | |
41 : ConstrainedWebDialogDelegateBase( | 39 : ConstrainedWebDialogDelegateBase( |
42 browser_context, delegate, tab_delegate), | 40 browser_context, delegate, tab_delegate), |
43 view_(view), | 41 view_(view), |
44 window_(NULL) {} | 42 window_(NULL) {} |
45 | 43 |
46 virtual ~ConstrainedWebDialogDelegateViews() {} | 44 virtual ~ConstrainedWebDialogDelegateViews() {} |
47 | 45 |
48 // WebDialogWebContentsDelegate interface. | 46 // WebDialogWebContentsDelegate interface. |
49 virtual void CloseContents(WebContents* source) OVERRIDE { | 47 virtual void CloseContents(WebContents* source) OVERRIDE { |
50 window_->Close(); | 48 window_->Close(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 virtual const views::Widget* GetWidget() const OVERRIDE { | 121 virtual const views::Widget* GetWidget() const OVERRIDE { |
124 return View::GetWidget(); | 122 return View::GetWidget(); |
125 } | 123 } |
126 virtual base::string16 GetWindowTitle() const OVERRIDE { | 124 virtual base::string16 GetWindowTitle() const OVERRIDE { |
127 return impl_->closed_via_webui() ? base::string16() : | 125 return impl_->closed_via_webui() ? base::string16() : |
128 GetWebDialogDelegate()->GetDialogTitle(); | 126 GetWebDialogDelegate()->GetDialogTitle(); |
129 } | 127 } |
130 virtual views::View* GetContentsView() OVERRIDE { | 128 virtual views::View* GetContentsView() OVERRIDE { |
131 return this; | 129 return this; |
132 } | 130 } |
133 // TODO(wittman): Remove this override once we move to the new style frame | |
134 // view on all dialogs. | |
135 virtual views::NonClientFrameView* CreateNonClientFrameView( | 131 virtual views::NonClientFrameView* CreateNonClientFrameView( |
136 views::Widget* widget) OVERRIDE { | 132 views::Widget* widget) OVERRIDE { |
137 return CreateConstrainedStyleNonClientFrameView( | 133 return views::DialogDelegate::CreateDialogFrameView(widget); |
138 widget, | |
139 GetWebContents()->GetBrowserContext()); | |
140 } | 134 } |
141 virtual bool ShouldShowCloseButton() const OVERRIDE { | 135 virtual bool ShouldShowCloseButton() const OVERRIDE { |
142 // No close button if the dialog doesn't want a title bar. | 136 // No close button if the dialog doesn't want a title bar. |
143 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle(); | 137 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle(); |
144 } | 138 } |
145 | 139 |
146 virtual ui::ModalType GetModalType() const OVERRIDE { | 140 virtual ui::ModalType GetModalType() const OVERRIDE { |
147 #if defined(USE_ASH) | 141 #if defined(USE_ASH) |
148 return ui::MODAL_TYPE_CHILD; | 142 return ui::MODAL_TYPE_CHILD; |
149 #else | 143 #else |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 impl_(new ConstrainedWebDialogDelegateViews(browser_context, | 186 impl_(new ConstrainedWebDialogDelegateViews(browser_context, |
193 delegate, | 187 delegate, |
194 tab_delegate, | 188 tab_delegate, |
195 this)) { | 189 this)) { |
196 SetWebContents(GetWebContents()); | 190 SetWebContents(GetWebContents()); |
197 | 191 |
198 // Pressing ESC closes the dialog. | 192 // Pressing ESC closes the dialog. |
199 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 193 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
200 } | 194 } |
201 | 195 |
202 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews()
{ | 196 ConstrainedWebDialogDelegateViewViews:: |
| 197 ~ConstrainedWebDialogDelegateViewViews() { |
203 } | 198 } |
204 | 199 |
205 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 200 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
206 content::BrowserContext* browser_context, | 201 content::BrowserContext* browser_context, |
207 WebDialogDelegate* delegate, | 202 WebDialogDelegate* delegate, |
208 WebDialogWebContentsDelegate* tab_delegate, | 203 WebDialogWebContentsDelegate* tab_delegate, |
209 content::WebContents* web_contents) { | 204 content::WebContents* web_contents) { |
210 ConstrainedWebDialogDelegateViewViews* constrained_delegate = | 205 ConstrainedWebDialogDelegateViewViews* constrained_delegate = |
211 new ConstrainedWebDialogDelegateViewViews( | 206 new ConstrainedWebDialogDelegateViewViews( |
212 browser_context, delegate, tab_delegate); | 207 browser_context, delegate, tab_delegate); |
213 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 208 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
214 WebContentsModalDialogManager::FromWebContents(web_contents); | 209 WebContentsModalDialogManager::FromWebContents(web_contents); |
215 WebContentsModalDialogManagerDelegate* modal_delegate = | 210 WebContentsModalDialogManagerDelegate* modal_delegate = |
216 web_contents_modal_dialog_manager->delegate(); | 211 web_contents_modal_dialog_manager->delegate(); |
217 DCHECK(modal_delegate); | 212 DCHECK(modal_delegate); |
218 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( | 213 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( |
219 constrained_delegate, | 214 constrained_delegate, |
220 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 215 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
221 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); | 216 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); |
222 constrained_delegate->SetWindow(window); | 217 constrained_delegate->SetWindow(window); |
223 return constrained_delegate; | 218 return constrained_delegate; |
224 } | 219 } |
OLD | NEW |