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

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

Issue 8136027: Print Preview: Make print preview tab modal. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix flaky browser tests 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
« no previous file with comments | « chrome/browser/resources/print_preview/print_header.js ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 /** 165 /**
166 * Disables the controls in the sidebar, shows the throbber and instructs the 166 * Disables the controls in the sidebar, shows the throbber and instructs the
167 * backend to open the native print dialog. 167 * backend to open the native print dialog.
168 */ 168 */
169 function onSystemDialogLinkClicked() { 169 function onSystemDialogLinkClicked() {
170 if (showingSystemDialog) 170 if (showingSystemDialog)
171 return; 171 return;
172 showingSystemDialog = true; 172 showingSystemDialog = true;
173 disableInputElementsInSidebar(); 173 disableInputElementsInSidebar();
174 printHeader.disableCancelButton();
174 $('system-dialog-throbber').classList.remove('hidden'); 175 $('system-dialog-throbber').classList.remove('hidden');
175 chrome.send('showSystemDialog'); 176 chrome.send('showSystemDialog');
176 } 177 }
177 178
178 /** 179 /**
179 * Similar to onSystemDialogLinkClicked(), but specific to the 180 * Similar to onSystemDialogLinkClicked(), but specific to the
180 * 'Launch native print dialog' UI. 181 * 'Launch native print dialog' UI.
181 */ 182 */
182 function launchNativePrintDialog() { 183 function launchNativePrintDialog() {
183 if (showingSystemDialog) 184 if (showingSystemDialog)
184 return; 185 return;
185 showingSystemDialog = true; 186 showingSystemDialog = true;
186 $('error-button').disabled = true; 187 $('error-button').disabled = true;
187 printHeader.disableCancelButton(); 188 printHeader.disableCancelButton();
188 $('native-print-dialog-throbber').classList.remove('hidden'); 189 $('native-print-dialog-throbber').classList.remove('hidden');
189 chrome.send('showSystemDialog'); 190 chrome.send('showSystemDialog');
190 } 191 }
191 192
192 /** 193 /**
193 * Disables the controls which need the initiator tab to generate preview
194 * data. This function is called when the initiator tab has crashed.
195 * @param {string} initiatorTabURL The URL of the initiator tab.
196 */
197 function onInitiatorTabCrashed(initiatorTabURL) {
198 disableInputElementsInSidebar();
199 if (initiatorTabURL) {
200 displayErrorMessageWithButton(
201 localStrings.getString('initiatorTabCrashed'),
202 localStrings.getString('reopenPage'),
203 function() { chrome.send('reloadCrashedInitiatorTab'); });
204 } else {
205 displayErrorMessage(localStrings.getString('initiatorTabCrashed'));
206 }
207 }
208
209 /**
210 * Disables the controls which need the initiator tab to generate preview
211 * data. This function is called when the initiator tab is closed.
212 * @param {string} initiatorTabURL The URL of the initiator tab.
213 */
214 function onInitiatorTabClosed(initiatorTabURL) {
215 disableInputElementsInSidebar();
216 if (initiatorTabURL) {
217 displayErrorMessageWithButton(
218 localStrings.getString('initiatorTabClosed'),
219 localStrings.getString('reopenPage'),
220 function() { window.location = initiatorTabURL; });
221 } else {
222 displayErrorMessage(localStrings.getString('initiatorTabClosed'));
223 }
224 }
225
226 /**
227 * Gets the selected printer capabilities and updates the controls accordingly. 194 * Gets the selected printer capabilities and updates the controls accordingly.
228 */ 195 */
229 function updateControlsWithSelectedPrinterCapabilities() { 196 function updateControlsWithSelectedPrinterCapabilities() {
230 var printerList = $('printer-list'); 197 var printerList = $('printer-list');
231 var selectedIndex = printerList.selectedIndex; 198 var selectedIndex = printerList.selectedIndex;
232 if (selectedIndex < 0) 199 if (selectedIndex < 0)
233 return; 200 return;
234 var skip_refresh = false; 201 var skip_refresh = false;
235 var selectedValue = printerList.options[selectedIndex].value; 202 var selectedValue = printerList.options[selectedIndex].value;
236 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) { 203 if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 * Updates the controls with printer capabilities information. 255 * Updates the controls with printer capabilities information.
289 * @param {Object} settingInfo printer setting information. 256 * @param {Object} settingInfo printer setting information.
290 */ 257 */
291 function updateWithPrinterCapabilities(settingInfo) { 258 function updateWithPrinterCapabilities(settingInfo) {
292 var customEvent = new cr.Event("printerCapabilitiesUpdated"); 259 var customEvent = new cr.Event("printerCapabilitiesUpdated");
293 customEvent.printerCapabilities = settingInfo; 260 customEvent.printerCapabilities = settingInfo;
294 document.dispatchEvent(customEvent); 261 document.dispatchEvent(customEvent);
295 } 262 }
296 263
297 /** 264 /**
265 * Reloads the printer list for cloud print.
266 */
267 function reloadCloudPrintersList() {
Albert Bodenhamer 2011/10/17 16:43:42 Nit: Wont this reload all printers? I know you'r
Lei Zhang 2011/10/17 18:18:57 Done.
268 $('printer-list').length = 0;
269 firstCloudPrintOptionPos = 0;
270 lastCloudPrintOptionPos = 0;
271 chrome.send('getPrinters');
272 }
273
274 /**
298 * Turn on the integration of Cloud Print. 275 * Turn on the integration of Cloud Print.
299 * @param {string} cloudPrintUrl The URL to use for cloud print servers. 276 * @param {string} cloudPrintUrl The URL to use for cloud print servers.
300 */ 277 */
301 function setUseCloudPrint(cloudPrintURL) { 278 function setUseCloudPrint(cloudPrintURL) {
302 useCloudPrint = true; 279 useCloudPrint = true;
303 cloudprint.setBaseURL(cloudPrintURL); 280 cloudprint.setBaseURL(cloudPrintURL);
304 } 281 }
305 282
306 /** 283 /**
307 * Take the PDF data handed to us and submit it to the cloud, closing the print 284 * Take the PDF data handed to us and submit it to the cloud, closing the print
308 * preview tab once the upload is successful. 285 * preview tab once the upload is successful.
309 * @param {string} data Data to send as the print job. 286 * @param {string} data Data to send as the print job.
310 */ 287 */
311 function printToCloud(data) { 288 function printToCloud(data) {
312 cloudprint.printToCloud(data, finishedCloudPrinting); 289 cloudprint.printToCloud(data, finishedCloudPrinting);
313 } 290 }
314 291
315 /** 292 /**
316 * Cloud print upload of the PDF file is finished, time to close the dialog. 293 * Cloud print upload of the PDF file is finished, time to close the dialog.
317 */ 294 */
318 function finishedCloudPrinting() { 295 function finishedCloudPrinting() {
319 window.location = cloudprint.getBaseURL(); 296 closePrintPreviewTab();
320 } 297 }
321 298
322 /** 299 /**
323 * Checks whether the specified settings are valid. 300 * Checks whether the specified settings are valid.
324 * 301 *
325 * @return {boolean} true if settings are valid, false if not. 302 * @return {boolean} true if settings are valid, false if not.
326 */ 303 */
327 function areSettingsValid() { 304 function areSettingsValid() {
328 var selectedPrinter = getSelectedPrinterName(); 305 var selectedPrinter = getSelectedPrinterName();
329 return pageSettings.isPageSelectionValid() && 306 return pageSettings.isPageSelectionValid() &&
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), 501 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()),
525 pageCount, 502 pageCount,
526 previewModifiable]); 503 previewModifiable]);
527 } 504 }
528 505
529 /** 506 /**
530 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print 507 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
531 * preview tab regarding the file selection cancel event. 508 * preview tab regarding the file selection cancel event.
532 */ 509 */
533 function fileSelectionCancelled() { 510 function fileSelectionCancelled() {
534 // TODO(thestig) re-enable controls here. 511 printHeader.enableCancelButton();
535 } 512 }
536 513
537 /** 514 /**
538 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print 515 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print
539 * preview tab regarding the file selection completed event. 516 * preview tab regarding the file selection completed event.
540 */ 517 */
541 function fileSelectionCompleted() { 518 function fileSelectionCompleted() {
542 // If the file selection is completed and the tab is not already closed it 519 // If the file selection is completed and the tab is not already closed it
543 // means that a pending print to pdf request exists. 520 // means that a pending print to pdf request exists.
544 disableInputElementsInSidebar(); 521 disableInputElementsInSidebar();
(...skipping 19 matching lines...) Expand all
564 } else { 541 } else {
565 $('printer-list')[0].value = defaultOrLastUsedPrinterName; 542 $('printer-list')[0].value = defaultOrLastUsedPrinterName;
566 updateControlsWithSelectedPrinterCapabilities(); 543 updateControlsWithSelectedPrinterCapabilities();
567 } 544 }
568 } 545 }
569 chrome.send('getPrinters'); 546 chrome.send('getPrinters');
570 } 547 }
571 548
572 /** 549 /**
573 * Fill the printer list drop down. 550 * Fill the printer list drop down.
574 * Called from PrintPreviewHandler::SendPrinterList(). 551 * Called from PrintPreviewHandler::SetupPrinterList().
575 * @param {Array} printers Array of printer info objects. 552 * @param {Array} printers Array of printer info objects.
576 */ 553 */
577 function setPrinters(printers) { 554 function setPrinters(printers) {
578 var printerList = $('printer-list'); 555 var printerList = $('printer-list');
579 // Remove empty entry added by setDefaultPrinter. 556 // Remove empty entry added by setDefaultPrinter.
580 if (printerList[0] && printerList[0].textContent == '') 557 if (printerList[0] && printerList[0].textContent == '')
581 printerList.remove(0); 558 printerList.remove(0);
582 for (var i = 0; i < printers.length; ++i) { 559 for (var i = 0; i < printers.length; ++i) {
583 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); 560 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName);
584 addDestinationListOption(printers[i].printerName, printers[i].deviceName, 561 addDestinationListOption(printers[i].printerName, printers[i].deviceName,
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 return; 1051 return;
1075 document.title = localStrings.getStringF( 1052 document.title = localStrings.getStringF(
1076 'printPreviewTitleFormat', initiatorTabTitle); 1053 'printPreviewTitleFormat', initiatorTabTitle);
1077 } 1054 }
1078 1055
1079 /** 1056 /**
1080 * Closes this print preview tab. 1057 * Closes this print preview tab.
1081 */ 1058 */
1082 function closePrintPreviewTab() { 1059 function closePrintPreviewTab() {
1083 chrome.send('closePrintPreviewTab'); 1060 chrome.send('closePrintPreviewTab');
1061 chrome.send('DialogClose');
1084 } 1062 }
1085 1063
1086 /** 1064 /**
1087 * Handle keyboard events. 1065 * Handle keyboard events.
1088 * @param {KeyboardEvent} e The keyboard event. 1066 * @param {KeyboardEvent} e The keyboard event.
1089 */ 1067 */
1090 function onKeyDown(e) { 1068 function onKeyDown(e) {
1091 // Escape key closes the dialog. 1069 // Escape key closes the dialog.
1092 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { 1070 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
1093 printHeader.disableCancelButton(); 1071 printHeader.disableCancelButton();
1094 closePrintPreviewTab(); 1072 closePrintPreviewTab();
1095 } 1073 }
1074 if (e.keyCode == 80) {
1075 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) ||
1076 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) {
1077 window.onkeydown = null;
1078 onSystemDialogLinkClicked();
1079 }
1080 }
1096 } 1081 }
1097 1082
1098 window.addEventListener('DOMContentLoaded', onLoad); 1083 window.addEventListener('DOMContentLoaded', onLoad);
1099 window.onkeydown = onKeyDown; 1084 window.onkeydown = onKeyDown;
1100 1085
1101 /// Pull in all other scripts in a single shot. 1086 /// Pull in all other scripts in a single shot.
1102 <include src="print_preview_animations.js"/> 1087 <include src="print_preview_animations.js"/>
1103 <include src="print_preview_cloud.js"/> 1088 <include src="print_preview_cloud.js"/>
1104 <include src="print_preview_utils.js"/> 1089 <include src="print_preview_utils.js"/>
1105 <include src="print_header.js"/> 1090 <include src="print_header.js"/>
1106 <include src="page_settings.js"/> 1091 <include src="page_settings.js"/>
1107 <include src="copies_settings.js"/> 1092 <include src="copies_settings.js"/>
1108 <include src="header_footer_settings.js"/> 1093 <include src="header_footer_settings.js"/>
1109 <include src="layout_settings.js"/> 1094 <include src="layout_settings.js"/>
1110 <include src="color_settings.js"/> 1095 <include src="color_settings.js"/>
1111 <include src="margin_settings.js"/> 1096 <include src="margin_settings.js"/>
1112 <include src="margin_textbox.js"/> 1097 <include src="margin_textbox.js"/>
1113 <include src="margin_line.js"/> 1098 <include src="margin_line.js"/>
1114 <include src="margin_utils.js"/> 1099 <include src="margin_utils.js"/>
1115 <include src="margins_ui.js"/> 1100 <include src="margins_ui.js"/>
1116 <include src="preview_area.js"/> 1101 <include src="preview_area.js"/>
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/print_header.js ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698