| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * Disables the controls in the sidebar, shows the throbber and instructs the | 184 * Disables the controls in the sidebar, shows the throbber and instructs the |
| 185 * backend to open the native print dialog. | 185 * backend to open the native print dialog. |
| 186 */ | 186 */ |
| 187 function onSystemDialogLinkClicked() { | 187 function onSystemDialogLinkClicked() { |
| 188 if (showingSystemDialog) | 188 if (showingSystemDialog) |
| 189 return; | 189 return; |
| 190 showingSystemDialog = true; | 190 showingSystemDialog = true; |
| 191 disableInputElementsInSidebar(); | 191 disableInputElementsInSidebar(); |
| 192 printHeader.disableCancelButton(); |
| 192 $('system-dialog-throbber').hidden = false; | 193 $('system-dialog-throbber').hidden = false; |
| 193 chrome.send('showSystemDialog'); | 194 chrome.send('showSystemDialog'); |
| 194 } | 195 } |
| 195 | 196 |
| 196 /** | 197 /** |
| 197 * Similar to onSystemDialogLinkClicked(), but specific to the | 198 * Similar to onSystemDialogLinkClicked(), but specific to the |
| 198 * 'Launch native print dialog' UI. | 199 * 'Launch native print dialog' UI. |
| 199 */ | 200 */ |
| 200 function launchNativePrintDialog() { | 201 function launchNativePrintDialog() { |
| 201 if (showingSystemDialog) | 202 if (showingSystemDialog) |
| 202 return; | 203 return; |
| 203 showingSystemDialog = true; | 204 showingSystemDialog = true; |
| 204 previewArea.errorButton.disabled = true; | 205 previewArea.errorButton.disabled = true; |
| 205 printHeader.disableCancelButton(); | 206 printHeader.disableCancelButton(); |
| 206 $('native-print-dialog-throbber').hidden = false; | 207 $('native-print-dialog-throbber').hidden = false; |
| 207 chrome.send('showSystemDialog'); | 208 chrome.send('showSystemDialog'); |
| 208 } | 209 } |
| 209 | 210 |
| 210 /** | 211 /** |
| 211 * Disables the controls which need the initiator tab to generate preview | |
| 212 * data. This function is called when the initiator tab has crashed. | |
| 213 * @param {string} initiatorTabURL The URL of the initiator tab. | |
| 214 */ | |
| 215 function onInitiatorTabCrashed(initiatorTabURL) { | |
| 216 disableInputElementsInSidebar(); | |
| 217 if (initiatorTabURL) { | |
| 218 previewArea.displayErrorMessageWithButtonAndNotify( | |
| 219 localStrings.getString('initiatorTabCrashed'), | |
| 220 localStrings.getString('reopenPage'), | |
| 221 function() { chrome.send('reloadCrashedInitiatorTab'); }); | |
| 222 } else { | |
| 223 previewArea.displayErrorMessageAndNotify( | |
| 224 localStrings.getString('initiatorTabCrashed')); | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 /** | |
| 229 * Disables the controls which need the initiator tab to generate preview | |
| 230 * data. This function is called when the initiator tab is closed. | |
| 231 * @param {string} initiatorTabURL The URL of the initiator tab. | |
| 232 */ | |
| 233 function onInitiatorTabClosed(initiatorTabURL) { | |
| 234 disableInputElementsInSidebar(); | |
| 235 if (initiatorTabURL) { | |
| 236 previewArea.displayErrorMessageWithButtonAndNotify( | |
| 237 localStrings.getString('initiatorTabClosed'), | |
| 238 localStrings.getString('reopenPage'), | |
| 239 function() { window.location = initiatorTabURL; }); | |
| 240 } else { | |
| 241 previewArea.displayErrorMessageAndNotify( | |
| 242 localStrings.getString('initiatorTabClosed')); | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 /** | |
| 247 * Gets the selected printer capabilities and updates the controls accordingly. | 212 * Gets the selected printer capabilities and updates the controls accordingly. |
| 248 */ | 213 */ |
| 249 function updateControlsWithSelectedPrinterCapabilities() { | 214 function updateControlsWithSelectedPrinterCapabilities() { |
| 250 var printerList = $('printer-list'); | 215 var printerList = $('printer-list'); |
| 251 var selectedIndex = printerList.selectedIndex; | 216 var selectedIndex = printerList.selectedIndex; |
| 252 if (selectedIndex < 0) | 217 if (selectedIndex < 0) |
| 253 return; | 218 return; |
| 254 var skip_refresh = false; | 219 var skip_refresh = false; |
| 255 var selectedValue = printerList.options[selectedIndex].value; | 220 var selectedValue = printerList.options[selectedIndex].value; |
| 256 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { | 221 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 * capabilities of the currently selected printer. It is called from C++ too. | 276 * capabilities of the currently selected printer. It is called from C++ too. |
| 312 * @param {Object} settingInfo printer setting information. | 277 * @param {Object} settingInfo printer setting information. |
| 313 */ | 278 */ |
| 314 function updateWithPrinterCapabilities(settingInfo) { | 279 function updateWithPrinterCapabilities(settingInfo) { |
| 315 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); | 280 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
| 316 customEvent.printerCapabilities = settingInfo; | 281 customEvent.printerCapabilities = settingInfo; |
| 317 document.dispatchEvent(customEvent); | 282 document.dispatchEvent(customEvent); |
| 318 } | 283 } |
| 319 | 284 |
| 320 /** | 285 /** |
| 286 * Reloads the printer list. |
| 287 */ |
| 288 function reloadPrintersList() { |
| 289 $('printer-list').length = 0; |
| 290 firstCloudPrintOptionPos = 0; |
| 291 lastCloudPrintOptionPos = 0; |
| 292 chrome.send('getPrinters'); |
| 293 } |
| 294 |
| 295 /** |
| 321 * Turn on the integration of Cloud Print. | 296 * Turn on the integration of Cloud Print. |
| 322 * @param {string} cloudPrintUrl The URL to use for cloud print servers. | 297 * @param {string} cloudPrintUrl The URL to use for cloud print servers. |
| 323 */ | 298 */ |
| 324 function setUseCloudPrint(cloudPrintURL) { | 299 function setUseCloudPrint(cloudPrintURL) { |
| 325 useCloudPrint = true; | 300 useCloudPrint = true; |
| 326 cloudprint.setBaseURL(cloudPrintURL); | 301 cloudprint.setBaseURL(cloudPrintURL); |
| 327 } | 302 } |
| 328 | 303 |
| 329 /** | 304 /** |
| 330 * Take the PDF data handed to us and submit it to the cloud, closing the print | 305 * Take the PDF data handed to us and submit it to the cloud, closing the print |
| 331 * preview tab once the upload is successful. | 306 * preview tab once the upload is successful. |
| 332 * @param {string} data Data to send as the print job. | 307 * @param {string} data Data to send as the print job. |
| 333 */ | 308 */ |
| 334 function printToCloud(data) { | 309 function printToCloud(data) { |
| 335 cloudprint.printToCloud(data, finishedCloudPrinting); | 310 cloudprint.printToCloud(data, finishedCloudPrinting); |
| 336 } | 311 } |
| 337 | 312 |
| 338 /** | 313 /** |
| 339 * Cloud print upload of the PDF file is finished, time to close the dialog. | 314 * Cloud print upload of the PDF file is finished, time to close the dialog. |
| 340 */ | 315 */ |
| 341 function finishedCloudPrinting() { | 316 function finishedCloudPrinting() { |
| 342 window.location = cloudprint.getBaseURL(); | 317 closePrintPreviewTab(); |
| 343 } | 318 } |
| 344 | 319 |
| 345 /** | 320 /** |
| 346 * Checks whether the specified settings are valid. | 321 * Checks whether the specified settings are valid. |
| 347 * | 322 * |
| 348 * @return {boolean} true if settings are valid, false if not. | 323 * @return {boolean} true if settings are valid, false if not. |
| 349 */ | 324 */ |
| 350 function areSettingsValid() { | 325 function areSettingsValid() { |
| 351 var selectedPrinter = getSelectedPrinterName(); | 326 var selectedPrinter = getSelectedPrinterName(); |
| 352 return pageSettings.isPageSelectionValid() && | 327 return pageSettings.isPageSelectionValid() && |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), | 525 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), |
| 551 pageCount, | 526 pageCount, |
| 552 previewModifiable]); | 527 previewModifiable]); |
| 553 } | 528 } |
| 554 | 529 |
| 555 /** | 530 /** |
| 556 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | 531 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print |
| 557 * preview tab regarding the file selection cancel event. | 532 * preview tab regarding the file selection cancel event. |
| 558 */ | 533 */ |
| 559 function fileSelectionCancelled() { | 534 function fileSelectionCancelled() { |
| 560 // TODO(thestig) re-enable controls here. | 535 printHeader.enableCancelButton(); |
| 561 } | 536 } |
| 562 | 537 |
| 563 /** | 538 /** |
| 564 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print | 539 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print |
| 565 * preview tab regarding the file selection completed event. | 540 * preview tab regarding the file selection completed event. |
| 566 */ | 541 */ |
| 567 function fileSelectionCompleted() { | 542 function fileSelectionCompleted() { |
| 568 // If the file selection is completed and the tab is not already closed it | 543 // If the file selection is completed and the tab is not already closed it |
| 569 // means that a pending print to pdf request exists. | 544 // means that a pending print to pdf request exists. |
| 570 disableInputElementsInSidebar(); | 545 disableInputElementsInSidebar(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 591 } else { | 566 } else { |
| 592 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 567 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
| 593 updateControlsWithSelectedPrinterCapabilities(); | 568 updateControlsWithSelectedPrinterCapabilities(); |
| 594 } | 569 } |
| 595 } | 570 } |
| 596 chrome.send('getPrinters'); | 571 chrome.send('getPrinters'); |
| 597 } | 572 } |
| 598 | 573 |
| 599 /** | 574 /** |
| 600 * Fill the printer list drop down. | 575 * Fill the printer list drop down. |
| 601 * Called from PrintPreviewHandler::SendPrinterList(). | 576 * Called from PrintPreviewHandler::SetupPrinterList(). |
| 602 * @param {Array} printers Array of printer info objects. | 577 * @param {Array} printers Array of printer info objects. |
| 603 */ | 578 */ |
| 604 function setPrinters(printers) { | 579 function setPrinters(printers) { |
| 605 var printerList = $('printer-list'); | 580 var printerList = $('printer-list'); |
| 606 // Remove empty entry added by setDefaultPrinter. | 581 // Remove empty entry added by setDefaultPrinter. |
| 607 if (printerList[0] && printerList[0].textContent == '') | 582 if (printerList[0] && printerList[0].textContent == '') |
| 608 printerList.remove(0); | 583 printerList.remove(0); |
| 609 for (var i = 0; i < printers.length; ++i) { | 584 for (var i = 0; i < printers.length; ++i) { |
| 610 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); | 585 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); |
| 611 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 586 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 return; | 1037 return; |
| 1063 document.title = localStrings.getStringF( | 1038 document.title = localStrings.getStringF( |
| 1064 'printPreviewTitleFormat', initiatorTabTitle); | 1039 'printPreviewTitleFormat', initiatorTabTitle); |
| 1065 } | 1040 } |
| 1066 | 1041 |
| 1067 /** | 1042 /** |
| 1068 * Closes this print preview tab. | 1043 * Closes this print preview tab. |
| 1069 */ | 1044 */ |
| 1070 function closePrintPreviewTab() { | 1045 function closePrintPreviewTab() { |
| 1071 chrome.send('closePrintPreviewTab'); | 1046 chrome.send('closePrintPreviewTab'); |
| 1047 chrome.send('DialogClose'); |
| 1072 } | 1048 } |
| 1073 | 1049 |
| 1074 /** | 1050 /** |
| 1075 * Handle keyboard events. | 1051 * Handle keyboard events. |
| 1076 * @param {KeyboardEvent} e The keyboard event. | 1052 * @param {KeyboardEvent} e The keyboard event. |
| 1077 */ | 1053 */ |
| 1078 function onKeyDown(e) { | 1054 function onKeyDown(e) { |
| 1079 // Escape key closes the dialog. | 1055 // Escape key closes the dialog. |
| 1080 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { | 1056 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { |
| 1081 printHeader.disableCancelButton(); | 1057 printHeader.disableCancelButton(); |
| 1082 closePrintPreviewTab(); | 1058 closePrintPreviewTab(); |
| 1083 } | 1059 } |
| 1060 if (e.keyCode == 80) { |
| 1061 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || |
| 1062 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { |
| 1063 window.onkeydown = null; |
| 1064 onSystemDialogLinkClicked(); |
| 1065 } |
| 1066 } |
| 1084 } | 1067 } |
| 1085 | 1068 |
| 1086 window.addEventListener('DOMContentLoaded', onLoad); | 1069 window.addEventListener('DOMContentLoaded', onLoad); |
| 1087 window.onkeydown = onKeyDown; | 1070 window.onkeydown = onKeyDown; |
| 1088 | 1071 |
| 1089 /// Pull in all other scripts in a single shot. | 1072 /// Pull in all other scripts in a single shot. |
| 1090 <include src="print_preview_animations.js"/> | 1073 <include src="print_preview_animations.js"/> |
| 1091 <include src="print_preview_cloud.js"/> | 1074 <include src="print_preview_cloud.js"/> |
| 1092 <include src="print_preview_utils.js"/> | 1075 <include src="print_preview_utils.js"/> |
| 1093 <include src="print_header.js"/> | 1076 <include src="print_header.js"/> |
| 1094 <include src="page_settings.js"/> | 1077 <include src="page_settings.js"/> |
| 1095 <include src="copies_settings.js"/> | 1078 <include src="copies_settings.js"/> |
| 1096 <include src="header_footer_settings.js"/> | 1079 <include src="header_footer_settings.js"/> |
| 1097 <include src="layout_settings.js"/> | 1080 <include src="layout_settings.js"/> |
| 1098 <include src="color_settings.js"/> | 1081 <include src="color_settings.js"/> |
| 1099 <include src="margin_settings.js"/> | 1082 <include src="margin_settings.js"/> |
| 1100 <include src="margin_textbox.js"/> | 1083 <include src="margin_textbox.js"/> |
| 1101 <include src="margin_utils.js"/> | 1084 <include src="margin_utils.js"/> |
| 1102 <include src="margins_ui.js"/> | 1085 <include src="margins_ui.js"/> |
| 1103 <include src="margins_ui_pair.js"/> | 1086 <include src="margins_ui_pair.js"/> |
| 1104 <include src="preview_area.js"/> | 1087 <include src="preview_area.js"/> |
| OLD | NEW |