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

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

Issue 318293002: Revert of Revert of Generalize printer color model handling, get rid of CUPS specific case. Enable supported paper szes… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * An interface to the native Chromium printing system layer. 9 * An interface to the native Chromium printing system layer.
10 * @constructor 10 * @constructor
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 /** 161 /**
162 * Requests the destination's printing capabilities. A CAPABILITIES_SET 162 * Requests the destination's printing capabilities. A CAPABILITIES_SET
163 * event will be dispatched in response. 163 * event will be dispatched in response.
164 * @param {string} destinationId ID of the destination. 164 * @param {string} destinationId ID of the destination.
165 */ 165 */
166 startGetLocalDestinationCapabilities: function(destinationId) { 166 startGetLocalDestinationCapabilities: function(destinationId) {
167 chrome.send('getPrinterCapabilities', [destinationId]); 167 chrome.send('getPrinterCapabilities', [destinationId]);
168 }, 168 },
169 169
170 /** 170 /**
171 * @param {!print_preview.Destination} destination Destination to print to.
172 * @param {!print_preview.ticket_items.Color} color Color ticket item.
173 * @return {number} Native layer color model.
174 * @private
175 */
176 getNativeColorModel_: function(destination, color) {
177 // For non-local printers native color model is ignored anyway.
178 var option = destination.isLocal ? color.getSelectedOption() : null;
179 var nativeColorModel = parseInt(option ? option.vendor_id : null);
180 if (isNaN(nativeColorModel)) {
181 return color.getValue() ?
182 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY;
183 }
184 return nativeColorModel;
185 },
186
187 /**
171 * Requests that a preview be generated. The following events may be 188 * Requests that a preview be generated. The following events may be
172 * dispatched in response: 189 * dispatched in response:
173 * - PAGE_COUNT_READY 190 * - PAGE_COUNT_READY
174 * - PAGE_LAYOUT_READY 191 * - PAGE_LAYOUT_READY
175 * - PAGE_PREVIEW_READY 192 * - PAGE_PREVIEW_READY
176 * - PREVIEW_GENERATION_DONE 193 * - PREVIEW_GENERATION_DONE
177 * - PREVIEW_GENERATION_FAIL 194 * - PREVIEW_GENERATION_FAIL
178 * @param {print_preview.Destination} destination Destination to print to. 195 * @param {print_preview.Destination} destination Destination to print to.
179 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the 196 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
180 * state of the print ticket. 197 * state of the print ticket.
181 * @param {!print_preview.DocumentInfo} documentInfo Document data model. 198 * @param {!print_preview.DocumentInfo} documentInfo Document data model.
182 * @param {number} ID of the preview request. 199 * @param {number} ID of the preview request.
183 */ 200 */
184 startGetPreview: function( 201 startGetPreview: function(
185 destination, printTicketStore, documentInfo, requestId) { 202 destination, printTicketStore, documentInfo, requestId) {
186 assert(printTicketStore.isTicketValidForPreview(), 203 assert(printTicketStore.isTicketValidForPreview(),
187 'Trying to generate preview when ticket is not valid'); 204 'Trying to generate preview when ticket is not valid');
188 205
189 var ticket = { 206 var ticket = {
190 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), 207 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
191 'mediaSize': printTicketStore.mediaSize.getValue(), 208 'mediaSize': printTicketStore.mediaSize.getValue(),
192 'landscape': printTicketStore.landscape.getValue(), 209 'landscape': printTicketStore.landscape.getValue(),
193 'color': printTicketStore.color.getValue() ? 210 'color': this.getNativeColorModel_(destination, printTicketStore.color),
194 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
195 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), 211 'headerFooterEnabled': printTicketStore.headerFooter.getValue(),
196 'marginsType': printTicketStore.marginsType.getValue(), 212 'marginsType': printTicketStore.marginsType.getValue(),
197 'isFirstRequest': requestId == 0, 213 'isFirstRequest': requestId == 0,
198 'requestID': requestId, 214 'requestID': requestId,
199 'previewModifiable': documentInfo.isModifiable, 215 'previewModifiable': documentInfo.isModifiable,
200 'printToPDF': 216 'printToPDF':
201 destination != null && 217 destination != null &&
202 destination.id == 218 destination.id ==
203 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 219 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
204 'printWithCloudPrint': destination != null && !destination.isLocal, 220 'printWithCloudPrint': destination != null && !destination.isLocal,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 */ 272 */
257 startPrint: function(destination, printTicketStore, cloudPrintInterface, 273 startPrint: function(destination, printTicketStore, cloudPrintInterface,
258 documentInfo, opt_isOpenPdfInPreview) { 274 documentInfo, opt_isOpenPdfInPreview) {
259 assert(printTicketStore.isTicketValid(), 275 assert(printTicketStore.isTicketValid(),
260 'Trying to print when ticket is not valid'); 276 'Trying to print when ticket is not valid');
261 277
262 var ticket = { 278 var ticket = {
263 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), 279 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
264 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, 280 'pageCount': printTicketStore.pageRange.getPageNumberSet().size,
265 'landscape': printTicketStore.landscape.getValue(), 281 'landscape': printTicketStore.landscape.getValue(),
266 'color': printTicketStore.color.getValue() ? 282 'color': this.getNativeColorModel_(destination, printTicketStore.color),
267 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
268 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), 283 'headerFooterEnabled': printTicketStore.headerFooter.getValue(),
269 'marginsType': printTicketStore.marginsType.getValue(), 284 'marginsType': printTicketStore.marginsType.getValue(),
270 'generateDraftData': true, // TODO(rltoscano): What should this be? 285 'generateDraftData': true, // TODO(rltoscano): What should this be?
271 'duplex': printTicketStore.duplex.getValue() ? 286 'duplex': printTicketStore.duplex.getValue() ?
272 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, 287 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX,
273 'copies': printTicketStore.copies.getValueAsNumber(), 288 'copies': printTicketStore.copies.getValueAsNumber(),
274 'collate': printTicketStore.collate.getValue(), 289 'collate': printTicketStore.collate.getValue(),
275 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), 290 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(),
276 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), 291 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(),
277 'previewModifiable': documentInfo.isModifiable, 292 'previewModifiable': documentInfo.isModifiable,
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 return this.serializedAppStateStr_; 865 return this.serializedAppStateStr_;
851 } 866 }
852 }; 867 };
853 868
854 // Export 869 // Export
855 return { 870 return {
856 NativeInitialSettings: NativeInitialSettings, 871 NativeInitialSettings: NativeInitialSettings,
857 NativeLayer: NativeLayer 872 NativeLayer: NativeLayer
858 }; 873 };
859 }); 874 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698