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_();
63 var hasAutoOrPortraitOption
= false;
64 var hasLandscapeOption
= false;
65 cap
.option
.forEach(function(option
) {
66 hasAutoOrPortraitOption
= hasAutoOrPortraitOption
||
67 option
.type
== 'AUTO' ||
68 option
.type
== 'PORTRAIT';
69 hasLandscapeOption
= hasLandscapeOption
|| option
.type
== 'LANDSCAPE';
71 // TODO(rltoscano): Technically, the print destination can still change
72 // the orientation of the print out (at least for cloud printers) if the
73 // document is not modifiable. But the preview wouldn't update in this
74 // case so it would be a bad user experience.
75 return this.getDocumentInfoInternal().isModifiable
&&
76 !this.getDocumentInfoInternal().hasCssMediaStyles
&&
77 hasAutoOrPortraitOption
&&
82 getDefaultValueInternal: function() {
83 var cap
= this.getPageOrientationCapability_();
84 var defaultOptions
= cap
.option
.filter(function(option
) {
85 return option
.is_default
;
87 return defaultOptions
.length
== 0 ? false :
88 defaultOptions
[0].type
== 'LANDSCAPE';
92 getCapabilityNotAvailableValueInternal: function() {
93 var doc
= this.getDocumentInfoInternal();
94 return doc
.hasCssMediaStyles
?
95 (doc
.pageSize
.width
> doc
.pageSize
.height
) :
100 updateValueInternal: function(value
) {
101 var updateMargins
= !this.isValueEqual(value
);
102 print_preview
.ticket_items
.TicketItem
.prototype.updateValueInternal
.call(
105 // Reset the user set margins when page orientation changes.
106 this.marginsType_
.updateValue(
107 print_preview
.ticket_items
.MarginsType
.Value
.DEFAULT
);
108 this.customMargins_
.updateValue(null);
113 * @return {Object} Page orientation capability of the selected destination.
116 getPageOrientationCapability_: function() {
117 var dest
= this.getSelectedDestInternal();
120 dest
.capabilities
.printer
&&
121 dest
.capabilities
.printer
.page_orientation
) ||