Chromium Code Reviews| 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); | |
|
csilv
2011/11/14 19:34:14
nit: space after comma, indent 4 spaces
kmadhusu
2011/11/16 17:59:40
Done.
| |
| 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 11 matching lines...) Expand all Loading... | |
| 175 function disableInputElementsInSidebar() { | 182 function disableInputElementsInSidebar() { |
| 176 var els = $('navbar-container').querySelectorAll('input, button, select'); | 183 var els = $('navbar-container').querySelectorAll('input, button, select'); |
| 177 for (var i = 0; i < els.length; i++) { | 184 for (var i = 0; i < els.length; i++) { |
| 178 if (els[i] == printHeader.cancelButton) | 185 if (els[i] == printHeader.cancelButton) |
| 179 continue; | 186 continue; |
| 180 els[i].disabled = true; | 187 els[i].disabled = true; |
| 181 } | 188 } |
| 182 } | 189 } |
| 183 | 190 |
| 184 /** | 191 /** |
| 192 * Enables the input elements in the sidebar. | |
| 193 */ | |
| 194 function enableInputElementsInSidebar() { | |
| 195 var els = $('navbar-container').querySelectorAll('input, button, select'); | |
| 196 for (var i = 0; i < els.length; i++) | |
| 197 els[i].disabled = false; | |
| 198 } | |
| 199 | |
| 200 /** | |
| 185 * Disables the controls in the sidebar, shows the throbber and instructs the | 201 * Disables the controls in the sidebar, shows the throbber and instructs the |
| 186 * backend to open the native print dialog. | 202 * backend to open the native print dialog. |
| 187 */ | 203 */ |
| 188 function onSystemDialogLinkClicked() { | 204 function onSystemDialogLinkClicked() { |
| 189 if (showingSystemDialog) | 205 if (showingSystemDialog) |
| 190 return; | 206 return; |
| 191 showingSystemDialog = true; | 207 showingSystemDialog = true; |
| 192 disableInputElementsInSidebar(); | 208 disableInputElementsInSidebar(); |
| 193 $('system-dialog-throbber').hidden = false; | 209 $('system-dialog-throbber').hidden = false; |
| 194 chrome.send('showSystemDialog'); | 210 chrome.send('showSystemDialog'); |
| 195 } | 211 } |
| 196 | 212 |
| 197 /** | 213 /** |
| 214 * Disables the controls in the sidebar, shows the throbber and instructs the | |
| 215 * backend to open the pdf in native preview app. This is only for Mac. | |
| 216 */ | |
| 217 function onOpenPdfInPreviewLinkClicked() { | |
| 218 if (previewAppRequested) | |
| 219 return; | |
| 220 previewAppRequested = true; | |
| 221 disableInputElementsInSidebar(); | |
| 222 $('open-preview-app-throbber').hidden = false; | |
| 223 printHeader.disableCancelButton(); | |
| 224 requestToPrintDocument(); | |
| 225 } | |
| 226 | |
| 227 /** | |
| 198 * Similar to onSystemDialogLinkClicked(), but specific to the | 228 * Similar to onSystemDialogLinkClicked(), but specific to the |
| 199 * 'Launch native print dialog' UI. | 229 * 'Launch native print dialog' UI. |
| 200 */ | 230 */ |
| 201 function launchNativePrintDialog() { | 231 function launchNativePrintDialog() { |
| 202 if (showingSystemDialog) | 232 if (showingSystemDialog) |
| 203 return; | 233 return; |
| 204 showingSystemDialog = true; | 234 showingSystemDialog = true; |
| 205 previewArea.errorButton.disabled = true; | 235 previewArea.errorButton.disabled = true; |
| 206 printHeader.disableCancelButton(); | 236 printHeader.disableCancelButton(); |
| 207 $('native-print-dialog-throbber').hidden = false; | 237 $('native-print-dialog-throbber').hidden = false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 275 } |
| 246 | 276 |
| 247 /** | 277 /** |
| 248 * Gets the selected printer capabilities and updates the controls accordingly. | 278 * Gets the selected printer capabilities and updates the controls accordingly. |
| 249 */ | 279 */ |
| 250 function updateControlsWithSelectedPrinterCapabilities() { | 280 function updateControlsWithSelectedPrinterCapabilities() { |
| 251 var printerList = $('printer-list'); | 281 var printerList = $('printer-list'); |
| 252 var selectedIndex = printerList.selectedIndex; | 282 var selectedIndex = printerList.selectedIndex; |
| 253 if (selectedIndex < 0) | 283 if (selectedIndex < 0) |
| 254 return; | 284 return; |
| 285 if (cr.isMac) | |
| 286 $('open-pdf-in-preview-link').disabled = false; | |
| 287 | |
| 255 var skip_refresh = false; | 288 var skip_refresh = false; |
| 256 var selectedValue = printerList.options[selectedIndex].value; | 289 var selectedValue = printerList.options[selectedIndex].value; |
| 257 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { | 290 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
| 258 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], | 291 cloudprint.updatePrinterCaps(printerList.options[selectedIndex], |
| 259 doUpdateCloudPrinterCapabilities); | 292 doUpdateCloudPrinterCapabilities); |
| 260 skip_refresh = true; | 293 skip_refresh = true; |
| 261 } else if (selectedValue == SIGN_IN || | 294 } else if (selectedValue == SIGN_IN || |
| 262 selectedValue == MANAGE_CLOUD_PRINTERS || | 295 selectedValue == MANAGE_CLOUD_PRINTERS || |
| 263 selectedValue == MANAGE_LOCAL_PRINTERS) { | 296 selectedValue == MANAGE_LOCAL_PRINTERS) { |
| 264 printerList.selectedIndex = lastSelectedPrinterIndex; | 297 printerList.selectedIndex = lastSelectedPrinterIndex; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 * Asks the browser to print the preview PDF based on current print | 492 * Asks the browser to print the preview PDF based on current print |
| 460 * settings. If the preview is still loading, printPendingFile() will get | 493 * settings. If the preview is still loading, printPendingFile() will get |
| 461 * called once the preview loads. | 494 * called once the preview loads. |
| 462 */ | 495 */ |
| 463 function requestToPrintDocument() { | 496 function requestToPrintDocument() { |
| 464 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; | 497 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; |
| 465 var selectedPrinterName = getSelectedPrinterName(); | 498 var selectedPrinterName = getSelectedPrinterName(); |
| 466 var printToPDF = selectedPrinterName == PRINT_TO_PDF; | 499 var printToPDF = selectedPrinterName == PRINT_TO_PDF; |
| 467 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; | 500 var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT; |
| 468 if (hasPendingPrintDocumentRequest) { | 501 if (hasPendingPrintDocumentRequest) { |
| 469 if (printToPDF) { | 502 if (previewAppRequested) { |
| 503 previewArea.showCustomMessage( | |
| 504 localStrings.getString('openingPDFInPreview')); | |
| 505 } else if (printToPDF) { | |
| 470 sendPrintDocumentRequest(); | 506 sendPrintDocumentRequest(); |
| 471 } else if (printWithCloudPrint) { | 507 } else if (printWithCloudPrint) { |
| 472 previewArea.showCustomMessage( | 508 previewArea.showCustomMessage( |
| 473 localStrings.getString('printWithCloudPrintWait')); | 509 localStrings.getString('printWithCloudPrintWait')); |
| 474 disableInputElementsInSidebar(); | 510 disableInputElementsInSidebar(); |
| 475 } else { | 511 } else { |
| 476 isTabHidden = true; | 512 isTabHidden = true; |
| 477 chrome.send('hidePreview'); | 513 chrome.send('hidePreview'); |
| 478 } | 514 } |
| 479 return; | 515 return; |
| 480 } | 516 } |
| 481 | 517 |
| 482 if (printToPDF) { | 518 if (printToPDF || previewAppRequested) { |
| 483 sendPrintDocumentRequest(); | 519 sendPrintDocumentRequest(); |
| 484 } else { | 520 } else { |
| 485 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); | 521 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); |
| 486 } | 522 } |
| 487 } | 523 } |
| 488 | 524 |
| 489 /** | 525 /** |
| 490 * Sends a message to cancel the pending print request. | 526 * Sends a message to cancel the pending print request. |
| 491 */ | 527 */ |
| 492 function cancelPendingPrintRequest() { | 528 function cancelPendingPrintRequest() { |
| 493 if (isTabHidden) | 529 if (isTabHidden) |
| 494 chrome.send('cancelPendingPrintRequest'); | 530 chrome.send('cancelPendingPrintRequest'); |
| 495 } | 531 } |
| 496 | 532 |
| 497 /** | 533 /** |
| 498 * Sends a message to initiate print workflow. | 534 * Sends a message to initiate print workflow. |
| 499 */ | 535 */ |
| 500 function sendPrintDocumentRequest() { | 536 function sendPrintDocumentRequest() { |
| 501 var printerList = $('printer-list'); | 537 var printerList = $('printer-list'); |
| 502 var printer = printerList[printerList.selectedIndex]; | 538 var printer = printerList[printerList.selectedIndex]; |
| 503 chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]); | 539 chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]); |
| 504 chrome.send('print', [JSON.stringify(getSettings()), | 540 |
| 541 var settings = getSettings(); | |
| 542 if (cr.isMac && previewAppRequested) | |
| 543 settings.OpenPDFInPreview = true; | |
| 544 | |
| 545 chrome.send('print', [JSON.stringify(settings), | |
| 505 cloudprint.getPrintTicketJSON(printer)]); | 546 cloudprint.getPrintTicketJSON(printer)]); |
| 506 } | 547 } |
| 507 | 548 |
| 508 /** | 549 /** |
| 509 * Loads the selected preview pages. | 550 * Loads the selected preview pages. |
| 510 */ | 551 */ |
| 511 function loadSelectedPages() { | 552 function loadSelectedPages() { |
| 512 pageSettings.updatePageSelection(); | 553 pageSettings.updatePageSelection(); |
| 513 var pageSet = pageSettings.previouslySelectedPages; | 554 var pageSet = pageSettings.previouslySelectedPages; |
| 514 var pageCount = pageSet.length; | 555 var pageCount = pageSet.length; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 localStrings.getString('previewFailed'), | 787 localStrings.getString('previewFailed'), |
| 747 localStrings.getString('launchNativeDialog'), | 788 localStrings.getString('launchNativeDialog'), |
| 748 launchNativePrintDialog); | 789 launchNativePrintDialog); |
| 749 } | 790 } |
| 750 | 791 |
| 751 /** | 792 /** |
| 752 * Display an error message when encountered invalid printer settings. | 793 * Display an error message when encountered invalid printer settings. |
| 753 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | 794 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). |
| 754 */ | 795 */ |
| 755 function invalidPrinterSettings() { | 796 function invalidPrinterSettings() { |
| 797 if (cr.isMac) { | |
| 798 if (previewAppRequested) { | |
| 799 $('open-preview-app-throbber').hidden = true; | |
| 800 previewArea.clearCustomMessageWithDots(); | |
| 801 previewAppRequested = false; | |
| 802 hasPendingPrintDocumentRequest = false; | |
| 803 enableInputElementsInSidebar(); | |
| 804 } | |
| 805 $('open-pdf-in-preview-link').disabled = true; | |
| 806 } | |
| 756 previewArea.displayErrorMessageAndNotify( | 807 previewArea.displayErrorMessageAndNotify( |
| 757 localStrings.getString('invalidPrinterSettings')); | 808 localStrings.getString('invalidPrinterSettings')); |
| 758 } | 809 } |
| 759 | 810 |
| 760 /** | 811 /** |
| 761 * Called when the PDF plugin loads its document. | 812 * Called when the PDF plugin loads its document. |
| 762 */ | 813 */ |
| 763 function onPDFLoad() { | 814 function onPDFLoad() { |
| 764 if (previewModifiable) { | 815 if (previewModifiable) { |
| 765 setPluginPreviewPageCount(); | 816 setPluginPreviewPageCount(); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1100 <include src="copies_settings.js"/> | 1151 <include src="copies_settings.js"/> |
| 1101 <include src="header_footer_settings.js"/> | 1152 <include src="header_footer_settings.js"/> |
| 1102 <include src="layout_settings.js"/> | 1153 <include src="layout_settings.js"/> |
| 1103 <include src="color_settings.js"/> | 1154 <include src="color_settings.js"/> |
| 1104 <include src="margin_settings.js"/> | 1155 <include src="margin_settings.js"/> |
| 1105 <include src="margin_textbox.js"/> | 1156 <include src="margin_textbox.js"/> |
| 1106 <include src="margin_utils.js"/> | 1157 <include src="margin_utils.js"/> |
| 1107 <include src="margins_ui.js"/> | 1158 <include src="margins_ui.js"/> |
| 1108 <include src="margins_ui_pair.js"/> | 1159 <include src="margins_ui_pair.js"/> |
| 1109 <include src="preview_area.js"/> | 1160 <include src="preview_area.js"/> |
| OLD | NEW |