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

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

Issue 2172363002: Created min size for print preview dialog and modified to allow the Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge ConstrainedWebDialog functions Created 4 years 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
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/webui/constrained_web_dialog_delegate_base.h" 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" 12 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
13 #include "components/constrained_window/constrained_window_views.h" 13 #include "components/constrained_window/constrained_window_views.h"
14 #include "components/guest_view/browser/guest_view_base.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h" 15 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 16 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "ui/gfx/native_widget_types.h"
18 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 20 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
19 #include "ui/views/controls/webview/webview.h" 21 #include "ui/views/controls/webview/webview.h"
20 #include "ui/views/view.h" 22 #include "ui/views/view.h"
21 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
22 #include "ui/views/window/dialog_delegate.h" 24 #include "ui/views/window/dialog_delegate.h"
23 #include "ui/web_dialogs/web_dialog_delegate.h" 25 #include "ui/web_dialogs/web_dialog_delegate.h"
24 #include "ui/web_dialogs/web_dialog_ui.h" 26 #include "ui/web_dialogs/web_dialog_ui.h"
25 27
26 namespace { 28 namespace {
27 29
28 // WebContentsObserver that tracks the lifetime of the WebContents to avoid 30 // WebContentsObserver that tracks the lifetime of the WebContents to avoid
29 // potential use after destruction. 31 // potential use after destruction.
30 class InitiatorWebContentsObserver 32 class InitiatorWebContentsObserver
31 : public content::WebContentsObserver { 33 : public content::WebContentsObserver {
32 public: 34 public:
33 explicit InitiatorWebContentsObserver(content::WebContents* web_contents) 35 explicit InitiatorWebContentsObserver(content::WebContents* web_contents)
34 : content::WebContentsObserver(web_contents) { 36 : content::WebContentsObserver(web_contents) {}
35 }
36 37
37 private: 38 private:
38 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver); 39 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver);
39 }; 40 };
40 41
41 class WebDialogWebContentsDelegateViews 42 class WebDialogWebContentsDelegateViews
42 : public ui::WebDialogWebContentsDelegate { 43 : public ui::WebDialogWebContentsDelegate {
43 public: 44 public:
44 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context, 45 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context,
45 InitiatorWebContentsObserver* observer, 46 InitiatorWebContentsObserver* observer,
46 views::WebView* web_view) 47 views::WebView* web_view)
47 : ui::WebDialogWebContentsDelegate(browser_context, 48 : ui::WebDialogWebContentsDelegate(browser_context,
48 new ChromeWebContentsHandler()), 49 new ChromeWebContentsHandler()),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 public views::WidgetDelegate { 147 public views::WidgetDelegate {
147 public: 148 public:
148 ConstrainedWebDialogDelegateViewViews( 149 ConstrainedWebDialogDelegateViewViews(
149 content::BrowserContext* browser_context, 150 content::BrowserContext* browser_context,
150 ui::WebDialogDelegate* delegate, 151 ui::WebDialogDelegate* delegate,
151 content::WebContents* web_contents, 152 content::WebContents* web_contents,
152 const gfx::Size& min_size, 153 const gfx::Size& min_size,
153 const gfx::Size& max_size) 154 const gfx::Size& max_size)
154 : views::WebView(browser_context), 155 : views::WebView(browser_context),
155 initiator_observer_(web_contents), 156 initiator_observer_(web_contents),
156 impl_(new ConstrainedWebDialogDelegateViews(browser_context, delegate, 157 impl_(new ConstrainedWebDialogDelegateViews(browser_context,
158 delegate,
157 &initiator_observer_, 159 &initiator_observer_,
158 this)), 160 this)),
159 min_size_(min_size), 161 min_size_(min_size),
160 max_size_(max_size) { 162 max_size_(max_size) {
161 SetWebContents(GetWebContents()); 163 SetWebContents(GetWebContents());
162 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 164 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
163 if (!max_size_.IsEmpty()) 165 if (!max_size_.IsEmpty())
164 EnableAutoResize(); 166 EnableAutoResize();
165 } 167 }
166 ~ConstrainedWebDialogDelegateViewViews() override {} 168 ~ConstrainedWebDialogDelegateViewViews() override {}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 201 }
200 views::View* GetContentsView() override { return this; } 202 views::View* GetContentsView() override { return this; }
201 views::NonClientFrameView* CreateNonClientFrameView( 203 views::NonClientFrameView* CreateNonClientFrameView(
202 views::Widget* widget) override { 204 views::Widget* widget) override {
203 return views::DialogDelegate::CreateDialogFrameView(widget, gfx::Insets()); 205 return views::DialogDelegate::CreateDialogFrameView(widget, gfx::Insets());
204 } 206 }
205 bool ShouldShowCloseButton() const override { 207 bool ShouldShowCloseButton() const override {
206 // No close button if the dialog doesn't want a title bar. 208 // No close button if the dialog doesn't want a title bar.
207 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle(); 209 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle();
208 } 210 }
209 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } 211 ui::ModalType GetModalType() const override {
212 #if defined(OS_MACOSX)
213 return ui::MODAL_TYPE_CHILD;
214 #elif defined(OS_WIN)
215 return ui::MODAL_TYPE_NONE;
216 #else // Linux, ChromeOS
217 return ui::MODAL_TYPE_WINDOW;
218 #endif
219 }
210 220
211 // views::WebView: 221 // views::WebView:
212 bool AcceleratorPressed(const ui::Accelerator& accelerator) override { 222 bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
213 // Pressing ESC closes the dialog. 223 // Pressing ESC closes the dialog.
214 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 224 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
215 GetWidget()->Close(); 225 GetWidget()->Close();
216 return true; 226 return true;
217 } 227 }
218 gfx::Size GetPreferredSize() const override { 228 gfx::Size GetPreferredSize() const override {
219 gfx::Size size; 229 gfx::Size size;
(...skipping 20 matching lines...) Expand all
240 void RenderViewHostChanged(content::RenderViewHost* old_host, 250 void RenderViewHostChanged(content::RenderViewHost* old_host,
241 content::RenderViewHost* new_host) override { 251 content::RenderViewHost* new_host) override {
242 if (!max_size_.IsEmpty()) 252 if (!max_size_.IsEmpty())
243 EnableAutoResize(); 253 EnableAutoResize();
244 } 254 }
245 void DocumentOnLoadCompletedInMainFrame() override { 255 void DocumentOnLoadCompletedInMainFrame() override {
246 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { 256 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) {
247 content::WebContents* top_level_web_contents = 257 content::WebContents* top_level_web_contents =
248 constrained_window::GetTopLevelWebContents( 258 constrained_window::GetTopLevelWebContents(
249 initiator_observer_.web_contents()); 259 initiator_observer_.web_contents());
250 if (top_level_web_contents) { 260 if (top_level_web_contents)
251 constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(), 261 constrained_window::ShowTopLevelModalDialog(
252 top_level_web_contents); 262 GetWidget()->GetNativeWindow(),
253 } 263 top_level_web_contents, this);
254 } 264 }
255 } 265 }
256 266
257 private: 267 private:
258 void EnableAutoResize() { 268 void EnableAutoResize() {
259 content::RenderViewHost* render_view_host = 269 content::RenderViewHost* render_view_host =
260 GetWebContents()->GetRenderViewHost(); 270 GetWebContents()->GetRenderViewHost();
261 render_view_host->EnableAutoResize(min_size_, max_size_); 271 render_view_host->EnableAutoResize(min_size_, max_size_);
262 } 272 }
263 273
264 InitiatorWebContentsObserver initiator_observer_; 274 InitiatorWebContentsObserver initiator_observer_;
265 275
266 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_; 276 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_;
267 277
268 // Minimum and maximum sizes to determine dialog bounds for auto-resizing. 278 // Minimum and maximum sizes to determine dialog bounds for auto-resizing.
269 const gfx::Size min_size_; 279 const gfx::Size min_size_;
270 const gfx::Size max_size_; 280 const gfx::Size max_size_;
271 281
272 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); 282 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
273 }; 283 };
274 284
275 } // namespace 285 } // namespace
276 286
287 // TODO: Rename this to ShowConstrainedWebDialogInWindow and propagate to all
288 // tests.
289 ConstrainedWebDialogDelegate* ShowTopLevelConstrainedWebDialogInWindow(
290 content::BrowserContext* browser_context,
291 ui::WebDialogDelegate* delegate,
292 content::WebContents* web_contents,
293 gfx::NativeView dialog_host_window) {
294 ConstrainedWebDialogDelegateViewViews* dialog =
295 new ConstrainedWebDialogDelegateViewViews(browser_context, delegate,
296 web_contents, gfx::Size(),
297 gfx::Size());
298 content::WebContents* top_web_contents =
299 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
300 views::Widget* widget =
301 views::DialogDelegate::CreateDialogWidget(dialog,
302 dialog_host_window,
303 nullptr);
304 constrained_window::ShowTopLevelModalDialog(widget->GetNativeWindow(),
305 top_web_contents, dialog);
306 return dialog;
307 }
308
277 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog( 309 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog(
278 content::BrowserContext* browser_context, 310 content::BrowserContext* browser_context,
279 ui::WebDialogDelegate* delegate, 311 ui::WebDialogDelegate* delegate,
280 content::WebContents* web_contents) { 312 content::WebContents* web_contents) {
281 ConstrainedWebDialogDelegateViewViews* dialog = 313 ConstrainedWebDialogDelegateViewViews* dialog =
282 new ConstrainedWebDialogDelegateViewViews( 314 new ConstrainedWebDialogDelegateViewViews(browser_context, delegate,
283 browser_context, delegate, web_contents, 315 web_contents, gfx::Size(),
284 gfx::Size(), gfx::Size()); 316 gfx::Size());
285 constrained_window::ShowWebModalDialogViews(dialog, web_contents); 317 constrained_window::ShowWebModalDialogViews(dialog, web_contents, dialog);
286 return dialog; 318 return dialog;
287 } 319 }
288 320
289 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize( 321 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize(
290 content::BrowserContext* browser_context, 322 content::BrowserContext* browser_context,
291 ui::WebDialogDelegate* delegate, 323 ui::WebDialogDelegate* delegate,
292 content::WebContents* web_contents, 324 content::WebContents* web_contents,
293 const gfx::Size& min_size, 325 const gfx::Size& min_size,
294 const gfx::Size& max_size) { 326 const gfx::Size& max_size) {
295 DCHECK(!min_size.IsEmpty()); 327 DCHECK(!min_size.IsEmpty());
296 DCHECK(!max_size.IsEmpty()); 328 DCHECK(!max_size.IsEmpty());
297 ConstrainedWebDialogDelegateViewViews* dialog = 329 ConstrainedWebDialogDelegateViewViews* dialog =
298 new ConstrainedWebDialogDelegateViewViews( 330 new ConstrainedWebDialogDelegateViewViews(
299 browser_context, delegate, web_contents, 331 browser_context, delegate, web_contents,
300 min_size, max_size); 332 min_size, max_size);//, false);
301
302 // For embedded WebContents, use the embedder's WebContents for constrained 333 // For embedded WebContents, use the embedder's WebContents for constrained
303 // window. 334 // window.
304 content::WebContents* top_level_web_contents = 335 content::WebContents* top_level_web_contents =
305 constrained_window::GetTopLevelWebContents(web_contents); 336 constrained_window::GetTopLevelWebContents(web_contents);
306 DCHECK(top_level_web_contents); 337 DCHECK(top_level_web_contents);
307 constrained_window::CreateWebModalDialogViews(dialog, top_level_web_contents); 338 constrained_window::CreateWebModalDialogViews(dialog, top_level_web_contents);
308 return dialog; 339 return dialog;
309 } 340 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm ('k') | chrome/browser/ui/webui/certificate_viewer_webui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698