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 * Header-footer ticket item whose value is a {@code boolean} that indicates | 9 * Header-footer ticket item whose value is a {@code boolean} that indicates |
10 * whether the document should be printed with headers and footers. | 10 * whether the document should be printed with headers and footers. |
11 * @param {!print_preview.AppState} appState App state used to persist whether | 11 * @param {!print_preview.AppState} appState App state used to persist whether |
12 * header-footer is enabled. | 12 * header-footer is enabled. |
13 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 13 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
14 * document to print. | 14 * document to print. |
15 * @param {!print_preview.ticket_items.MarginsType} marginsType Ticket item | 15 * @param {!print_preview.ticket_items.MarginsType} marginsType Ticket item |
16 * that stores which predefined margins to print with. | 16 * that stores which predefined margins to print with. |
17 * @param {!print_preview.ticket_items.CustomMargins} customMargins Ticket | 17 * @param {!print_preview.ticket_items.CustomMargins} customMargins Ticket |
18 * item that stores custom margin values. | 18 * item that stores custom margin values. |
19 * @param {!print_preview.ticket_items.MediaSize} mediaSize Ticket item that | 19 * @param {!print_preview.ticket_items.MediaSize} mediaSize Ticket item that |
20 * stores media size values. | 20 * stores media size values. |
21 * @param {!print_preview.ticket_items.Landscape} landscape Ticket item that | 21 * @param {!print_preview.ticket_items.Landscape} landscape Ticket item that |
22 * stores landscape values. | 22 * stores landscape values. |
23 * @constructor | 23 * @constructor |
24 * @extends {print_preview.ticket_items.TicketItem} | 24 * @extends {print_preview.ticket_items.TicketItem} |
25 */ | 25 */ |
26 function HeaderFooter(appState, documentInfo, marginsType, customMargins, | 26 function HeaderFooter( |
27 mediaSize, landscape) { | 27 appState, documentInfo, marginsType, customMargins, mediaSize, |
| 28 landscape) { |
28 print_preview.ticket_items.TicketItem.call( | 29 print_preview.ticket_items.TicketItem.call( |
29 this, | 30 this, appState, print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED, |
30 appState, | 31 null /*destinationStore*/, documentInfo); |
31 print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED, | |
32 null /*destinationStore*/, | |
33 documentInfo); | |
34 | 32 |
35 /** | 33 /** |
36 * Ticket item that stores which predefined margins to print with. | 34 * Ticket item that stores which predefined margins to print with. |
37 * @private {!print_preview.ticket_items.MarginsType} | 35 * @private {!print_preview.ticket_items.MarginsType} |
38 */ | 36 */ |
39 this.marginsType_ = marginsType; | 37 this.marginsType_ = marginsType; |
40 | 38 |
41 /** | 39 /** |
42 * Ticket item that stores custom margin values. | 40 * Ticket item that stores custom margin values. |
43 * @private {!print_preview.ticket_items.CustomMargins} | 41 * @private {!print_preview.ticket_items.CustomMargins} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 /** @override */ | 77 /** @override */ |
80 isCapabilityAvailable: function() { | 78 isCapabilityAvailable: function() { |
81 if (!this.getDocumentInfoInternal().isModifiable) { | 79 if (!this.getDocumentInfoInternal().isModifiable) { |
82 return false; | 80 return false; |
83 } | 81 } |
84 if (this.marginsType_.getValue() == | 82 if (this.marginsType_.getValue() == |
85 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS) { | 83 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS) { |
86 return false; | 84 return false; |
87 } | 85 } |
88 var microns = this.landscape_.getValue() ? | 86 var microns = this.landscape_.getValue() ? |
89 this.mediaSize_.getValue().width_microns : | 87 this.mediaSize_.getValue().width_microns : |
90 this.mediaSize_.getValue().height_microns; | 88 this.mediaSize_.getValue().height_microns; |
91 if (microns < HeaderFooter.MINIMUM_HEIGHT_MICRONS_) { | 89 if (microns < HeaderFooter.MINIMUM_HEIGHT_MICRONS_) { |
92 // If this is a small paper size, there is not space for headers | 90 // If this is a small paper size, there is not space for headers |
93 // and footers regardless of the margins. | 91 // and footers regardless of the margins. |
94 return false; | 92 return false; |
95 } | 93 } |
96 if (this.marginsType_.getValue() == | 94 if (this.marginsType_.getValue() == |
97 print_preview.ticket_items.MarginsTypeValue.MINIMUM) { | 95 print_preview.ticket_items.MarginsTypeValue.MINIMUM) { |
98 return true; | 96 return true; |
99 } | 97 } |
100 var margins; | 98 var margins; |
101 if (this.marginsType_.getValue() == | 99 if (this.marginsType_.getValue() == |
102 print_preview.ticket_items.MarginsTypeValue.CUSTOM) { | 100 print_preview.ticket_items.MarginsTypeValue.CUSTOM) { |
103 if (!this.customMargins_.isValid()) { | 101 if (!this.customMargins_.isValid()) { |
104 return false; | 102 return false; |
105 } | 103 } |
106 margins = this.customMargins_.getValue(); | 104 margins = this.customMargins_.getValue(); |
107 } else { | 105 } else { |
108 margins = this.getDocumentInfoInternal().margins; | 106 margins = this.getDocumentInfoInternal().margins; |
109 } | 107 } |
110 var orientEnum = print_preview.ticket_items.CustomMarginsOrientation; | 108 var orientEnum = print_preview.ticket_items.CustomMarginsOrientation; |
111 return margins == null || | 109 return margins == null || margins.get(orientEnum.TOP) > 0 || |
112 margins.get(orientEnum.TOP) > 0 || | 110 margins.get(orientEnum.BOTTOM) > 0; |
113 margins.get(orientEnum.BOTTOM) > 0; | |
114 }, | 111 }, |
115 | 112 |
116 /** @override */ | 113 /** @override */ |
117 getDefaultValueInternal: function() { | 114 getDefaultValueInternal: function() { |
118 return true; | 115 return true; |
119 }, | 116 }, |
120 | 117 |
121 /** @override */ | 118 /** @override */ |
122 getCapabilityNotAvailableValueInternal: function() { | 119 getCapabilityNotAvailableValueInternal: function() { |
123 return false; | 120 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
141 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 138 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
142 this.dispatchChangeEventInternal.bind(this)); | 139 this.dispatchChangeEventInternal.bind(this)); |
143 this.getTrackerInternal().add( | 140 this.getTrackerInternal().add( |
144 this.landscape_, | 141 this.landscape_, |
145 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 142 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
146 this.dispatchChangeEventInternal.bind(this)); | 143 this.dispatchChangeEventInternal.bind(this)); |
147 } | 144 } |
148 }; | 145 }; |
149 | 146 |
150 // Export | 147 // Export |
151 return { | 148 return {HeaderFooter: HeaderFooter}; |
152 HeaderFooter: HeaderFooter | |
153 }; | |
154 }); | 149 }); |
OLD | NEW |