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