OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // require: cr/ui/print_preview_cloud.js | 5 // require: cr/ui/print_preview_cloud.js |
6 | 6 |
7 var localStrings = new LocalStrings(); | 7 var localStrings = new LocalStrings(); |
8 | 8 |
9 // If useCloudPrint is true we attempt to connect to cloud print | 9 // If useCloudPrint is true we attempt to connect to cloud print |
10 // and populate the list of printers with cloud print printers. | 10 // and populate the list of printers with cloud print printers. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 var colorSettings; | 76 var colorSettings; |
77 | 77 |
78 // @type {print_preview.PreviewArea} Holds information related to the preview | 78 // @type {print_preview.PreviewArea} Holds information related to the preview |
79 // area (on the right). | 79 // area (on the right). |
80 var previewArea; | 80 var previewArea; |
81 | 81 |
82 // True if the user has click 'Advanced...' in order to open the system print | 82 // True if the user has click 'Advanced...' in order to open the system print |
83 // dialog. | 83 // dialog. |
84 var showingSystemDialog = false; | 84 var showingSystemDialog = false; |
85 | 85 |
| 86 // True if the user has clicked 'Open PDF in Preview' option. |
| 87 var previewAppRequested = false; |
| 88 |
86 // The range of options in the printer dropdown controlled by cloud print. | 89 // The range of options in the printer dropdown controlled by cloud print. |
87 var firstCloudPrintOptionPos = 0; | 90 var firstCloudPrintOptionPos = 0; |
88 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; | 91 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
89 | 92 |
90 // Store the current previewUid. | 93 // Store the current previewUid. |
91 var currentPreviewUid = ''; | 94 var currentPreviewUid = ''; |
92 | 95 |
93 // True if we need to generate draft preview data. | 96 // True if we need to generate draft preview data. |
94 var generateDraftData = true; | 97 var generateDraftData = true; |
95 | 98 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 $('cancel-button').focus(); | 147 $('cancel-button').focus(); |
145 previewArea.displayErrorMessageWithButtonAndNotify( | 148 previewArea.displayErrorMessageWithButtonAndNotify( |
146 localStrings.getString('noPlugin'), | 149 localStrings.getString('noPlugin'), |
147 localStrings.getString('launchNativeDialog'), | 150 localStrings.getString('launchNativeDialog'), |
148 launchNativePrintDialog); | 151 launchNativePrintDialog); |
149 $('mainview').parentElement.removeChild($('dummy-viewer')); | 152 $('mainview').parentElement.removeChild($('dummy-viewer')); |
150 return; | 153 return; |
151 } | 154 } |
152 | 155 |
153 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); | 156 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); |
| 157 if (cr.isMac) { |
| 158 $('open-pdf-in-preview-link').addEventListener( |
| 159 'click', onOpenPdfInPreviewLinkClicked); |
| 160 } |
154 $('mainview').parentElement.removeChild($('dummy-viewer')); | 161 $('mainview').parentElement.removeChild($('dummy-viewer')); |
155 | 162 |
156 $('printer-list').disabled = true; | 163 $('printer-list').disabled = true; |
157 | 164 |
158 pageSettings = print_preview.PageSettings.getInstance(); | 165 pageSettings = print_preview.PageSettings.getInstance(); |
159 copiesSettings = print_preview.CopiesSettings.getInstance(); | 166 copiesSettings = print_preview.CopiesSettings.getInstance(); |
160 layoutSettings = print_preview.LayoutSettings.getInstance(); | 167 layoutSettings = print_preview.LayoutSettings.getInstance(); |
161 marginSettings = print_preview.MarginSettings.getInstance(); | 168 marginSettings = print_preview.MarginSettings.getInstance(); |
162 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 169 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
163 colorSettings = print_preview.ColorSettings.getInstance(); | 170 colorSettings = print_preview.ColorSettings.getInstance(); |
(...skipping 27 matching lines...) Expand all Loading... |
191 function disableInputElementsInSidebar() { | 198 function disableInputElementsInSidebar() { |
192 var els = $('navbar-container').querySelectorAll('input, button, select'); | 199 var els = $('navbar-container').querySelectorAll('input, button, select'); |
193 for (var i = 0; i < els.length; i++) { | 200 for (var i = 0; i < els.length; i++) { |
194 if (els[i] == printHeader.cancelButton) | 201 if (els[i] == printHeader.cancelButton) |
195 continue; | 202 continue; |
196 els[i].disabled = true; | 203 els[i].disabled = true; |
197 } | 204 } |
198 } | 205 } |
199 | 206 |
200 /** | 207 /** |
| 208 * Enables the input elements in the sidebar. |
| 209 */ |
| 210 function enableInputElementsInSidebar() { |
| 211 var els = $('navbar-container').querySelectorAll('input, button, select'); |
| 212 for (var i = 0; i < els.length; i++) |
| 213 els[i].disabled = false; |
| 214 } |
| 215 |
| 216 /** |
201 * Disables the controls in the sidebar, shows the throbber and instructs the | 217 * Disables the controls in the sidebar, shows the throbber and instructs the |
202 * backend to open the native print dialog. | 218 * backend to open the native print dialog. |
203 */ | 219 */ |
204 function onSystemDialogLinkClicked() { | 220 function onSystemDialogLinkClicked() { |
205 if (showingSystemDialog) | 221 if (showingSystemDialog) |
206 return; | 222 return; |
207 showingSystemDialog = true; | 223 showingSystemDialog = true; |
208 disableInputElementsInSidebar(); | 224 disableInputElementsInSidebar(); |
209 printHeader.disableCancelButton(); | 225 printHeader.disableCancelButton(); |
210 $('system-dialog-throbber').hidden = false; | 226 $('system-dialog-throbber').hidden = false; |
211 chrome.send('showSystemDialog'); | 227 chrome.send('showSystemDialog'); |
212 } | 228 } |
213 | 229 |
214 /** | 230 /** |
| 231 * Disables the controls in the sidebar, shows the throbber and instructs the |
| 232 * backend to open the pdf in native preview app. This is only for Mac. |
| 233 */ |
| 234 function onOpenPdfInPreviewLinkClicked() { |
| 235 if (previewAppRequested) |
| 236 return; |
| 237 previewAppRequested = true; |
| 238 disableInputElementsInSidebar(); |
| 239 $('open-preview-app-throbber').hidden = false; |
| 240 printHeader.disableCancelButton(); |
| 241 requestToPrintDocument(); |
| 242 } |
| 243 |
| 244 /** |
215 * Similar to onSystemDialogLinkClicked(), but specific to the | 245 * Similar to onSystemDialogLinkClicked(), but specific to the |
216 * 'Launch native print dialog' UI. | 246 * 'Launch native print dialog' UI. |
217 */ | 247 */ |
218 function launchNativePrintDialog() { | 248 function launchNativePrintDialog() { |
219 if (showingSystemDialog) | 249 if (showingSystemDialog) |
220 return; | 250 return; |
221 showingSystemDialog = true; | 251 showingSystemDialog = true; |
222 previewArea.errorButton.disabled = true; | 252 previewArea.errorButton.disabled = true; |
223 printHeader.disableCancelButton(); | 253 printHeader.disableCancelButton(); |
224 $('native-print-dialog-throbber').hidden = false; | 254 $('native-print-dialog-throbber').hidden = false; |
225 chrome.send('showSystemDialog'); | 255 chrome.send('showSystemDialog'); |
226 } | 256 } |
227 | 257 |
228 /** | 258 /** |
229 * Gets the selected printer capabilities and updates the controls accordingly. | 259 * Gets the selected printer capabilities and updates the controls accordingly. |
230 */ | 260 */ |
231 function updateControlsWithSelectedPrinterCapabilities() { | 261 function updateControlsWithSelectedPrinterCapabilities() { |
232 var printerList = $('printer-list'); | 262 var printerList = $('printer-list'); |
233 var selectedIndex = printerList.selectedIndex; | 263 var selectedIndex = printerList.selectedIndex; |
234 if (selectedIndex < 0) | 264 if (selectedIndex < 0) |
235 return; | 265 return; |
| 266 if (cr.isMac) |
| 267 $('open-pdf-in-preview-link').disabled = false; |
| 268 |
236 var skip_refresh = false; | 269 var skip_refresh = false; |
237 var selectedValue = printerList.options[selectedIndex].value; | 270 var selectedValue = printerList.options[selectedIndex].value; |
238 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { | 271 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
239 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], | 272 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], |
240 doUpdateCloudPrinterCapabilities); | 273 doUpdateCloudPrinterCapabilities); |
241 skip_refresh = true; | 274 skip_refresh = true; |
242 } else if (selectedValue == SIGN_IN || | 275 } else if (selectedValue == SIGN_IN || |
243 selectedValue == MANAGE_CLOUD_PRINTERS || | 276 selectedValue == MANAGE_CLOUD_PRINTERS || |
244 selectedValue == MANAGE_LOCAL_PRINTERS) { | 277 selectedValue == MANAGE_LOCAL_PRINTERS) { |
245 printerList.selectedIndex = lastSelectedPrinterIndex; | 278 printerList.selectedIndex = lastSelectedPrinterIndex; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 * Asks the browser to print the preview PDF based on current print | 487 * Asks the browser to print the preview PDF based on current print |
455 * settings. If the preview is still loading, printPendingFile() will get | 488 * settings. If the preview is still loading, printPendingFile() will get |
456 * called once the preview loads. | 489 * called once the preview loads. |
457 */ | 490 */ |
458 function requestToPrintDocument() { | 491 function requestToPrintDocument() { |
459 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; | 492 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; |
460 var selectedPrinterName = getSelectedPrinterName(); | 493 var selectedPrinterName = getSelectedPrinterName(); |
461 var printToPDF = selectedPrinterName == PRINT_TO_PDF; | 494 var printToPDF = selectedPrinterName == PRINT_TO_PDF; |
462 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; | 495 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; |
463 if (hasPendingPrintDocumentRequest) { | 496 if (hasPendingPrintDocumentRequest) { |
464 if (printToPDF) { | 497 if (previewAppRequested) { |
| 498 previewArea.showCustomMessage( |
| 499 localStrings.getString('openingPDFInPreview')); |
| 500 } else if (printToPDF) { |
465 sendPrintDocumentRequest(); | 501 sendPrintDocumentRequest(); |
466 } else if (printWithCloudPrint) { | 502 } else if (printWithCloudPrint) { |
467 previewArea.showCustomMessage( | 503 previewArea.showCustomMessage( |
468 localStrings.getString('printWithCloudPrintWait')); | 504 localStrings.getString('printWithCloudPrintWait')); |
469 disableInputElementsInSidebar(); | 505 disableInputElementsInSidebar(); |
470 } else { | 506 } else { |
471 isTabHidden = true; | 507 isTabHidden = true; |
472 chrome.send('hidePreview'); | 508 chrome.send('hidePreview'); |
473 } | 509 } |
474 return; | 510 return; |
475 } | 511 } |
476 | 512 |
477 if (printToPDF) { | 513 if (printToPDF || previewAppRequested) { |
478 sendPrintDocumentRequest(); | 514 sendPrintDocumentRequest(); |
479 } else { | 515 } else { |
480 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); | 516 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); |
481 } | 517 } |
482 } | 518 } |
483 | 519 |
484 /** | 520 /** |
485 * Sends a message to cancel the pending print request. | 521 * Sends a message to cancel the pending print request. |
486 */ | 522 */ |
487 function cancelPendingPrintRequest() { | 523 function cancelPendingPrintRequest() { |
488 if (isTabHidden) | 524 if (isTabHidden) |
489 chrome.send('cancelPendingPrintRequest'); | 525 chrome.send('cancelPendingPrintRequest'); |
490 } | 526 } |
491 | 527 |
492 /** | 528 /** |
493 * Sends a message to initiate print workflow. | 529 * Sends a message to initiate print workflow. |
494 */ | 530 */ |
495 function sendPrintDocumentRequest() { | 531 function sendPrintDocumentRequest() { |
496 var printerList = $('printer-list'); | 532 var printerList = $('printer-list'); |
497 var printer = printerList[printerList.selectedIndex]; | 533 var printer = printerList[printerList.selectedIndex]; |
498 chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]); | 534 chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]); |
499 chrome.send('print', [JSON.stringify(getSettings()), | 535 |
| 536 var settings = getSettings(); |
| 537 if (cr.isMac && previewAppRequested) |
| 538 settings.OpenPDFInPreview = true; |
| 539 |
| 540 chrome.send('print', [JSON.stringify(settings), |
500 cloudprint.getPrintTicketJSON(printer)]); | 541 cloudprint.getPrintTicketJSON(printer)]); |
501 } | 542 } |
502 | 543 |
503 /** | 544 /** |
504 * Loads the selected preview pages. | 545 * Loads the selected preview pages. |
505 */ | 546 */ |
506 function loadSelectedPages() { | 547 function loadSelectedPages() { |
507 pageSettings.updatePageSelection(); | 548 pageSettings.updatePageSelection(); |
508 var pageSet = pageSettings.previouslySelectedPages; | 549 var pageSet = pageSettings.previouslySelectedPages; |
509 var pageCount = pageSet.length; | 550 var pageCount = pageSet.length; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 localStrings.getString('previewFailed'), | 778 localStrings.getString('previewFailed'), |
738 localStrings.getString('launchNativeDialog'), | 779 localStrings.getString('launchNativeDialog'), |
739 launchNativePrintDialog); | 780 launchNativePrintDialog); |
740 } | 781 } |
741 | 782 |
742 /** | 783 /** |
743 * Display an error message when encountered invalid printer settings. | 784 * Display an error message when encountered invalid printer settings. |
744 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | 785 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). |
745 */ | 786 */ |
746 function invalidPrinterSettings() { | 787 function invalidPrinterSettings() { |
| 788 if (cr.isMac) { |
| 789 if (previewAppRequested) { |
| 790 $('open-preview-app-throbber').hidden = true; |
| 791 previewArea.clearCustomMessageWithDots(); |
| 792 previewAppRequested = false; |
| 793 hasPendingPrintDocumentRequest = false; |
| 794 enableInputElementsInSidebar(); |
| 795 } |
| 796 $('open-pdf-in-preview-link').disabled = true; |
| 797 } |
747 previewArea.displayErrorMessageAndNotify( | 798 previewArea.displayErrorMessageAndNotify( |
748 localStrings.getString('invalidPrinterSettings')); | 799 localStrings.getString('invalidPrinterSettings')); |
749 } | 800 } |
750 | 801 |
751 /** | 802 /** |
752 * Called when the PDF plugin loads its document. | 803 * Called when the PDF plugin loads its document. |
753 */ | 804 */ |
754 function onPDFLoad() { | 805 function onPDFLoad() { |
755 if (previewModifiable) { | 806 if (previewModifiable) { |
756 setPluginPreviewPageCount(); | 807 setPluginPreviewPageCount(); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 <include src="copies_settings.js"/> | 1145 <include src="copies_settings.js"/> |
1095 <include src="header_footer_settings.js"/> | 1146 <include src="header_footer_settings.js"/> |
1096 <include src="layout_settings.js"/> | 1147 <include src="layout_settings.js"/> |
1097 <include src="color_settings.js"/> | 1148 <include src="color_settings.js"/> |
1098 <include src="margin_settings.js"/> | 1149 <include src="margin_settings.js"/> |
1099 <include src="margin_textbox.js"/> | 1150 <include src="margin_textbox.js"/> |
1100 <include src="margin_utils.js"/> | 1151 <include src="margin_utils.js"/> |
1101 <include src="margins_ui.js"/> | 1152 <include src="margins_ui.js"/> |
1102 <include src="margins_ui_pair.js"/> | 1153 <include src="margins_ui_pair.js"/> |
1103 <include src="preview_area.js"/> | 1154 <include src="preview_area.js"/> |
OLD | NEW |