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() {
10 * @param {!print_preview.AppState} appState App state used to persist DPI
12 * @param {!print_preview.DestinationStore} destinationStore Destination store
13 * used to determine if a destination has the DPI capability.
15 * @extends {print_preview.ticket_items.TicketItem}
17 function Dpi(appState, destinationStore) {
18 print_preview.ticket_items.TicketItem.call(
21 print_preview.AppState.Field.DPI,
26 __proto__: print_preview.ticket_items.TicketItem.prototype,
29 wouldValueBeValid: function(value) {
30 if (!this.isCapabilityAvailable())
32 return this.capability.option.some(function(option) {
33 return option.horizontal_dpi == value.horizontal_dpi &&
34 option.vertical_dpi == value.vertical_dpi &&
35 option.vendor_id == value.vendor_id;
40 isCapabilityAvailable: function() {
41 return !!this.capability &&
42 !!this.capability.option &&
43 this.capability.option.length > 1;
47 isValueEqual: function(value) {
48 var myValue = this.getValue();
49 return myValue.horizontal_dpi == value.horizontal_dpi &&
50 myValue.vertical_dpi == value.vertical_dpi &&
51 myValue.vendor_id == value.vendor_id;
54 /** @return {Object} DPI capability of the selected destination. */
56 var destination = this.getSelectedDestInternal();
57 return (destination &&
58 destination.capabilities &&
59 destination.capabilities.printer &&
60 destination.capabilities.printer.dpi) ||
65 getDefaultValueInternal: function() {
66 var defaultOptions = this.capability.option.filter(function(option) {
67 return option.is_default;
69 return defaultOptions.length > 0 ? defaultOptions[0] : null;
73 getCapabilityNotAvailableValueInternal: function() {