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

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: Testing 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();
dpapad 2011/06/28 02:25:30 Why remove the autofocus attribute from the html a
James Hawkins 2011/06/28 04:02:34 autofocus is somewhat crappy and focuses disabled
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) {
198 displayErrorMessageWithButton( 228 displayErrorMessageWithButton(
199 localStrings.getString('initiatorTabClosed'), 229 localStrings.getString('initiatorTabClosed'),
200 localStrings.getString('reopenPage'), 230 localStrings.getString('reopenPage'),
201 function() { window.location = initiatorTabURL; }); 231 function() { window.location = initiatorTabURL; });
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 683
654 if (hasPendingPrintFileRequest) 684 if (hasPendingPrintFileRequest)
655 printFile(); 685 printFile();
656 } 686 }
657 687
658 /** 688 /**
659 * Create the PDF plugin or reload the existing one. 689 * Create the PDF plugin or reload the existing one.
660 * @param {string} previewUid Preview unique identifier. 690 * @param {string} previewUid Preview unique identifier.
661 */ 691 */
662 function createPDFPlugin(previewUid) { 692 function createPDFPlugin(previewUid) {
663 // Enable the print button.
664 if (!$('printer-list').disabled)
665 $('print-button').disabled = false;
666
667 var pdfViewer = $('pdf-viewer'); 693 var pdfViewer = $('pdf-viewer');
668 if (pdfViewer) { 694 if (pdfViewer) {
669 // Need to call this before the reload(), where the plugin resets its 695 // Need to call this before the reload(), where the plugin resets its
670 // internal page count. 696 // internal page count.
671 pdfViewer.goToPage('0'); 697 pdfViewer.goToPage('0');
672 698
673 pdfViewer.reload(); 699 pdfViewer.reload();
674 pdfViewer.grayscale(!isColor()); 700 pdfViewer.grayscale(!isColor());
675 return; 701 return;
676 } 702 }
(...skipping 20 matching lines...) Expand all
697 dummyPlugin.removePrintButton); 723 dummyPlugin.removePrintButton);
698 } 724 }
699 725
700 /** 726 /**
701 * Updates the state of print button depending on the user selection. 727 * Updates the state of print button depending on the user selection.
702 * The button is enabled only when the following conditions are true. 728 * The button is enabled only when the following conditions are true.
703 * 1) The selected page ranges are valid. 729 * 1) The selected page ranges are valid.
704 * 2) The number of copies is valid (if applicable). 730 * 2) The number of copies is valid (if applicable).
705 */ 731 */
706 function updatePrintButtonState() { 732 function updatePrintButtonState() {
733 if (showingSystemDialog)
734 return;
735
707 if (getSelectedPrinterName() == PRINT_TO_PDF) { 736 if (getSelectedPrinterName() == PRINT_TO_PDF) {
708 $('print-button').disabled = !isSelectedPagesValid(); 737 $('print-button').disabled = !isSelectedPagesValid();
709 } else { 738 } else {
710 $('print-button').disabled = (!isNumberOfCopiesValid() || 739 $('print-button').disabled = (!isNumberOfCopiesValid() ||
711 !isSelectedPagesValid()); 740 !isSelectedPagesValid());
712 } 741 }
713 } 742 }
714 743
715 window.addEventListener('DOMContentLoaded', onLoad); 744 window.addEventListener('DOMContentLoaded', onLoad);
716 745
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 this.isLandscape = ''; 1000 this.isLandscape = '';
972 } 1001 }
973 1002
974 /** 1003 /**
975 * Takes a snapshot of the print settings. 1004 * Takes a snapshot of the print settings.
976 */ 1005 */
977 PrintSettings.prototype.save = function() { 1006 PrintSettings.prototype.save = function() {
978 this.deviceName = getSelectedPrinterName(); 1007 this.deviceName = getSelectedPrinterName();
979 this.isLandscape = isLandscape(); 1008 this.isLandscape = isLandscape();
980 } 1009 }
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