Chromium Code Reviews| 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/printing/print_preview_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate(WebContents* initiator) | 73 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate(WebContents* initiator) |
| 74 : initiator_(initiator) { | 74 : initiator_(initiator) { |
| 75 } | 75 } |
| 76 | 76 |
| 77 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { | 77 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { |
| 78 } | 78 } |
| 79 | 79 |
| 80 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { | 80 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { |
| 81 // Not used, returning dummy value. | 81 return ui::MODAL_TYPE_CHILD; |
| 82 NOTREACHED(); | |
| 83 return ui::MODAL_TYPE_WINDOW; | |
| 84 } | 82 } |
| 85 | 83 |
| 86 base::string16 PrintPreviewDialogDelegate::GetDialogTitle() const { | 84 base::string16 PrintPreviewDialogDelegate::GetDialogTitle() const { |
| 87 // Only used on Windows? UI folks prefer no title. | 85 // Only used on Windows? UI folks prefer no title. |
| 88 return base::string16(); | 86 return base::string16(); |
| 89 } | 87 } |
| 90 | 88 |
| 91 GURL PrintPreviewDialogDelegate::GetDialogContentURL() const { | 89 GURL PrintPreviewDialogDelegate::GetDialogContentURL() const { |
| 92 return GURL(chrome::kChromeUIPrintURL); | 90 return GURL(chrome::kChromeUIPrintURL); |
| 93 } | 91 } |
| 94 | 92 |
| 95 void PrintPreviewDialogDelegate::GetWebUIMessageHandlers( | 93 void PrintPreviewDialogDelegate::GetWebUIMessageHandlers( |
| 96 std::vector<WebUIMessageHandler*>* /* handlers */) const { | 94 std::vector<WebUIMessageHandler*>* /* handlers */) const { |
| 97 // PrintPreviewUI adds its own message handlers. | 95 // PrintPreviewUI adds its own message handlers. |
| 98 } | 96 } |
| 99 | 97 |
| 100 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { | 98 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { |
| 101 DCHECK(size); | 99 DCHECK(size); |
| 100 const int kBorder = 25; | |
| 101 // Gives ChromeOS dialogs the requested minimum sizei of 438x455 without | |
|
Lei Zhang
2016/08/19 03:28:46
s/sizei/size/
rbpotter
2016/08/19 16:59:42
Done.
| |
| 102 // changing the existing behavior on Mac OSX. For all other platforms, the min | |
| 103 // size is later overridden by the size of the parent window. | |
| 104 #if defined(OS_MACOSX) | |
| 102 const gfx::Size kMinDialogSize(800, 480); | 105 const gfx::Size kMinDialogSize(800, 480); |
| 103 const int kBorder = 25; | 106 #else |
| 107 const gfx::Size kMinDialogSize(438, 455); | |
| 108 #endif | |
| 104 *size = kMinDialogSize; | 109 *size = kMinDialogSize; |
| 105 | 110 |
| 106 web_modal::WebContentsModalDialogHost* host = nullptr; | 111 web_modal::WebContentsModalDialogHost* host = nullptr; |
| 107 content::WebContents* outermost_web_contents = | 112 content::WebContents* outermost_web_contents = |
| 108 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); | 113 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); |
| 109 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); | 114 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); |
| 110 if (browser) | 115 if (browser) |
| 111 host = browser->window()->GetWebContentsModalDialogHost(); | 116 host = browser->window()->GetWebContentsModalDialogHost(); |
| 112 | 117 |
| 113 if (host) | 118 if (host) |
| 114 size->SetToMax(host->GetMaximumDialogSize()); | 119 size->SetToMax(host->GetMaximumDialogSize()); |
| 115 else | 120 else |
| 116 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); | 121 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); |
| 122 #if defined(OS_MACOSX) | |
| 117 size->Enlarge(-2 * kBorder, -kBorder); | 123 size->Enlarge(-2 * kBorder, -kBorder); |
| 124 #else | |
| 125 int shrink_width = | |
| 126 std::max(-size->width() + kMinDialogSize.width(), -2 * kBorder); | |
|
Lei Zhang
2016/08/19 03:28:46
If you stick with |shrink_width|, do kMinDialogSiz
rbpotter
2016/08/19 16:59:42
Done.
| |
| 127 int shrink_height = | |
| 128 std::max(-size->height() + kMinDialogSize.height(), -kBorder); | |
| 129 size->Enlarge(shrink_width, shrink_height); | |
| 130 #endif | |
| 118 | 131 |
| 119 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
| 120 // Limit the maximum size on MacOS X. | 133 // Limit the maximum size on MacOS X. |
| 121 // http://crbug.com/105815 | 134 // http://crbug.com/105815 |
| 122 const gfx::Size kMaxDialogSize(1000, 660); | 135 const gfx::Size kMaxDialogSize(1000, 660); |
| 123 size->SetToMin(kMaxDialogSize); | 136 size->SetToMin(kMaxDialogSize); |
| 124 #endif | 137 #endif |
| 125 } | 138 } |
| 126 | 139 |
| 127 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { | 140 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 | 375 |
| 363 RemoveInitiator(contents); | 376 RemoveInitiator(contents); |
| 364 } | 377 } |
| 365 | 378 |
| 366 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( | 379 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| 367 WebContents* initiator) { | 380 WebContents* initiator) { |
| 368 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); | 381 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); |
| 369 | 382 |
| 370 // The dialog delegates are deleted when the dialog is closed. | 383 // The dialog delegates are deleted when the dialog is closed. |
| 371 ConstrainedWebDialogDelegate* web_dialog_delegate = | 384 ConstrainedWebDialogDelegate* web_dialog_delegate = |
| 372 ShowConstrainedWebDialog(initiator->GetBrowserContext(), | 385 ShowNonClippedConstrainedWebDialog( |
| 373 new PrintPreviewDialogDelegate(initiator), | 386 initiator->GetBrowserContext(), |
| 374 initiator); | 387 new PrintPreviewDialogDelegate(initiator), initiator); |
| 375 | 388 |
| 376 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); | 389 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); |
| 377 | 390 |
| 378 // Clear the zoom level for the print preview dialog so it isn't affected by | 391 // Clear the zoom level for the print preview dialog so it isn't affected by |
| 379 // the default zoom level. This also controls the zoom level of the OOP PDF | 392 // the default zoom level. This also controls the zoom level of the OOP PDF |
| 380 // extension when iframed by the print preview dialog. | 393 // extension when iframed by the print preview dialog. |
| 381 GURL print_url(chrome::kChromeUIPrintURL); | 394 GURL print_url(chrome::kChromeUIPrintURL); |
| 382 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) | 395 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) |
| 383 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); | 396 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); |
| 384 PrintViewManager::CreateForWebContents(preview_dialog); | 397 PrintViewManager::CreateForWebContents(preview_dialog); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 if (initiator) { | 484 if (initiator) { |
| 472 RemoveObservers(initiator); | 485 RemoveObservers(initiator); |
| 473 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 486 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
| 474 } | 487 } |
| 475 | 488 |
| 476 preview_dialog_map_.erase(preview_dialog); | 489 preview_dialog_map_.erase(preview_dialog); |
| 477 RemoveObservers(preview_dialog); | 490 RemoveObservers(preview_dialog); |
| 478 } | 491 } |
| 479 | 492 |
| 480 } // namespace printing | 493 } // namespace printing |
| OLD | NEW |