Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 7976017: Simplified print preview printer selection to be more consistent with Chrome (Closed)
Patch Set: Fixed flow in chrome Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // The range of options in the printer dropdown controlled by cloud print. 78 // The range of options in the printer dropdown controlled by cloud print.
79 var firstCloudPrintOptionPos = 0; 79 var firstCloudPrintOptionPos = 0;
80 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; 80 var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
81 81
82 // Store the current previewUid. 82 // Store the current previewUid.
83 var currentPreviewUid = ''; 83 var currentPreviewUid = '';
84 84
85 // True if we need to generate draft preview data. 85 // True if we need to generate draft preview data.
86 var generateDraftData = true; 86 var generateDraftData = true;
87 87
88 // TODO(abodenha@chromium.org) A lot of cloud print specific logic has
89 // made its way into this file. Refactor to create a cleaner boundary
90 // between print preview and GCP code. Reference bug 88098 when fixing.
91
92 // A dictionary of cloud printers that have been added to the printer 88 // A dictionary of cloud printers that have been added to the printer
93 // dropdown. 89 // dropdown.
94 var addedCloudPrinters = {}; 90 var addedCloudPrinters = {};
95 91
96 // The maximum number of cloud printers to allow in the dropdown. 92 // The maximum number of cloud printers to allow in the dropdown.
97 const maxCloudPrinters = 10; 93 const maxCloudPrinters = 10;
98 94
99 const MIN_REQUEST_ID = 0; 95 const MIN_REQUEST_ID = 0;
100 const MAX_REQUEST_ID = 32000; 96 const MAX_REQUEST_ID = 32000;
101 97
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 * Gets the selected printer capabilities and updates the controls accordingly. 212 * Gets the selected printer capabilities and updates the controls accordingly.
217 */ 213 */
218 function updateControlsWithSelectedPrinterCapabilities() { 214 function updateControlsWithSelectedPrinterCapabilities() {
219 var printerList = $('printer-list'); 215 var printerList = $('printer-list');
220 var selectedIndex = printerList.selectedIndex; 216 var selectedIndex = printerList.selectedIndex;
221 if (selectedIndex < 0) 217 if (selectedIndex < 0)
222 return; 218 return;
223 var skip_refresh = false; 219 var skip_refresh = false;
224 var selectedValue = printerList.options[selectedIndex].value; 220 var selectedValue = printerList.options[selectedIndex].value;
225 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { 221 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) {
226 updateWithCloudPrinterCapabilities(); 222 cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
227 skip_refresh = true; 223 doUpdateCloudPrinterCapabilities);
228 } else if (selectedValue == PRINT_WITH_CLOUD_PRINT) {
229 // If a preview is pending this will just disable controls.
230 // Once the preview completes we'll try again.
231 printWithCloudPrintDialog();
232 skip_refresh = true; 224 skip_refresh = true;
233 } else if (selectedValue == SIGN_IN || 225 } else if (selectedValue == SIGN_IN ||
234 selectedValue == MANAGE_CLOUD_PRINTERS || 226 selectedValue == MANAGE_CLOUD_PRINTERS ||
235 selectedValue == MANAGE_LOCAL_PRINTERS) { 227 selectedValue == MANAGE_LOCAL_PRINTERS) {
236 printerList.selectedIndex = lastSelectedPrinterIndex; 228 printerList.selectedIndex = lastSelectedPrinterIndex;
237 chrome.send(selectedValue); 229 chrome.send(selectedValue);
238 skip_refresh = true; 230 skip_refresh = true;
239 } else if (selectedValue == PRINT_TO_PDF) { 231 } else if (selectedValue == PRINT_TO_PDF ||
232 selectedValue == PRINT_WITH_CLOUD_PRINT) {
kmadhusu 2011/09/21 21:57:41 Adding this option here will hide copies, color an
Albert Bodenhamer 2011/09/22 23:23:39 Layout works fine. Did you mean duplex? Copies, c
240 updateWithPrinterCapabilities({ 233 updateWithPrinterCapabilities({
241 'disableColorOption': true, 234 'disableColorOption': true,
242 'setColorAsDefault': true, 235 'setColorAsDefault': true,
243 'setDuplexAsDefault': false, 236 'setDuplexAsDefault': false,
244 'printerColorModelForColor': colorSettings.COLOR, 237 'printerColorModelForColor': colorSettings.COLOR,
245 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE, 238 'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE,
246 'disableCopiesOption': true}); 239 'disableCopiesOption': true});
247 } else { 240 } else {
248 // This message will call back to 'updateWithPrinterCapabilities' 241 // This message will call back to 'updateWithPrinterCapabilities'
249 // function. 242 // function.
250 chrome.send('getPrinterCapabilities', [selectedValue]); 243 chrome.send('getPrinterCapabilities', [selectedValue]);
251 } 244 }
252 if (!skip_refresh) { 245 if (!skip_refresh) {
253 lastSelectedPrinterIndex = selectedIndex; 246 lastSelectedPrinterIndex = selectedIndex;
254 247
255 // Regenerate the preview data based on selected printer settings. 248 // Regenerate the preview data based on selected printer settings.
256 setDefaultValuesAndRegeneratePreview(true); 249 setDefaultValuesAndRegeneratePreview(true);
257 } 250 }
258 } 251 }
259 252
260 /** 253 /**
261 * Updates the printer capabilities for the currently selected
262 * cloud print printer.
263 */
264 function updateWithCloudPrinterCapabilities() {
265 var printerList = $('printer-list');
266 var selectedIndex = printerList.selectedIndex;
267 cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
268 doUpdateCloudPrinterCapabilities);
269 }
270
271 /**
272 * Helper function to do the actual work of updating cloud printer 254 * Helper function to do the actual work of updating cloud printer
273 * capabilities. 255 * capabilities.
274 * @param {Object} printer The printer object to set capabilities for. 256 * @param {Object} printer The printer object to set capabilities for.
275 */ 257 */
276 function doUpdateCloudPrinterCapabilities(printer) { 258 function doUpdateCloudPrinterCapabilities(printer) {
277 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), 259 var settings = {'disableColorOption': !cloudprint.supportsColor(printer),
278 'setColorAsDefault': cloudprint.colorIsDefault(printer), 260 'setColorAsDefault': cloudprint.colorIsDefault(printer),
279 'disableCopiesOption': true, 261 'disableCopiesOption': true,
280 'disableLandscapeOption': true}; 262 'disableLandscapeOption': true};
281 updateWithPrinterCapabilities(settings); 263 updateWithPrinterCapabilities(settings);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 306 }
325 307
326 /** 308 /**
327 * Checks whether the specified settings are valid. 309 * Checks whether the specified settings are valid.
328 * 310 *
329 * @return {boolean} true if settings are valid, false if not. 311 * @return {boolean} true if settings are valid, false if not.
330 */ 312 */
331 function areSettingsValid() { 313 function areSettingsValid() {
332 return pageSettings.isPageSelectionValid() && 314 return pageSettings.isPageSelectionValid() &&
333 (copiesSettings.isValid() || 315 (copiesSettings.isValid() ||
334 getSelectedPrinterName() == PRINT_TO_PDF); 316 getSelectedPrinterName() == PRINT_TO_PDF ||
317 getSelectedPrinterName() == PRINT_WITH_CLOUD_PRINT);
kmadhusu 2011/09/21 21:57:41 var selectedPrinter = getSelectedPrinterName(); an
Albert Bodenhamer 2011/09/22 23:23:39 Done.
335 } 318 }
336 319
337 /** 320 /**
338 * Creates an object based on the values in the printer settings. 321 * Creates an object based on the values in the printer settings.
339 * 322 *
340 * @return {Object} Object containing print job settings. 323 * @return {Object} Object containing print job settings.
341 */ 324 */
342 function getSettings() { 325 function getSettings() {
343 var deviceName = getSelectedPrinterName(); 326 var deviceName = getSelectedPrinterName();
344 var printToPDF = (deviceName == PRINT_TO_PDF); 327 var printToPDF = (deviceName == PRINT_TO_PDF);
328 var printWithCloudPrint = (deviceName == PRINT_WITH_CLOUD_PRINT);
dpapad 2011/09/22 18:11:57 Nit: No need for parenthesis here, same for line 3
Albert Bodenhamer 2011/09/22 23:23:39 Done.
345 329
346 var settings = 330 var settings =
347 {'deviceName': deviceName, 331 {'deviceName': deviceName,
348 'pageRange': pageSettings.selectedPageRanges, 332 'pageRange': pageSettings.selectedPageRanges,
349 'duplex': copiesSettings.duplexMode, 333 'duplex': copiesSettings.duplexMode,
350 'copies': copiesSettings.numberOfCopies, 334 'copies': copiesSettings.numberOfCopies,
351 'collate': copiesSettings.isCollated(), 335 'collate': copiesSettings.isCollated(),
352 'landscape': layoutSettings.isLandscape(), 336 'landscape': layoutSettings.isLandscape(),
353 'color': colorSettings.colorMode, 337 'color': colorSettings.colorMode,
354 'printToPDF': printToPDF, 338 'printToPDF': printToPDF,
339 'printWithCloudPrint': printWithCloudPrint,
355 'isFirstRequest' : false, 340 'isFirstRequest' : false,
356 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(), 341 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(),
357 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(), 342 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(),
358 'margins': marginSettings.customMargins, 343 'margins': marginSettings.customMargins,
359 'requestID': -1, 344 'requestID': -1,
360 'generateDraftData': generateDraftData}; 345 'generateDraftData': generateDraftData};
361 346
362 var printerList = $('printer-list'); 347 var printerList = $('printer-list');
363 var selectedPrinter = printerList.selectedIndex; 348 var selectedPrinter = printerList.selectedIndex;
364 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { 349 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 414 }
430 415
431 /** 416 /**
432 * Asks the browser to print the preview PDF based on current print 417 * Asks the browser to print the preview PDF based on current print
433 * settings. If the preview is still loading, printPendingFile() will get 418 * settings. If the preview is still loading, printPendingFile() will get
434 * called once the preview loads. 419 * called once the preview loads.
435 */ 420 */
436 function requestToPrintDocument() { 421 function requestToPrintDocument() {
437 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; 422 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady;
438 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; 423 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF;
439 424 var printWithCloudPrint = getSelectedPrinterName() == PRINT_WITH_CLOUD_PRINT;
440 if (hasPendingPrintDocumentRequest) { 425 if (hasPendingPrintDocumentRequest) {
441 if (printToPDF) { 426 if (printToPDF) {
442 sendPrintDocumentRequest(); 427 sendPrintDocumentRequest();
428 } else if (printWithCloudPrint) {
429 showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
kmadhusu 2011/09/21 21:57:41 Along with the progress message, you also want to
dpapad 2011/09/22 18:11:57 We only show the throbber if the link was clicked
Albert Bodenhamer 2011/09/22 23:23:39 I'm going with dpapad@ on this one. The option sh
430 disableInputElementsInSidebar();
443 } else { 431 } else {
444 isTabHidden = true; 432 isTabHidden = true;
445 chrome.send('hidePreview'); 433 chrome.send('hidePreview');
446 } 434 }
447 return; 435 return;
448 } 436 }
449 437
450 if (printToPDF) { 438 if (printToPDF) {
451 sendPrintDocumentRequest(); 439 sendPrintDocumentRequest();
452 } else { 440 } else {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 * the default printer is a cloud printer. 533 * the default printer is a cloud printer.
546 */ 534 */
547 function setDefaultPrinter(printer_name, cloudPrintData) { 535 function setDefaultPrinter(printer_name, cloudPrintData) {
548 // Add a placeholder value so the printer list looks valid. 536 // Add a placeholder value so the printer list looks valid.
549 addDestinationListOption('', '', true, true, true); 537 addDestinationListOption('', '', true, true, true);
550 if (printer_name) { 538 if (printer_name) {
551 defaultOrLastUsedPrinterName = printer_name; 539 defaultOrLastUsedPrinterName = printer_name;
552 if (cloudPrintData) { 540 if (cloudPrintData) {
553 cloudprint.setDefaultPrinter(printer_name, 541 cloudprint.setDefaultPrinter(printer_name,
554 cloudPrintData, 542 cloudPrintData,
555 addCloudPrinters, 543 addDestinationListOptionAtPosition,
556 doUpdateCloudPrinterCapabilities); 544 doUpdateCloudPrinterCapabilities);
557 } else { 545 } else {
558 $('printer-list')[0].value = defaultOrLastUsedPrinterName; 546 $('printer-list')[0].value = defaultOrLastUsedPrinterName;
559 updateControlsWithSelectedPrinterCapabilities(); 547 updateControlsWithSelectedPrinterCapabilities();
560 } 548 }
561 } 549 }
562 chrome.send('getPrinters'); 550 chrome.send('getPrinters');
563 } 551 }
564 552
565 /** 553 /**
(...skipping 25 matching lines...) Expand all
591 if (useCloudPrint) { 579 if (useCloudPrint) {
592 addDestinationListOption(localStrings.getString('printWithCloudPrint'), 580 addDestinationListOption(localStrings.getString('printWithCloudPrint'),
593 PRINT_WITH_CLOUD_PRINT, 581 PRINT_WITH_CLOUD_PRINT,
594 false, 582 false,
595 false, 583 false,
596 false); 584 false);
597 addDestinationListOption('', '', false, true, true); 585 addDestinationListOption('', '', false, true, true);
598 } 586 }
599 // Add options to manage printers. 587 // Add options to manage printers.
600 if (!cr.isChromeOS) { 588 if (!cr.isChromeOS) {
601 addDestinationListOption(localStrings.getString('manageLocalPrinters'), 589 addDestinationListOption(localStrings.getString('managePrinters'),
602 MANAGE_LOCAL_PRINTERS, false, false, false); 590 MANAGE_LOCAL_PRINTERS, false, false, false);
603 } else if (useCloudPrint) { 591 } else if (useCloudPrint) {
604 // Fetch recent printers. 592 // Fetch recent printers.
605 cloudprint.fetchPrinters(addCloudPrinters, false); 593 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false);
606 // Fetch the full printer list. 594 // Fetch the full printer list.
607 cloudprint.fetchPrinters(addCloudPrinters, true); 595 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true);
608 addDestinationListOption(localStrings.getString('manageCloudPrinters'), 596 addDestinationListOption(localStrings.getString('managePrinters'),
609 MANAGE_CLOUD_PRINTERS, false, false, false); 597 MANAGE_CLOUD_PRINTERS, false, false, false);
610 } 598 }
611 599
612 printerList.disabled = false; 600 printerList.disabled = false;
613 601
614 if (!hasRequestedPreview()) 602 if (!hasRequestedPreview())
615 updateControlsWithSelectedPrinterCapabilities(); 603 updateControlsWithSelectedPrinterCapabilities();
616 } 604 }
617 605
618 /** 606 /**
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 var option = createDestinationListOption(optionText, 664 var option = createDestinationListOption(optionText,
677 optionValue, 665 optionValue,
678 isDefault, 666 isDefault,
679 isDisabled, 667 isDisabled,
680 isSeparator); 668 isSeparator);
681 var printerList = $('printer-list'); 669 var printerList = $('printer-list');
682 var before = printerList[position]; 670 var before = printerList[position];
683 printerList.add(option, before); 671 printerList.add(option, before);
684 return option; 672 return option;
685 } 673 }
686
687 /**
688 * Test if a particular cloud printer has already been added to the
689 * printer dropdown.
690 * @param {string} id A unique value to track this printer.
691 * @return {boolean} True if this id has previously been passed to
692 * trackCloudPrinterAdded.
693 */
694 function cloudPrinterAlreadyAdded(id) {
695 return (addedCloudPrinters[id]);
696 }
697
698 /**
699 * Record that a cloud printer will added to the printer dropdown.
700 * @param {string} id A unique value to track this printer.
701 * @return {boolean} False if adding this printer would exceed
702 * |maxCloudPrinters|.
703 */
704 function trackCloudPrinterAdded(id) {
705 if (Object.keys(addedCloudPrinters).length < maxCloudPrinters) {
706 addedCloudPrinters[id] = true;
707 return true;
708 } else {
709 return false;
710 }
711 }
712
713
714 /**
715 * Add cloud printers to the list drop down.
716 * Called from the cloudprint object on receipt of printer information from the
717 * cloud print server.
718 * @param {Array} printers Array of printer info objects.
719 * @return {Object} The currently selected printer.
720 */
721 function addCloudPrinters(printers) {
722 var isFirstPass = false;
723 var printerList = $('printer-list');
724
725 if (firstCloudPrintOptionPos == lastCloudPrintOptionPos) {
726 isFirstPass = true;
727 // Remove empty entry added by setDefaultPrinter.
728 if (printerList[0] && printerList[0].textContent == '')
729 printerList.remove(0);
730 var option = addDestinationListOptionAtPosition(
731 lastCloudPrintOptionPos++,
732 localStrings.getString('cloudPrinters'),
733 'Label',
734 false,
735 true,
736 false);
737 cloudprint.setCloudPrint(option, null, null);
738 }
739 if (printers != null) {
740 for (var i = 0; i < printers.length; i++) {
741 if (!cloudPrinterAlreadyAdded(printers[i]['id'])) {
742 if (!trackCloudPrinterAdded(printers[i]['id'])) {
743 break;
744 }
745 var option = addDestinationListOptionAtPosition(
746 lastCloudPrintOptionPos++,
747 printers[i]['name'],
748 printers[i]['id'],
749 printers[i]['name'] == defaultOrLastUsedPrinterName,
750 false,
751 false);
752 cloudprint.setCloudPrint(option,
753 printers[i]['name'],
754 printers[i]['id']);
755 }
756 }
757 } else {
758 if (!cloudPrinterAlreadyAdded(SIGN_IN)) {
759 addDestinationListOptionAtPosition(lastCloudPrintOptionPos++,
760 localStrings.getString('signIn'),
761 SIGN_IN,
762 false,
763 false,
764 false);
765 trackCloudPrinterAdded(SIGN_IN);
766 }
767 }
768 if (isFirstPass) {
769 addDestinationListOptionAtPosition(lastCloudPrintOptionPos,
770 '',
771 '',
772 false,
773 true,
774 true);
775 addDestinationListOptionAtPosition(lastCloudPrintOptionPos + 1,
776 localStrings.getString('localPrinters'),
777 '',
778 false,
779 true,
780 false);
781 }
782 var selectedPrinter = printerList.selectedIndex;
783 if (selectedPrinter < 0)
784 return null;
785 return printerList.options[selectedPrinter];
786 }
787
788 /** 674 /**
789 * Sets the color mode for the PDF plugin. 675 * Sets the color mode for the PDF plugin.
790 * Called from PrintPreviewHandler::ProcessColorSetting(). 676 * Called from PrintPreviewHandler::ProcessColorSetting().
791 * @param {boolean} color is true if the PDF plugin should display in color. 677 * @param {boolean} color is true if the PDF plugin should display in color.
792 */ 678 */
793 function setColor(color) { 679 function setColor(color) {
794 var pdfViewer = $('pdf-viewer'); 680 var pdfViewer = $('pdf-viewer');
795 if (!pdfViewer) { 681 if (!pdfViewer) {
796 return; 682 return;
797 } 683 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 // TODO(aayushkumar): Do something here! 788 // TODO(aayushkumar): Do something here!
903 } 789 }
904 790
905 /** 791 /**
906 * This function sends a request to hide the overlay layer only if there is no 792 * This function sends a request to hide the overlay layer only if there is no
907 * pending print document request and we are not waiting for the print ready 793 * pending print document request and we are not waiting for the print ready
908 * metafile. 794 * metafile.
909 */ 795 */
910 function checkAndHideOverlayLayerIfValid() { 796 function checkAndHideOverlayLayerIfValid() {
911 var selectedPrinter = getSelectedPrinterName(); 797 var selectedPrinter = getSelectedPrinterName();
912 var printToPDF = selectedPrinter == PRINT_TO_PDF; 798 var printToDialog = selectedPrinter == PRINT_TO_PDF ||
913 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; 799 selectedPrinter == PRINT_WITH_CLOUD_PRINT;
dpapad 2011/09/22 18:11:57 Nit: Do regular 4 space indent, since the stylegui
Albert Bodenhamer 2011/09/22 23:23:39 Done.
914 if ((printToPDF || printWithCloudPrint || !previewModifiable) && 800 if ((printToDialog || !previewModifiable) &&
915 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) { 801 !isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) {
916 return; 802 return;
917 } 803 }
918 hideOverlayLayer(); 804 hideOverlayLayer();
919 } 805 }
920 806
921 /** 807 /**
922 * Called when no pipelining previewed pages. 808 * Called when no pipelining previewed pages.
923 * @param {string} previewUid Preview unique identifier. 809 * @param {string} previewUid Preview unique identifier.
924 * @param {number} previewResponseId The preview request id that resulted in 810 * @param {number} previewResponseId The preview request id that resulted in
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 */ 895 */
1010 function sendPrintDocumentRequestIfNeeded() { 896 function sendPrintDocumentRequestIfNeeded() {
1011 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) 897 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded)
1012 return; 898 return;
1013 899
1014 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or 900 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or
1015 // the preview source is not modifiable, we need the print ready data for 901 // the preview source is not modifiable, we need the print ready data for
1016 // printing. If the preview source is modifiable, we need to wait till all 902 // printing. If the preview source is modifiable, we need to wait till all
1017 // the requested pages are loaded in the plugin for printing. 903 // the requested pages are loaded in the plugin for printing.
1018 var selectedPrinter = getSelectedPrinterName(); 904 var selectedPrinter = getSelectedPrinterName();
1019 var printToPDF = selectedPrinter == PRINT_TO_PDF; 905 var printToDialog = selectedPrinter == PRINT_TO_PDF ||
1020 var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT; 906 selectedPrinter == PRINT_WITH_CLOUD_PRINT;
1021 if (((printToPDF || !previewModifiable || printWithCloudPrint) && 907 if (((printToDialog || !previewModifiable) &&
1022 !isPrintReadyMetafileReady) || 908 !isPrintReadyMetafileReady) ||
dpapad 2011/09/22 18:11:57 This can fit in the previous line now.
Albert Bodenhamer 2011/09/22 23:23:39 Done.
1023 (previewModifiable && hasPendingPreviewRequest)) { 909 (previewModifiable && hasPendingPreviewRequest)) {
1024 return; 910 return;
1025 } 911 }
1026 912
1027 hasPendingPrintDocumentRequest = false; 913 hasPendingPrintDocumentRequest = false;
1028 if (printWithCloudPrint) {
1029 chrome.send('printWithCloudPrint');
1030 return;
1031 }
1032 914
1033 if (!areSettingsValid()) { 915 if (!areSettingsValid()) {
1034 if (isTabHidden) 916 if (isTabHidden)
1035 cancelPendingPrintRequest(); 917 cancelPendingPrintRequest();
1036 return; 918 return;
1037 } 919 }
1038 sendPrintDocumentRequest(); 920 sendPrintDocumentRequest();
1039 } 921 }
1040 922
1041 /** 923 /**
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 * 'getInitiatorTabTitle' message. 1016 * 'getInitiatorTabTitle' message.
1135 * @param {string} initiatorTabTitle The title of the initiator tab. 1017 * @param {string} initiatorTabTitle The title of the initiator tab.
1136 */ 1018 */
1137 function setInitiatorTabTitle(initiatorTabTitle) { 1019 function setInitiatorTabTitle(initiatorTabTitle) {
1138 if (initiatorTabTitle == '') 1020 if (initiatorTabTitle == '')
1139 return; 1021 return;
1140 document.title = localStrings.getStringF( 1022 document.title = localStrings.getStringF(
1141 'printPreviewTitleFormat', initiatorTabTitle); 1023 'printPreviewTitleFormat', initiatorTabTitle);
1142 } 1024 }
1143 1025
1144 /**
1145 * Attempt to hide the preview tab and display the Cloud Print
1146 * dialog instead. Just disables controls if we're waiting on a new preview
1147 * to be generated.
1148 */
1149 function printWithCloudPrintDialog() {
1150 if (isPrintReadyMetafileReady) {
1151 chrome.send('printWithCloudPrint');
1152 } else {
1153 showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
1154 disableInputElementsInSidebar();
1155 hasPendingPrintDocumentRequest = true;
1156 }
1157 }
1158
1159 /// Pull in all other scripts in a single shot. 1026 /// Pull in all other scripts in a single shot.
1160 <include src="print_preview_animations.js"/> 1027 <include src="print_preview_animations.js"/>
1161 <include src="print_preview_cloud.js"/> 1028 <include src="print_preview_cloud.js"/>
1162 <include src="print_preview_utils.js"/> 1029 <include src="print_preview_utils.js"/>
1163 <include src="print_header.js"/> 1030 <include src="print_header.js"/>
1164 <include src="page_settings.js"/> 1031 <include src="page_settings.js"/>
1165 <include src="copies_settings.js"/> 1032 <include src="copies_settings.js"/>
1166 <include src="header_footer_settings.js"/> 1033 <include src="header_footer_settings.js"/>
1167 <include src="layout_settings.js"/> 1034 <include src="layout_settings.js"/>
1168 <include src="color_settings.js"/> 1035 <include src="color_settings.js"/>
1169 <include src="margin_settings.js"/> 1036 <include src="margin_settings.js"/>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698