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

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: Fix Mac compile error. Created 4 years, 4 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
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"
(...skipping 11 matching lines...) Expand all
22 #include "ui/views/window/dialog_delegate.h" 22 #include "ui/views/window/dialog_delegate.h"
23 #include "ui/web_dialogs/web_dialog_delegate.h" 23 #include "ui/web_dialogs/web_dialog_delegate.h"
24 #include "ui/web_dialogs/web_dialog_ui.h" 24 #include "ui/web_dialogs/web_dialog_ui.h"
25 25
26 namespace { 26 namespace {
27 27
28 // WebContentsObserver that tracks the lifetime of the WebContents to avoid 28 // WebContentsObserver that tracks the lifetime of the WebContents to avoid
29 // potential use after destruction. 29 // potential use after destruction.
30 class InitiatorWebContentsObserver 30 class InitiatorWebContentsObserver
31 : public content::WebContentsObserver { 31 : public content::WebContentsObserver {
32 public: 32 public:
33 explicit InitiatorWebContentsObserver(content::WebContents* web_contents) 33 explicit InitiatorWebContentsObserver(content::WebContents* web_contents)
34 : content::WebContentsObserver(web_contents) { 34 : content::WebContentsObserver(web_contents) {
35 } 35 }
36 36
37 private: 37 private:
38 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver); 38 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver);
39 }; 39 };
40 40
41 class WebDialogWebContentsDelegateViews 41 class WebDialogWebContentsDelegateViews
42 : public ui::WebDialogWebContentsDelegate { 42 : public ui::WebDialogWebContentsDelegate {
43 public: 43 public:
44 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context, 44 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context,
45 InitiatorWebContentsObserver* observer, 45 InitiatorWebContentsObserver* observer,
46 views::WebView* web_view) 46 views::WebView* web_view)
47 : ui::WebDialogWebContentsDelegate(browser_context, 47 : ui::WebDialogWebContentsDelegate(browser_context,
48 new ChromeWebContentsHandler()), 48 new ChromeWebContentsHandler()),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 class ConstrainedWebDialogDelegateViewViews 137 class ConstrainedWebDialogDelegateViewViews
138 : public views::WebView, 138 : public views::WebView,
139 public ConstrainedWebDialogDelegate, 139 public ConstrainedWebDialogDelegate,
140 public views::WidgetDelegate { 140 public views::WidgetDelegate {
141 public: 141 public:
142 ConstrainedWebDialogDelegateViewViews( 142 ConstrainedWebDialogDelegateViewViews(
143 content::BrowserContext* browser_context, 143 content::BrowserContext* browser_context,
144 ui::WebDialogDelegate* delegate, 144 ui::WebDialogDelegate* delegate,
145 content::WebContents* web_contents, 145 content::WebContents* web_contents,
146 const gfx::Size& min_size, 146 const gfx::Size& min_size,
147 const gfx::Size& max_size) 147 const gfx::Size& max_size,
148 bool is_nonclipped)
148 : views::WebView(browser_context), 149 : views::WebView(browser_context),
149 initiator_observer_(web_contents), 150 initiator_observer_(web_contents),
150 impl_(new ConstrainedWebDialogDelegateViews(browser_context, delegate, 151 impl_(new ConstrainedWebDialogDelegateViews(browser_context,
152 delegate,
151 &initiator_observer_, 153 &initiator_observer_,
152 this)), 154 this)),
153 min_size_(min_size), 155 min_size_(min_size),
154 max_size_(max_size) { 156 max_size_(max_size),
157 is_nonclipped_(is_nonclipped) {
155 SetWebContents(GetWebContents()); 158 SetWebContents(GetWebContents());
156 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 159 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
157 if (!max_size_.IsEmpty()) 160 if (!max_size_.IsEmpty())
158 EnableAutoResize(); 161 EnableAutoResize();
159 } 162 }
160 ~ConstrainedWebDialogDelegateViewViews() override {} 163 ~ConstrainedWebDialogDelegateViewViews() override {}
161 164
162 // ConstrainedWebDialogDelegate: 165 // ConstrainedWebDialogDelegate:
163 const ui::WebDialogDelegate* GetWebDialogDelegate() const override { 166 const ui::WebDialogDelegate* GetWebDialogDelegate() const override {
164 return impl_->GetWebDialogDelegate(); 167 return impl_->GetWebDialogDelegate();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (!max_size_.IsEmpty()) 234 if (!max_size_.IsEmpty())
232 EnableAutoResize(); 235 EnableAutoResize();
233 } 236 }
234 void RenderViewHostChanged(content::RenderViewHost* old_host, 237 void RenderViewHostChanged(content::RenderViewHost* old_host,
235 content::RenderViewHost* new_host) override { 238 content::RenderViewHost* new_host) override {
236 if (!max_size_.IsEmpty()) 239 if (!max_size_.IsEmpty())
237 EnableAutoResize(); 240 EnableAutoResize();
238 } 241 }
239 void DocumentOnLoadCompletedInMainFrame() override { 242 void DocumentOnLoadCompletedInMainFrame() override {
240 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { 243 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) {
241 constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(), 244 if (is_nonclipped_) {
242 initiator_observer_.web_contents()); 245 constrained_window::ShowNonClippedModalDialog(
246 GetWidget()->GetNativeWindow(),
247 initiator_observer_.web_contents());
248 } else {
249 constrained_window::ShowModalDialog(
250 GetWidget()->GetNativeWindow(),
251 initiator_observer_.web_contents());
252 }
243 } 253 }
244 } 254 }
245
246 private: 255 private:
247 void EnableAutoResize() { 256 void EnableAutoResize() {
248 content::RenderViewHost* render_view_host = 257 content::RenderViewHost* render_view_host =
249 GetWebContents()->GetRenderViewHost(); 258 GetWebContents()->GetRenderViewHost();
250 render_view_host->EnableAutoResize(min_size_, max_size_); 259 render_view_host->EnableAutoResize(min_size_, max_size_);
251 } 260 }
252 261
253 InitiatorWebContentsObserver initiator_observer_; 262 InitiatorWebContentsObserver initiator_observer_;
254 263
255 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_; 264 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_;
256 265
257 // Minimum and maximum sizes to determine dialog bounds for auto-resizing. 266 // Minimum and maximum sizes to determine dialog bounds for auto-resizing.
258 const gfx::Size min_size_; 267 const gfx::Size min_size_;
259 const gfx::Size max_size_; 268 const gfx::Size max_size_;
260 269
270 // If true, dialog has bounds that are not constrained by the parent window's
271 // bounds, so it can extend outside of the parent window when resized.
272 bool is_nonclipped_;
273
261 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); 274 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
262 }; 275 };
263 276
264 } // namespace 277 } // namespace
265 278
266 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog( 279 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog(
267 content::BrowserContext* browser_context, 280 content::BrowserContext* browser_context,
268 ui::WebDialogDelegate* delegate, 281 ui::WebDialogDelegate* delegate,
269 content::WebContents* web_contents) { 282 content::WebContents* web_contents) {
270 ConstrainedWebDialogDelegateViewViews* dialog = 283 ConstrainedWebDialogDelegateViewViews* dialog =
271 new ConstrainedWebDialogDelegateViewViews( 284 new ConstrainedWebDialogDelegateViewViews(
272 browser_context, delegate, web_contents, 285 browser_context, delegate, web_contents,
273 gfx::Size(), gfx::Size()); 286 gfx::Size(), gfx::Size(), false);
274 constrained_window::ShowWebModalDialogViews(dialog, web_contents); 287 constrained_window::ShowWebModalDialogViews(dialog, web_contents);
275 return dialog; 288 return dialog;
276 } 289 }
277 290
291 ConstrainedWebDialogDelegate* ShowNonClippedConstrainedWebDialog(
292 content::BrowserContext* browser_context,
293 ui::WebDialogDelegate* delegate,
294 content::WebContents* web_contents) {
295 ConstrainedWebDialogDelegateViewViews* dialog =
296 new ConstrainedWebDialogDelegateViewViews(browser_context, delegate,
297 web_contents, gfx::Size(),
298 gfx::Size(), true);
299 constrained_window::ShowNonClippedWebModalDialogViews(dialog, web_contents);
300 return dialog;
301 }
302
278 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize( 303 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize(
279 content::BrowserContext* browser_context, 304 content::BrowserContext* browser_context,
280 ui::WebDialogDelegate* delegate, 305 ui::WebDialogDelegate* delegate,
281 content::WebContents* web_contents, 306 content::WebContents* web_contents,
282 const gfx::Size& min_size, 307 const gfx::Size& min_size,
283 const gfx::Size& max_size) { 308 const gfx::Size& max_size) {
284 DCHECK(!min_size.IsEmpty()); 309 DCHECK(!min_size.IsEmpty());
285 DCHECK(!max_size.IsEmpty()); 310 DCHECK(!max_size.IsEmpty());
286 ConstrainedWebDialogDelegateViewViews* dialog = 311 ConstrainedWebDialogDelegateViewViews* dialog =
287 new ConstrainedWebDialogDelegateViewViews( 312 new ConstrainedWebDialogDelegateViewViews(
288 browser_context, delegate, web_contents, 313 browser_context, delegate, web_contents,
289 min_size, max_size); 314 min_size, max_size, false);
290 constrained_window::CreateWebModalDialogViews(dialog, web_contents); 315 constrained_window::CreateWebModalDialogViews(dialog, web_contents);
291 return dialog; 316 return dialog;
292 } 317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698