OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('print_preview.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Landscape ticket item whose value is a {@code boolean} that indicates | 9 * Landscape ticket item whose value is a {@code boolean} that indicates |
10 * whether the document should be printed in landscape orientation. | 10 * whether the document should be printed in landscape orientation. |
11 * @param {!print_preview.AppState} appState App state object used to persist | 11 * @param {!print_preview.AppState} appState App state object used to persist |
12 * ticket item values. | 12 * ticket item values. |
13 * @param {!print_preview.DestinationStore} destinationStore Destination store | 13 * @param {!print_preview.DestinationStore} destinationStore Destination store |
14 * used to determine the default landscape value and if landscape | 14 * used to determine the default landscape value and if landscape |
15 * printing is available. | 15 * printing is available. |
16 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 16 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
17 * document to print. | 17 * document to print. |
18 * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when | 18 * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when |
19 * landscape value changes. | 19 * landscape value changes. |
20 * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when | 20 * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when |
21 * landscape value changes. | 21 * landscape value changes. |
22 * @constructor | 22 * @constructor |
23 * @extends {print_preview.ticket_items.TicketItem} | 23 * @extends {print_preview.ticket_items.TicketItem} |
24 */ | 24 */ |
25 function Landscape(appState, destinationStore, documentInfo, marginsType, | 25 function Landscape( |
26 customMargins) { | 26 appState, destinationStore, documentInfo, marginsType, customMargins) { |
27 print_preview.ticket_items.TicketItem.call( | 27 print_preview.ticket_items.TicketItem.call( |
28 this, | 28 this, appState, print_preview.AppStateField.IS_LANDSCAPE_ENABLED, |
29 appState, | 29 destinationStore, documentInfo); |
30 print_preview.AppStateField.IS_LANDSCAPE_ENABLED, | |
31 destinationStore, | |
32 documentInfo); | |
33 | 30 |
34 /** | 31 /** |
35 * Margins ticket item. Reset when landscape ticket item changes. | 32 * Margins ticket item. Reset when landscape ticket item changes. |
36 * @type {!print_preview.ticket_items.MarginsType} | 33 * @type {!print_preview.ticket_items.MarginsType} |
37 * @private | 34 * @private |
38 */ | 35 */ |
39 this.marginsType_ = marginsType; | 36 this.marginsType_ = marginsType; |
40 | 37 |
41 /** | 38 /** |
42 * Custom margins ticket item. Reset when landscape ticket item changes. | 39 * Custom margins ticket item. Reset when landscape ticket item changes. |
(...skipping 13 matching lines...) Expand all Loading... |
56 | 53 |
57 /** @override */ | 54 /** @override */ |
58 isCapabilityAvailable: function() { | 55 isCapabilityAvailable: function() { |
59 var cap = this.getPageOrientationCapability_(); | 56 var cap = this.getPageOrientationCapability_(); |
60 if (!cap) | 57 if (!cap) |
61 return false; | 58 return false; |
62 var hasAutoOrPortraitOption = false; | 59 var hasAutoOrPortraitOption = false; |
63 var hasLandscapeOption = false; | 60 var hasLandscapeOption = false; |
64 cap.option.forEach(function(option) { | 61 cap.option.forEach(function(option) { |
65 hasAutoOrPortraitOption = hasAutoOrPortraitOption || | 62 hasAutoOrPortraitOption = hasAutoOrPortraitOption || |
66 option.type == 'AUTO' || | 63 option.type == 'AUTO' || option.type == 'PORTRAIT'; |
67 option.type == 'PORTRAIT'; | |
68 hasLandscapeOption = hasLandscapeOption || option.type == 'LANDSCAPE'; | 64 hasLandscapeOption = hasLandscapeOption || option.type == 'LANDSCAPE'; |
69 }); | 65 }); |
70 // TODO(rltoscano): Technically, the print destination can still change | 66 // TODO(rltoscano): Technically, the print destination can still change |
71 // the orientation of the print out (at least for cloud printers) if the | 67 // 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 | 68 // document is not modifiable. But the preview wouldn't update in this |
73 // case so it would be a bad user experience. | 69 // case so it would be a bad user experience. |
74 return this.getDocumentInfoInternal().isModifiable && | 70 return this.getDocumentInfoInternal().isModifiable && |
75 !this.getDocumentInfoInternal().hasCssMediaStyles && | 71 !this.getDocumentInfoInternal().hasCssMediaStyles && |
76 hasAutoOrPortraitOption && | 72 hasAutoOrPortraitOption && hasLandscapeOption; |
77 hasLandscapeOption; | |
78 }, | 73 }, |
79 | 74 |
80 /** @override */ | 75 /** @override */ |
81 getDefaultValueInternal: function() { | 76 getDefaultValueInternal: function() { |
82 var cap = this.getPageOrientationCapability_(); | 77 var cap = this.getPageOrientationCapability_(); |
83 var defaultOptions = cap.option.filter(function(option) { | 78 var defaultOptions = cap.option.filter(function(option) { |
84 return option.is_default; | 79 return option.is_default; |
85 }); | 80 }); |
86 return defaultOptions.length == 0 ? false : | 81 return defaultOptions.length == 0 ? false : |
87 defaultOptions[0].type == 'LANDSCAPE'; | 82 defaultOptions[0].type == 'LANDSCAPE'; |
88 }, | 83 }, |
89 | 84 |
90 /** @override */ | 85 /** @override */ |
91 getCapabilityNotAvailableValueInternal: function() { | 86 getCapabilityNotAvailableValueInternal: function() { |
92 var doc = this.getDocumentInfoInternal(); | 87 var doc = this.getDocumentInfoInternal(); |
93 return doc.hasCssMediaStyles ? | 88 return doc.hasCssMediaStyles ? |
94 (doc.pageSize.width > doc.pageSize.height) : | 89 (doc.pageSize.width > doc.pageSize.height) : |
95 false; | 90 false; |
96 }, | 91 }, |
97 | 92 |
98 /** @override */ | 93 /** @override */ |
99 updateValueInternal: function(value) { | 94 updateValueInternal: function(value) { |
100 var updateMargins = !this.isValueEqual(value); | 95 var updateMargins = !this.isValueEqual(value); |
101 print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call( | 96 print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call( |
102 this, value); | 97 this, value); |
103 if (updateMargins) { | 98 if (updateMargins) { |
104 // Reset the user set margins when page orientation changes. | 99 // Reset the user set margins when page orientation changes. |
105 this.marginsType_.updateValue( | 100 this.marginsType_.updateValue( |
106 print_preview.ticket_items.MarginsTypeValue.DEFAULT); | 101 print_preview.ticket_items.MarginsTypeValue.DEFAULT); |
107 this.customMargins_.updateValue(null); | 102 this.customMargins_.updateValue(null); |
108 } | 103 } |
109 }, | 104 }, |
110 | 105 |
111 /** | 106 /** |
112 * @return {boolean} Whether capability contains the |value|. | 107 * @return {boolean} Whether capability contains the |value|. |
113 * @param {string} value Option to check. | 108 * @param {string} value Option to check. |
114 */ | 109 */ |
115 hasOption: function(value) { | 110 hasOption: function(value) { |
116 var cap = this.getPageOrientationCapability_(); | 111 var cap = this.getPageOrientationCapability_(); |
117 if (!cap) | 112 if (!cap) |
118 return false; | 113 return false; |
119 return cap.option.some(function(option) { | 114 return cap.option.some(function(option) { |
120 return option.type == value; | 115 return option.type == value; |
121 }); | 116 }); |
122 }, | 117 }, |
123 | 118 |
124 /** | 119 /** |
125 * @return {Object} Page orientation capability of the selected destination. | 120 * @return {Object} Page orientation capability of the selected destination. |
126 * @private | 121 * @private |
127 */ | 122 */ |
128 getPageOrientationCapability_: function() { | 123 getPageOrientationCapability_: function() { |
129 var dest = this.getSelectedDestInternal(); | 124 var dest = this.getSelectedDestInternal(); |
130 return (dest && | 125 return (dest && dest.capabilities && dest.capabilities.printer && |
131 dest.capabilities && | |
132 dest.capabilities.printer && | |
133 dest.capabilities.printer.page_orientation) || | 126 dest.capabilities.printer.page_orientation) || |
134 null; | 127 null; |
135 } | 128 } |
136 }; | 129 }; |
137 | 130 |
138 // Export | 131 // Export |
139 return { | 132 return {Landscape: Landscape}; |
140 Landscape: Landscape | |
141 }; | |
142 }); | 133 }); |
OLD | NEW |