Commit 659682ad authored by David Tseng's avatar David Tseng Committed by Commit Bot

Refine display_size_slider behavior when prefs change

This change observes pref changes and triggers dynamic slider updates.

Since a caller setting prefs is not aware of tick markings, we also make the slider resolve updates to round to the tick to the right of the value.

Change-Id: I8a02ae2c18541a880596d6aefba117ff54234a4e
Reviewed-on: https://chromium-review.googlesource.com/1159400
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580340}
parent 5b9c975e
...@@ -128,6 +128,16 @@ Polymer({ ...@@ -128,6 +128,16 @@ Polymer({
'pageup end': 'resetToMaxIndex_', 'pageup end': 'resetToMaxIndex_',
}, },
/** @override */
ready: function() {
chrome.settingsPrivate.onPrefsChanged.addListener((prefs) => {
prefs.forEach((pref) => {
if (pref.key == this.pref.key && this.pref.value != pref.value)
this.pref.value = pref.value;
});
});
},
/** @private {boolean} */ /** @private {boolean} */
usedMouse_: false, usedMouse_: false,
...@@ -469,18 +479,20 @@ Polymer({ ...@@ -469,18 +479,20 @@ Polymer({
updateIndex_: function() { updateIndex_: function() {
if (!this.ticks || this.ticks.length == 0) if (!this.ticks || this.ticks.length == 0)
return; return;
if (!this.pref) if (!this.pref || typeof(this.pref.value) != 'number')
return; return;
let resolvedTick = this.ticks.length - 1;
for (let i = 0; i < this.ticks.length; i++) { for (let i = 0; i < this.ticks.length; i++) {
if (this.ticks[i].value == this.pref.value) { if (this.ticks[i].value >= this.pref.value) {
this._setIndex(i); resolvedTick = i;
this.setAttribute( break;
'aria-valuenow',
this.getAriaValueForIndex_(this.ticks, this.index));
this.setAttribute(
'aria-valuetext', this.getLabelForIndex_(this.ticks, this.index));
} }
} }
this._setIndex(resolvedTick);
this.setAttribute(
'aria-valuenow', this.getAriaValueForIndex_(this.ticks, this.index));
this.setAttribute(
'aria-valuetext', this.getLabelForIndex_(this.ticks, this.index));
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment