Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / data / ticket_items / landscape.js
blobcf70bd6dce64e96f6165906ffc6e5c2be43447bd
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
3 // found in the LICENSE file.
5 cr.define('print_preview.ticket_items', function() {
6 'use strict';
8 /**
9 * Landscape ticket item whose value is a {@code boolean} that indicates
10 * whether the document should be printed in landscape orientation.
11 * @param {!print_preview.AppState} appState App state object used to persist
12 * ticket item values.
13 * @param {!print_preview.DestinationStore} destinationStore Destination store
14 * used to determine the default landscape value and if landscape
15 * printing is available.
16 * @param {!print_preview.DocumentInfo} documentInfo Information about the
17 * document to print.
18 * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
19 * landscape value changes.
20 * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when
21 * landscape value changes.
22 * @constructor
23 * @extends {print_preview.ticket_items.TicketItem}
25 function Landscape(appState, destinationStore, documentInfo, marginsType,
26 customMargins) {
27 print_preview.ticket_items.TicketItem.call(
28 this,
29 appState,
30 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED,
31 destinationStore,
32 documentInfo);
34 /**
35 * Margins ticket item. Reset when landscape ticket item changes.
36 * @type {!print_preview.ticket_items.MarginsType}
37 * @private
39 this.marginsType_ = marginsType;
41 /**
42 * Custom margins ticket item. Reset when landscape ticket item changes.
43 * @type {!print_preview.ticket_items.CustomMargins}
44 * @private
46 this.customMargins_ = customMargins;
49 Landscape.prototype = {
50 __proto__: print_preview.ticket_items.TicketItem.prototype,
52 /** @override */
53 wouldValueBeValid: function(value) {
54 return true;
57 /** @override */
58 isCapabilityAvailable: function() {
59 var cap = this.getPageOrientationCapability_();
60 if (!cap)
61 return false;
62 var hasAutoOrPortraitOption = false;
63 var hasLandscapeOption = false;
64 cap.option.forEach(function(option) {
65 hasAutoOrPortraitOption = hasAutoOrPortraitOption ||
66 option.type == 'AUTO' ||
67 option.type == 'PORTRAIT';
68 hasLandscapeOption = hasLandscapeOption || option.type == 'LANDSCAPE';
69 });
70 // TODO(rltoscano): Technically, the print destination can still change
71 // the orientation of the print out (at least for cloud printers) if the
72 // document is not modifiable. But the preview wouldn't update in this
73 // case so it would be a bad user experience.
74 return this.getDocumentInfoInternal().isModifiable &&
75 !this.getDocumentInfoInternal().hasCssMediaStyles &&
76 hasAutoOrPortraitOption &&
77 hasLandscapeOption;
80 /** @override */
81 getDefaultValueInternal: function() {
82 var cap = this.getPageOrientationCapability_();
83 var defaultOptions = cap.option.filter(function(option) {
84 return option.is_default;
85 });
86 return defaultOptions.length == 0 ? false :
87 defaultOptions[0].type == 'LANDSCAPE';
90 /** @override */
91 getCapabilityNotAvailableValueInternal: function() {
92 var doc = this.getDocumentInfoInternal();
93 return doc.hasCssMediaStyles ?
94 (doc.pageSize.width > doc.pageSize.height) :
95 false;
98 /** @override */
99 updateValueInternal: function(value) {
100 var updateMargins = !this.isValueEqual(value);
101 print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
102 this, value);
103 if (updateMargins) {
104 // Reset the user set margins when page orientation changes.
105 this.marginsType_.updateValue(
106 print_preview.ticket_items.MarginsType.Value.DEFAULT);
107 this.customMargins_.updateValue(null);
112 * @return {boolean} Whether capability contains the |value|.
113 * @param {string} value Option to check.
115 hasOption: function(value) {
116 var cap = this.getPageOrientationCapability_();
117 if (!cap)
118 return false;
119 return cap.option.some(function(option) {
120 return option.type == value;
125 * @return {Object} Page orientation capability of the selected destination.
126 * @private
128 getPageOrientationCapability_: function() {
129 var dest = this.getSelectedDestInternal();
130 return (dest &&
131 dest.capabilities &&
132 dest.capabilities.printer &&
133 dest.capabilities.printer.page_orientation) ||
134 null;
138 // Export
139 return {
140 Landscape: Landscape