| 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. | |
| 82 NOTREACHED(); | |
| 83 return ui::MODAL_TYPE_WINDOW; | 81 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 |
| 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(kMinDialogSize.width() - size->width(), -2 * kBorder); |
| 127 int shrink_height = |
| 128 std::max(kMinDialogSize.height() - size->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 10 matching lines...) Expand all Loading... |
| 138 } | 151 } |
| 139 | 152 |
| 140 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { | 153 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { |
| 141 return false; | 154 return false; |
| 142 } | 155 } |
| 143 | 156 |
| 144 } // namespace | 157 } // namespace |
| 145 | 158 |
| 146 namespace printing { | 159 namespace printing { |
| 147 | 160 |
| 161 ui::WebDialogDelegate * GetPrintPreviewDialogDelegate( |
| 162 content::WebContents * initiator) { |
| 163 return new PrintPreviewDialogDelegate(initiator); |
| 164 } |
| 165 |
| 148 PrintPreviewDialogController::PrintPreviewDialogController() | 166 PrintPreviewDialogController::PrintPreviewDialogController() |
| 149 : waiting_for_new_preview_page_(false), | 167 : waiting_for_new_preview_page_(false), |
| 150 is_creating_print_preview_dialog_(false) { | 168 is_creating_print_preview_dialog_(false) { |
| 151 } | 169 } |
| 152 | 170 |
| 153 // static | 171 // static |
| 154 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { | 172 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { |
| 155 if (!g_browser_process) | 173 if (!g_browser_process) |
| 156 return nullptr; | 174 return nullptr; |
| 157 return g_browser_process->print_preview_dialog_controller(); | 175 return g_browser_process->print_preview_dialog_controller(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 374 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 357 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) || | 375 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) || |
| 358 ui::PageTransitionTypeIncludingQualifiersIs(type, | 376 ui::PageTransitionTypeIncludingQualifiersIs(type, |
| 359 ui::PAGE_TRANSITION_LINK))) | 377 ui::PAGE_TRANSITION_LINK))) |
| 360 return; | 378 return; |
| 361 } | 379 } |
| 362 | 380 |
| 363 RemoveInitiator(contents); | 381 RemoveInitiator(contents); |
| 364 } | 382 } |
| 365 | 383 |
| 384 ConstrainedWebDialogDelegate* PrintPreviewDialogController:: |
| 385 GetWebDialogDelegate(WebContents* initiator) { |
| 386 return ShowTopLevelConstrainedWebDialog( |
| 387 initiator->GetBrowserContext(), |
| 388 new PrintPreviewDialogDelegate(initiator), initiator); |
| 389 } |
| 390 |
| 366 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( | 391 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
| 367 WebContents* initiator) { | 392 WebContents* initiator) { |
| 368 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); | 393 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); |
| 369 | 394 |
| 370 // The dialog delegates are deleted when the dialog is closed. | 395 // The dialog delegates are deleted when the dialog is closed. |
| 371 ConstrainedWebDialogDelegate* web_dialog_delegate = | 396 ConstrainedWebDialogDelegate* web_dialog_delegate = |
| 372 ShowConstrainedWebDialog(initiator->GetBrowserContext(), | 397 GetWebDialogDelegate(initiator); |
| 373 new PrintPreviewDialogDelegate(initiator), | 398 // ShowTopLevelConstrainedWebDialog( |
| 374 initiator); | 399 // initiator->GetBrowserContext(), |
| 400 // new PrintPreviewDialogDelegate(initiator), initiator); |
| 375 | 401 |
| 376 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); | 402 WebContents* preview_dialog = web_dialog_delegate->GetWebContents(); |
| 377 | 403 |
| 378 // 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 |
| 379 // 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 |
| 380 // extension when iframed by the print preview dialog. | 406 // extension when iframed by the print preview dialog. |
| 381 GURL print_url(chrome::kChromeUIPrintURL); | 407 GURL print_url(chrome::kChromeUIPrintURL); |
| 382 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) | 408 content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) |
| 383 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); | 409 ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); |
| 384 PrintViewManager::CreateForWebContents(preview_dialog); | 410 PrintViewManager::CreateForWebContents(preview_dialog); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (initiator) { | 514 if (initiator) { |
| 489 RemoveObservers(initiator); | 515 RemoveObservers(initiator); |
| 490 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 516 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
| 491 } | 517 } |
| 492 | 518 |
| 493 preview_dialog_map_.erase(preview_dialog); | 519 preview_dialog_map_.erase(preview_dialog); |
| 494 RemoveObservers(preview_dialog); | 520 RemoveObservers(preview_dialog); |
| 495 } | 521 } |
| 496 | 522 |
| 497 } // namespace printing | 523 } // namespace printing |
| OLD | NEW |