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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 /** | 200 /** |
201 * 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 |
202 * backend to open the native print dialog. | 202 * backend to open the native print dialog. |
203 */ | 203 */ |
204 function onSystemDialogLinkClicked() { | 204 function onSystemDialogLinkClicked() { |
205 if (showingSystemDialog) | 205 if (showingSystemDialog) |
206 return; | 206 return; |
207 showingSystemDialog = true; | 207 showingSystemDialog = true; |
208 disableInputElementsInSidebar(); | 208 disableInputElementsInSidebar(); |
209 printHeader.disableCancelButton(); | |
210 $('system-dialog-throbber').hidden = false; | 209 $('system-dialog-throbber').hidden = false; |
211 chrome.send('showSystemDialog'); | 210 chrome.send('showSystemDialog'); |
212 } | 211 } |
213 | 212 |
214 /** | 213 /** |
215 * Similar to onSystemDialogLinkClicked(), but specific to the | 214 * Similar to onSystemDialogLinkClicked(), but specific to the |
216 * 'Launch native print dialog' UI. | 215 * 'Launch native print dialog' UI. |
217 */ | 216 */ |
218 function launchNativePrintDialog() { | 217 function launchNativePrintDialog() { |
219 if (showingSystemDialog) | 218 if (showingSystemDialog) |
220 return; | 219 return; |
221 showingSystemDialog = true; | 220 showingSystemDialog = true; |
222 previewArea.errorButton.disabled = true; | 221 previewArea.errorButton.disabled = true; |
223 printHeader.disableCancelButton(); | 222 printHeader.disableCancelButton(); |
224 $('native-print-dialog-throbber').hidden = false; | 223 $('native-print-dialog-throbber').hidden = false; |
225 chrome.send('showSystemDialog'); | 224 chrome.send('showSystemDialog'); |
226 } | 225 } |
227 | 226 |
228 /** | 227 /** |
| 228 * Disables the controls which need the initiator tab to generate preview |
| 229 * data. This function is called when the initiator tab has crashed. |
| 230 * @param {string} initiatorTabURL The URL of the initiator tab. |
| 231 */ |
| 232 function onInitiatorTabCrashed(initiatorTabURL) { |
| 233 disableInputElementsInSidebar(); |
| 234 if (initiatorTabURL) { |
| 235 previewArea.displayErrorMessageWithButtonAndNotify( |
| 236 localStrings.getString('initiatorTabCrashed'), |
| 237 localStrings.getString('reopenPage'), |
| 238 function() { chrome.send('reloadCrashedInitiatorTab'); }); |
| 239 } else { |
| 240 previewArea.displayErrorMessageAndNotify( |
| 241 localStrings.getString('initiatorTabCrashed')); |
| 242 } |
| 243 } |
| 244 |
| 245 /** |
| 246 * Disables the controls which need the initiator tab to generate preview |
| 247 * data. This function is called when the initiator tab is closed. |
| 248 * @param {string} initiatorTabURL The URL of the initiator tab. |
| 249 */ |
| 250 function onInitiatorTabClosed(initiatorTabURL) { |
| 251 disableInputElementsInSidebar(); |
| 252 if (initiatorTabURL) { |
| 253 previewArea.displayErrorMessageWithButtonAndNotify( |
| 254 localStrings.getString('initiatorTabClosed'), |
| 255 localStrings.getString('reopenPage'), |
| 256 function() { window.location = initiatorTabURL; }); |
| 257 } else { |
| 258 previewArea.displayErrorMessageAndNotify( |
| 259 localStrings.getString('initiatorTabClosed')); |
| 260 } |
| 261 } |
| 262 |
| 263 /** |
229 * Gets the selected printer capabilities and updates the controls accordingly. | 264 * Gets the selected printer capabilities and updates the controls accordingly. |
230 */ | 265 */ |
231 function updateControlsWithSelectedPrinterCapabilities() { | 266 function updateControlsWithSelectedPrinterCapabilities() { |
232 var printerList = $('printer-list'); | 267 var printerList = $('printer-list'); |
233 var selectedIndex = printerList.selectedIndex; | 268 var selectedIndex = printerList.selectedIndex; |
234 if (selectedIndex < 0) | 269 if (selectedIndex < 0) |
235 return; | 270 return; |
236 var skip_refresh = false; | 271 var skip_refresh = false; |
237 var selectedValue = printerList.options[selectedIndex].value; | 272 var selectedValue = printerList.options[selectedIndex].value; |
238 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { | 273 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 * capabilities of the currently selected printer. It is called from C++ too. | 332 * capabilities of the currently selected printer. It is called from C++ too. |
298 * @param {Object} settingInfo printer setting information. | 333 * @param {Object} settingInfo printer setting information. |
299 */ | 334 */ |
300 function updateWithPrinterCapabilities(settingInfo) { | 335 function updateWithPrinterCapabilities(settingInfo) { |
301 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); | 336 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
302 customEvent.printerCapabilities = settingInfo; | 337 customEvent.printerCapabilities = settingInfo; |
303 document.dispatchEvent(customEvent); | 338 document.dispatchEvent(customEvent); |
304 } | 339 } |
305 | 340 |
306 /** | 341 /** |
307 * Reloads the printer list. | |
308 */ | |
309 function reloadPrintersList() { | |
310 $('printer-list').length = 0; | |
311 firstCloudPrintOptionPos = 0; | |
312 lastCloudPrintOptionPos = 0; | |
313 chrome.send('getPrinters'); | |
314 } | |
315 | |
316 /** | |
317 * Turn on the integration of Cloud Print. | 342 * Turn on the integration of Cloud Print. |
318 * @param {string} cloudPrintUrl The URL to use for cloud print servers. | 343 * @param {string} cloudPrintUrl The URL to use for cloud print servers. |
319 */ | 344 */ |
320 function setUseCloudPrint(cloudPrintURL) { | 345 function setUseCloudPrint(cloudPrintURL) { |
321 useCloudPrint = true; | 346 useCloudPrint = true; |
322 cloudprint.setBaseURL(cloudPrintURL); | 347 cloudprint.setBaseURL(cloudPrintURL); |
323 } | 348 } |
324 | 349 |
325 /** | 350 /** |
326 * Take the PDF data handed to us and submit it to the cloud, closing the print | 351 * Take the PDF data handed to us and submit it to the cloud, closing the print |
327 * preview tab once the upload is successful. | 352 * preview tab once the upload is successful. |
328 * @param {string} data Data to send as the print job. | 353 * @param {string} data Data to send as the print job. |
329 */ | 354 */ |
330 function printToCloud(data) { | 355 function printToCloud(data) { |
331 cloudprint.printToCloud(data, finishedCloudPrinting); | 356 cloudprint.printToCloud(data, finishedCloudPrinting); |
332 } | 357 } |
333 | 358 |
334 /** | 359 /** |
335 * Cloud print upload of the PDF file is finished, time to close the dialog. | 360 * Cloud print upload of the PDF file is finished, time to close the dialog. |
336 */ | 361 */ |
337 function finishedCloudPrinting() { | 362 function finishedCloudPrinting() { |
338 closePrintPreviewTab(); | 363 window.location = cloudprint.getBaseURL(); |
339 } | 364 } |
340 | 365 |
341 /** | 366 /** |
342 * Checks whether the specified settings are valid. | 367 * Checks whether the specified settings are valid. |
343 * | 368 * |
344 * @return {boolean} true if settings are valid, false if not. | 369 * @return {boolean} true if settings are valid, false if not. |
345 */ | 370 */ |
346 function areSettingsValid() { | 371 function areSettingsValid() { |
347 var selectedPrinter = getSelectedPrinterName(); | 372 var selectedPrinter = getSelectedPrinterName(); |
348 return pageSettings.isPageSelectionValid() && | 373 return pageSettings.isPageSelectionValid() && |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), | 571 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), |
547 pageCount, | 572 pageCount, |
548 previewModifiable]); | 573 previewModifiable]); |
549 } | 574 } |
550 | 575 |
551 /** | 576 /** |
552 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | 577 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print |
553 * preview tab regarding the file selection cancel event. | 578 * preview tab regarding the file selection cancel event. |
554 */ | 579 */ |
555 function fileSelectionCancelled() { | 580 function fileSelectionCancelled() { |
556 printHeader.enableCancelButton(); | 581 // TODO(thestig) re-enable controls here. |
557 } | 582 } |
558 | 583 |
559 /** | 584 /** |
560 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print | 585 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print |
561 * preview tab regarding the file selection completed event. | 586 * preview tab regarding the file selection completed event. |
562 */ | 587 */ |
563 function fileSelectionCompleted() { | 588 function fileSelectionCompleted() { |
564 // If the file selection is completed and the tab is not already closed it | 589 // If the file selection is completed and the tab is not already closed it |
565 // means that a pending print to pdf request exists. | 590 // means that a pending print to pdf request exists. |
566 disableInputElementsInSidebar(); | 591 disableInputElementsInSidebar(); |
(...skipping 20 matching lines...) Expand all Loading... |
587 } else { | 612 } else { |
588 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 613 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
589 updateControlsWithSelectedPrinterCapabilities(); | 614 updateControlsWithSelectedPrinterCapabilities(); |
590 } | 615 } |
591 } | 616 } |
592 chrome.send('getPrinters'); | 617 chrome.send('getPrinters'); |
593 } | 618 } |
594 | 619 |
595 /** | 620 /** |
596 * Fill the printer list drop down. | 621 * Fill the printer list drop down. |
597 * Called from PrintPreviewHandler::SetupPrinterList(). | 622 * Called from PrintPreviewHandler::SendPrinterList(). |
598 * @param {Array} printers Array of printer info objects. | 623 * @param {Array} printers Array of printer info objects. |
599 */ | 624 */ |
600 function setPrinters(printers) { | 625 function setPrinters(printers) { |
601 var printerList = $('printer-list'); | 626 var printerList = $('printer-list'); |
602 // Remove empty entry added by setDefaultPrinter. | 627 // Remove empty entry added by setDefaultPrinter. |
603 if (printerList[0] && printerList[0].textContent == '') | 628 if (printerList[0] && printerList[0].textContent == '') |
604 printerList.remove(0); | 629 printerList.remove(0); |
605 for (var i = 0; i < printers.length; ++i) { | 630 for (var i = 0; i < printers.length; ++i) { |
606 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); | 631 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); |
607 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 632 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 return; | 1078 return; |
1054 document.title = localStrings.getStringF( | 1079 document.title = localStrings.getStringF( |
1055 'printPreviewTitleFormat', initiatorTabTitle); | 1080 'printPreviewTitleFormat', initiatorTabTitle); |
1056 } | 1081 } |
1057 | 1082 |
1058 /** | 1083 /** |
1059 * Closes this print preview tab. | 1084 * Closes this print preview tab. |
1060 */ | 1085 */ |
1061 function closePrintPreviewTab() { | 1086 function closePrintPreviewTab() { |
1062 chrome.send('closePrintPreviewTab'); | 1087 chrome.send('closePrintPreviewTab'); |
1063 chrome.send('DialogClose'); | |
1064 } | 1088 } |
1065 | 1089 |
1066 /** | 1090 /** |
1067 * Handle keyboard events. | 1091 * Handle keyboard events. |
1068 * @param {KeyboardEvent} e The keyboard event. | 1092 * @param {KeyboardEvent} e The keyboard event. |
1069 */ | 1093 */ |
1070 function onKeyDown(e) { | 1094 function onKeyDown(e) { |
1071 // Escape key closes the dialog. | 1095 // Escape key closes the dialog. |
1072 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { | 1096 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { |
1073 printHeader.disableCancelButton(); | 1097 printHeader.disableCancelButton(); |
1074 closePrintPreviewTab(); | 1098 closePrintPreviewTab(); |
1075 } | 1099 } |
1076 if (e.keyCode == 80) { | |
1077 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || | |
1078 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { | |
1079 window.onkeydown = null; | |
1080 onSystemDialogLinkClicked(); | |
1081 } | |
1082 } | |
1083 } | 1100 } |
1084 | 1101 |
1085 window.addEventListener('DOMContentLoaded', onLoad); | 1102 window.addEventListener('DOMContentLoaded', onLoad); |
1086 window.onkeydown = onKeyDown; | 1103 window.onkeydown = onKeyDown; |
1087 | 1104 |
1088 /// Pull in all other scripts in a single shot. | 1105 /// Pull in all other scripts in a single shot. |
1089 <include src="print_preview_animations.js"/> | 1106 <include src="print_preview_animations.js"/> |
1090 <include src="print_preview_cloud.js"/> | 1107 <include src="print_preview_cloud.js"/> |
1091 <include src="print_preview_utils.js"/> | 1108 <include src="print_preview_utils.js"/> |
1092 <include src="print_header.js"/> | 1109 <include src="print_header.js"/> |
1093 <include src="page_settings.js"/> | 1110 <include src="page_settings.js"/> |
1094 <include src="copies_settings.js"/> | 1111 <include src="copies_settings.js"/> |
1095 <include src="header_footer_settings.js"/> | 1112 <include src="header_footer_settings.js"/> |
1096 <include src="layout_settings.js"/> | 1113 <include src="layout_settings.js"/> |
1097 <include src="color_settings.js"/> | 1114 <include src="color_settings.js"/> |
1098 <include src="margin_settings.js"/> | 1115 <include src="margin_settings.js"/> |
1099 <include src="margin_textbox.js"/> | 1116 <include src="margin_textbox.js"/> |
1100 <include src="margin_utils.js"/> | 1117 <include src="margin_utils.js"/> |
1101 <include src="margins_ui.js"/> | 1118 <include src="margins_ui.js"/> |
1102 <include src="margins_ui_pair.js"/> | 1119 <include src="margins_ui_pair.js"/> |
1103 <include src="preview_area.js"/> | 1120 <include src="preview_area.js"/> |
OLD | NEW |