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', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Represents a single option in the Other Options settings section. | 9 * Represents a single option in the Other Options settings section. |
10 * @param {!print_preview.ticket_items.TicketItem} ticketItem The ticket item | 10 * @param {!print_preview.ticket_items.TicketItem} ticketItem The ticket item |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 }, | 63 }, |
64 | 64 |
65 /** @return {HTMLElement} The checkbox HTML element. */ | 65 /** @return {HTMLElement} The checkbox HTML element. */ |
66 get checkbox() { | 66 get checkbox() { |
67 return this.checkbox_; | 67 return this.checkbox_; |
68 }, | 68 }, |
69 | 69 |
70 /** Initializes container and checkbox */ | 70 /** Initializes container and checkbox */ |
71 decorate: function() { | 71 decorate: function() { |
72 this.container_ = $(this.cssId_); | 72 this.container_ = $(this.cssId_); |
73 this.checkbox_ = /** @type {HTMLElement} */( | 73 this.checkbox_ = /** @type {HTMLElement} */ ( |
74 this.container_.querySelector('.checkbox')); | 74 this.container_.querySelector('.checkbox')); |
75 }, | 75 }, |
76 | 76 |
77 /** Resets container and checkbox. */ | 77 /** Resets container and checkbox. */ |
78 exitDocument: function() { | 78 exitDocument: function() { |
79 this.container_ = null; | 79 this.container_ = null; |
80 this.checkbox_ = null; | 80 this.checkbox_ = null; |
81 }, | 81 }, |
82 | 82 |
83 /** Called when the checkbox is clicked. Updates the ticket item value. */ | 83 /** Called when the checkbox is clicked. Updates the ticket item value. */ |
(...skipping 12 matching lines...) Expand all Loading... |
96 otherOptionsSettings.updateUiStateInternal(); | 96 otherOptionsSettings.updateUiStateInternal(); |
97 }, | 97 }, |
98 | 98 |
99 /** | 99 /** |
100 * @param {boolean} collapseContent Whether the settings section has content | 100 * @param {boolean} collapseContent Whether the settings section has content |
101 * collapsed. | 101 * collapsed. |
102 * @return {boolean} Whether this element should be visible. | 102 * @return {boolean} Whether this element should be visible. |
103 */ | 103 */ |
104 isVisible: function(collapseContent) { | 104 isVisible: function(collapseContent) { |
105 return this.ticketItem_.isCapabilityAvailable() && | 105 return this.ticketItem_.isCapabilityAvailable() && |
106 (!this.collapsible_ || !collapseContent); | 106 (!this.collapsible_ || !collapseContent); |
107 }, | 107 }, |
108 | 108 |
109 /** | 109 /** |
110 * Sets the visibility of the element. | 110 * Sets the visibility of the element. |
111 * @param {boolean} collapseContent Whether the settings section has content | 111 * @param {boolean} collapseContent Whether the settings section has content |
112 * collapsed. | 112 * collapsed. |
113 */ | 113 */ |
114 setVisibility: function(collapseContent) { | 114 setVisibility: function(collapseContent) { |
115 setIsVisible(assert(this.container_), this.isVisible(collapseContent)); | 115 setIsVisible(assert(this.container_), this.isVisible(collapseContent)); |
116 }, | 116 }, |
(...skipping 18 matching lines...) Expand all Loading... |
135 */ | 135 */ |
136 function OtherOptionsSettings( | 136 function OtherOptionsSettings( |
137 duplex, fitToPage, cssBackground, selectionOnly, headerFooter, | 137 duplex, fitToPage, cssBackground, selectionOnly, headerFooter, |
138 rasterize) { | 138 rasterize) { |
139 print_preview.SettingsSection.call(this); | 139 print_preview.SettingsSection.call(this); |
140 /** | 140 /** |
141 * @private {boolean} rasterizeEnabled Whether the print as image feature is | 141 * @private {boolean} rasterizeEnabled Whether the print as image feature is |
142 * enabled. | 142 * enabled. |
143 */ | 143 */ |
144 this.rasterizeEnabled_ = (!cr.isWindows && !cr.isMac) && | 144 this.rasterizeEnabled_ = (!cr.isWindows && !cr.isMac) && |
145 loadTimeData.getBoolean('printPdfAsImageEnabled'); | 145 loadTimeData.getBoolean('printPdfAsImageEnabled'); |
146 | 146 |
147 /** | 147 /** |
148 * @private {!Array<!CheckboxTicketItemElement>} checkbox ticket item | 148 * @private {!Array<!CheckboxTicketItemElement>} checkbox ticket item |
149 * elements representing the different options in the section. | 149 * elements representing the different options in the section. |
150 * Selection only must always be the last element in the array. | 150 * Selection only must always be the last element in the array. |
151 */ | 151 */ |
152 this.elements_ = [ | 152 this.elements_ = [ |
153 new CheckboxTicketItemElement(headerFooter, true, | 153 new CheckboxTicketItemElement( |
154 'header-footer-container'), | 154 headerFooter, true, 'header-footer-container'), |
155 new CheckboxTicketItemElement(fitToPage, false, | 155 new CheckboxTicketItemElement(fitToPage, false, 'fit-to-page-container'), |
156 'fit-to-page-container'), | |
157 new CheckboxTicketItemElement(duplex, false, 'duplex-container'), | 156 new CheckboxTicketItemElement(duplex, false, 'duplex-container'), |
158 new CheckboxTicketItemElement(cssBackground, true, | 157 new CheckboxTicketItemElement( |
159 'css-background-container'), | 158 cssBackground, true, 'css-background-container'), |
160 new CheckboxTicketItemElement(selectionOnly, true, | 159 new CheckboxTicketItemElement( |
161 'selection-only-container') | 160 selectionOnly, true, 'selection-only-container') |
162 ]; | 161 ]; |
163 if (this.rasterizeEnabled_) { | 162 if (this.rasterizeEnabled_) { |
164 this.elements_.splice(4, 0, | 163 this.elements_.splice( |
165 new CheckboxTicketItemElement(rasterize, true, | 164 4, 0, |
166 'rasterize-container')); | 165 new CheckboxTicketItemElement( |
| 166 rasterize, true, 'rasterize-container')); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 OtherOptionsSettings.prototype = { | 170 OtherOptionsSettings.prototype = { |
171 __proto__: print_preview.SettingsSection.prototype, | 171 __proto__: print_preview.SettingsSection.prototype, |
172 | 172 |
173 /** @override */ | 173 /** @override */ |
174 isAvailable: function() { | 174 isAvailable: function() { |
175 return this.elements_.some(function(element) { | 175 return this.elements_.some(function(element) { |
176 return element.ticketItem.isCapabilityAvailable(); | 176 return element.ticketItem.isCapabilityAvailable(); |
(...skipping 15 matching lines...) Expand all Loading... |
192 * other elements. */ | 192 * other elements. */ |
193 for (var i = 0; i < this.elements_.length - 1; i++) | 193 for (var i = 0; i < this.elements_.length - 1; i++) |
194 this.elements_[i].checkbox.disabled = !isEnabled; | 194 this.elements_[i].checkbox.disabled = !isEnabled; |
195 }, | 195 }, |
196 | 196 |
197 /** @override */ | 197 /** @override */ |
198 enterDocument: function() { | 198 enterDocument: function() { |
199 print_preview.SettingsSection.prototype.enterDocument.call(this); | 199 print_preview.SettingsSection.prototype.enterDocument.call(this); |
200 this.elements_.forEach(function(element) { | 200 this.elements_.forEach(function(element) { |
201 this.tracker.add( | 201 this.tracker.add( |
202 assert(element.checkbox), | 202 assert(element.checkbox), 'click', |
203 'click', | |
204 element.onCheckboxClick.bind(element)); | 203 element.onCheckboxClick.bind(element)); |
205 this.tracker.add( | 204 this.tracker.add( |
206 element.ticketItem, | 205 element.ticketItem, |
207 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 206 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
208 element.onTicketItemChange.bind(element, this)); | 207 element.onTicketItemChange.bind(element, this)); |
209 }, this); | 208 }, this); |
210 }, | 209 }, |
211 | 210 |
212 /** @override */ | 211 /** @override */ |
213 exitDocument: function() { | 212 exitDocument: function() { |
(...skipping 21 matching lines...) Expand all Loading... |
235 /** @override */ | 234 /** @override */ |
236 isSectionVisibleInternal: function() { | 235 isSectionVisibleInternal: function() { |
237 return this.elements_.some(function(element) { | 236 return this.elements_.some(function(element) { |
238 return element.isVisible(this.collapseContent); | 237 return element.isVisible(this.collapseContent); |
239 }, this); | 238 }, this); |
240 }, | 239 }, |
241 | 240 |
242 }; | 241 }; |
243 | 242 |
244 // Export | 243 // Export |
245 return { | 244 return {OtherOptionsSettings: OtherOptionsSettings}; |
246 OtherOptionsSettings: OtherOptionsSettings | |
247 }; | |
248 }); | 245 }); |
OLD | NEW |