1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr.define('print_preview.ticket_items', function() {
9 * Media size ticket item.
10 * @param {!print_preview.AppState} appState App state used to persist media
12 * @param {!print_preview.DestinationStore} destinationStore Destination store
13 * used to determine if a destination has the media size capability.
14 * @param {!print_preview.DocumentInfo} documentInfo Information about the
16 * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
17 * landscape value changes.
18 * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when
19 * landscape value changes.
21 * @extends {print_preview.ticket_items.TicketItem}
24 appState, destinationStore, documentInfo, marginsType, customMargins) {
25 print_preview.ticket_items.TicketItem.call(
28 print_preview.AppState.Field.MEDIA_SIZE,
33 * Margins ticket item. Reset when this item changes.
34 * @private {!print_preview.ticket_items.MarginsType}
36 this.marginsType_ = marginsType;
39 * Custom margins ticket item. Reset when this item changes.
40 * @private {!print_preview.ticket_items.CustomMargins}
42 this.customMargins_ = customMargins;
45 MediaSize.prototype = {
46 __proto__: print_preview.ticket_items.TicketItem.prototype,
49 wouldValueBeValid: function(value) {
50 if (!this.isCapabilityAvailable()) {
53 return this.capability.option.some(function(option) {
54 return option.width_microns == value.width_microns &&
55 option.height_microns == value.height_microns &&
56 option.is_continuous_feed == value.is_continuous_feed &&
57 option.vendor_id == value.vendor_id;
62 isCapabilityAvailable: function() {
63 var knownSizeToSaveAsPdf =
64 (!this.getDocumentInfoInternal().isModifiable ||
65 this.getDocumentInfoInternal().hasCssMediaStyles) &&
66 this.getSelectedDestInternal() &&
67 this.getSelectedDestInternal().id ==
68 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
69 return !knownSizeToSaveAsPdf && !!this.capability;
73 isValueEqual: function(value) {
74 var myValue = this.getValue();
75 return myValue.width_microns == value.width_microns &&
76 myValue.height_microns == value.height_microns &&
77 myValue.is_continuous_feed == value.is_continuous_feed &&
78 myValue.vendor_id == value.vendor_id;
81 /** @return {Object} Media size capability of the selected destination. */
83 var destination = this.getSelectedDestInternal();
84 return (destination &&
85 destination.capabilities &&
86 destination.capabilities.printer &&
87 destination.capabilities.printer.media_size) ||
92 getDefaultValueInternal: function() {
93 var defaultOptions = this.capability.option.filter(function(option) {
94 return option.is_default;
96 return defaultOptions.length > 0 ? defaultOptions[0] : null;
100 getCapabilityNotAvailableValueInternal: function() {
105 updateValueInternal: function(value) {
106 var updateMargins = !this.isValueEqual(value);
107 print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
110 // Reset the user set margins when media size changes.
111 this.marginsType_.updateValue(
112 print_preview.ticket_items.MarginsType.Value.DEFAULT);
113 this.customMargins_.updateValue(null);