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

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 fix. Created 9 years, 5 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
11 // The previously selected pages by the user. It is used in 11 // The previously selected pages by the user. It is used in
12 // onPageSelectionMayHaveChanged() to make sure that a new preview is not 12 // onPageSelectionMayHaveChanged() to make sure that a new preview is not
13 // requested more often than necessary. 13 // requested more often than necessary.
14 var previouslySelectedPages = []; 14 var previouslySelectedPages = [];
15 15
16 // Timer id of the page range textfield. It is used to reset the timer whenever 16 // Timer id of the page range text field. It is used to reset the timer whenever
17 // needed. 17 // needed.
18 var timerId; 18 var timerId;
19 19
20 // Store the last selected printer index. 20 // Store the last selected printer index.
21 var lastSelectedPrinterIndex = 0; 21 var lastSelectedPrinterIndex = 0;
22 22
23 // Used to disable some printing options when the preview is not modifiable. 23 // Used to disable some printing options when the preview is not modifiable.
24 var previewModifiable = false; 24 var previewModifiable = false;
25 25
26 // Destination list special value constants. 26 // Destination list special value constants.
(...skipping 14 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()) {
65 disableInputElementsInSidebar();
61 displayErrorMessageWithButton(localStrings.getString('noPlugin'), 66 displayErrorMessageWithButton(localStrings.getString('noPlugin'),
62 localStrings.getString('launchNativeDialog'), 67 localStrings.getString('launchNativeDialog'),
63 showSystemDialog); 68 launchNativePrintDialog);
64 $('mainview').parentElement.removeChild($('dummy-viewer')); 69 $('mainview').parentElement.removeChild($('dummy-viewer'));
65 return; 70 return;
66 } 71 }
67 72
68 $('system-dialog-link').addEventListener('click', showSystemDialog); 73 $('print-button').focus();
74 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked);
69 $('mainview').parentElement.removeChild($('dummy-viewer')); 75 $('mainview').parentElement.removeChild($('dummy-viewer'));
70 76
71 $('printer-list').disabled = true; 77 $('printer-list').disabled = true;
72 $('print-button').onclick = printFile; 78 $('print-button').onclick = printFile;
73 79
74 setDefaultHandlersForPagesAndCopiesControls(); 80 setDefaultHandlersForPagesAndCopiesControls();
75 showLoadingAnimation(); 81 showLoadingAnimation();
76 chrome.send('getDefaultPrinter'); 82 chrome.send('getDefaultPrinter');
77 } 83 }
78 84
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 */ 168 */
163 function removeEventListeners() { 169 function removeEventListeners() {
164 clearTimeout(timerId); 170 clearTimeout(timerId);
165 setDefaultHandlersForPagesAndCopiesControls(); 171 setDefaultHandlersForPagesAndCopiesControls();
166 172
167 // Controls that require preview rendering 173 // Controls that require preview rendering
168 $('landscape').onclick = null; 174 $('landscape').onclick = null;
169 $('portrait').onclick = null; 175 $('portrait').onclick = null;
170 $('printer-list').onchange = null; 176 $('printer-list').onchange = null;
171 177
172 // Controls that dont require preview rendering. 178 // Controls that don't require preview rendering.
173 $('two-sided').onclick = null; 179 $('two-sided').onclick = null;
174 $('color').onclick = null; 180 $('color').onclick = null;
175 $('bw').onclick = null; 181 $('bw').onclick = null;
176 } 182 }
177 183
178 /** 184 /**
185 * Disables the input elements in the sidebar.
186 */
187 function disableInputElementsInSidebar() {
188 var els = $('sidebar').querySelectorAll('input, button, select');
189 for (var i = 0; i < els.length; i++)
190 els[i].disabled = true;
191 }
192
193 /**
179 * Asks the browser to close the preview tab. 194 * Asks the browser to close the preview tab.
180 */ 195 */
181 function handleCancelButtonClick() { 196 function handleCancelButtonClick() {
182 chrome.send('closePrintPreviewTab'); 197 chrome.send('closePrintPreviewTab');
183 } 198 }
184 199
185 /** 200 /**
186 * Asks the browser to show the native print dialog for printing. 201 * Disables the controls in the sidebar, shows the throbber and instructs the
202 * backend to open the native print dialog.
187 */ 203 */
188 function showSystemDialog() { 204 function onSystemDialogLinkClicked() {
205 showingSystemDialog = true;
206 disableInputElementsInSidebar();
207 $('system-dialog-throbber').classList.remove('hidden');
189 chrome.send('showSystemDialog'); 208 chrome.send('showSystemDialog');
190 } 209 }
191 210
211 /**
212 * Similar to onSystemDialogLinkClicked(), but specific to the
213 * 'Launch native print dialog' UI.
214 */
215 function launchNativePrintDialog() {
216 showingSystemDialog = true;
217 $('error-button').disabled = true;
218 $('native-print-dialog-throbber').classList.remove('hidden');
219 chrome.send('showSystemDialog');
220 }
221
192 /** 222 /**
193 * Disables the controls which need the initiator tab to generate preview 223 * Disables the controls which need the initiator tab to generate preview
194 * data. This function is called when the initiator tab is closed. 224 * data. This function is called when the initiator tab is closed.
195 * @param {string} initiatorTabURL The URL of the initiator tab. 225 * @param {string} initiatorTabURL The URL of the initiator tab.
196 */ 226 */
197 function onInitiatorTabClosed(initiatorTabURL) { 227 function onInitiatorTabClosed(initiatorTabURL) {
228 disableInputElementsInSidebar();
198 displayErrorMessageWithButton( 229 displayErrorMessageWithButton(
199 localStrings.getString('initiatorTabClosed'), 230 localStrings.getString('initiatorTabClosed'),
200 localStrings.getString('reopenPage'), 231 localStrings.getString('reopenPage'),
201 function() { window.location = initiatorTabURL; }); 232 function() { window.location = initiatorTabURL; });
202 } 233 }
203 234
204 /** 235 /**
205 * Gets the selected printer capabilities and updates the controls accordingly. 236 * Gets the selected printer capabilities and updates the controls accordingly.
206 */ 237 */
207 function updateControlsWithSelectedPrinterCapabilities() { 238 function updateControlsWithSelectedPrinterCapabilities() {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 * Display an error message in the center of the preview area followed by a 592 * Display an error message in the center of the preview area followed by a
562 * button. 593 * button.
563 * @param {string} errorMessage The error message to be displayed. 594 * @param {string} errorMessage The error message to be displayed.
564 * @param {string} buttonText The text to be displayed within the button. 595 * @param {string} buttonText The text to be displayed within the button.
565 * @param {string} buttonListener The listener to be executed when the button is 596 * @param {string} buttonListener The listener to be executed when the button is
566 * clicked. 597 * clicked.
567 */ 598 */
568 function displayErrorMessageWithButton( 599 function displayErrorMessageWithButton(
569 errorMessage, buttonText, buttonListener) { 600 errorMessage, buttonText, buttonListener) {
570 var errorButton = $('error-button'); 601 var errorButton = $('error-button');
602 errorButton.disabled = false;
571 errorButton.textContent = buttonText; 603 errorButton.textContent = buttonText;
572 errorButton.onclick = buttonListener; 604 errorButton.onclick = buttonListener;
573 errorButton.classList.remove('hidden'); 605 errorButton.classList.remove('hidden');
606 $('system-dialog-throbber').classList.add('hidden');
607 $('native-print-dialog-throbber').classList.add('hidden');
574 displayErrorMessage(errorMessage); 608 displayErrorMessage(errorMessage);
575 } 609 }
576 610
577 /** 611 /**
578 * Display an error message when print preview fails. 612 * Display an error message when print preview fails.
579 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). 613 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed().
580 */ 614 */
581 function printPreviewFailed() { 615 function printPreviewFailed() {
582 displayErrorMessage(localStrings.getString('previewFailed')); 616 displayErrorMessage(localStrings.getString('previewFailed'));
583 } 617 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 687
654 if (hasPendingPrintFileRequest) 688 if (hasPendingPrintFileRequest)
655 printFile(); 689 printFile();
656 } 690 }
657 691
658 /** 692 /**
659 * Create the PDF plugin or reload the existing one. 693 * Create the PDF plugin or reload the existing one.
660 * @param {string} previewUid Preview unique identifier. 694 * @param {string} previewUid Preview unique identifier.
661 */ 695 */
662 function createPDFPlugin(previewUid) { 696 function createPDFPlugin(previewUid) {
663 // Enable the print button.
664 if (!$('printer-list').disabled)
665 $('print-button').disabled = false;
666
667 var pdfViewer = $('pdf-viewer'); 697 var pdfViewer = $('pdf-viewer');
668 if (pdfViewer) { 698 if (pdfViewer) {
669 // Need to call this before the reload(), where the plugin resets its 699 // Need to call this before the reload(), where the plugin resets its
670 // internal page count. 700 // internal page count.
671 pdfViewer.goToPage('0'); 701 pdfViewer.goToPage('0');
672 702
673 pdfViewer.reload(); 703 pdfViewer.reload();
674 pdfViewer.grayscale(!isColor()); 704 pdfViewer.grayscale(!isColor());
675 return; 705 return;
676 } 706 }
(...skipping 21 matching lines...) Expand all
698 dummyPlugin.removePrintButton); 728 dummyPlugin.removePrintButton);
699 } 729 }
700 730
701 /** 731 /**
702 * Updates the state of print button depending on the user selection. 732 * Updates the state of print button depending on the user selection.
703 * The button is enabled only when the following conditions are true. 733 * The button is enabled only when the following conditions are true.
704 * 1) The selected page ranges are valid. 734 * 1) The selected page ranges are valid.
705 * 2) The number of copies is valid (if applicable). 735 * 2) The number of copies is valid (if applicable).
706 */ 736 */
707 function updatePrintButtonState() { 737 function updatePrintButtonState() {
738 if (showingSystemDialog)
739 return;
740
708 if (getSelectedPrinterName() == PRINT_TO_PDF) { 741 if (getSelectedPrinterName() == PRINT_TO_PDF) {
709 $('print-button').disabled = !isSelectedPagesValid(); 742 $('print-button').disabled = !isSelectedPagesValid();
710 } else { 743 } else {
711 $('print-button').disabled = (!isNumberOfCopiesValid() || 744 $('print-button').disabled = (!isNumberOfCopiesValid() ||
712 !isSelectedPagesValid()); 745 !isSelectedPagesValid());
713 } 746 }
714 } 747 }
715 748
716 window.addEventListener('DOMContentLoaded', onLoad); 749 window.addEventListener('DOMContentLoaded', onLoad);
717 750
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 this.isLandscape = ''; 1005 this.isLandscape = '';
973 } 1006 }
974 1007
975 /** 1008 /**
976 * Takes a snapshot of the print settings. 1009 * Takes a snapshot of the print settings.
977 */ 1010 */
978 PrintSettings.prototype.save = function() { 1011 PrintSettings.prototype.save = function() {
979 this.deviceName = getSelectedPrinterName(); 1012 this.deviceName = getSelectedPrinterName();
980 this.isLandscape = isLandscape(); 1013 this.isLandscape = isLandscape();
981 } 1014 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.html ('k') | chrome/browser/resources/webui.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698