OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Modal dialog for print destination's advanced settings. | 9 * Modal dialog for print destination's advanced settings. |
10 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the | 10 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the |
(...skipping 19 matching lines...) Expand all Loading... |
30 /** @private {!print_preview.SearchBox} */ | 30 /** @private {!print_preview.SearchBox} */ |
31 this.searchBox_ = new print_preview.SearchBox( | 31 this.searchBox_ = new print_preview.SearchBox( |
32 loadTimeData.getString('advancedSettingsSearchBoxPlaceholder')); | 32 loadTimeData.getString('advancedSettingsSearchBoxPlaceholder')); |
33 this.addChild(this.searchBox_); | 33 this.addChild(this.searchBox_); |
34 | 34 |
35 /** @private {print_preview.Destination} */ | 35 /** @private {print_preview.Destination} */ |
36 this.destination_ = null; | 36 this.destination_ = null; |
37 | 37 |
38 /** @private {!Array<!print_preview.AdvancedSettingsItem>} */ | 38 /** @private {!Array<!print_preview.AdvancedSettingsItem>} */ |
39 this.items_ = []; | 39 this.items_ = []; |
40 }; | 40 } |
41 | 41 |
42 /** | 42 /** |
43 * CSS classes used by the component. | 43 * CSS classes used by the component. |
44 * @enum {string} | 44 * @enum {string} |
45 * @private | 45 * @private |
46 */ | 46 */ |
47 AdvancedSettings.Classes_ = { | 47 AdvancedSettings.Classes_ = { |
48 EXTRA_PADDING: 'advanced-settings-item-extra-padding' | 48 EXTRA_PADDING: 'advanced-settings-item-extra-padding' |
49 }; | 49 }; |
50 | 50 |
(...skipping 12 matching lines...) Expand all Loading... |
63 this.destination_.displayName); | 63 this.destination_.displayName); |
64 this.setIsVisible(true); | 64 this.setIsVisible(true); |
65 this.renderSettings_(); | 65 this.renderSettings_(); |
66 }, | 66 }, |
67 | 67 |
68 /** @override */ | 68 /** @override */ |
69 enterDocument: function() { | 69 enterDocument: function() { |
70 print_preview.Overlay.prototype.enterDocument.call(this); | 70 print_preview.Overlay.prototype.enterDocument.call(this); |
71 | 71 |
72 this.tracker.add( | 72 this.tracker.add( |
73 this.getChildElement('.button-strip .cancel-button'), | 73 assert(this.getChildElement('.button-strip .cancel-button')), |
74 'click', | 74 'click', |
75 this.cancel.bind(this)); | 75 this.cancel.bind(this)); |
76 | 76 |
77 this.tracker.add( | 77 this.tracker.add( |
78 this.getChildElement('.button-strip .done-button'), | 78 assert(this.getChildElement('.button-strip .done-button')), |
79 'click', | 79 'click', |
80 this.onApplySettings_.bind(this)); | 80 this.onApplySettings_.bind(this)); |
81 | 81 |
82 this.tracker.add( | 82 this.tracker.add( |
83 this.searchBox_, | 83 assert(this.searchBox_), |
84 print_preview.SearchBox.EventType.SEARCH, | 84 print_preview.SearchBox.EventType.SEARCH, |
85 this.onSearch_.bind(this)); | 85 this.onSearch_.bind(this)); |
86 }, | 86 }, |
87 | 87 |
88 /** @override */ | 88 /** @override */ |
89 decorateInternal: function() { | 89 decorateInternal: function() { |
90 this.searchBox_.render(this.getChildElement('.search-box-area')); | 90 this.searchBox_.render(assert(this.getChildElement('.search-box-area'))); |
91 }, | 91 }, |
92 | 92 |
93 /** @override */ | 93 /** @override */ |
94 onSetVisibleInternal: function(isVisible) { | 94 onSetVisibleInternal: function(isVisible) { |
95 if (isVisible) { | 95 if (isVisible) { |
96 this.searchBox_.focus(); | 96 this.searchBox_.focus(); |
97 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. | 97 this.metrics_.record(print_preview.Metrics.PrintSettingsUiBucket. |
98 ADVANCED_SETTINGS_DIALOG_SHOWN); | 98 ADVANCED_SETTINGS_DIALOG_SHOWN); |
99 } else { | 99 } else { |
100 this.resetSearch_(); | 100 this.resetSearch_(); |
(...skipping 23 matching lines...) Expand all Loading... |
124 var elStyle = window.getComputedStyle(this.getElement()); | 124 var elStyle = window.getComputedStyle(this.getElement()); |
125 return this.getElement().offsetHeight - | 125 return this.getElement().offsetHeight - |
126 parseInt(elStyle.getPropertyValue('padding-top'), 10) - | 126 parseInt(elStyle.getPropertyValue('padding-top'), 10) - |
127 parseInt(elStyle.getPropertyValue('padding-bottom'), 10) - | 127 parseInt(elStyle.getPropertyValue('padding-bottom'), 10) - |
128 this.getChildElement('.settings-area').offsetTop - | 128 this.getChildElement('.settings-area').offsetTop - |
129 this.getChildElement('.action-area').offsetHeight; | 129 this.getChildElement('.action-area').offsetHeight; |
130 }, | 130 }, |
131 | 131 |
132 /** | 132 /** |
133 * Filters displayed settings with the given query. | 133 * Filters displayed settings with the given query. |
134 * @param {?string} query Query to filter settings by. | 134 * @param {?RegExp} query Query to filter settings by. |
135 * @private | 135 * @private |
136 */ | 136 */ |
137 filterLists_: function(query) { | 137 filterLists_: function(query) { |
138 var atLeastOneMatch = false; | 138 var atLeastOneMatch = false; |
139 var lastVisibleItemWithBubble = null; | 139 var lastVisibleItemWithBubble = null; |
140 this.items_.forEach(function(item) { | 140 this.items_.forEach(function(item) { |
141 item.updateSearchQuery(query); | 141 item.updateSearchQuery(query); |
142 if (getIsVisible(item.getElement())) | 142 if (getIsVisible(item.getElement())) |
143 atLeastOneMatch = true; | 143 atLeastOneMatch = true; |
144 if (item.searchBubbleShown) | 144 if (item.searchBubbleShown) |
145 lastVisibleItemWithBubble = item; | 145 lastVisibleItemWithBubble = item; |
146 }); | 146 }); |
147 setIsVisible( | 147 setIsVisible( |
148 this.getChildElement('.no-settings-match-hint'), !atLeastOneMatch); | 148 assert(this.getChildElement('.no-settings-match-hint')), |
| 149 !atLeastOneMatch); |
149 setIsVisible( | 150 setIsVisible( |
150 this.getChildElement('.' + AdvancedSettings.Classes_.EXTRA_PADDING), | 151 assert(this.getChildElement( |
| 152 '.' + AdvancedSettings.Classes_.EXTRA_PADDING)), |
151 !!lastVisibleItemWithBubble); | 153 !!lastVisibleItemWithBubble); |
152 }, | 154 }, |
153 | 155 |
154 /** | 156 /** |
155 * Resets the filter query. | 157 * Resets the filter query. |
156 * @private | 158 * @private |
157 */ | 159 */ |
158 resetSearch_: function() { | 160 resetSearch_: function() { |
159 this.searchBox_.setQuery(null); | 161 this.searchBox_.setQuery(null); |
160 this.filterLists_(null); | 162 this.filterLists_(null); |
(...skipping 19 matching lines...) Expand all Loading... |
180 if (!vendorCapabilities) | 182 if (!vendorCapabilities) |
181 return; | 183 return; |
182 | 184 |
183 var availableHeight = this.getAvailableContentHeight_(); | 185 var availableHeight = this.getAvailableContentHeight_(); |
184 var containerEl = this.getChildElement('.settings-area'); | 186 var containerEl = this.getChildElement('.settings-area'); |
185 containerEl.style.maxHeight = availableHeight + 'px'; | 187 containerEl.style.maxHeight = availableHeight + 'px'; |
186 var settingsEl = this.getChildElement('.settings'); | 188 var settingsEl = this.getChildElement('.settings'); |
187 | 189 |
188 vendorCapabilities.forEach(function(capability) { | 190 vendorCapabilities.forEach(function(capability) { |
189 var item = new print_preview.AdvancedSettingsItem( | 191 var item = new print_preview.AdvancedSettingsItem( |
190 this.eventTarget_, this.printTicketStore_, capability); | 192 this.printTicketStore_, capability); |
191 this.addChild(item); | 193 this.addChild(item); |
192 item.render(settingsEl); | 194 item.render(assert(settingsEl)); |
193 this.items_.push(item); | 195 this.items_.push(item); |
194 }.bind(this)); | 196 }.bind(this)); |
195 | 197 |
| 198 var searchBoxArea = assert(this.getChildElement('.search-box-area')); |
196 if (this.items_.length <= 1) { | 199 if (this.items_.length <= 1) { |
197 setIsVisible(this.getChildElement('.search-box-area'), false); | 200 setIsVisible(searchBoxArea, false); |
198 } else { | 201 } else { |
199 setIsVisible(this.getChildElement('.search-box-area'), true); | 202 setIsVisible(searchBoxArea, true); |
200 this.searchBox_.focus(); | 203 this.searchBox_.focus(); |
201 } | 204 } |
202 | 205 |
203 extraPadding = document.createElement('div'); | 206 extraPadding = document.createElement('div'); |
204 extraPadding.classList.add(AdvancedSettings.Classes_.EXTRA_PADDING); | 207 extraPadding.classList.add(AdvancedSettings.Classes_.EXTRA_PADDING); |
205 extraPadding.hidden = true; | 208 extraPadding.hidden = true; |
206 settingsEl.appendChild(extraPadding); | 209 settingsEl.appendChild(extraPadding); |
207 }, | 210 }, |
208 | 211 |
209 /** | 212 /** |
(...skipping 21 matching lines...) Expand all Loading... |
231 | 234 |
232 this.printTicketStore_.vendorItems.updateValue(values); | 235 this.printTicketStore_.vendorItems.updateValue(values); |
233 } | 236 } |
234 }; | 237 }; |
235 | 238 |
236 // Export | 239 // Export |
237 return { | 240 return { |
238 AdvancedSettings: AdvancedSettings | 241 AdvancedSettings: AdvancedSettings |
239 }; | 242 }; |
240 }); | 243 }); |
OLD | NEW |