| 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('options', function() { | 5 cr.define('options', function() { |
| 6 | |
| 7 var Preferences = options.Preferences; | 6 var Preferences = options.Preferences; |
| 8 | 7 |
| 9 /** | 8 /** |
| 10 * Allows an element to be disabled for several reasons. | 9 * Allows an element to be disabled for several reasons. |
| 11 * The element is disabled if at least one reason is true, and the reasons | 10 * The element is disabled if at least one reason is true, and the reasons |
| 12 * can be set separately. | 11 * can be set separately. |
| 13 * @private | 12 * @private |
| 14 * @param {!HTMLElement} el The element to update. | 13 * @param {!HTMLElement} el The element to update. |
| 15 * @param {string} reason The reason for disabling the element. | 14 * @param {string} reason The reason for disabling the element. |
| 16 * @param {boolean} disabled Whether the element should be disabled or enabled | 15 * @param {boolean} disabled Whether the element should be disabled or enabled |
| 17 * for the given |reason|. | 16 * for the given |reason|. |
| 18 */ | 17 */ |
| 19 function updateDisabledState_(el, reason, disabled) { | 18 function updateDisabledState(el, reason, disabled) { |
| 20 if (!el.disabledReasons) | 19 if (!el.disabledReasons) |
| 21 el.disabledReasons = {}; | 20 el.disabledReasons = {}; |
| 21 |
| 22 if (el.disabled && (Object.keys(el.disabledReasons).length == 0)) { | 22 if (el.disabled && (Object.keys(el.disabledReasons).length == 0)) { |
| 23 // The element has been previously disabled without a reason, so we add | 23 // The element has been previously disabled without a reason, so we add |
| 24 // one to keep it disabled. | 24 // one to keep it disabled. |
| 25 el.disabledReasons.other = true; | 25 el.disabledReasons.other = true; |
| 26 } | 26 } |
| 27 |
| 27 if (!el.disabled) { | 28 if (!el.disabled) { |
| 28 // If the element is not disabled, there should be no reason, except for | 29 // If the element is not disabled, there should be no reason, except for |
| 29 // 'other'. | 30 // 'other'. |
| 30 delete el.disabledReasons.other; | 31 delete el.disabledReasons.other; |
| 31 if (Object.keys(el.disabledReasons).length > 0) | 32 if (Object.keys(el.disabledReasons).length > 0) |
| 32 console.error('Element is not disabled but should be'); | 33 console.error('Element is not disabled but should be'); |
| 33 } | 34 } |
| 34 if (disabled) { | 35 |
| 36 if (disabled) |
| 35 el.disabledReasons[reason] = true; | 37 el.disabledReasons[reason] = true; |
| 36 } else { | 38 else |
| 37 delete el.disabledReasons[reason]; | 39 delete el.disabledReasons[reason]; |
| 38 } | 40 |
| 39 el.disabled = Object.keys(el.disabledReasons).length > 0; | 41 el.disabled = Object.keys(el.disabledReasons).length > 0; |
| 40 } | 42 } |
| 41 | 43 |
| 42 ///////////////////////////////////////////////////////////////////////////// | 44 ///////////////////////////////////////////////////////////////////////////// |
| 43 // PrefInputElement class: | 45 // PrefInputElement class: |
| 44 | 46 |
| 45 /** | 47 /** |
| 46 * Define a constructor that uses an input element as its underlying element. | 48 * Define a constructor that uses an input element as its underlying element. |
| 47 * @constructor | 49 * @constructor |
| 48 * @extends {HTMLInputElement} | 50 * @extends {HTMLInputElement} |
| 49 */ | 51 */ |
| 50 var PrefInputElement = cr.ui.define('input'); | 52 var PrefInputElement = cr.ui.define('input'); |
| 51 | 53 |
| 52 PrefInputElement.prototype = { | 54 PrefInputElement.prototype = { |
| 53 // Set up the prototype chain | 55 // Set up the prototype chain |
| 54 __proto__: HTMLInputElement.prototype, | 56 __proto__: HTMLInputElement.prototype, |
| 55 | 57 |
| 56 /** | 58 /** |
| 57 * Initialization function for the cr.ui framework. | 59 * Initialization function for the cr.ui framework. |
| 58 */ | 60 */ |
| 59 decorate: function() { | 61 decorate: function() { |
| 60 var self = this; | 62 var self = this; |
| 61 | 63 |
| 62 // Listen for user events. | 64 // Listen for user events. |
| 63 this.addEventListener('change', this.handleChange_.bind(this)); | 65 this.addEventListener('change', this.handleChange.bind(this)); |
| 64 | 66 |
| 65 // Listen for pref changes. | 67 // Listen for pref changes. |
| 66 Preferences.getInstance().addEventListener(this.pref, function(event) { | 68 Preferences.getInstance().addEventListener(this.pref, function(event) { |
| 67 if (event.value.uncommitted && !self.dialogPref) | 69 if (event.value.uncommitted && !self.dialogPref) |
| 68 return; | 70 return; |
| 69 self.updateStateFromPref_(event); | 71 self.updateStateFromPref(event); |
| 70 updateDisabledState_(self, 'notUserModifiable', event.value.disabled); | 72 updateDisabledState(self, 'notUserModifiable', event.value.disabled); |
| 71 self.controlledBy = event.value.controlledBy; | 73 self.controlledBy = event.value.controlledBy; |
| 72 }); | 74 }); |
| 73 }, | 75 }, |
| 74 | 76 |
| 75 /** | 77 /** |
| 76 * Handle changes to the input element's state made by the user. If a custom | 78 * Handle changes to the input element's state made by the user. If a custom |
| 77 * change handler does not suppress it, a default handler is invoked that | 79 * change handler does not suppress it, a default handler is invoked that |
| 78 * updates the associated pref. | 80 * updates the associated pref. |
| 79 * @param {Event} event Change event. | 81 * @param {Event} event Change event. |
| 80 * @private | 82 * @protected |
| 81 */ | 83 */ |
| 82 handleChange_: function(event) { | 84 handleChange: function(event) { |
| 83 if (!this.customChangeHandler(event)) | 85 if (!this.customChangeHandler(event)) |
| 84 this.updatePrefFromState_(); | 86 this.updatePrefFromState(); |
| 85 }, | 87 }, |
| 86 | 88 |
| 87 /** | 89 /** |
| 88 * Handles changes to the pref. If a custom change handler does not suppress | 90 * Handles changes to the pref. If a custom change handler does not suppress |
| 89 * it, a default handler is invoked that update the input element's state. | 91 * it, a default handler is invoked that updates the input element's state. |
| 90 * @param {Event} event Pref change event. | 92 * @param {Event} event Pref change event. |
| 91 * @private | 93 * @protected |
| 92 */ | 94 */ |
| 93 updateStateFromPref_: function(event) { | 95 updateStateFromPref: function(event) { |
| 94 if (!this.customPrefChangeHandler(event)) | 96 if (!this.customPrefChangeHandler(event)) |
| 95 this.value = event.value.value; | 97 this.value = event.value.value; |
| 96 }, | 98 }, |
| 97 | 99 |
| 98 /** | 100 /** |
| 99 * See |updateDisabledState_| above. | 101 * See |updateDisabledState| above. |
| 100 */ | 102 */ |
| 101 setDisabled: function(reason, disabled) { | 103 setDisabled: function(reason, disabled) { |
| 102 updateDisabledState_(this, reason, disabled); | 104 updateDisabledState(this, reason, disabled); |
| 103 }, | 105 }, |
| 104 | 106 |
| 105 /** | 107 /** |
| 106 * Custom change handler that is invoked first when the user makes changes | 108 * Custom change handler that is invoked first when the user makes changes |
| 107 * to the input element's state. If it returns false, a default handler is | 109 * to the input element's state. If it returns false, a default handler is |
| 108 * invoked next that updates the associated pref. If it returns true, the | 110 * invoked next that updates the associated pref. If it returns true, the |
| 109 * default handler is suppressed (i.e., this works like stopPropagation or | 111 * default handler is suppressed (i.e., this works like stopPropagation or |
| 110 * cancelBubble). | 112 * cancelBubble). |
| 111 * @param {Event} event Input element change event. | 113 * @param {Event} event Input element change event. |
| 112 */ | 114 */ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 /** | 175 /** |
| 174 * Initialization function for the cr.ui framework. | 176 * Initialization function for the cr.ui framework. |
| 175 */ | 177 */ |
| 176 decorate: function() { | 178 decorate: function() { |
| 177 PrefInputElement.prototype.decorate.call(this); | 179 PrefInputElement.prototype.decorate.call(this); |
| 178 this.type = 'checkbox'; | 180 this.type = 'checkbox'; |
| 179 | 181 |
| 180 // Consider a checked dialog checkbox as a 'suggestion' which is committed | 182 // Consider a checked dialog checkbox as a 'suggestion' which is committed |
| 181 // once the user confirms the dialog. | 183 // once the user confirms the dialog. |
| 182 if (this.dialogPref && this.checked) | 184 if (this.dialogPref && this.checked) |
| 183 this.updatePrefFromState_(); | 185 this.updatePrefFromState(); |
| 184 }, | 186 }, |
| 185 | 187 |
| 186 /** | 188 /** |
| 187 * Update the associated pref when when the user makes changes to the | 189 * Update the associated pref when when the user makes changes to the |
| 188 * checkbox state. | 190 * checkbox state. |
| 189 * @private | 191 * @override |
| 190 */ | 192 */ |
| 191 updatePrefFromState_: function() { | 193 updatePrefFromState: function() { |
| 192 var value = this.inverted_pref ? !this.checked : this.checked; | 194 var value = this.inverted_pref ? !this.checked : this.checked; |
| 193 Preferences.setBooleanPref(this.pref, value, | 195 Preferences.setBooleanPref(this.pref, value, |
| 194 !this.dialogPref, this.metric); | 196 !this.dialogPref, this.metric); |
| 195 }, | 197 }, |
| 196 | 198 |
| 199 /** @override */ |
| 200 updateStateFromPref: function(event) { |
| 201 if (!this.customPrefChangeHandler(event)) |
| 202 this.defaultPrefChangeHandler(event); |
| 203 }, |
| 204 |
| 197 /** | 205 /** |
| 198 * Update the checkbox state when the associated pref changes. | 206 * @param {Event} event A pref change event. |
| 199 * @param {Event} event Pref change event. | |
| 200 * @private | |
| 201 */ | 207 */ |
| 202 updateStateFromPref_: function(event) { | 208 defaultPrefChangeHandler: function(event) { |
| 203 if (this.customPrefChangeHandler(event)) | |
| 204 return; | |
| 205 var value = Boolean(event.value.value); | 209 var value = Boolean(event.value.value); |
| 206 this.checked = this.inverted_pref ? !value : value; | 210 this.checked = this.inverted_pref ? !value : value; |
| 207 }, | 211 }, |
| 208 }; | 212 }; |
| 209 | 213 |
| 210 /** | 214 /** |
| 211 * Whether the mapping between checkbox state and associated pref is inverted. | 215 * Whether the mapping between checkbox state and associated pref is inverted. |
| 212 */ | 216 */ |
| 213 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); | 217 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); |
| 214 | 218 |
| 215 ///////////////////////////////////////////////////////////////////////////// | 219 ///////////////////////////////////////////////////////////////////////////// |
| 216 // PrefNumber class: | 220 // PrefNumber class: |
| 217 | 221 |
| 218 // Define a constructor that uses an input element as its underlying element. | 222 // Define a constructor that uses an input element as its underlying element. |
| 219 var PrefNumber = cr.ui.define('input'); | 223 var PrefNumber = cr.ui.define('input'); |
| 220 | 224 |
| 221 PrefNumber.prototype = { | 225 PrefNumber.prototype = { |
| 222 // Set up the prototype chain | 226 // Set up the prototype chain |
| 223 __proto__: PrefInputElement.prototype, | 227 __proto__: PrefInputElement.prototype, |
| 224 | 228 |
| 225 /** | 229 /** |
| 226 * Initialization function for the cr.ui framework. | 230 * Initialization function for the cr.ui framework. |
| 227 */ | 231 */ |
| 228 decorate: function() { | 232 decorate: function() { |
| 229 PrefInputElement.prototype.decorate.call(this); | 233 PrefInputElement.prototype.decorate.call(this); |
| 230 this.type = 'number'; | 234 this.type = 'number'; |
| 231 }, | 235 }, |
| 232 | 236 |
| 233 /** | 237 /** |
| 234 * Update the associated pref when when the user inputs a number. | 238 * Update the associated pref when the user inputs a number. |
| 235 * @private | 239 * @override |
| 236 */ | 240 */ |
| 237 updatePrefFromState_: function() { | 241 updatePrefFromState: function() { |
| 238 if (this.validity.valid) { | 242 if (this.validity.valid) { |
| 239 Preferences.setIntegerPref(this.pref, this.value, | 243 Preferences.setIntegerPref(this.pref, this.value, |
| 240 !this.dialogPref, this.metric); | 244 !this.dialogPref, this.metric); |
| 241 } | 245 } |
| 242 }, | 246 }, |
| 243 }; | 247 }; |
| 244 | 248 |
| 245 ///////////////////////////////////////////////////////////////////////////// | 249 ///////////////////////////////////////////////////////////////////////////// |
| 246 // PrefRadio class: | 250 // PrefRadio class: |
| 247 | 251 |
| 248 //Define a constructor that uses an input element as its underlying element. | 252 //Define a constructor that uses an input element as its underlying element. |
| 249 var PrefRadio = cr.ui.define('input'); | 253 var PrefRadio = cr.ui.define('input'); |
| 250 | 254 |
| 251 PrefRadio.prototype = { | 255 PrefRadio.prototype = { |
| 252 // Set up the prototype chain | 256 // Set up the prototype chain |
| 253 __proto__: PrefInputElement.prototype, | 257 __proto__: PrefInputElement.prototype, |
| 254 | 258 |
| 255 /** | 259 /** |
| 256 * Initialization function for the cr.ui framework. | 260 * Initialization function for the cr.ui framework. |
| 257 */ | 261 */ |
| 258 decorate: function() { | 262 decorate: function() { |
| 259 PrefInputElement.prototype.decorate.call(this); | 263 PrefInputElement.prototype.decorate.call(this); |
| 260 this.type = 'radio'; | 264 this.type = 'radio'; |
| 261 }, | 265 }, |
| 262 | 266 |
| 263 /** | 267 /** |
| 264 * Update the associated pref when when the user selects the radio button. | 268 * Update the associated pref when when the user selects the radio button. |
| 265 * @private | 269 * @override |
| 266 */ | 270 */ |
| 267 updatePrefFromState_: function() { | 271 updatePrefFromState: function() { |
| 268 if (this.value == 'true' || this.value == 'false') { | 272 if (this.value == 'true' || this.value == 'false') { |
| 269 Preferences.setBooleanPref(this.pref, | 273 Preferences.setBooleanPref(this.pref, |
| 270 this.value == String(this.checked), | 274 this.value == String(this.checked), |
| 271 !this.dialogPref, this.metric); | 275 !this.dialogPref, this.metric); |
| 272 } else { | 276 } else { |
| 273 Preferences.setIntegerPref(this.pref, this.value, | 277 Preferences.setIntegerPref(this.pref, this.value, |
| 274 !this.dialogPref, this.metric); | 278 !this.dialogPref, this.metric); |
| 275 } | 279 } |
| 276 }, | 280 }, |
| 277 | 281 |
| 278 /** | 282 /** @override */ |
| 279 * Update the radio button state when the associated pref changes. | 283 updateStateFromPref: function(event) { |
| 280 * @param {Event} event Pref change event. | |
| 281 * @private | |
| 282 */ | |
| 283 updateStateFromPref_: function(event) { | |
| 284 if (!this.customPrefChangeHandler(event)) | 284 if (!this.customPrefChangeHandler(event)) |
| 285 this.checked = this.value == String(event.value.value); | 285 this.checked = this.value == String(event.value.value); |
| 286 }, | 286 }, |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 ///////////////////////////////////////////////////////////////////////////// | 289 ///////////////////////////////////////////////////////////////////////////// |
| 290 // PrefRange class: | 290 // PrefRange class: |
| 291 | 291 |
| 292 /** | 292 /** |
| 293 * Define a constructor that uses an input element as its underlying element. | 293 * Define a constructor that uses an input element as its underlying element. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 // fixed. | 317 // fixed. |
| 318 // https://bugs.webkit.org/show_bug.cgi?id=52256 | 318 // https://bugs.webkit.org/show_bug.cgi?id=52256 |
| 319 this.addEventListener('keyup', this.handleRelease_.bind(this)); | 319 this.addEventListener('keyup', this.handleRelease_.bind(this)); |
| 320 this.addEventListener('mouseup', this.handleRelease_.bind(this)); | 320 this.addEventListener('mouseup', this.handleRelease_.bind(this)); |
| 321 this.addEventListener('touchcancel', this.handleRelease_.bind(this)); | 321 this.addEventListener('touchcancel', this.handleRelease_.bind(this)); |
| 322 this.addEventListener('touchend', this.handleRelease_.bind(this)); | 322 this.addEventListener('touchend', this.handleRelease_.bind(this)); |
| 323 }, | 323 }, |
| 324 | 324 |
| 325 /** | 325 /** |
| 326 * Update the associated pref when when the user releases the slider. | 326 * Update the associated pref when when the user releases the slider. |
| 327 * @private | 327 * @override |
| 328 */ | 328 */ |
| 329 updatePrefFromState_: function() { | 329 updatePrefFromState: function() { |
| 330 Preferences.setIntegerPref( | 330 Preferences.setIntegerPref( |
| 331 this.pref, | 331 this.pref, |
| 332 this.mapPositionToPref(parseInt(this.value, 10)), | 332 this.mapPositionToPref(parseInt(this.value, 10)), |
| 333 !this.dialogPref, | 333 !this.dialogPref, |
| 334 this.metric); | 334 this.metric); |
| 335 }, | 335 }, |
| 336 | 336 |
| 337 /** | 337 /** @override */ |
| 338 * Ignore changes to the slider position made by the user while the slider | 338 handleChange: function() { |
| 339 * has not been released. | 339 // Ignore changes to the slider position made by the user while the slider |
| 340 * @private | 340 // has not been released. |
| 341 */ | |
| 342 handleChange_: function() { | |
| 343 }, | 341 }, |
| 344 | 342 |
| 345 /** | 343 /** |
| 346 * Handle changes to the slider position made by the user when the slider is | 344 * Handle changes to the slider position made by the user when the slider is |
| 347 * released. If a custom change handler does not suppress it, a default | 345 * released. If a custom change handler does not suppress it, a default |
| 348 * handler is invoked that updates the associated pref. | 346 * handler is invoked that updates the associated pref. |
| 349 * @param {Event} event Change event. | 347 * @param {Event} event Change event. |
| 350 * @private | 348 * @private |
| 351 */ | 349 */ |
| 352 handleRelease_: function(event) { | 350 handleRelease_: function(event) { |
| 353 if (!this.customChangeHandler(event)) | 351 if (!this.customChangeHandler(event)) |
| 354 this.updatePrefFromState_(); | 352 this.updatePrefFromState(); |
| 355 }, | 353 }, |
| 356 | 354 |
| 357 /** | 355 /** |
| 358 * Handles changes to the pref associated with the slider. If a custom | 356 * Handles changes to the pref associated with the slider. If a custom |
| 359 * change handler does not suppress it, a default handler is invoked that | 357 * change handler does not suppress it, a default handler is invoked that |
| 360 * updates the slider position. | 358 * updates the slider position. |
| 361 * @param {Event} event Pref change event. | 359 * @override. |
| 362 * @private | |
| 363 */ | 360 */ |
| 364 updateStateFromPref_: function(event) { | 361 updateStateFromPref: function(event) { |
| 365 if (this.customPrefChangeHandler(event)) | 362 if (this.customPrefChangeHandler(event)) |
| 366 return; | 363 return; |
| 367 var value = event.value.value; | 364 var value = event.value.value; |
| 368 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; | 365 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; |
| 369 }, | 366 }, |
| 370 | 367 |
| 371 /** | 368 /** |
| 372 * Map slider position to the range of values provided by the client, | 369 * Map slider position to the range of values provided by the client, |
| 373 * represented by |valueMap|. | 370 * represented by |valueMap|. |
| 374 * @param {number} position The slider position to map. | 371 * @param {number} position The slider position to map. |
| 375 */ | 372 */ |
| 376 mapPositionToPref: function(position) { | 373 mapPositionToPref: function(position) { |
| 377 return this.valueMap ? this.valueMap[position] : position; | 374 return this.valueMap ? this.valueMap[position] : position; |
| 378 }, | 375 }, |
| 379 }; | 376 }; |
| 380 | 377 |
| 381 ///////////////////////////////////////////////////////////////////////////// | 378 ///////////////////////////////////////////////////////////////////////////// |
| 382 // PrefSelect class: | 379 // PrefSelect class: |
| 383 | 380 |
| 384 // Define a constructor that uses a select element as its underlying element. | 381 // Define a constructor that uses a select element as its underlying element. |
| 385 var PrefSelect = cr.ui.define('select'); | 382 var PrefSelect = cr.ui.define('select'); |
| 386 | 383 |
| 387 PrefSelect.prototype = { | 384 PrefSelect.prototype = { |
| 388 // Set up the prototype chain | 385 // Set up the prototype chain |
| 389 __proto__: PrefInputElement.prototype, | 386 __proto__: PrefInputElement.prototype, |
| 390 | 387 |
| 391 /** | 388 /** |
| 392 * Update the associated pref when when the user selects an item. | 389 * Update the associated pref when when the user selects an item. |
| 393 * @private | 390 * @override |
| 394 */ | 391 */ |
| 395 updatePrefFromState_: function() { | 392 updatePrefFromState: function() { |
| 396 var value = this.options[this.selectedIndex].value; | 393 var value = this.options[this.selectedIndex].value; |
| 397 switch (this.dataType) { | 394 switch (this.dataType) { |
| 398 case 'number': | 395 case 'number': |
| 399 Preferences.setIntegerPref(this.pref, value, | 396 Preferences.setIntegerPref(this.pref, value, |
| 400 !this.dialogPref, this.metric); | 397 !this.dialogPref, this.metric); |
| 401 break; | 398 break; |
| 402 case 'double': | 399 case 'double': |
| 403 Preferences.setDoublePref(this.pref, value, | 400 Preferences.setDoublePref(this.pref, value, |
| 404 !this.dialogPref, this.metric); | 401 !this.dialogPref, this.metric); |
| 405 break; | 402 break; |
| 406 case 'boolean': | 403 case 'boolean': |
| 407 Preferences.setBooleanPref(this.pref, value == 'true', | 404 Preferences.setBooleanPref(this.pref, value == 'true', |
| 408 !this.dialogPref, this.metric); | 405 !this.dialogPref, this.metric); |
| 409 break; | 406 break; |
| 410 case 'string': | 407 case 'string': |
| 411 Preferences.setStringPref(this.pref, value, | 408 Preferences.setStringPref(this.pref, value, |
| 412 !this.dialogPref, this.metric); | 409 !this.dialogPref, this.metric); |
| 413 break; | 410 break; |
| 414 default: | 411 default: |
| 415 console.error('Unknown data type for <select> UI element: ' + | 412 console.error('Unknown data type for <select> UI element: ' + |
| 416 this.dataType); | 413 this.dataType); |
| 417 } | 414 } |
| 418 }, | 415 }, |
| 419 | 416 |
| 420 /** | 417 /** @override */ |
| 421 * Update the selected item when the associated pref changes. | 418 updateStateFromPref: function(event) { |
| 422 * @param {Event} event Pref change event. | |
| 423 * @private | |
| 424 */ | |
| 425 updateStateFromPref_: function(event) { | |
| 426 if (this.customPrefChangeHandler(event)) | 419 if (this.customPrefChangeHandler(event)) |
| 427 return; | 420 return; |
| 428 | 421 |
| 429 // Make sure the value is a string, because the value is stored as a | 422 // Make sure the value is a string, because the value is stored as a |
| 430 // string in the HTMLOptionElement. | 423 // string in the HTMLOptionElement. |
| 431 var value = String(event.value.value); | 424 var value = String(event.value.value); |
| 432 | 425 |
| 433 var found = false; | 426 var found = false; |
| 434 for (var i = 0; i < this.options.length; i++) { | 427 for (var i = 0; i < this.options.length; i++) { |
| 435 if (this.options[i].value == value) { | 428 if (this.options[i].value == value) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 463 |
| 471 // Listen for user events. | 464 // Listen for user events. |
| 472 window.addEventListener('unload', function() { | 465 window.addEventListener('unload', function() { |
| 473 if (document.activeElement == self) | 466 if (document.activeElement == self) |
| 474 self.blur(); | 467 self.blur(); |
| 475 }); | 468 }); |
| 476 }, | 469 }, |
| 477 | 470 |
| 478 /** | 471 /** |
| 479 * Update the associated pref when when the user inputs text. | 472 * Update the associated pref when when the user inputs text. |
| 480 * @private | 473 * @override |
| 481 */ | 474 */ |
| 482 updatePrefFromState_: function(event) { | 475 updatePrefFromState: function(event) { |
| 483 switch (this.dataType) { | 476 switch (this.dataType) { |
| 484 case 'number': | 477 case 'number': |
| 485 Preferences.setIntegerPref(this.pref, this.value, | 478 Preferences.setIntegerPref(this.pref, this.value, |
| 486 !this.dialogPref, this.metric); | 479 !this.dialogPref, this.metric); |
| 487 break; | 480 break; |
| 488 case 'double': | 481 case 'double': |
| 489 Preferences.setDoublePref(this.pref, this.value, | 482 Preferences.setDoublePref(this.pref, this.value, |
| 490 !this.dialogPref, this.metric); | 483 !this.dialogPref, this.metric); |
| 491 break; | 484 break; |
| 492 case 'url': | 485 case 'url': |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 decorate: function() { | 540 decorate: function() { |
| 548 var self = this; | 541 var self = this; |
| 549 | 542 |
| 550 // Listen for pref changes. | 543 // Listen for pref changes. |
| 551 // This element behaves like a normal button and does not affect the | 544 // This element behaves like a normal button and does not affect the |
| 552 // underlying preference; it just becomes disabled when the preference is | 545 // underlying preference; it just becomes disabled when the preference is |
| 553 // managed, and its value is false. This is useful for buttons that should | 546 // managed, and its value is false. This is useful for buttons that should |
| 554 // be disabled when the underlying Boolean preference is set to false by a | 547 // be disabled when the underlying Boolean preference is set to false by a |
| 555 // policy or extension. | 548 // policy or extension. |
| 556 Preferences.getInstance().addEventListener(this.pref, function(event) { | 549 Preferences.getInstance().addEventListener(this.pref, function(event) { |
| 557 updateDisabledState_(self, 'notUserModifiable', | 550 updateDisabledState(self, 'notUserModifiable', |
| 558 event.value.disabled && !event.value.value); | 551 event.value.disabled && !event.value.value); |
| 559 self.controlledBy = event.value.controlledBy; | 552 self.controlledBy = event.value.controlledBy; |
| 560 }); | 553 }); |
| 561 }, | 554 }, |
| 562 | 555 |
| 563 /** | 556 /** |
| 564 * See |updateDisabledState_| above. | 557 * See |updateDisabledState| above. |
| 565 */ | 558 */ |
| 566 setDisabled: function(reason, disabled) { | 559 setDisabled: function(reason, disabled) { |
| 567 updateDisabledState_(this, reason, disabled); | 560 updateDisabledState(this, reason, disabled); |
| 568 }, | 561 }, |
| 569 }; | 562 }; |
| 570 | 563 |
| 571 /** | 564 /** |
| 572 * The name of the associated preference. | 565 * The name of the associated preference. |
| 573 */ | 566 */ |
| 574 cr.defineProperty(PrefButton, 'pref', cr.PropertyKind.ATTR); | 567 cr.defineProperty(PrefButton, 'pref', cr.PropertyKind.ATTR); |
| 575 | 568 |
| 576 /** | 569 /** |
| 577 * Whether the associated preference is controlled by a source other than the | 570 * Whether the associated preference is controlled by a source other than the |
| 578 * user's setting (can be 'policy', 'extension', 'recommended' or unset). | 571 * user's setting (can be 'policy', 'extension', 'recommended' or unset). |
| 579 */ | 572 */ |
| 580 cr.defineProperty(PrefButton, 'controlledBy', cr.PropertyKind.ATTR); | 573 cr.defineProperty(PrefButton, 'controlledBy', cr.PropertyKind.ATTR); |
| 581 | 574 |
| 582 // Export | 575 // Export |
| 583 return { | 576 return { |
| 584 PrefCheckbox: PrefCheckbox, | 577 PrefCheckbox: PrefCheckbox, |
| 585 PrefInputElement: PrefInputElement, | 578 PrefInputElement: PrefInputElement, |
| 586 PrefNumber: PrefNumber, | 579 PrefNumber: PrefNumber, |
| 587 PrefRadio: PrefRadio, | 580 PrefRadio: PrefRadio, |
| 588 PrefRange: PrefRange, | 581 PrefRange: PrefRange, |
| 589 PrefSelect: PrefSelect, | 582 PrefSelect: PrefSelect, |
| 590 PrefTextField: PrefTextField, | 583 PrefTextField: PrefTextField, |
| 591 PrefPortNumber: PrefPortNumber, | 584 PrefPortNumber: PrefPortNumber, |
| 592 PrefButton: PrefButton | 585 PrefButton: PrefButton |
| 593 }; | 586 }; |
| 594 | |
| 595 }); | 587 }); |
| OLD | NEW |