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

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

Issue 7202012: Print Preview: Display a throbber when the user requests the system print (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 6 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 | Annotate | Revision Log
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 var localStrings = new LocalStrings(); 5 var localStrings = new LocalStrings();
6 6
7 // The total page count of the previewed document regardless of which pages the 7 // The total page count of the previewed document regardless of which pages the
8 // user has selected. 8 // user has selected.
9 var totalPageCount; 9 var totalPageCount;
10 10
(...skipping 30 matching lines...) Expand all
41 41
42 // True when preview tab has some error. 42 // True when preview tab has some error.
43 var hasError = false; 43 var hasError = false;
44 44
45 // True when preview tab is hidden. 45 // True when preview tab is hidden.
46 var isTabHidden = false; 46 var isTabHidden = false;
47 47
48 // True when draft preview data is requested for preview. 48 // True when draft preview data is requested for preview.
49 var draftDocument = true; 49 var draftDocument = true;
50 50
51 // True if the user has click 'Advanced...' in order to open the system print
52 // dialog.
53 var showingSystemDialog = false;
54
51 /** 55 /**
52 * Window onload handler, sets up the page and starts print preview by getting 56 * Window onload handler, sets up the page and starts print preview by getting
53 * the printer list. 57 * the printer list.
54 */ 58 */
55 function onLoad() { 59 function onLoad() {
56 cr.enablePlatformSpecificCSSRules(); 60 cr.enablePlatformSpecificCSSRules();
57 61
58 $('cancel-button').addEventListener('click', handleCancelButtonClick); 62 $('cancel-button').addEventListener('click', handleCancelButtonClick);
59 63
60 if (!checkCompatiblePluginExists()) { 64 if (!checkCompatiblePluginExists()) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 */ 166 */
163 function removeEventListeners() { 167 function removeEventListeners() {
164 clearTimeout(timerId); 168 clearTimeout(timerId);
165 setDefaultHandlersForPagesAndCopiesControls(); 169 setDefaultHandlersForPagesAndCopiesControls();
166 170
167 // Controls that require preview rendering 171 // Controls that require preview rendering
168 $('landscape').onclick = null; 172 $('landscape').onclick = null;
169 $('portrait').onclick = null; 173 $('portrait').onclick = null;
170 $('printer-list').onchange = null; 174 $('printer-list').onchange = null;
171 175
172 // Controls that dont require preview rendering. 176 // Controls that don't require preview rendering.
173 $('two-sided').onclick = null; 177 $('two-sided').onclick = null;
174 $('color').onclick = null; 178 $('color').onclick = null;
175 $('bw').onclick = null; 179 $('bw').onclick = null;
176 } 180 }
177 181
178 /** 182 /**
183 * Disables the input elements in the controls pane.
184 */
185 function disableInputElements() {
186 var els = document.querySelectorAll('input, button, select');
187 for (var i = 0; i < els.length; i++)
188 els[i].disabled = true;
189 }
190
191 /**
179 * Asks the browser to close the preview tab. 192 * Asks the browser to close the preview tab.
180 */ 193 */
181 function handleCancelButtonClick() { 194 function handleCancelButtonClick() {
182 chrome.send('closePrintPreviewTab'); 195 chrome.send('closePrintPreviewTab');
183 } 196 }
184 197
185 /** 198 /**
186 * Asks the browser to show the native print dialog for printing. 199 * Asks the browser to show the native print dialog for printing.
187 */ 200 */
188 function showSystemDialog() { 201 function showSystemDialog() {
202 showingSystemDialog = true;
203 disableInputElements();
204 $('system-dialog-throbber').classList.remove('hidden');
189 chrome.send('showSystemDialog'); 205 chrome.send('showSystemDialog');
190 } 206 }
191 207
192 /** 208 /**
193 * Disables the controls which need the initiator tab to generate preview 209 * Disables the controls which need the initiator tab to generate preview
194 * data. This function is called when the initiator tab is closed. 210 * data. This function is called when the initiator tab is closed.
195 * @param {string} initiatorTabURL The URL of the initiator tab. 211 * @param {string} initiatorTabURL The URL of the initiator tab.
196 */ 212 */
197 function onInitiatorTabClosed(initiatorTabURL) { 213 function onInitiatorTabClosed(initiatorTabURL) {
198 displayErrorMessageWithButton( 214 displayErrorMessageWithButton(
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 665
650 if (hasPendingPrintFileRequest) 666 if (hasPendingPrintFileRequest)
651 printFile(); 667 printFile();
652 } 668 }
653 669
654 /** 670 /**
655 * Create the PDF plugin or reload the existing one. 671 * Create the PDF plugin or reload the existing one.
656 * @param {string} previewUid Preview unique identifier. 672 * @param {string} previewUid Preview unique identifier.
657 */ 673 */
658 function createPDFPlugin(previewUid) { 674 function createPDFPlugin(previewUid) {
659 // Enable the print button.
660 if (!$('printer-list').disabled)
661 $('print-button').disabled = false;
662
663 var pdfViewer = $('pdf-viewer'); 675 var pdfViewer = $('pdf-viewer');
664 if (pdfViewer) { 676 if (pdfViewer) {
665 // Need to call this before the reload(), where the plugin resets its 677 // Need to call this before the reload(), where the plugin resets its
666 // internal page count. 678 // internal page count.
667 pdfViewer.goToPage('0'); 679 pdfViewer.goToPage('0');
668 680
669 pdfViewer.reload(); 681 pdfViewer.reload();
670 pdfViewer.grayscale(!isColor()); 682 pdfViewer.grayscale(!isColor());
671 return; 683 return;
672 } 684 }
(...skipping 20 matching lines...) Expand all
693 dummyPlugin.removePrintButton); 705 dummyPlugin.removePrintButton);
694 } 706 }
695 707
696 /** 708 /**
697 * Updates the state of print button depending on the user selection. 709 * Updates the state of print button depending on the user selection.
698 * The button is enabled only when the following conditions are true. 710 * The button is enabled only when the following conditions are true.
699 * 1) The selected page ranges are valid. 711 * 1) The selected page ranges are valid.
700 * 2) The number of copies is valid (if applicable). 712 * 2) The number of copies is valid (if applicable).
701 */ 713 */
702 function updatePrintButtonState() { 714 function updatePrintButtonState() {
715 if (showingSystemDialog)
716 return;
717
703 if (getSelectedPrinterName() == PRINT_TO_PDF) { 718 if (getSelectedPrinterName() == PRINT_TO_PDF) {
704 $('print-button').disabled = !isSelectedPagesValid(); 719 $('print-button').disabled = !isSelectedPagesValid();
705 } else { 720 } else {
706 $('print-button').disabled = (!isNumberOfCopiesValid() || 721 $('print-button').disabled = (!isNumberOfCopiesValid() ||
707 !isSelectedPagesValid()); 722 !isSelectedPagesValid());
708 } 723 }
709 } 724 }
710 725
711 window.addEventListener('DOMContentLoaded', onLoad); 726 window.addEventListener('DOMContentLoaded', onLoad);
712 727
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 this.isLandscape = ''; 982 this.isLandscape = '';
968 } 983 }
969 984
970 /** 985 /**
971 * Takes a snapshot of the print settings. 986 * Takes a snapshot of the print settings.
972 */ 987 */
973 PrintSettings.prototype.save = function() { 988 PrintSettings.prototype.save = function() {
974 this.deviceName = getSelectedPrinterName(); 989 this.deviceName = getSelectedPrinterName();
975 this.isLandscape = isLandscape(); 990 this.isLandscape = isLandscape();
976 } 991 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698