Chromium Code Reviews| Index: chrome/browser/resources/print_preview/print_preview.js |
| diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js |
| index 24919446d36ecbfa7522528dabf4aec3361e3cbe..5ec7cc3dbbf5161aa053671bf471fad566acfda4 100644 |
| --- a/chrome/browser/resources/print_preview/print_preview.js |
| +++ b/chrome/browser/resources/print_preview/print_preview.js |
| @@ -83,6 +83,9 @@ var previewArea; |
| // dialog. |
| var showingSystemDialog = false; |
| +// True if the user has clicked 'Open PDF in Preview' option. |
| +var previewAppRequested = false; |
| + |
| // The range of options in the printer dropdown controlled by cloud print. |
| var firstCloudPrintOptionPos = 0; |
| var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
| @@ -151,6 +154,10 @@ function onLoad() { |
| } |
| $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); |
| + if (cr.isMac) { |
| + $('open-pdf-in-preview-link').addEventListener( |
| + 'click',onOpenPdfInPreviewLinkClicked); |
|
csilv
2011/11/14 19:34:14
nit: space after comma, indent 4 spaces
kmadhusu
2011/11/16 17:59:40
Done.
|
| + } |
| $('mainview').parentElement.removeChild($('dummy-viewer')); |
| $('printer-list').disabled = true; |
| @@ -182,6 +189,15 @@ function disableInputElementsInSidebar() { |
| } |
| /** |
| + * Enables the input elements in the sidebar. |
| + */ |
| +function enableInputElementsInSidebar() { |
| + var els = $('navbar-container').querySelectorAll('input, button, select'); |
| + for (var i = 0; i < els.length; i++) |
| + els[i].disabled = false; |
| +} |
| + |
| +/** |
| * Disables the controls in the sidebar, shows the throbber and instructs the |
| * backend to open the native print dialog. |
| */ |
| @@ -195,6 +211,20 @@ function onSystemDialogLinkClicked() { |
| } |
| /** |
| + * Disables the controls in the sidebar, shows the throbber and instructs the |
| + * backend to open the pdf in native preview app. This is only for Mac. |
| + */ |
| +function onOpenPdfInPreviewLinkClicked() { |
| + if (previewAppRequested) |
| + return; |
| + previewAppRequested = true; |
| + disableInputElementsInSidebar(); |
| + $('open-preview-app-throbber').hidden = false; |
| + printHeader.disableCancelButton(); |
| + requestToPrintDocument(); |
| +} |
| + |
| +/** |
| * Similar to onSystemDialogLinkClicked(), but specific to the |
| * 'Launch native print dialog' UI. |
| */ |
| @@ -252,6 +282,9 @@ function updateControlsWithSelectedPrinterCapabilities() { |
| var selectedIndex = printerList.selectedIndex; |
| if (selectedIndex < 0) |
| return; |
| + if (cr.isMac) |
| + $('open-pdf-in-preview-link').disabled = false; |
| + |
| var skip_refresh = false; |
| var selectedValue = printerList.options[selectedIndex].value; |
| if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
| @@ -466,7 +499,10 @@ function requestToPrintDocument() { |
| var printToPDF = selectedPrinterName == PRINT_TO_PDF; |
| var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; |
| if (hasPendingPrintDocumentRequest) { |
| - if (printToPDF) { |
| + if (previewAppRequested) { |
| + previewArea.showCustomMessage( |
| + localStrings.getString('openingPDFInPreview')); |
| + } else if (printToPDF) { |
| sendPrintDocumentRequest(); |
| } else if (printWithCloudPrint) { |
| previewArea.showCustomMessage( |
| @@ -479,7 +515,7 @@ function requestToPrintDocument() { |
| return; |
| } |
| - if (printToPDF) { |
| + if (printToPDF || previewAppRequested) { |
| sendPrintDocumentRequest(); |
| } else { |
| window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); |
| @@ -501,7 +537,12 @@ function sendPrintDocumentRequest() { |
| var printerList = $('printer-list'); |
| var printer = printerList[printerList.selectedIndex]; |
| chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]); |
| - chrome.send('print', [JSON.stringify(getSettings()), |
| + |
| + var settings = getSettings(); |
| + if (cr.isMac && previewAppRequested) |
| + settings.OpenPDFInPreview = true; |
| + |
| + chrome.send('print', [JSON.stringify(settings), |
| cloudprint.getPrintTicketJSON(printer)]); |
| } |
| @@ -753,6 +794,16 @@ function printPreviewFailed() { |
| * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). |
| */ |
| function invalidPrinterSettings() { |
| + if (cr.isMac) { |
| + if (previewAppRequested) { |
| + $('open-preview-app-throbber').hidden = true; |
| + previewArea.clearCustomMessageWithDots(); |
| + previewAppRequested = false; |
| + hasPendingPrintDocumentRequest = false; |
| + enableInputElementsInSidebar(); |
| + } |
| + $('open-pdf-in-preview-link').disabled = true; |
| + } |
| previewArea.displayErrorMessageAndNotify( |
| localStrings.getString('invalidPrinterSettings')); |
| } |