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

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

Issue 8564040: Revert 110035 - Print Preview: Making margin selection sticky (part 2/2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 157
158 pageSettings = print_preview.PageSettings.getInstance(); 158 pageSettings = print_preview.PageSettings.getInstance();
159 copiesSettings = print_preview.CopiesSettings.getInstance(); 159 copiesSettings = print_preview.CopiesSettings.getInstance();
160 layoutSettings = print_preview.LayoutSettings.getInstance(); 160 layoutSettings = print_preview.LayoutSettings.getInstance();
161 marginSettings = print_preview.MarginSettings.getInstance(); 161 marginSettings = print_preview.MarginSettings.getInstance();
162 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); 162 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance();
163 colorSettings = print_preview.ColorSettings.getInstance(); 163 colorSettings = print_preview.ColorSettings.getInstance();
164 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 164 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
165 165
166 previewArea.showLoadingAnimation(); 166 previewArea.showLoadingAnimation();
167 chrome.send('getInitialSettings'); 167 chrome.send('getInitiatorTabTitle');
168 } 168 chrome.send('getDefaultPrinter');
169 169 chrome.send('getNumberFormatAndMeasurementSystem');
170 /**
171 * @param {string} initiatorTabTitle The title of the initiator tab.
172 * @param {object} initialSettings An object containing all the initial
173 * settings.
174 */
175 function setInitialSettings(initialSettings) {
176 setInitiatorTabTitle(initialSettings['initiatorTabTitle']);
177 previewModifiable = initialSettings['previewModifiable'];
178 if (previewModifiable) {
179 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem(
180 initialSettings['numberFormat'],
181 initialSettings['measurementSystem']);
182 marginSettings.setLastUsedMargins(initialSettings);
183 }
184 setDefaultPrinter(initialSettings['printerName'],
185 initialSettings['cloudPrintData']);
186 } 170 }
187 171
188 /** 172 /**
189 * Disables the input elements in the sidebar. 173 * Disables the input elements in the sidebar.
190 */ 174 */
191 function disableInputElementsInSidebar() { 175 function disableInputElementsInSidebar() {
192 var els = $('navbar-container').querySelectorAll('input, button, select'); 176 var els = $('navbar-container').querySelectorAll('input, button, select');
193 for (var i = 0; i < els.length; i++) { 177 for (var i = 0; i < els.length; i++) {
194 if (els[i] == printHeader.cancelButton) 178 if (els[i] == printHeader.cancelButton)
195 continue; 179 continue;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 sendPrintDocumentRequest(); 277 sendPrintDocumentRequest();
294 } else { 278 } else {
295 // This message will call back to 'updateWithPrinterCapabilities' 279 // This message will call back to 'updateWithPrinterCapabilities'
296 // function. 280 // function.
297 chrome.send('getPrinterCapabilities', [selectedValue]); 281 chrome.send('getPrinterCapabilities', [selectedValue]);
298 } 282 }
299 if (!skip_refresh) { 283 if (!skip_refresh) {
300 lastSelectedPrinterIndex = selectedIndex; 284 lastSelectedPrinterIndex = selectedIndex;
301 285
302 // Regenerate the preview data based on selected printer settings. 286 // Regenerate the preview data based on selected printer settings.
303 // Do not reset the margins if no preview request has been made. 287 setDefaultValuesAndRegeneratePreview(true);
304 var resetMargins = lastPreviewRequestID != initialPreviewRequestID;
305 setDefaultValuesAndRegeneratePreview(resetMargins);
306 } 288 }
307 } 289 }
308 290
309 /** 291 /**
310 * Helper function to do the actual work of updating cloud printer 292 * Helper function to do the actual work of updating cloud printer
311 * capabilities. 293 * capabilities.
312 * @param {Object} printer The printer object to set capabilities for. 294 * @param {Object} printer The printer object to set capabilities for.
313 */ 295 */
314 function doUpdateCloudPrinterCapabilities(printer) { 296 function doUpdateCloudPrinterCapabilities(printer) {
315 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), 297 var settings = {'disableColorOption': !cloudprint.supportsColor(printer),
316 'setColorAsDefault': cloudprint.colorIsDefault(printer), 298 'setColorAsDefault': cloudprint.colorIsDefault(printer),
317 'disableCopiesOption': true, 299 'disableCopiesOption': true,
318 'disableLandscapeOption': true}; 300 'disableLandscapeOption': true};
319 updateWithPrinterCapabilities(settings); 301 updateWithPrinterCapabilities(settings);
320 var printerList = $('printer-list'); 302 var printerList = $('printer-list');
321 var selectedIndex = printerList.selectedIndex; 303 var selectedIndex = printerList.selectedIndex;
322 lastSelectedPrinterIndex = selectedIndex; 304 lastSelectedPrinterIndex = selectedIndex;
323 305
324 // Regenerate the preview data based on selected printer settings. 306 // Regenerate the preview data based on selected printer settings.
325 // Do not reset the margins if no preview request has been made. 307 setDefaultValuesAndRegeneratePreview(true);
326 var resetMargins = lastPreviewRequestID != initialPreviewRequestID;
327 setDefaultValuesAndRegeneratePreview(resetMargins);
328 } 308 }
329 309
330 /** 310 /**
331 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the 311 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the
332 * capabilities of the currently selected printer. It is called from C++ too. 312 * capabilities of the currently selected printer. It is called from C++ too.
333 * @param {Object} settingInfo printer setting information. 313 * @param {Object} settingInfo printer setting information.
334 */ 314 */
335 function updateWithPrinterCapabilities(settingInfo) { 315 function updateWithPrinterCapabilities(settingInfo) {
336 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); 316 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED);
337 customEvent.printerCapabilities = settingInfo; 317 customEvent.printerCapabilities = settingInfo;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 disableInputElementsInSidebar(); 571 disableInputElementsInSidebar();
592 previewArea.showCustomMessage( 572 previewArea.showCustomMessage(
593 localStrings.getString('printingToPDFInProgress')); 573 localStrings.getString('printingToPDFInProgress'));
594 } 574 }
595 575
596 /** 576 /**
597 * Set the default printer. If there is one, generate a print preview. 577 * Set the default printer. If there is one, generate a print preview.
598 * @param {string} printer Name of the default printer. Empty if none. 578 * @param {string} printer Name of the default printer. Empty if none.
599 * @param {string} cloudPrintData Cloud print related data to restore if 579 * @param {string} cloudPrintData Cloud print related data to restore if
600 * the default printer is a cloud printer. 580 * the default printer is a cloud printer.
581 * @param {number} lastUsedMarginsType Indicates the last used margins type
582 * (matches enum MarginType in printing/print_job_constants.h.
601 */ 583 */
602 function setDefaultPrinter(printerName, cloudPrintData) { 584 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) {
585 // Setting the margin selection to the last used one.
586 marginSettings.setLastUsedMarginsType(lastUsedMarginsType);
603 // Add a placeholder value so the printer list looks valid. 587 // Add a placeholder value so the printer list looks valid.
604 addDestinationListOption('', '', true, true, true); 588 addDestinationListOption('', '', true, true, true);
605 if (printerName) { 589 if (printer_name) {
606 defaultOrLastUsedPrinterName = printerName; 590 defaultOrLastUsedPrinterName = printer_name;
607 if (cloudPrintData) { 591 if (cloudPrintData) {
608 cloudprint.setDefaultPrinter(printerName, 592 cloudprint.setDefaultPrinter(printer_name,
609 cloudPrintData, 593 cloudPrintData,
610 addDestinationListOptionAtPosition, 594 addDestinationListOptionAtPosition,
611 doUpdateCloudPrinterCapabilities); 595 doUpdateCloudPrinterCapabilities);
612 } else { 596 } else {
613 $('printer-list')[0].value = defaultOrLastUsedPrinterName; 597 $('printer-list')[0].value = defaultOrLastUsedPrinterName;
614 updateControlsWithSelectedPrinterCapabilities(); 598 updateControlsWithSelectedPrinterCapabilities();
615 } 599 }
616 } 600 }
617 chrome.send('getPrinters'); 601 chrome.send('getPrinters');
618 } 602 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 772
789 function setPluginPreviewPageCount() { 773 function setPluginPreviewPageCount() {
790 $('pdf-viewer').printPreviewPageCount( 774 $('pdf-viewer').printPreviewPageCount(
791 pageSettings.previouslySelectedPages.length); 775 pageSettings.previouslySelectedPages.length);
792 } 776 }
793 777
794 /** 778 /**
795 * Update the page count and check the page range. 779 * Update the page count and check the page range.
796 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). 780 * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
797 * @param {number} pageCount The number of pages. 781 * @param {number} pageCount The number of pages.
782 * @param {boolean} isModifiable Indicates whether the previewed document can be
783 * modified.
798 * @param {number} previewResponseId The preview request id that resulted in 784 * @param {number} previewResponseId The preview request id that resulted in
799 * this response. 785 * this response.
800 */ 786 */
801 function onDidGetPreviewPageCount(pageCount, previewResponseId) { 787 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) {
802 if (!isExpectedPreviewResponse(previewResponseId)) 788 if (!isExpectedPreviewResponse(previewResponseId))
803 return; 789 return;
804 pageSettings.updateState(pageCount); 790 pageSettings.updateState(pageCount);
791 previewModifiable = isModifiable;
805 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) 792 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded())
806 return; 793 return;
807 794
808 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); 795 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY);
809 } 796 }
810 797
811 /** 798 /**
812 * @param {printing::PageSizeMargins} pageLayout The default layout of the page 799 * @param {printing::PageSizeMargins} pageLayout The default layout of the page
813 * in points. 800 * in points.
814 */ 801 */
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 * Takes a snapshot of the print settings. 1051 * Takes a snapshot of the print settings.
1065 */ 1052 */
1066 PrintSettings.prototype.save = function() { 1053 PrintSettings.prototype.save = function() {
1067 this.deviceName = getSelectedPrinterName(); 1054 this.deviceName = getSelectedPrinterName();
1068 this.isLandscape = layoutSettings.isLandscape(); 1055 this.isLandscape = layoutSettings.isLandscape();
1069 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); 1056 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter();
1070 } 1057 }
1071 1058
1072 /** 1059 /**
1073 * Updates the title of the print preview tab according to |initiatorTabTitle|. 1060 * Updates the title of the print preview tab according to |initiatorTabTitle|.
1061 * Called from PrintPreviewUI::OnGetInitiatorTabTitle as a result of sending a
1062 * 'getInitiatorTabTitle' message.
1074 * @param {string} initiatorTabTitle The title of the initiator tab. 1063 * @param {string} initiatorTabTitle The title of the initiator tab.
1075 */ 1064 */
1076 function setInitiatorTabTitle(initiatorTabTitle) { 1065 function setInitiatorTabTitle(initiatorTabTitle) {
1077 if (initiatorTabTitle == '') 1066 if (initiatorTabTitle == '')
1078 return; 1067 return;
1079 document.title = localStrings.getStringF( 1068 document.title = localStrings.getStringF(
1080 'printPreviewTitleFormat', initiatorTabTitle); 1069 'printPreviewTitleFormat', initiatorTabTitle);
1081 } 1070 }
1082 1071
1083 /** 1072 /**
(...skipping 27 matching lines...) Expand all
1111 <include src="copies_settings.js"/> 1100 <include src="copies_settings.js"/>
1112 <include src="header_footer_settings.js"/> 1101 <include src="header_footer_settings.js"/>
1113 <include src="layout_settings.js"/> 1102 <include src="layout_settings.js"/>
1114 <include src="color_settings.js"/> 1103 <include src="color_settings.js"/>
1115 <include src="margin_settings.js"/> 1104 <include src="margin_settings.js"/>
1116 <include src="margin_textbox.js"/> 1105 <include src="margin_textbox.js"/>
1117 <include src="margin_utils.js"/> 1106 <include src="margin_utils.js"/>
1118 <include src="margins_ui.js"/> 1107 <include src="margins_ui.js"/>
1119 <include src="margins_ui_pair.js"/> 1108 <include src="margins_ui_pair.js"/>
1120 <include src="preview_area.js"/> 1109 <include src="preview_area.js"/>
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/margin_settings.js ('k') | chrome/browser/ui/webui/print_preview_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698