Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: chrome/browser/resources/settings/controls/settings_slider.js

Issue 2877173002: Add scale to settings-slider (Closed)
Patch Set: Less code in the |scale| comment. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/controls/settings_slider.js
diff --git a/chrome/browser/resources/settings/controls/settings_slider.js b/chrome/browser/resources/settings/controls/settings_slider.js
index 1d7e2a94372ca4f788a7972bb1dc37e8c08cf372..5c5388af35fafb8bcfb36c16a0a00bde837f321c 100644
--- a/chrome/browser/resources/settings/controls/settings_slider.js
+++ b/chrome/browser/resources/settings/controls/settings_slider.js
@@ -23,6 +23,16 @@ Polymer({
/** @type {!Array<number>} Values corresponding to each tick. */
tickValues: {type: Array, value: []},
+ /**
+ * A scale factor used to support fractional pref values since paper-slider
+ * only supports integers. This is not compatible with |tickValues|,
+ * i.e. if |scale| is not 1 then |tickValues| must be empty.
+ */
+ scale: {
+ type: Number,
+ value: 1,
+ },
+
min: Number,
max: Number,
@@ -58,7 +68,7 @@ Polymer({
if (this.tickValues && this.tickValues.length > 0)
newValue = this.tickValues[sliderValue];
else
- newValue = sliderValue;
+ newValue = sliderValue / this.scale;
this.set('pref.value', newValue);
},
@@ -77,9 +87,11 @@ Polymer({
valueChanged_: function() {
// If |tickValues| is empty, simply set current value to the slider.
if (this.tickValues.length == 0) {
- this.$.slider.value = this.pref.value;
+ this.$.slider.value =
+ /** @type {number} */ (this.pref.value) * this.scale;
return;
}
+ assert(this.scale == 1);
// First update the slider settings if |tickValues| was set.
var numTicks = Math.max(1, this.tickValues.length);

Powered by Google App Engine
This is Rietveld 408576698