| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate(WebContents* initiator) | 72 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate(WebContents* initiator) |
| 73 : initiator_(initiator) { | 73 : initiator_(initiator) { |
| 74 } | 74 } |
| 75 | 75 |
| 76 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { | 76 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { |
| 77 } | 77 } |
| 78 | 78 |
| 79 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { | 79 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { |
| 80 // Not used, returning dummy value. | 80 #if defined(USE_AURA) |
| 81 NOTREACHED(); | |
| 82 return ui::MODAL_TYPE_WINDOW; | 81 return ui::MODAL_TYPE_WINDOW; |
| 82 #else |
| 83 return ui::MODAL_TYPE_CHILD; |
| 84 #endif |
| 83 } | 85 } |
| 84 | 86 |
| 85 base::string16 PrintPreviewDialogDelegate::GetDialogTitle() const { | 87 base::string16 PrintPreviewDialogDelegate::GetDialogTitle() const { |
| 86 // Only used on Windows? UI folks prefer no title. | 88 // Only used on Windows? UI folks prefer no title. |
| 87 return base::string16(); | 89 return base::string16(); |
| 88 } | 90 } |
| 89 | 91 |
| 90 GURL PrintPreviewDialogDelegate::GetDialogContentURL() const { | 92 GURL PrintPreviewDialogDelegate::GetDialogContentURL() const { |
| 91 return GURL(chrome::kChromeUIPrintURL); | 93 return GURL(chrome::kChromeUIPrintURL); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void PrintPreviewDialogDelegate::GetWebUIMessageHandlers( | 96 void PrintPreviewDialogDelegate::GetWebUIMessageHandlers( |
| 95 std::vector<WebUIMessageHandler*>* /* handlers */) const { | 97 std::vector<WebUIMessageHandler*>* /* handlers */) const { |
| 96 // PrintPreviewUI adds its own message handlers. | 98 // PrintPreviewUI adds its own message handlers. |
| 97 } | 99 } |
| 98 | 100 |
| 99 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { | 101 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { |
| 100 DCHECK(size); | 102 DCHECK(size); |
| 103 const int kBorder = 25; |
| 104 // Gives ChromeOS dialogs the requested minimum size of 438x455 without |
| 105 // changing the existing behavior on Mac OSX. For all other platforms, the min |
| 106 // size is later overridden by the size of the parent window. |
| 107 #if defined(OS_MACOSX) |
| 101 const gfx::Size kMinDialogSize(800, 480); | 108 const gfx::Size kMinDialogSize(800, 480); |
| 102 const int kBorder = 25; | 109 #else |
| 110 const gfx::Size kMinDialogSize(438, 455); |
| 111 #endif |
| 103 *size = kMinDialogSize; | 112 *size = kMinDialogSize; |
| 104 | 113 |
| 105 web_modal::WebContentsModalDialogHost* host = nullptr; | 114 web_modal::WebContentsModalDialogHost* host = nullptr; |
| 106 content::WebContents* outermost_web_contents = | 115 content::WebContents* outermost_web_contents = |
| 107 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); | 116 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); |
| 108 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); | 117 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); |
| 109 if (browser) | 118 if (browser) |
| 110 host = browser->window()->GetWebContentsModalDialogHost(); | 119 host = browser->window()->GetWebContentsModalDialogHost(); |
| 111 | 120 |
| 112 if (host) | 121 if (host) |
| 113 size->SetToMax(host->GetMaximumDialogSize()); | 122 size->SetToMax(host->GetMaximumDialogSize()); |
| 114 else | 123 else |
| 115 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); | 124 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); |
| 125 #if defined(OS_MACOSX) |
| 116 size->Enlarge(-2 * kBorder, -kBorder); | 126 size->Enlarge(-2 * kBorder, -kBorder); |
| 127 #else |
| 128 int shrink_width = |
| 129 std::max(kMinDialogSize.width() - size->width(), -2 * kBorder); |
| 130 int shrink_height = |
| 131 std::max(kMinDialogSize.height() - size->height(), -kBorder); |
| 132 size->Enlarge(shrink_width, shrink_height); |
| 133 #endif |
| 117 | 134 |
| 118 #if defined(OS_MACOSX) | 135 #if defined(OS_MACOSX) |
| 119 // Limit the maximum size on MacOS X. | 136 // Limit the maximum size on MacOS X. |
| 120 // http://crbug.com/105815 | 137 // http://crbug.com/105815 |
| 121 const gfx::Size kMaxDialogSize(1000, 660); | 138 const gfx::Size kMaxDialogSize(1000, 660); |
| 122 size->SetToMin(kMaxDialogSize); | 139 size->SetToMin(kMaxDialogSize); |
| 123 #endif | 140 #endif |
| 124 } | 141 } |
| 125 | 142 |
| 126 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { | 143 std::string PrintPreviewDialogDelegate::GetDialogArgs() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 } | 154 } |
| 138 | 155 |
| 139 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { | 156 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { |
| 140 return false; | 157 return false; |
| 141 } | 158 } |
| 142 | 159 |
| 143 } // namespace | 160 } // namespace |
| 144 | 161 |
| 145 namespace printing { | 162 namespace printing { |
| 146 | 163 |
| 164 ui::WebDialogDelegate * GetPrintPreviewDialogDelegate( |
| 165 content::WebContents * initiator) { |
| 166 return new PrintPreviewDialogDelegate(initiator); |
| 167 } |
| 168 |
| 147 PrintPreviewDialogController::PrintPreviewDialogController() | 169 PrintPreviewDialogController::PrintPreviewDialogController() |
| 148 : waiting_for_new_preview_page_(false), | 170 : waiting_for_new_preview_page_(false), |
| 149 is_creating_print_preview_dialog_(false) { | 171 is_creating_print_preview_dialog_(false) { |
| 150 } | 172 } |
| 151 | 173 |
| 152 // static | 174 // static |
| 153 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { | 175 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { |
| 154 if (!g_browser_process) | 176 if (!g_browser_process) |
| 155 return nullptr; | 177 return nullptr; |
| 156 return g_browser_process->print_preview_dialog_controller(); | 178 return g_browser_process->print_preview_dialog_controller(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 377 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 356 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) || | 378 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) || |
| 357 ui::PageTransitionTypeIncludingQualifiersIs(type, | 379 ui::PageTransitionTypeIncludingQualifiersIs(type, |
| 358 ui::PAGE_TRANSITION_LINK))) | 380 ui::PAGE_TRANSITION_LINK))) |
| 359 return; | 381 return; |
| 360 } | 382 } |
| 361 | 383 |
| 362 RemoveInitiator(contents); | 384 RemoveInitiator(contents); |
| 363 } | 385 } |
| 364 | 386 |
| 387 ConstrainedWebDialogDelegate* PrintPreviewDialogController:: |
| 388 GetWebDialogDelegate(WebContents* initiator) { |
| 389 return ShowConstrainedWebDialog( |
| 390 initiator->GetBrowserContext(), |
| 391 new PrintPreviewDialogDelegate(initiator), initiator); |
| 392 } |
| 393 |
| 365 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( | 394 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| 366 WebContents* initiator) { | 395 WebContents* initiator) { |
| 367 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); | 396 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); |
| 368 | 397 |
| 369 // The dialog delegates are deleted when the dialog is closed. | 398 // The dialog delegates are deleted when the dialog is closed. |
| 370 ConstrainedWebDialogDelegate* web_dialog_delegate = | 399 ConstrainedWebDialogDelegate* web_dialog_delegate = |
| 371 ShowConstrainedWebDialog(initiator->GetBrowserContext(), | 400 GetWebDialogDelegate(initiator); |
| 372 new PrintPreviewDialogDelegate(initiator), | |
| 373 initiator); | |
| 374 | 401 |
| 375 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); | 402 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); |
| 376 | 403 |
| 377 // Clear the zoom level for the print preview dialog so it isn't affected by | 404 // Clear the zoom level for the print preview dialog so it isn't affected by |
| 378 // the default zoom level. This also controls the zoom level of the OOP PDF | 405 // the default zoom level. This also controls the zoom level of the OOP PDF |
| 379 // extension when iframed by the print preview dialog. | 406 // extension when iframed by the print preview dialog. |
| 380 GURL print_url(chrome::kChromeUIPrintURL); | 407 GURL print_url(chrome::kChromeUIPrintURL); |
| 381 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) | 408 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) |
| 382 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); | 409 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); |
| 383 PrintViewManager::CreateForWebContents(preview_dialog); | 410 PrintViewManager::CreateForWebContents(preview_dialog); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 if (initiator) { | 514 if (initiator) { |
| 488 RemoveObservers(initiator); | 515 RemoveObservers(initiator); |
| 489 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 516 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
| 490 } | 517 } |
| 491 | 518 |
| 492 preview_dialog_map_.erase(preview_dialog); | 519 preview_dialog_map_.erase(preview_dialog); |
| 493 RemoveObservers(preview_dialog); | 520 RemoveObservers(preview_dialog); |
| 494 } | 521 } |
| 495 | 522 |
| 496 } // namespace printing | 523 } // namespace printing |
| OLD | NEW |