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

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

Issue 8223009: Print Preview: Keep the cancel button enabled whenever possible. Hook up the escape key to cancel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 // 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // True when a pending print file request exists. 47 // True when a pending print file request exists.
48 var hasPendingPrintDocumentRequest = false; 48 var hasPendingPrintDocumentRequest = false;
49 49
50 // True when the complete metafile for the previewed doc is ready. 50 // True when the complete metafile for the previewed doc is ready.
51 var isPrintReadyMetafileReady = false; 51 var isPrintReadyMetafileReady = false;
52 52
53 // True when preview tab is hidden. 53 // True when preview tab is hidden.
54 var isTabHidden = false; 54 var isTabHidden = false;
55 55
56 // Object holding the print and cancel buttons.
57 var printHeader;
58
56 // Object holding all the pages related settings. 59 // Object holding all the pages related settings.
57 var pageSettings; 60 var pageSettings;
58 61
59 // Object holding all the copies related settings. 62 // Object holding all the copies related settings.
60 var copiesSettings; 63 var copiesSettings;
61 64
62 // Object holding all the layout related settings. 65 // Object holding all the layout related settings.
63 var layoutSettings; 66 var layoutSettings;
64 67
65 // Object holding all the margin related settings. 68 // Object holding all the margin related settings.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 100
98 /** 101 /**
99 * Window onload handler, sets up the page and starts print preview by getting 102 * Window onload handler, sets up the page and starts print preview by getting
100 * the printer list. 103 * the printer list.
101 */ 104 */
102 function onLoad() { 105 function onLoad() {
103 cr.enablePlatformSpecificCSSRules(); 106 cr.enablePlatformSpecificCSSRules();
104 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); 107 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID);
105 lastPreviewRequestID = initialPreviewRequestID; 108 lastPreviewRequestID = initialPreviewRequestID;
106 109
110 printHeader = print_preview.PrintHeader.getInstance();
111 printHeader.addEventListeners();
112
107 if (!checkCompatiblePluginExists()) { 113 if (!checkCompatiblePluginExists()) {
108 disableInputElementsInSidebar(); 114 disableInputElementsInSidebar();
109 displayErrorMessageWithButton(localStrings.getString('noPlugin'), 115 displayErrorMessageWithButton(localStrings.getString('noPlugin'),
110 localStrings.getString('launchNativeDialog'), 116 localStrings.getString('launchNativeDialog'),
111 launchNativePrintDialog); 117 launchNativePrintDialog);
112 $('mainview').parentElement.removeChild($('dummy-viewer')); 118 $('mainview').parentElement.removeChild($('dummy-viewer'));
113 return; 119 return;
114 } 120 }
115 121
116 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); 122 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked);
117 $('mainview').parentElement.removeChild($('dummy-viewer')); 123 $('mainview').parentElement.removeChild($('dummy-viewer'));
118 124
119 $('printer-list').disabled = true; 125 $('printer-list').disabled = true;
120 126
121 printHeader = print_preview.PrintHeader.getInstance();
122 pageSettings = print_preview.PageSettings.getInstance(); 127 pageSettings = print_preview.PageSettings.getInstance();
123 copiesSettings = print_preview.CopiesSettings.getInstance(); 128 copiesSettings = print_preview.CopiesSettings.getInstance();
124 layoutSettings = print_preview.LayoutSettings.getInstance(); 129 layoutSettings = print_preview.LayoutSettings.getInstance();
125 marginSettings = print_preview.MarginSettings.getInstance(); 130 marginSettings = print_preview.MarginSettings.getInstance();
126 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); 131 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance();
127 colorSettings = print_preview.ColorSettings.getInstance(); 132 colorSettings = print_preview.ColorSettings.getInstance();
128 printHeader.addEventListeners();
129 pageSettings.addEventListeners(); 133 pageSettings.addEventListeners();
130 copiesSettings.addEventListeners(); 134 copiesSettings.addEventListeners();
131 headerFooterSettings.addEventListeners(); 135 headerFooterSettings.addEventListeners();
132 layoutSettings.addEventListeners(); 136 layoutSettings.addEventListeners();
133 marginSettings.addEventListeners(); 137 marginSettings.addEventListeners();
134 colorSettings.addEventListeners(); 138 colorSettings.addEventListeners();
135 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 139 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
136 140
137 showLoadingAnimation(); 141 showLoadingAnimation();
138 chrome.send('getInitiatorTabTitle'); 142 chrome.send('getInitiatorTabTitle');
139 chrome.send('getDefaultPrinter'); 143 chrome.send('getDefaultPrinter');
140 } 144 }
141 145
142 /** 146 /**
143 * Disables the input elements in the sidebar. 147 * Disables the input elements in the sidebar.
144 */ 148 */
145 function disableInputElementsInSidebar() { 149 function disableInputElementsInSidebar() {
146 var els = $('sidebar').querySelectorAll('input, button, select'); 150 var els = $('sidebar').querySelectorAll('input, button, select');
147 for (var i = 0; i < els.length; i++) 151 for (var i = 0; i < els.length; i++) {
152 if (els[i] == printHeader.cancelButton)
153 continue;
148 els[i].disabled = true; 154 els[i].disabled = true;
155 }
149 } 156 }
150 157
151 /** 158 /**
152 * Disables the controls in the sidebar, shows the throbber and instructs the 159 * Disables the controls in the sidebar, shows the throbber and instructs the
153 * backend to open the native print dialog. 160 * backend to open the native print dialog.
154 */ 161 */
155 function onSystemDialogLinkClicked() { 162 function onSystemDialogLinkClicked() {
156 if (showingSystemDialog) 163 if (showingSystemDialog)
157 return; 164 return;
158 showingSystemDialog = true; 165 showingSystemDialog = true;
159 disableInputElementsInSidebar(); 166 disableInputElementsInSidebar();
160 $('system-dialog-throbber').classList.remove('hidden'); 167 $('system-dialog-throbber').classList.remove('hidden');
161 chrome.send('showSystemDialog'); 168 chrome.send('showSystemDialog');
162 } 169 }
163 170
164 /** 171 /**
165 * Similar to onSystemDialogLinkClicked(), but specific to the 172 * Similar to onSystemDialogLinkClicked(), but specific to the
166 * 'Launch native print dialog' UI. 173 * 'Launch native print dialog' UI.
167 */ 174 */
168 function launchNativePrintDialog() { 175 function launchNativePrintDialog() {
169 if (showingSystemDialog) 176 if (showingSystemDialog)
170 return; 177 return;
171 showingSystemDialog = true; 178 showingSystemDialog = true;
172 $('error-button').disabled = true; 179 $('error-button').disabled = true;
180 cr.dispatchSimpleEvent(document, 'disableCancelButton');
173 $('native-print-dialog-throbber').classList.remove('hidden'); 181 $('native-print-dialog-throbber').classList.remove('hidden');
174 chrome.send('showSystemDialog'); 182 chrome.send('showSystemDialog');
175 } 183 }
176 184
177 /** 185 /**
178 * Disables the controls which need the initiator tab to generate preview 186 * Disables the controls which need the initiator tab to generate preview
179 * data. This function is called when the initiator tab has crashed. 187 * data. This function is called when the initiator tab has crashed.
180 * @param {string} initiatorTabURL The URL of the initiator tab. 188 * @param {string} initiatorTabURL The URL of the initiator tab.
181 */ 189 */
182 function onInitiatorTabCrashed(initiatorTabURL) { 190 function onInitiatorTabCrashed(initiatorTabURL) {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 hasPendingPreviewRequest = false; 893 hasPendingPreviewRequest = false;
886 createPDFPlugin(PRINT_READY_DATA_INDEX); 894 createPDFPlugin(PRINT_READY_DATA_INDEX);
887 } 895 }
888 896
889 cr.dispatchSimpleEvent(document, 'updatePrintButton'); 897 cr.dispatchSimpleEvent(document, 'updatePrintButton');
890 if (previewModifiable) 898 if (previewModifiable)
891 sendPrintDocumentRequestIfNeeded(); 899 sendPrintDocumentRequestIfNeeded();
892 } 900 }
893 901
894 /** 902 /**
895 * Checks to see if the requested print data is available for printing and 903 * Checks to see if the requested print data is available for printing and
896 * sends a print document request if needed. 904 * sends a print document request if needed.
897 */ 905 */
898 function sendPrintDocumentRequestIfNeeded() { 906 function sendPrintDocumentRequestIfNeeded() {
899 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) 907 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded)
900 return; 908 return;
901 909
902 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or 910 // If the selected printer is PRINT_TO_PDF or PRINT_WITH_CLOUD_PRINT or
903 // the preview source is not modifiable, we need the print ready data for 911 // the preview source is not modifiable, we need the print ready data for
904 // printing. If the preview source is modifiable, we need to wait till all 912 // printing. If the preview source is modifiable, we need to wait till all
905 // the requested pages are loaded in the plugin for printing. 913 // the requested pages are loaded in the plugin for printing.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 * 'getInitiatorTabTitle' message. 1023 * 'getInitiatorTabTitle' message.
1016 * @param {string} initiatorTabTitle The title of the initiator tab. 1024 * @param {string} initiatorTabTitle The title of the initiator tab.
1017 */ 1025 */
1018 function setInitiatorTabTitle(initiatorTabTitle) { 1026 function setInitiatorTabTitle(initiatorTabTitle) {
1019 if (initiatorTabTitle == '') 1027 if (initiatorTabTitle == '')
1020 return; 1028 return;
1021 document.title = localStrings.getStringF( 1029 document.title = localStrings.getStringF(
1022 'printPreviewTitleFormat', initiatorTabTitle); 1030 'printPreviewTitleFormat', initiatorTabTitle);
1023 } 1031 }
1024 1032
1033 /**
1034 * Closes this print preview tab.
1035 */
1036 function closePrintPreviewTab() {
1037 chrome.send('closePrintPreviewTab');
1038 }
1039
1040 /**
1041 * Handle keyboard events.
1042 * @param {Event} e The keyboard event.
1043 */
1044 function onKeyDown(e) {
1045 // Escape key closes the dialog.
1046 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
1047 cr.dispatchSimpleEvent(document, 'disableCancelButton');
dpapad 2011/10/10 19:53:24 Is it necessary to disable the cancel button here,
Lei Zhang 2011/10/10 20:03:14 Not sure. If the user presses escape many times qu
1048 closePrintPreviewTab();
1049 return
dpapad 2011/10/10 19:53:24 Nit: semicolon.
Lei Zhang 2011/10/10 20:03:14 Done.
1050 }
1051 }
1052
1025 window.addEventListener('DOMContentLoaded', onLoad); 1053 window.addEventListener('DOMContentLoaded', onLoad);
1054 window.addEventListener('keydown', onKeyDown);
1026 1055
1027 /// Pull in all other scripts in a single shot. 1056 /// Pull in all other scripts in a single shot.
1028 <include src="print_preview_animations.js"/> 1057 <include src="print_preview_animations.js"/>
1029 <include src="print_preview_cloud.js"/> 1058 <include src="print_preview_cloud.js"/>
1030 <include src="print_preview_utils.js"/> 1059 <include src="print_preview_utils.js"/>
1031 <include src="print_header.js"/> 1060 <include src="print_header.js"/>
1032 <include src="page_settings.js"/> 1061 <include src="page_settings.js"/>
1033 <include src="copies_settings.js"/> 1062 <include src="copies_settings.js"/>
1034 <include src="header_footer_settings.js"/> 1063 <include src="header_footer_settings.js"/>
1035 <include src="layout_settings.js"/> 1064 <include src="layout_settings.js"/>
1036 <include src="color_settings.js"/> 1065 <include src="color_settings.js"/>
1037 <include src="margin_settings.js"/> 1066 <include src="margin_settings.js"/>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698