Chromium Code Reviews| 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 /** | |
| 5 * Specifies a custom vendor capability. | |
| 6 * @typedef {{ | |
| 7 * id: (string), | |
| 8 * display_name: (string), | |
| 9 * localized_display_name: (string | undefined), | |
| 10 * type: (string), | |
| 11 * select_cap: ({ | |
| 12 * option: (Array<{ | |
| 13 * display_name: (string), | |
| 14 * type: (string | undefined), | |
| 15 * value: (number | string | boolean), | |
| 16 * is_default: (boolean | undefined) | |
| 17 * }>|undefined) | |
| 18 * }|undefined) | |
| 19 * }} | |
| 20 */ | |
| 21 print_preview.VendorCapability; | |
| 4 | 22 |
| 5 cr.define('print_preview', function() { | 23 cr.define('print_preview', function() { |
| 6 'use strict'; | 24 'use strict'; |
| 7 | 25 |
| 8 /** | 26 /** |
| 9 * Component that renders a destination item in a destination list. | 27 * Component that renders a destination item in a destination list. |
| 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection | |
| 11 * events to. | |
| 12 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the | 28 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the |
| 13 * print ticket to print. | 29 * print ticket to print. |
| 14 * @param {!Object} capability Capability to render. | 30 * @param {!print_preview.VendorCapability} capability Capability to render. |
| 15 * @constructor | 31 * @constructor |
| 16 * @extends {print_preview.Component} | 32 * @extends {print_preview.Component} |
| 17 */ | 33 */ |
| 18 function AdvancedSettingsItem(eventTarget, printTicketStore, capability) { | 34 function AdvancedSettingsItem(printTicketStore, capability) { |
| 19 print_preview.Component.call(this); | 35 print_preview.Component.call(this); |
| 20 | 36 |
| 21 /** | 37 /** |
| 22 * Event target to dispatch selection events to. | |
| 23 * @private {!cr.EventTarget} | |
| 24 */ | |
| 25 this.eventTarget_ = eventTarget; | |
| 26 | |
| 27 /** | |
| 28 * Contains the print ticket to print. | 38 * Contains the print ticket to print. |
| 29 * @private {!print_preview.PrintTicketStore} | 39 * @private {!print_preview.PrintTicketStore} |
| 30 */ | 40 */ |
| 31 this.printTicketStore_ = printTicketStore; | 41 this.printTicketStore_ = printTicketStore; |
| 32 | 42 |
| 33 /** | 43 /** |
| 34 * Capability this component renders. | 44 * Capability this component renders. |
| 35 * @private {!Object} | 45 * @private {!print_preview.VendorCapability} |
| 36 */ | 46 */ |
| 37 this.capability_ = capability; | 47 this.capability_ = capability; |
| 38 | 48 |
| 39 /** | 49 /** |
| 40 * Value selected by user. {@code null}, if user has not changed the default | 50 * Value selected by user. {@code null}, if user has not changed the default |
| 41 * value yet (still, the value can be the default one, if it is what user | 51 * value yet (still, the value can be the default one, if it is what user |
| 42 * selected). | 52 * selected). |
| 43 * @private {?string} | 53 * @private {?string} |
| 44 */ | 54 */ |
| 45 this.selectedValue_ = null; | 55 this.selectedValue_ = null; |
| 46 | 56 |
| 47 /** | 57 /** |
| 48 * Active filter query. | 58 * Active filter query. |
| 49 * @private {RegExp} | 59 * @private {RegExp} |
| 50 */ | 60 */ |
| 51 this.query_ = null; | 61 this.query_ = null; |
| 52 | 62 |
| 53 /** | 63 /** |
| 54 * Search hint for the control. | 64 * Search hint for the control. |
| 55 * @private {print_preview.SearchBubble} | 65 * @private {print_preview.SearchBubble} |
| 56 */ | 66 */ |
| 57 this.searchBubble_ = null; | 67 this.searchBubble_ = null; |
| 58 | 68 |
| 59 /** @private {!EventTracker} */ | 69 /** @private {!EventTracker} */ |
| 60 this.tracker_ = new EventTracker(); | 70 this.tracker_ = new EventTracker(); |
| 61 }; | 71 } |
| 62 | 72 |
| 63 AdvancedSettingsItem.prototype = { | 73 AdvancedSettingsItem.prototype = { |
| 64 __proto__: print_preview.Component.prototype, | 74 __proto__: print_preview.Component.prototype, |
| 65 | 75 |
| 66 /** @override */ | 76 /** @override */ |
| 67 createDom: function() { | 77 createDom: function() { |
| 68 this.setElementInternal(this.cloneTemplateInternal( | 78 this.setElementInternal(this.cloneTemplateInternal( |
| 69 'advanced-settings-item-template')); | 79 'advanced-settings-item-template')); |
| 70 | 80 |
| 71 this.tracker_.add( | 81 this.tracker_.add( |
| 72 this.select_, 'change', this.onSelectChange_.bind(this)); | 82 assert(this.select_), 'change', this.onSelectChange_.bind(this)); |
| 73 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this)); | 83 this.tracker_.add( |
| 84 assert(this.text_), 'input', this.onTextInput_.bind(this)); | |
| 74 | 85 |
| 75 this.initializeValue_(); | 86 this.initializeValue_(); |
| 76 | 87 |
| 77 this.renderCapability_(); | 88 this.renderCapability_(); |
| 78 }, | 89 }, |
| 79 | 90 |
| 80 /** | 91 /** |
| 81 * ID of the corresponding vendor capability. | 92 * ID of the corresponding vendor capability. |
| 82 * @return {string} | 93 * @return {string} |
| 83 */ | 94 */ |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 109 | 120 |
| 110 get searchBubbleShown() { | 121 get searchBubbleShown() { |
| 111 return getIsVisible(this.getElement()) && !!this.searchBubble_; | 122 return getIsVisible(this.getElement()) && !!this.searchBubble_; |
| 112 }, | 123 }, |
| 113 | 124 |
| 114 /** | 125 /** |
| 115 * @return {HTMLSelectElement} Select element. | 126 * @return {HTMLSelectElement} Select element. |
| 116 * @private | 127 * @private |
| 117 */ | 128 */ |
| 118 get select_() { | 129 get select_() { |
| 119 return this.getChildElement( | 130 return /** @type {HTMLSelectElement} */( |
| 120 '.advanced-settings-item-value-select-control'); | 131 this.getChildElement('.advanced-settings-item-value-select-control')); |
| 121 }, | 132 }, |
| 122 | 133 |
| 123 /** | 134 /** |
| 124 * @return {HTMLSelectElement} Text element. | 135 * @return {HTMLSelectElement} Text element. |
| 125 * @private | 136 * @private |
| 126 */ | 137 */ |
| 127 get text_() { | 138 get text_() { |
| 128 return this.getChildElement('.advanced-settings-item-value-text-control'); | 139 return /** @type {HTMLSelectElement} */( |
|
dpapad
2017/05/04 01:20:04
How about casting to !HTMLSelectElement here, and
rbpotter
2017/05/04 01:43:07
Done.
| |
| 140 this.getChildElement('.advanced-settings-item-value-text-control')); | |
| 129 }, | 141 }, |
| 130 | 142 |
| 131 /** | 143 /** |
| 132 * Called when the select element value is changed. | 144 * Called when the select element value is changed. |
| 133 * @private | 145 * @private |
| 134 */ | 146 */ |
| 135 onSelectChange_: function() { | 147 onSelectChange_: function() { |
| 136 this.selectedValue_ = this.select_.value; | 148 this.selectedValue_ = this.select_.value; |
| 137 }, | 149 }, |
| 138 | 150 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 this.initializeSelectValue_(); | 261 this.initializeSelectValue_(); |
| 250 else | 262 else |
| 251 this.initializeTextValue_(); | 263 this.initializeTextValue_(); |
| 252 }, | 264 }, |
| 253 | 265 |
| 254 /** | 266 /** |
| 255 * Initializes the select element. | 267 * Initializes the select element. |
| 256 * @private | 268 * @private |
| 257 */ | 269 */ |
| 258 initializeSelectValue_: function() { | 270 initializeSelectValue_: function() { |
| 259 setIsVisible( | 271 setIsVisible(assert(this.getChildElement( |
| 260 this.getChildElement('.advanced-settings-item-value-select'), true); | 272 '.advanced-settings-item-value-select')), true); |
| 261 var selectEl = this.select_; | 273 var selectEl = this.select_; |
| 262 var indexToSelect = 0; | 274 var indexToSelect = 0; |
| 263 this.capability_.select_cap.option.forEach(function(option, index) { | 275 this.capability_.select_cap.option.forEach(function(option, index) { |
| 264 var item = document.createElement('option'); | 276 var item = document.createElement('option'); |
| 265 item.text = this.getEntityDisplayName_(option); | 277 item.text = this.getEntityDisplayName_(option); |
| 266 item.value = option.value; | 278 item.value = option.value; |
| 267 if (option.is_default) | 279 if (option.is_default) |
| 268 indexToSelect = index; | 280 indexToSelect = index; |
| 269 selectEl.appendChild(item); | 281 selectEl.appendChild(item); |
| 270 }, this); | 282 }, this); |
| 271 for (var i = 0, option; option = selectEl.options[i]; i++) { | 283 for (var i = 0, option; option = selectEl.options[i]; i++) { |
| 272 if (option.value == this.selectedValue_) { | 284 if (option.value == this.selectedValue_) { |
| 273 indexToSelect = i; | 285 indexToSelect = i; |
| 274 break; | 286 break; |
| 275 } | 287 } |
| 276 } | 288 } |
| 277 selectEl.selectedIndex = indexToSelect; | 289 selectEl.selectedIndex = indexToSelect; |
| 278 }, | 290 }, |
| 279 | 291 |
| 280 /** | 292 /** |
| 281 * Initializes the text element. | 293 * Initializes the text element. |
| 282 * @private | 294 * @private |
| 283 */ | 295 */ |
| 284 initializeTextValue_: function() { | 296 initializeTextValue_: function() { |
| 285 setIsVisible( | 297 setIsVisible(assert(this.getChildElement( |
| 286 this.getChildElement('.advanced-settings-item-value-text'), true); | 298 '.advanced-settings-item-value-text')), true); |
| 287 | 299 |
| 288 var defaultValue = null; | 300 var defaultValue = null; |
| 289 if (this.capability_.type == 'TYPED_VALUE' && | 301 if (this.capability_.type == 'TYPED_VALUE' && |
| 290 this.capability_.typed_value_cap) { | 302 this.capability_.typed_value_cap) { |
| 291 defaultValue = this.capability_.typed_value_cap.default || null; | 303 defaultValue = this.capability_.typed_value_cap.default || null; |
| 292 } else if (this.capability_.type == 'RANGE' && | 304 } else if (this.capability_.type == 'RANGE' && |
| 293 this.capability_.range_cap) { | 305 this.capability_.range_cap) { |
| 294 defaultValue = this.capability_.range_cap.default || null; | 306 defaultValue = this.capability_.range_cap.default || null; |
| 295 } | 307 } |
| 296 | 308 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 318 } | 330 } |
| 319 }); | 331 }); |
| 320 } | 332 } |
| 321 }; | 333 }; |
| 322 | 334 |
| 323 // Export | 335 // Export |
| 324 return { | 336 return { |
| 325 AdvancedSettingsItem: AdvancedSettingsItem | 337 AdvancedSettingsItem: AdvancedSettingsItem |
| 326 }; | 338 }; |
| 327 }); | 339 }); |
| OLD | NEW |