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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 * Window onload handler, sets up the page and starts print preview by getting | 107 * Window onload handler, sets up the page and starts print preview by getting |
108 * the printer list. | 108 * the printer list. |
109 */ | 109 */ |
110 function onLoad() { | 110 function onLoad() { |
111 cr.enablePlatformSpecificCSSRules(); | 111 cr.enablePlatformSpecificCSSRules(); |
112 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); | 112 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); |
113 lastPreviewRequestID = initialPreviewRequestID; | 113 lastPreviewRequestID = initialPreviewRequestID; |
114 | 114 |
115 previewArea = print_preview.PreviewArea.getInstance(); | 115 previewArea = print_preview.PreviewArea.getInstance(); |
116 printHeader = print_preview.PrintHeader.getInstance(); | 116 printHeader = print_preview.PrintHeader.getInstance(); |
117 addEventListeners(); | |
117 | 118 |
118 if (!checkCompatiblePluginExists()) { | 119 if (!checkCompatiblePluginExists()) { |
119 disableInputElementsInSidebar(); | 120 disableInputElementsInSidebar(); |
120 previewArea.displayErrorMessageWithButton( | 121 previewArea.displayErrorMessageWithButton( |
121 localStrings.getString('noPlugin'), | 122 localStrings.getString('noPlugin'), |
122 localStrings.getString('launchNativeDialog'), | 123 localStrings.getString('launchNativeDialog'), |
123 launchNativePrintDialog); | 124 launchNativePrintDialog); |
124 cancelPendingPrintRequest(); | |
125 $('mainview').parentElement.removeChild($('dummy-viewer')); | 125 $('mainview').parentElement.removeChild($('dummy-viewer')); |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); | 129 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); |
130 $('mainview').parentElement.removeChild($('dummy-viewer')); | 130 $('mainview').parentElement.removeChild($('dummy-viewer')); |
131 | 131 |
132 $('printer-list').disabled = true; | 132 $('printer-list').disabled = true; |
133 | 133 |
134 pageSettings = print_preview.PageSettings.getInstance(); | 134 pageSettings = print_preview.PageSettings.getInstance(); |
135 copiesSettings = print_preview.CopiesSettings.getInstance(); | 135 copiesSettings = print_preview.CopiesSettings.getInstance(); |
136 layoutSettings = print_preview.LayoutSettings.getInstance(); | 136 layoutSettings = print_preview.LayoutSettings.getInstance(); |
137 marginSettings = print_preview.MarginSettings.getInstance(); | 137 marginSettings = print_preview.MarginSettings.getInstance(); |
138 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 138 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
139 colorSettings = print_preview.ColorSettings.getInstance(); | 139 colorSettings = print_preview.ColorSettings.getInstance(); |
140 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 140 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
141 | 141 |
142 previewArea.showLoadingAnimation(); | 142 previewArea.showLoadingAnimation(); |
143 chrome.send('getInitiatorTabTitle'); | 143 chrome.send('getInitiatorTabTitle'); |
144 chrome.send('getDefaultPrinter'); | 144 chrome.send('getDefaultPrinter'); |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Adds event listeners for various events. | |
149 */ | |
150 function addEventListeners() { | |
151 document.addEventListener('errorOccurred', onErrorOccurred); | |
Evan Stade
2011/10/19 22:34:11
why does this have its own helper function? at thi
dpapad
2011/10/19 22:56:21
Done.
| |
152 } | |
153 | |
154 /** | |
155 * Executes when an 'errorOccurred' event occurs. | |
156 */ | |
157 function onErrorOccurred() { | |
Evan Stade
2011/10/19 22:34:11
likewise, move the body of cancelpendingprintreque
dpapad
2011/10/19 22:56:21
Done.
| |
158 cancelPendingPrintRequest(); | |
159 } | |
160 | |
161 /** | |
148 * Disables the input elements in the sidebar. | 162 * Disables the input elements in the sidebar. |
149 */ | 163 */ |
150 function disableInputElementsInSidebar() { | 164 function disableInputElementsInSidebar() { |
151 var els = $('sidebar').querySelectorAll('input, button, select'); | 165 var els = $('sidebar').querySelectorAll('input, button, select'); |
152 for (var i = 0; i < els.length; i++) { | 166 for (var i = 0; i < els.length; i++) { |
153 if (els[i] == printHeader.cancelButton) | 167 if (els[i] == printHeader.cancelButton) |
154 continue; | 168 continue; |
155 els[i].disabled = true; | 169 els[i].disabled = true; |
156 } | 170 } |
157 } | 171 } |
(...skipping 30 matching lines...) Expand all Loading... | |
188 * data. This function is called when the initiator tab has crashed. | 202 * data. This function is called when the initiator tab has crashed. |
189 * @param {string} initiatorTabURL The URL of the initiator tab. | 203 * @param {string} initiatorTabURL The URL of the initiator tab. |
190 */ | 204 */ |
191 function onInitiatorTabCrashed(initiatorTabURL) { | 205 function onInitiatorTabCrashed(initiatorTabURL) { |
192 disableInputElementsInSidebar(); | 206 disableInputElementsInSidebar(); |
193 if (initiatorTabURL) { | 207 if (initiatorTabURL) { |
194 previewArea.displayErrorMessageWithButton( | 208 previewArea.displayErrorMessageWithButton( |
195 localStrings.getString('initiatorTabCrashed'), | 209 localStrings.getString('initiatorTabCrashed'), |
196 localStrings.getString('reopenPage'), | 210 localStrings.getString('reopenPage'), |
197 function() { chrome.send('reloadCrashedInitiatorTab'); }); | 211 function() { chrome.send('reloadCrashedInitiatorTab'); }); |
198 cancelPendingPrintRequest(); | |
199 } else { | 212 } else { |
200 previewArea.displayErrorMessage( | 213 previewArea.displayErrorMessage( |
201 localStrings.getString('initiatorTabCrashed')); | 214 localStrings.getString('initiatorTabCrashed')); |
202 cancelPendingPrintRequest(); | |
203 } | 215 } |
204 } | 216 } |
205 | 217 |
206 /** | 218 /** |
207 * Disables the controls which need the initiator tab to generate preview | 219 * Disables the controls which need the initiator tab to generate preview |
208 * data. This function is called when the initiator tab is closed. | 220 * data. This function is called when the initiator tab is closed. |
209 * @param {string} initiatorTabURL The URL of the initiator tab. | 221 * @param {string} initiatorTabURL The URL of the initiator tab. |
210 */ | 222 */ |
211 function onInitiatorTabClosed(initiatorTabURL) { | 223 function onInitiatorTabClosed(initiatorTabURL) { |
212 disableInputElementsInSidebar(); | 224 disableInputElementsInSidebar(); |
213 if (initiatorTabURL) { | 225 if (initiatorTabURL) { |
214 previewArea.displayErrorMessageWithButton( | 226 previewArea.displayErrorMessageWithButton( |
215 localStrings.getString('initiatorTabClosed'), | 227 localStrings.getString('initiatorTabClosed'), |
216 localStrings.getString('reopenPage'), | 228 localStrings.getString('reopenPage'), |
217 function() { window.location = initiatorTabURL; }); | 229 function() { window.location = initiatorTabURL; }); |
218 cancelPendingPrintRequest(); | |
219 } else { | 230 } else { |
220 previewArea.displayErrorMessage( | 231 previewArea.displayErrorMessage( |
221 localStrings.getString('initiatorTabClosed')); | 232 localStrings.getString('initiatorTabClosed')); |
222 cancelPendingPrintRequest(); | |
223 } | 233 } |
224 } | 234 } |
225 | 235 |
226 /** | 236 /** |
227 * Gets the selected printer capabilities and updates the controls accordingly. | 237 * Gets the selected printer capabilities and updates the controls accordingly. |
228 */ | 238 */ |
229 function updateControlsWithSelectedPrinterCapabilities() { | 239 function updateControlsWithSelectedPrinterCapabilities() { |
230 var printerList = $('printer-list'); | 240 var printerList = $('printer-list'); |
231 var selectedIndex = printerList.selectedIndex; | 241 var selectedIndex = printerList.selectedIndex; |
232 if (selectedIndex < 0) | 242 if (selectedIndex < 0) |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 | 721 |
712 /** | 722 /** |
713 * Display an error message when print preview fails. | 723 * Display an error message when print preview fails. |
714 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | 724 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). |
715 */ | 725 */ |
716 function printPreviewFailed() { | 726 function printPreviewFailed() { |
717 previewArea.displayErrorMessageWithButton( | 727 previewArea.displayErrorMessageWithButton( |
718 localStrings.getString('previewFailed'), | 728 localStrings.getString('previewFailed'), |
719 localStrings.getString('launchNativeDialog'), | 729 localStrings.getString('launchNativeDialog'), |
720 launchNativePrintDialog); | 730 launchNativePrintDialog); |
721 cancelPendingPrintRequest(); | |
722 } | 731 } |
723 | 732 |
724 /** | 733 /** |
725 * Display an error message when encountered invalid printer settings. | 734 * Display an error message when encountered invalid printer settings. |
726 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | 735 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). |
727 */ | 736 */ |
728 function invalidPrinterSettings() { | 737 function invalidPrinterSettings() { |
729 previewArea.displayErrorMessage( | 738 previewArea.displayErrorMessage( |
730 localStrings.getString('invalidPrinterSettings')); | 739 localStrings.getString('invalidPrinterSettings')); |
731 cancelPendingPrintRequest(); | |
732 } | 740 } |
733 | 741 |
734 /** | 742 /** |
735 * Called when the PDF plugin loads its document. | 743 * Called when the PDF plugin loads its document. |
736 */ | 744 */ |
737 function onPDFLoad() { | 745 function onPDFLoad() { |
738 if (previewModifiable) { | 746 if (previewModifiable) { |
739 setPluginPreviewPageCount(); | 747 setPluginPreviewPageCount(); |
740 } | 748 } |
741 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 749 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 <include src="copies_settings.js"/> | 1081 <include src="copies_settings.js"/> |
1074 <include src="header_footer_settings.js"/> | 1082 <include src="header_footer_settings.js"/> |
1075 <include src="layout_settings.js"/> | 1083 <include src="layout_settings.js"/> |
1076 <include src="color_settings.js"/> | 1084 <include src="color_settings.js"/> |
1077 <include src="margin_settings.js"/> | 1085 <include src="margin_settings.js"/> |
1078 <include src="margin_textbox.js"/> | 1086 <include src="margin_textbox.js"/> |
1079 <include src="margin_utils.js"/> | 1087 <include src="margin_utils.js"/> |
1080 <include src="margins_ui.js"/> | 1088 <include src="margins_ui.js"/> |
1081 <include src="margins_ui_pair.js"/> | 1089 <include src="margins_ui_pair.js"/> |
1082 <include src="preview_area.js"/> | 1090 <include src="preview_area.js"/> |
OLD | NEW |