| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * settings-slider wraps a paper-slider. It maps the slider's values from a | 7 * settings-slider wraps a paper-slider. It maps the slider's values from a |
| 8 * linear UI range to a range of real values. When |value| does not map exactly | 8 * linear UI range to a range of real values. When |value| does not map exactly |
| 9 * to a tick mark, it interpolates to the nearest tick. | 9 * to a tick mark, it interpolates to the nearest tick. |
| 10 * | 10 * |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 tickValues: {type: Array, value: []}, | 24 tickValues: {type: Array, value: []}, |
| 25 | 25 |
| 26 min: Number, | 26 min: Number, |
| 27 | 27 |
| 28 max: Number, | 28 max: Number, |
| 29 | 29 |
| 30 labelMin: String, | 30 labelMin: String, |
| 31 | 31 |
| 32 labelMax: String, | 32 labelMax: String, |
| 33 | 33 |
| 34 disabled: Boolean, |
| 35 |
| 34 /** @private */ | 36 /** @private */ |
| 35 disableSlider_: { | 37 disableSlider_: { |
| 36 computed: 'computeDisableSlider_(pref.*)', | 38 computed: 'computeDisableSlider_(pref.*, disabled)', |
| 37 type: Boolean, | 39 type: Boolean, |
| 38 }, | 40 }, |
| 39 }, | 41 }, |
| 40 | 42 |
| 41 observers: [ | 43 observers: [ |
| 42 'valueChanged_(pref.*, tickValues.*)', | 44 'valueChanged_(pref.*, tickValues.*)', |
| 43 ], | 45 ], |
| 44 | 46 |
| 45 /** | 47 /** |
| 46 * Sets the |pref.value| property to the value corresponding to the knob | 48 * Sets the |pref.value| property to the value corresponding to the knob |
| 47 * position after a user action. | 49 * position after a user action. |
| 48 * @private | 50 * @private |
| 49 */ | 51 */ |
| 50 onSliderChanged_: function() { | 52 onSliderChanged_: function() { |
| 51 var newValue; | 53 var newValue; |
| 52 if (this.tickValues && this.tickValues.length > 0) | 54 if (this.tickValues && this.tickValues.length > 0) |
| 53 newValue = this.tickValues[this.$.slider.immediateValue]; | 55 newValue = this.tickValues[this.$.slider.immediateValue]; |
| 54 else | 56 else |
| 55 newValue = this.$.slider.immediateValue; | 57 newValue = this.$.slider.immediateValue; |
| 56 | 58 |
| 57 this.set('pref.value', newValue); | 59 this.set('pref.value', newValue); |
| 58 }, | 60 }, |
| 59 | 61 |
| 60 /** @private */ | 62 /** @private */ |
| 61 computeDisableSlider_: function() { | 63 computeDisableSlider_: function() { |
| 62 return this.hasAttribute('disabled') || this.isPrefEnforced(); | 64 return this.disabled || this.isPrefEnforced(); |
| 63 }, | 65 }, |
| 64 | 66 |
| 65 /** | 67 /** |
| 66 * Updates the knob position when |pref.value| changes. If the knob is still | 68 * Updates the knob position when |pref.value| changes. If the knob is still |
| 67 * being dragged, this instead forces |pref.value| back to the current | 69 * being dragged, this instead forces |pref.value| back to the current |
| 68 * position. | 70 * position. |
| 69 * @private | 71 * @private |
| 70 */ | 72 */ |
| 71 valueChanged_: function() { | 73 valueChanged_: function() { |
| 72 // If |tickValues| is empty, simply set current value to the slider. | 74 // If |tickValues| is empty, simply set current value to the slider. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (difference < minDifference) { | 126 if (difference < minDifference) { |
| 125 closestIndex = i; | 127 closestIndex = i; |
| 126 minDifference = difference; | 128 minDifference = difference; |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 | 131 |
| 130 assert(typeof closestIndex != 'undefined'); | 132 assert(typeof closestIndex != 'undefined'); |
| 131 return closestIndex; | 133 return closestIndex; |
| 132 }, | 134 }, |
| 133 }); | 135 }); |
| OLD | NEW |