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 size of 438x455 without changing | |
| 102 // the existing behavior on Mac OSX. For all other platforms, the min size | |
| 103 // is later overriden by the size of the parent window. | |
|
Lei Zhang
2016/08/18 20:30:57
overridden?
rbpotter
2016/08/19 01:59:09
Done.
| |
| 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); | |
|
Lei Zhang
2016/08/18 20:30:57
So no behavior changes on Windows/Linux, right?
rbpotter
2016/08/19 01:59:09
There will be no behavior changes in terms of the
Lei Zhang
2016/08/19 03:28:46
No, seems ok.
| |
| 108 #endif | |
| 104 *size = kMinDialogSize; | 109 *size = kMinDialogSize; |
| 105 | |
| 106 web_modal::WebContentsModalDialogHost* host = nullptr; | 110 web_modal::WebContentsModalDialogHost* host = nullptr; |
| 107 content::WebContents* outermost_web_contents = | 111 content::WebContents* outermost_web_contents = |
| 108 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); | 112 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); |
| 109 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); | 113 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); |
| 110 if (browser) | 114 if (browser) |
| 111 host = browser->window()->GetWebContentsModalDialogHost(); | 115 host = browser->window()->GetWebContentsModalDialogHost(); |
| 112 | 116 |
| 113 if (host) | 117 if (host) |
| 114 size->SetToMax(host->GetMaximumDialogSize()); | 118 size->SetToMax(host->GetMaximumDialogSize()); |
| 115 else | 119 else |
| 116 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); | 120 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); |
| 121 #if defined(OS_MACOSX) | |
| 117 size->Enlarge(-2 * kBorder, -kBorder); | 122 size->Enlarge(-2 * kBorder, -kBorder); |
| 118 | 123 #else |
| 124 int expand_width = | |
| 125 std::min(size->width() - kMinDialogSize.width(), 2 * kBorder); | |
| 126 int expand_height = | |
| 127 std::min(size->height() - kMinDialogSize.height(), kBorder); | |
| 128 size->Enlarge(-expand_width, -expand_height); | |
|
Lei Zhang
2016/08/18 20:30:57
Why not just calculate |expand_width| so it's nega
rbpotter
2016/08/19 01:59:09
Done. I thought it was more readable to take the m
Lei Zhang
2016/08/19 03:28:46
*shrug* If you like it better the other way, feel
| |
| 129 #endif | |
| 119 #if defined(OS_MACOSX) | 130 #if defined(OS_MACOSX) |
| 120 // Limit the maximum size on MacOS X. | 131 // Limit the maximum size on MacOS X. |
| 121 // http://crbug.com/105815 | 132 // http://crbug.com/105815 |
| 122 const gfx::Size kMaxDialogSize(1000, 660); | 133 const gfx::Size kMaxDialogSize(1000, 660); |
| 123 size->SetToMin(kMaxDialogSize); | 134 size->SetToMin(kMaxDialogSize); |
| 124 #endif | 135 #endif |
| 125 } | 136 } |
| 126 | 137 |
| 127 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { | 138 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { |
| 128 return std::string(); | 139 return std::string(); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 369 |
| 359 RemoveInitiator(contents); | 370 RemoveInitiator(contents); |
| 360 } | 371 } |
| 361 | 372 |
| 362 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( | 373 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| 363 WebContents* initiator) { | 374 WebContents* initiator) { |
| 364 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); | 375 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); |
| 365 | 376 |
| 366 // The dialog delegates are deleted when the dialog is closed. | 377 // The dialog delegates are deleted when the dialog is closed. |
| 367 ConstrainedWebDialogDelegate* web_dialog_delegate = | 378 ConstrainedWebDialogDelegate* web_dialog_delegate = |
| 368 ShowConstrainedWebDialog(initiator->GetBrowserContext(), | 379 ShowNonClippedConstrainedWebDialog( |
| 369 new PrintPreviewDialogDelegate(initiator), | 380 initiator->GetBrowserContext(), |
| 370 initiator); | 381 new PrintPreviewDialogDelegate(initiator), initiator); |
| 371 | |
| 372 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); | 382 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); |
| 373 | 383 |
| 374 // Clear the zoom level for the print preview dialog so it isn't affected by | 384 // Clear the zoom level for the print preview dialog so it isn't affected by |
| 375 // the default zoom level. This also controls the zoom level of the OOP PDF | 385 // the default zoom level. This also controls the zoom level of the OOP PDF |
| 376 // extension when iframed by the print preview dialog. | 386 // extension when iframed by the print preview dialog. |
| 377 GURL print_url(chrome::kChromeUIPrintURL); | 387 GURL print_url(chrome::kChromeUIPrintURL); |
| 378 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) | 388 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) |
| 379 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); | 389 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); |
| 380 PrintViewManager::CreateForWebContents(preview_dialog); | 390 PrintViewManager::CreateForWebContents(preview_dialog); |
| 381 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 391 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 if (initiator) { | 477 if (initiator) { |
| 468 RemoveObservers(initiator); | 478 RemoveObservers(initiator); |
| 469 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 479 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
| 470 } | 480 } |
| 471 | 481 |
| 472 preview_dialog_map_.erase(preview_dialog); | 482 preview_dialog_map_.erase(preview_dialog); |
| 473 RemoveObservers(preview_dialog); | 483 RemoveObservers(preview_dialog); |
| 474 } | 484 } |
| 475 | 485 |
| 476 } // namespace printing | 486 } // namespace printing |
| OLD | NEW |