BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / data / ticket_items / dpi.js
blob28d2351de22c7426ee6f56559ef210a6248a7d01
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() {
6   'use strict';
8   /**
9    * DPI ticket item.
10    * @param {!print_preview.AppState} appState App state used to persist DPI
11    *     selection.
12    * @param {!print_preview.DestinationStore} destinationStore Destination store
13    *     used to determine if a destination has the DPI capability.
14    * @constructor
15    * @extends {print_preview.ticket_items.TicketItem}
16    */
17   function Dpi(appState, destinationStore) {
18     print_preview.ticket_items.TicketItem.call(
19         this,
20         appState,
21         print_preview.AppState.Field.DPI,
22         destinationStore);
23   };
25   Dpi.prototype = {
26     __proto__: print_preview.ticket_items.TicketItem.prototype,
28     /** @override */
29     wouldValueBeValid: function(value) {
30       if (!this.isCapabilityAvailable())
31         return false;
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;
36       });
37     },
39     /** @override */
40     isCapabilityAvailable: function() {
41       return !!this.capability &&
42              !!this.capability.option &&
43              this.capability.option.length > 1;
44     },
46     /** @override */
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;
52     },
54     /** @return {Object} DPI capability of the selected destination. */
55     get capability() {
56       var destination = this.getSelectedDestInternal();
57       return (destination &&
58               destination.capabilities &&
59               destination.capabilities.printer &&
60               destination.capabilities.printer.dpi) ||
61              null;
62     },
64     /** @override */
65     getDefaultValueInternal: function() {
66       var defaultOptions = this.capability.option.filter(function(option) {
67         return option.is_default;
68       });
69       return defaultOptions.length > 0 ? defaultOptions[0] : null;
70     },
72     /** @override */
73     getCapabilityNotAvailableValueInternal: function() {
74       return {};
75     }
76   };
78   // Export
79   return {
80     Dpi: Dpi
81   };
82 });