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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 // Object holding all the header footer related settings. | 66 // Object holding all the header footer related settings. |
| 67 var headerFooterSettings; | 67 var headerFooterSettings; |
| 68 | 68 |
| 69 // Object holding all the color related settings. | 69 // Object holding all the color related settings. |
| 70 var colorSettings; | 70 var colorSettings; |
| 71 | 71 |
| 72 // True if the user has click 'Advanced...' in order to open the system print | 72 // True if the user has click 'Advanced...' in order to open the system print |
| 73 // dialog. | 73 // dialog. |
| 74 var showingSystemDialog = false; | 74 var showingSystemDialog = false; |
| 75 | 75 |
| 76 // True when there is a pending request to print to pdf. It means that the user | |
| 77 // has requested to save to pdf but the pdf file is not ready yet. | |
| 78 var hasPendingPrintToPdfRequest = false; | |
|
kmadhusu
2011/09/07 20:42:57
This variable is not required. You can reuse "has
dpapad
2011/09/07 23:42:39
I am using this variable so that I can keep displa
dpapad
2011/09/08 03:29:20
Done.
| |
| 79 | |
| 76 // The range of options in the printer dropdown controlled by cloud print. | 80 // The range of options in the printer dropdown controlled by cloud print. |
| 77 var firstCloudPrintOptionPos = 0; | 81 var firstCloudPrintOptionPos = 0; |
| 78 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; | 82 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
| 79 | 83 |
| 80 // Store the current previewUid. | 84 // Store the current previewUid. |
| 81 var currentPreviewUid = ''; | 85 var currentPreviewUid = ''; |
| 82 | 86 |
| 83 // True if we need to generate draft preview data. | 87 // True if we need to generate draft preview data. |
| 84 var generateDraftData = true; | 88 var generateDraftData = true; |
| 85 | 89 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 /** | 431 /** |
| 428 * Asks the browser to print the preview PDF based on current print | 432 * Asks the browser to print the preview PDF based on current print |
| 429 * settings. If the preview is still loading, printPendingFile() will get | 433 * settings. If the preview is still loading, printPendingFile() will get |
| 430 * called once the preview loads. | 434 * called once the preview loads. |
| 431 */ | 435 */ |
| 432 function requestToPrintDocument() { | 436 function requestToPrintDocument() { |
| 433 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; | 437 hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady; |
| 434 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; | 438 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; |
| 435 | 439 |
| 436 if (hasPendingPrintDocumentRequest) { | 440 if (hasPendingPrintDocumentRequest) { |
| 437 if (printToPDF) { | 441 if (printToPDF) { |
|
kmadhusu
2011/09/07 20:42:57
You need to disable the input controls as soon as
dpapad
2011/09/07 23:42:39
See my next comment.
| |
| 438 // TODO(thestig) disable controls here. | 442 sendPrintDocumentRequest(); |
| 439 } else { | 443 } else { |
| 440 isTabHidden = true; | 444 isTabHidden = true; |
| 441 chrome.send('hidePreview'); | 445 chrome.send('hidePreview'); |
| 442 } | 446 } |
| 443 return; | 447 return; |
| 444 } | 448 } |
| 445 | 449 |
| 446 if (printToPDF) { | 450 if (printToPDF) { |
| 447 sendPrintDocumentRequest(); | 451 sendPrintDocumentRequest(); |
| 448 } else { | 452 } else { |
| 449 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); | 453 window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000); |
| 450 } | 454 } |
| 451 } | 455 } |
| 452 | 456 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 536 |
| 533 /** | 537 /** |
| 534 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | 538 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print |
| 535 * preview tab regarding the file selection cancel event. | 539 * preview tab regarding the file selection cancel event. |
| 536 */ | 540 */ |
| 537 function fileSelectionCancelled() { | 541 function fileSelectionCancelled() { |
| 538 // TODO(thestig) re-enable controls here. | 542 // TODO(thestig) re-enable controls here. |
| 539 } | 543 } |
| 540 | 544 |
| 541 /** | 545 /** |
| 546 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print | |
| 547 * preview tab regarding the file selection completed event. | |
| 548 */ | |
| 549 function fileSelectionCompleted() { | |
| 550 // If the file selection is completed and the tab is not already closed it | |
| 551 // means that a pending print to pdf request exists. | |
| 552 disableInputElementsInSidebar(); | |
|
kmadhusu
2011/09/07 20:42:57
Move the disableInput..() function call to line #4
dpapad
2011/09/07 23:42:39
If I disable the controls at line 442, and then th
kmadhusu
2011/09/08 00:04:33
I am not sure about the time it takes to show the
dpapad
2011/09/08 00:11:51
The main point of this CL is to make opening the f
| |
| 553 hasPendingPrintToPdfRequest = true; | |
| 554 showCustomMessage(localStrings.getString('printingToPDFInProgress')); | |
| 555 } | |
| 556 | |
| 557 /** | |
| 542 * Set the default printer. If there is one, generate a print preview. | 558 * Set the default printer. If there is one, generate a print preview. |
| 543 * @param {string} printer Name of the default printer. Empty if none. | 559 * @param {string} printer Name of the default printer. Empty if none. |
| 544 * @param {string} cloudPrintData Cloud print related data to restore if | 560 * @param {string} cloudPrintData Cloud print related data to restore if |
| 545 * the default printer is a cloud printer. | 561 * the default printer is a cloud printer. |
| 546 */ | 562 */ |
| 547 function setDefaultPrinter(printer_name, cloudPrintData) { | 563 function setDefaultPrinter(printer_name, cloudPrintData) { |
| 548 // Add a placeholder value so the printer list looks valid. | 564 // Add a placeholder value so the printer list looks valid. |
| 549 addDestinationListOption('', '', true, true, true); | 565 addDestinationListOption('', '', true, true, true); |
| 550 if (printer_name) { | 566 if (printer_name) { |
| 551 defaultOrLastUsedPrinterName = printer_name; | 567 defaultOrLastUsedPrinterName = printer_name; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 cloudprint.setColor(printerList[printerList.selectedIndex], color); | 832 cloudprint.setColor(printerList[printerList.selectedIndex], color); |
| 817 } | 833 } |
| 818 | 834 |
| 819 /** | 835 /** |
| 820 * Display an error message in the center of the preview area. | 836 * Display an error message in the center of the preview area. |
| 821 * @param {string} errorMessage The error message to be displayed. | 837 * @param {string} errorMessage The error message to be displayed. |
| 822 */ | 838 */ |
| 823 function displayErrorMessage(errorMessage) { | 839 function displayErrorMessage(errorMessage) { |
| 824 $('print-button').disabled = true; | 840 $('print-button').disabled = true; |
| 825 $('overlay-layer').classList.remove('invisible'); | 841 $('overlay-layer').classList.remove('invisible'); |
| 826 $('dancing-dots-text').classList.add('hidden'); | 842 $('custom-message').innerHTML = errorMessage; |
|
arv (Not doing code reviews)
2011/09/07 21:53:52
Add a var so you do not have to call $ multiple ti
arv (Not doing code reviews)
2011/09/07 21:53:52
Do you really need innerHTML here? Are you escapin
dpapad
2011/09/08 03:29:20
Done.
dpapad
2011/09/08 03:29:20
Done.
| |
| 827 $('error-text').innerHTML = errorMessage; | 843 $('custom-message').classList.remove('hidden'); |
|
arv (Not doing code reviews)
2011/09/07 21:53:52
$('custom-message').hidden = false;
dpapad
2011/09/08 03:29:20
Done.
| |
| 828 $('error-text').classList.remove('hidden'); | 844 $('custom-message-with-dots').innerHTML = ''; |
|
arv (Not doing code reviews)
2011/09/07 21:53:52
textContent = ''
dpapad
2011/09/08 03:29:20
In this case innerHTML is needed since the content
| |
| 845 $('custom-message-with-dots').classList.add('hidden'); | |
| 829 var pdfViewer = $('pdf-viewer'); | 846 var pdfViewer = $('pdf-viewer'); |
| 830 if (pdfViewer) | 847 if (pdfViewer) |
| 831 $('mainview').removeChild(pdfViewer); | 848 $('mainview').removeChild(pdfViewer); |
| 832 | 849 |
| 833 if (isTabHidden) | 850 if (isTabHidden) |
| 834 cancelPendingPrintRequest(); | 851 cancelPendingPrintRequest(); |
| 835 } | 852 } |
| 836 | 853 |
| 837 /** | 854 /** |
| 838 * Display an error message in the center of the preview area followed by a | 855 * Display an error message in the center of the preview area followed by a |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 | 891 |
| 875 /** | 892 /** |
| 876 * Called when the PDF plugin loads its document. | 893 * Called when the PDF plugin loads its document. |
| 877 */ | 894 */ |
| 878 function onPDFLoad() { | 895 function onPDFLoad() { |
| 879 if (previewModifiable) { | 896 if (previewModifiable) { |
| 880 setPluginPreviewPageCount(); | 897 setPluginPreviewPageCount(); |
| 881 } | 898 } |
| 882 $('pdf-viewer').fitToHeight(); | 899 $('pdf-viewer').fitToHeight(); |
| 883 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 900 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
| 884 hideLoadingAnimation(); | 901 hideOverlayLayer(); |
| 885 } | 902 } |
| 886 | 903 |
| 887 function setPluginPreviewPageCount() { | 904 function setPluginPreviewPageCount() { |
| 888 $('pdf-viewer').printPreviewPageCount( | 905 $('pdf-viewer').printPreviewPageCount( |
| 889 pageSettings.previouslySelectedPages.length); | 906 pageSettings.previouslySelectedPages.length); |
| 890 } | 907 } |
| 891 | 908 |
| 892 /** | 909 /** |
| 893 * Update the page count and check the page range. | 910 * Update the page count and check the page range. |
| 894 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 911 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 919 * @param {number} previewResponseId The preview request id that resulted in | 936 * @param {number} previewResponseId The preview request id that resulted in |
| 920 * this response. | 937 * this response. |
| 921 */ | 938 */ |
| 922 function reloadPreviewPages(previewUid, previewResponseId) { | 939 function reloadPreviewPages(previewUid, previewResponseId) { |
| 923 if (!isExpectedPreviewResponse(previewResponseId)) | 940 if (!isExpectedPreviewResponse(previewResponseId)) |
| 924 return; | 941 return; |
| 925 hasPendingPreviewRequest = false; | 942 hasPendingPreviewRequest = false; |
| 926 isPrintReadyMetafileReady = true; | 943 isPrintReadyMetafileReady = true; |
| 927 | 944 |
| 928 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 945 cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
| 929 hideLoadingAnimation(); | 946 hideOverlayLayer(); |
| 930 var pageSet = pageSettings.previouslySelectedPages; | 947 var pageSet = pageSettings.previouslySelectedPages; |
| 931 for (var i = 0; i < pageSet.length; i++) | 948 for (var i = 0; i < pageSet.length; i++) |
| 932 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); | 949 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); |
| 933 // TODO(dpapad): handle pending print file requests. | 950 // TODO(dpapad): handle pending print file requests. |
| 934 } | 951 } |
| 935 | 952 |
| 936 /** | 953 /** |
| 937 * Notification that a print preview page has been rendered. | 954 * Notification that a print preview page has been rendered. |
| 938 * Check if the settings have changed and request a regeneration if needed. | 955 * Check if the settings have changed and request a regeneration if needed. |
| 939 * Called from PrintPreviewUI::OnDidPreviewPage(). | 956 * Called from PrintPreviewUI::OnDidPreviewPage(). |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 <include src="print_preview_animations.js"/> | 1118 <include src="print_preview_animations.js"/> |
| 1102 <include src="print_preview_cloud.js"/> | 1119 <include src="print_preview_cloud.js"/> |
| 1103 <include src="print_preview_utils.js"/> | 1120 <include src="print_preview_utils.js"/> |
| 1104 <include src="print_header.js"/> | 1121 <include src="print_header.js"/> |
| 1105 <include src="page_settings.js"/> | 1122 <include src="page_settings.js"/> |
| 1106 <include src="copies_settings.js"/> | 1123 <include src="copies_settings.js"/> |
| 1107 <include src="header_footer_settings.js"/> | 1124 <include src="header_footer_settings.js"/> |
| 1108 <include src="layout_settings.js"/> | 1125 <include src="layout_settings.js"/> |
| 1109 <include src="color_settings.js"/> | 1126 <include src="color_settings.js"/> |
| 1110 <include src="margin_settings.js"/> | 1127 <include src="margin_settings.js"/> |
| OLD | NEW |