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() {
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
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
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.
23 * @extends {print_preview.ticket_items.TicketItem}
25 function Landscape(appState
, destinationStore
, documentInfo
, marginsType
,
27 print_preview
.ticket_items
.TicketItem
.call(
30 print_preview
.AppState
.Field
.IS_LANDSCAPE_ENABLED
,
35 * Margins ticket item. Reset when landscape ticket item changes.
36 * @type {!print_preview.ticket_items.MarginsType}
39 this.marginsType_
= marginsType
;
42 * Custom margins ticket item. Reset when landscape ticket item changes.
43 * @type {!print_preview.ticket_items.CustomMargins}
46 this.customMargins_
= customMargins
;
49 Landscape
.prototype = {
50 __proto__
: print_preview
.ticket_items
.TicketItem
.prototype,
53 wouldValueBeValid: function(value
) {
58 isCapabilityAvailable: function() {
59 var cap
= this.getPageOrientationCapability_();
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';
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
&&
81 getDefaultValueInternal: function() {
82 var cap
= this.getPageOrientationCapability_();
83 var defaultOptions
= cap
.option
.filter(function(option
) {
84 return option
.is_default
;
86 return defaultOptions
.length
== 0 ? false :
87 defaultOptions
[0].type
== 'LANDSCAPE';
91 getCapabilityNotAvailableValueInternal: function() {
92 var doc
= this.getDocumentInfoInternal();
93 return doc
.hasCssMediaStyles
?
94 (doc
.pageSize
.width
> doc
.pageSize
.height
) :
99 updateValueInternal: function(value
) {
100 var updateMargins
= !this.isValueEqual(value
);
101 print_preview
.ticket_items
.TicketItem
.prototype.updateValueInternal
.call(
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_();
119 return cap
.option
.some(function(option
) {
120 return option
.type
== value
;
125 * @return {Object} Page orientation capability of the selected destination.
128 getPageOrientationCapability_: function() {
129 var dest
= this.getSelectedDestInternal();
132 dest
.capabilities
.printer
&&
133 dest
.capabilities
.printer
.page_orientation
) ||