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

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

Issue 2862203002: Print Preview: Fix data/ errors (Closed)
Patch Set: Fix destination resolver Created 3 years, 7 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
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 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or 8 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or
9 // better yet, carry over any print ticket state that is possible. I.e. if 9 // better yet, carry over any print ticket state that is possible. I.e. if
10 // destination changes, the new destination might not support duplex anymore, 10 // destination changes, the new destination might not support duplex anymore,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 * @private 52 * @private
53 */ 53 */
54 this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder(); 54 this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder();
55 55
56 /** 56 /**
57 * Current measurement system. Used to work with margin measurements. 57 * Current measurement system. Used to work with margin measurements.
58 * @type {!print_preview.MeasurementSystem} 58 * @type {!print_preview.MeasurementSystem}
59 * @private 59 * @private
60 */ 60 */
61 this.measurementSystem_ = new print_preview.MeasurementSystem( 61 this.measurementSystem_ = new print_preview.MeasurementSystem(
62 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); 62 ',', '.', print_preview.MeasurementSystemUnitType.IMPERIAL);
63 63
64 /** 64 /**
65 * Collate ticket item. 65 * Collate ticket item.
66 * @type {!print_preview.ticket_items.Collate} 66 * @type {!print_preview.ticket_items.Collate}
67 * @private 67 * @private
68 */ 68 */
69 this.collate_ = new print_preview.ticket_items.Collate( 69 this.collate_ = new print_preview.ticket_items.Collate(
70 this.appState_, this.destinationStore_); 70 this.appState_, this.destinationStore_);
71 71
72 /** 72 /**
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 this.tracker_ = new EventTracker(); 218 this.tracker_ = new EventTracker();
219 219
220 /** 220 /**
221 * Whether the print preview has been initialized. 221 * Whether the print preview has been initialized.
222 * @type {boolean} 222 * @type {boolean}
223 * @private 223 * @private
224 */ 224 */
225 this.isInitialized_ = false; 225 this.isInitialized_ = false;
226 226
227 this.addEventListeners_(); 227 this.addEventListeners_();
228 }; 228 }
229 229
230 /** 230 /**
231 * Event types dispatched by the print ticket store. 231 * Event types dispatched by the print ticket store.
232 * @enum {string} 232 * @enum {string}
233 */ 233 */
234 PrintTicketStore.EventType = { 234 PrintTicketStore.EventType = {
235 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', 235 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE',
236 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', 236 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE',
237 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', 237 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE',
238 TICKET_CHANGE: 'print_preview.PrintTicketStore.TICKET_CHANGE' 238 TICKET_CHANGE: 'print_preview.PrintTicketStore.TICKET_CHANGE'
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 * local system. 322 * local system.
323 */ 323 */
324 get measurementSystem() { 324 get measurementSystem() {
325 return this.measurementSystem_; 325 return this.measurementSystem_;
326 }, 326 },
327 327
328 /** 328 /**
329 * Initializes the print ticket store. Dispatches an INITIALIZE event. 329 * Initializes the print ticket store. Dispatches an INITIALIZE event.
330 * @param {string} thousandsDelimeter Delimeter of the thousands place. 330 * @param {string} thousandsDelimeter Delimeter of the thousands place.
331 * @param {string} decimalDelimeter Delimeter of the decimal point. 331 * @param {string} decimalDelimeter Delimeter of the decimal point.
332 * @param {!print_preview.MeasurementSystem.UnitType} unitType Type of unit 332 * @param {!print_preview.MeasurementSystemUnitType} unitType Type of unit
333 * of the local measurement system. 333 * of the local measurement system.
334 * @param {boolean} selectionOnly Whether only selected content should be 334 * @param {boolean} selectionOnly Whether only selected content should be
335 * printed. 335 * printed.
336 */ 336 */
337 init: function( 337 init: function(
338 thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) { 338 thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) {
339 this.measurementSystem_.setSystem(thousandsDelimeter, decimalDelimeter, 339 this.measurementSystem_.setSystem(thousandsDelimeter, decimalDelimeter,
340 unitType); 340 unitType);
341 this.selectionOnly_.updateValue(selectionOnly); 341 this.selectionOnly_.updateValue(selectionOnly);
342 342
343 // Initialize ticket with user's previous values. 343 // Initialize ticket with user's previous values.
344 if (this.appState_.hasField( 344 if (this.appState_.hasField(
345 print_preview.AppState.Field.IS_COLOR_ENABLED)) { 345 print_preview.AppStateField.IS_COLOR_ENABLED)) {
346 this.color_.updateValue( 346 this.color_.updateValue(
347 /** @type {!Object} */(this.appState_.getField( 347 /** @type {!Object} */(this.appState_.getField(
348 print_preview.AppState.Field.IS_COLOR_ENABLED))); 348 print_preview.AppStateField.IS_COLOR_ENABLED)));
349 } 349 }
350 if (this.appState_.hasField(print_preview.AppState.Field.DPI)) { 350 if (this.appState_.hasField(print_preview.AppStateField.DPI)) {
351 this.dpi_.updateValue( 351 this.dpi_.updateValue(
352 /** @type {!Object} */(this.appState_.getField( 352 /** @type {!Object} */(this.appState_.getField(
353 print_preview.AppState.Field.DPI))); 353 print_preview.AppStateField.DPI)));
354 } 354 }
355 if (this.appState_.hasField( 355 if (this.appState_.hasField(
356 print_preview.AppState.Field.IS_DUPLEX_ENABLED)) { 356 print_preview.AppStateField.IS_DUPLEX_ENABLED)) {
357 this.duplex_.updateValue( 357 this.duplex_.updateValue(
358 /** @type {!Object} */(this.appState_.getField( 358 /** @type {!Object} */(this.appState_.getField(
359 print_preview.AppState.Field.IS_DUPLEX_ENABLED))); 359 print_preview.AppStateField.IS_DUPLEX_ENABLED)));
360 } 360 }
361 if (this.appState_.hasField(print_preview.AppState.Field.MEDIA_SIZE)) { 361 if (this.appState_.hasField(print_preview.AppStateField.MEDIA_SIZE)) {
362 this.mediaSize_.updateValue( 362 this.mediaSize_.updateValue(
363 /** @type {!Object} */(this.appState_.getField( 363 /** @type {!Object} */(this.appState_.getField(
364 print_preview.AppState.Field.MEDIA_SIZE))); 364 print_preview.AppStateField.MEDIA_SIZE)));
365 } 365 }
366 if (this.appState_.hasField( 366 if (this.appState_.hasField(
367 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)) { 367 print_preview.AppStateField.IS_LANDSCAPE_ENABLED)) {
368 this.landscape_.updateValue( 368 this.landscape_.updateValue(
369 /** @type {!Object} */(this.appState_.getField( 369 /** @type {!Object} */(this.appState_.getField(
370 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED))); 370 print_preview.AppStateField.IS_LANDSCAPE_ENABLED)));
371 } 371 }
372 // Initialize margins after landscape because landscape may reset margins. 372 // Initialize margins after landscape because landscape may reset margins.
373 if (this.appState_.hasField(print_preview.AppState.Field.MARGINS_TYPE)) { 373 if (this.appState_.hasField(print_preview.AppStateField.MARGINS_TYPE)) {
374 this.marginsType_.updateValue( 374 this.marginsType_.updateValue(
375 /** @type {!Object} */(this.appState_.getField( 375 /** @type {!Object} */(this.appState_.getField(
376 print_preview.AppState.Field.MARGINS_TYPE))); 376 print_preview.AppStateField.MARGINS_TYPE)));
377 } 377 }
378 if (this.appState_.hasField( 378 if (this.appState_.hasField(
379 print_preview.AppState.Field.CUSTOM_MARGINS)) { 379 print_preview.AppStateField.CUSTOM_MARGINS)) {
380 this.customMargins_.updateValue( 380 this.customMargins_.updateValue(
381 /** @type {!Object} */(this.appState_.getField( 381 /** @type {!Object} */(this.appState_.getField(
382 print_preview.AppState.Field.CUSTOM_MARGINS))); 382 print_preview.AppStateField.CUSTOM_MARGINS)));
383 } 383 }
384 if (this.appState_.hasField( 384 if (this.appState_.hasField(
385 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED)) { 385 print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED)) {
386 this.headerFooter_.updateValue( 386 this.headerFooter_.updateValue(
387 /** @type {!Object} */(this.appState_.getField( 387 /** @type {!Object} */(this.appState_.getField(
388 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED))); 388 print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED)));
389 } 389 }
390 if (this.appState_.hasField( 390 if (this.appState_.hasField(
391 print_preview.AppState.Field.IS_COLLATE_ENABLED)) { 391 print_preview.AppStateField.IS_COLLATE_ENABLED)) {
392 this.collate_.updateValue( 392 this.collate_.updateValue(
393 /** @type {!Object} */(this.appState_.getField( 393 /** @type {!Object} */(this.appState_.getField(
394 print_preview.AppState.Field.IS_COLLATE_ENABLED))); 394 print_preview.AppStateField.IS_COLLATE_ENABLED)));
395 } 395 }
396 if (this.appState_.hasField( 396 if (this.appState_.hasField(
397 print_preview.AppState.Field.IS_FIT_TO_PAGE_ENABLED)) { 397 print_preview.AppStateField.IS_FIT_TO_PAGE_ENABLED)) {
398 this.fitToPage_.updateValue( 398 this.fitToPage_.updateValue(
399 /** @type {!Object} */(this.appState_.getField( 399 /** @type {!Object} */(this.appState_.getField(
400 print_preview.AppState.Field.IS_FIT_TO_PAGE_ENABLED))); 400 print_preview.AppStateField.IS_FIT_TO_PAGE_ENABLED)));
401 } 401 }
402 if (this.appState_.hasField( 402 if (this.appState_.hasField(
403 print_preview.AppState.Field.SCALING)) { 403 print_preview.AppStateField.SCALING)) {
404 this.scaling_.updateValue( 404 this.scaling_.updateValue(
405 /** @type {!Object} */(this.appState_.getField( 405 /** @type {!Object} */(this.appState_.getField(
406 print_preview.AppState.Field.SCALING))); 406 print_preview.AppStateField.SCALING)));
407 } 407 }
408 if (this.appState_.hasField( 408 if (this.appState_.hasField(
409 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED)) { 409 print_preview.AppStateField.IS_CSS_BACKGROUND_ENABLED)) {
410 this.cssBackground_.updateValue( 410 this.cssBackground_.updateValue(
411 /** @type {!Object} */(this.appState_.getField( 411 /** @type {!Object} */(this.appState_.getField(
412 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED))); 412 print_preview.AppStateField.IS_CSS_BACKGROUND_ENABLED)));
413 } 413 }
414 if (this.appState_.hasField( 414 if (this.appState_.hasField(
415 print_preview.AppState.Field.VENDOR_OPTIONS)) { 415 print_preview.AppStateField.VENDOR_OPTIONS)) {
416 this.vendorItems_.updateValue( 416 this.vendorItems_.updateValue(
417 /** @type {!Object<string>} */(this.appState_.getField( 417 /** @type {!Object<string>} */(this.appState_.getField(
418 print_preview.AppState.Field.VENDOR_OPTIONS))); 418 print_preview.AppStateField.VENDOR_OPTIONS)));
419 } 419 }
420 }, 420 },
421 421
422 /** 422 /**
423 * @return {boolean} {@code true} if the stored print ticket is valid, 423 * @return {boolean} {@code true} if the stored print ticket is valid,
424 * {@code false} otherwise. 424 * {@code false} otherwise.
425 */ 425 */
426 isTicketValid: function() { 426 isTicketValid: function() {
427 return this.isTicketValidForPreview() && 427 return this.isTicketValidForPreview() &&
428 (!this.copies_.isCapabilityAvailable() || this.copies_.isValid()) && 428 (!this.copies_.isCapabilityAvailable() || this.copies_.isValid()) &&
429 (!this.pageRange_.isCapabilityAvailable() || 429 (!this.pageRange_.isCapabilityAvailable() ||
430 this.pageRange_.isValid()); 430 this.pageRange_.isValid());
431 }, 431 },
432 432
433 /** @return {boolean} Whether the ticket is valid for preview generation. */ 433 /** @return {boolean} Whether the ticket is valid for preview generation. */
434 isTicketValidForPreview: function() { 434 isTicketValidForPreview: function() {
435 return (!this.marginsType_.isCapabilityAvailable() || 435 return (!this.marginsType_.isCapabilityAvailable() ||
436 !this.marginsType_.isValueEqual( 436 !this.marginsType_.isValueEqual(
437 print_preview.ticket_items.MarginsTypeValue.CUSTOM) || 437 print_preview.ticket_items.MarginsTypeValue.CUSTOM) ||
438 this.customMargins_.isValid()); 438 this.customMargins_.isValid());
439 }, 439 },
440 440
441 /** 441 /**
442 * Creates an object that represents a Google Cloud Print print ticket. 442 * Creates an object that represents a Google Cloud Print print ticket.
443 * @param {!print_preview.Destination} destination Destination to print to. 443 * @param {!print_preview.Destination} destination Destination to print to.
444 * @return {!Object} Google Cloud Print print ticket. 444 * @return {string} Google Cloud Print print ticket.
445 */ 445 */
446 createPrintTicket: function(destination) { 446 createPrintTicket: function(destination) {
447 assert(!destination.isLocal || 447 assert(!destination.isLocal ||
448 destination.isPrivet || destination.isExtension, 448 destination.isPrivet || destination.isExtension,
449 'Trying to create a Google Cloud Print print ticket for a local ' + 449 'Trying to create a Google Cloud Print print ticket for a local ' +
450 ' non-privet and non-extension destination'); 450 ' non-privet and non-extension destination');
451 451
452 assert(destination.capabilities, 452 assert(destination.capabilities,
453 'Trying to create a Google Cloud Print print ticket for a ' + 453 'Trying to create a Google Cloud Print print ticket for a ' +
454 'destination with no print capabilities'); 454 'destination with no print capabilities');
(...skipping 29 matching lines...) Expand all
484 height_microns: value.height_microns, 484 height_microns: value.height_microns,
485 is_continuous_feed: value.is_continuous_feed, 485 is_continuous_feed: value.is_continuous_feed,
486 vendor_id: value.vendor_id 486 vendor_id: value.vendor_id
487 }; 487 };
488 } 488 }
489 if (!this.landscape.isCapabilityAvailable()) { 489 if (!this.landscape.isCapabilityAvailable()) {
490 // In this case "orientation" option is hidden from user, so user can't 490 // In this case "orientation" option is hidden from user, so user can't
491 // adjust it for page content, see Landscape.isCapabilityAvailable(). 491 // adjust it for page content, see Landscape.isCapabilityAvailable().
492 // We can improve results if we set AUTO here. 492 // We can improve results if we set AUTO here.
493 if (this.landscape.hasOption('AUTO')) 493 if (this.landscape.hasOption('AUTO'))
494 cjt.print.page_orientation = { type: 'AUTO' }; 494 cjt.print.page_orientation = {type: 'AUTO'};
495 } else if (this.landscape.isUserEdited()) { 495 } else if (this.landscape.isUserEdited()) {
496 cjt.print.page_orientation = 496 cjt.print.page_orientation =
497 {type: this.landscape.getValue() ? 'LANDSCAPE' : 'PORTRAIT'}; 497 {type: this.landscape.getValue() ? 'LANDSCAPE' : 'PORTRAIT'};
498 } 498 }
499 if (this.dpi.isCapabilityAvailable()) { 499 if (this.dpi.isCapabilityAvailable()) {
500 var value = this.dpi.getValue(); 500 var value = this.dpi.getValue();
501 cjt.print.dpi = { 501 cjt.print.dpi = {
502 horizontal_dpi: value.horizontal_dpi, 502 horizontal_dpi: value.horizontal_dpi,
503 vertical_dpi: value.vertical_dpi, 503 vertical_dpi: value.vertical_dpi,
504 vendor_id: value.vendor_id 504 vendor_id: value.vendor_id
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 onDocumentInfoChange_: function() { 593 onDocumentInfoChange_: function() {
594 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); 594 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE);
595 }, 595 },
596 }; 596 };
597 597
598 // Export 598 // Export
599 return { 599 return {
600 PrintTicketStore: PrintTicketStore 600 PrintTicketStore: PrintTicketStore
601 }; 601 };
602 }); 602 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698