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

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

Issue 8351048: Print Preview: Making margin selection sticky (part 2/2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing coments Created 9 years, 1 month 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 pageSettings = print_preview.PageSettings.getInstance(); 157 pageSettings = print_preview.PageSettings.getInstance();
158 copiesSettings = print_preview.CopiesSettings.getInstance(); 158 copiesSettings = print_preview.CopiesSettings.getInstance();
159 layoutSettings = print_preview.LayoutSettings.getInstance(); 159 layoutSettings = print_preview.LayoutSettings.getInstance();
160 marginSettings = print_preview.MarginSettings.getInstance(); 160 marginSettings = print_preview.MarginSettings.getInstance();
161 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); 161 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance();
162 colorSettings = print_preview.ColorSettings.getInstance(); 162 colorSettings = print_preview.ColorSettings.getInstance();
163 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 163 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
164 164
165 previewArea.showLoadingAnimation(); 165 previewArea.showLoadingAnimation();
166 chrome.send('getInitiatorTabTitle'); 166 chrome.send('getInitiatorTabTitle');
167 chrome.send('getDefaultPrinter'); 167 serializeRequests();
168 chrome.send('getNumberFormatAndMeasurementSystem'); 168 chrome.send('getNumberFormatAndMeasurementSystem');
169 } 169 }
170 170
171 /** 171 /**
172 * Serializes requests |getNumberFormatAndMeasurementSystem|,
173 * |getLastUsedMarginSettings| and |getDefaultPrinter|. It guarantees that
174 * responses to those requests will arrive in the order requested.
175 */
176 function serializeRequests() {
177 print_preview.setNumberFormatAndMeasurementSystem =
178 function(numberFormat, measurementSystem) {
179 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem(
vandebo (ex-Chrome) 2011/11/02 22:36:54 As discussed, this is brittle, save the old value
dpapad 2011/11/03 00:15:27 Done.
180 numberFormat, measurementSystem);
181 chrome.send('getLastUsedMarginSettings');
182 };
183 print_preview.setLastUsedMargins = function (
184 lastUsedMarginType, lastUsedMargins) {
185 marginSettings.setLastUsedMargins(lastUsedMarginType, lastUsedMargins);
186 chrome.send('getDefaultPrinter');
187 };
188 }
189
190 /**
172 * Disables the input elements in the sidebar. 191 * Disables the input elements in the sidebar.
173 */ 192 */
174 function disableInputElementsInSidebar() { 193 function disableInputElementsInSidebar() {
175 var els = $('sidebar').querySelectorAll('input, button, select'); 194 var els = $('sidebar').querySelectorAll('input, button, select');
176 for (var i = 0; i < els.length; i++) { 195 for (var i = 0; i < els.length; i++) {
177 if (els[i] == printHeader.cancelButton) 196 if (els[i] == printHeader.cancelButton)
178 continue; 197 continue;
179 els[i].disabled = true; 198 els[i].disabled = true;
180 } 199 }
181 } 200 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 sendPrintDocumentRequest(); 295 sendPrintDocumentRequest();
277 } else { 296 } else {
278 // This message will call back to 'updateWithPrinterCapabilities' 297 // This message will call back to 'updateWithPrinterCapabilities'
279 // function. 298 // function.
280 chrome.send('getPrinterCapabilities', [selectedValue]); 299 chrome.send('getPrinterCapabilities', [selectedValue]);
281 } 300 }
282 if (!skip_refresh) { 301 if (!skip_refresh) {
283 lastSelectedPrinterIndex = selectedIndex; 302 lastSelectedPrinterIndex = selectedIndex;
284 303
285 // Regenerate the preview data based on selected printer settings. 304 // Regenerate the preview data based on selected printer settings.
286 setDefaultValuesAndRegeneratePreview(true); 305 setDefaultValuesAndRegeneratePreview(false);
287 } 306 }
288 } 307 }
289 308
290 /** 309 /**
291 * Helper function to do the actual work of updating cloud printer 310 * Helper function to do the actual work of updating cloud printer
292 * capabilities. 311 * capabilities.
293 * @param {Object} printer The printer object to set capabilities for. 312 * @param {Object} printer The printer object to set capabilities for.
294 */ 313 */
295 function doUpdateCloudPrinterCapabilities(printer) { 314 function doUpdateCloudPrinterCapabilities(printer) {
296 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), 315 var settings = {'disableColorOption': !cloudprint.supportsColor(printer),
297 'setColorAsDefault': cloudprint.colorIsDefault(printer), 316 'setColorAsDefault': cloudprint.colorIsDefault(printer),
298 'disableCopiesOption': true, 317 'disableCopiesOption': true,
299 'disableLandscapeOption': true}; 318 'disableLandscapeOption': true};
300 updateWithPrinterCapabilities(settings); 319 updateWithPrinterCapabilities(settings);
301 var printerList = $('printer-list'); 320 var printerList = $('printer-list');
302 var selectedIndex = printerList.selectedIndex; 321 var selectedIndex = printerList.selectedIndex;
303 lastSelectedPrinterIndex = selectedIndex; 322 lastSelectedPrinterIndex = selectedIndex;
304 323
305 // Regenerate the preview data based on selected printer settings. 324 // Regenerate the preview data based on selected printer settings.
306 setDefaultValuesAndRegeneratePreview(true); 325 setDefaultValuesAndRegeneratePreview(false);
307 } 326 }
308 327
309 /** 328 /**
310 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the 329 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the
311 * capabilities of the currently selected printer. It is called from C++ too. 330 * capabilities of the currently selected printer. It is called from C++ too.
312 * @param {Object} settingInfo printer setting information. 331 * @param {Object} settingInfo printer setting information.
313 */ 332 */
314 function updateWithPrinterCapabilities(settingInfo) { 333 function updateWithPrinterCapabilities(settingInfo) {
315 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); 334 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED);
316 customEvent.printerCapabilities = settingInfo; 335 customEvent.printerCapabilities = settingInfo;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 disableInputElementsInSidebar(); 589 disableInputElementsInSidebar();
571 previewArea.showCustomMessage( 590 previewArea.showCustomMessage(
572 localStrings.getString('printingToPDFInProgress')); 591 localStrings.getString('printingToPDFInProgress'));
573 } 592 }
574 593
575 /** 594 /**
576 * Set the default printer. If there is one, generate a print preview. 595 * Set the default printer. If there is one, generate a print preview.
577 * @param {string} printer Name of the default printer. Empty if none. 596 * @param {string} printer Name of the default printer. Empty if none.
578 * @param {string} cloudPrintData Cloud print related data to restore if 597 * @param {string} cloudPrintData Cloud print related data to restore if
579 * the default printer is a cloud printer. 598 * the default printer is a cloud printer.
580 * @param {number} lastUsedMarginsType Indicates the last used margins type
581 * (matches enum MarginType in printing/print_job_constants.h.
582 */ 599 */
583 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { 600 function setDefaultPrinter(printer_name, cloudPrintData) {
584 // Setting the margin selection to the last used one.
585 marginSettings.setLastUsedMarginsType(lastUsedMarginsType);
586 // Add a placeholder value so the printer list looks valid. 601 // Add a placeholder value so the printer list looks valid.
587 addDestinationListOption('', '', true, true, true); 602 addDestinationListOption('', '', true, true, true);
588 if (printer_name) { 603 if (printer_name) {
589 defaultOrLastUsedPrinterName = printer_name; 604 defaultOrLastUsedPrinterName = printer_name;
590 if (cloudPrintData) { 605 if (cloudPrintData) {
591 cloudprint.setDefaultPrinter(printer_name, 606 cloudprint.setDefaultPrinter(printer_name,
592 cloudPrintData, 607 cloudPrintData,
593 addDestinationListOptionAtPosition, 608 addDestinationListOptionAtPosition,
594 doUpdateCloudPrinterCapabilities); 609 doUpdateCloudPrinterCapabilities);
595 } else { 610 } else {
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 <include src="copies_settings.js"/> 1114 <include src="copies_settings.js"/>
1100 <include src="header_footer_settings.js"/> 1115 <include src="header_footer_settings.js"/>
1101 <include src="layout_settings.js"/> 1116 <include src="layout_settings.js"/>
1102 <include src="color_settings.js"/> 1117 <include src="color_settings.js"/>
1103 <include src="margin_settings.js"/> 1118 <include src="margin_settings.js"/>
1104 <include src="margin_textbox.js"/> 1119 <include src="margin_textbox.js"/>
1105 <include src="margin_utils.js"/> 1120 <include src="margin_utils.js"/>
1106 <include src="margins_ui.js"/> 1121 <include src="margins_ui.js"/>
1107 <include src="margins_ui_pair.js"/> 1122 <include src="margins_ui_pair.js"/>
1108 <include src="preview_area.js"/> 1123 <include src="preview_area.js"/>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698