Index: chrome/browser/resources/settings/device_page/display.js |
diff --git a/chrome/browser/resources/settings/device_page/display.js b/chrome/browser/resources/settings/device_page/display.js |
index 6ad553b9eac1358ff4c46fde61b98a0fd1521a5e..3307314f33bd0e572571682ade4b071b2c99cd34 100644 |
--- a/chrome/browser/resources/settings/device_page/display.js |
+++ b/chrome/browser/resources/settings/device_page/display.js |
@@ -53,14 +53,14 @@ Polymer({ |
notify: true, |
}, |
- /** Maximum mode index value for slider. */ |
- maxModeIndex_: {type: Number, value: 0}, |
+ /** @private {!Array<number>} Mode index values for slider. */ |
dschuyler
2016/12/22 02:36:35
This looks like a departure from the common style,
stevenjb
2016/12/22 02:55:25
It's shorthand, used more commonly when the type i
michaelpg
2016/12/22 07:31:32
We must be searching differently, because I found
|
+ modeValues_: Array, |
- /** Selected mode index value for slider. */ |
- selectedModeIndex_: {type: Number}, |
+ /** @private Selected mode index value for slider. */ |
+ selectedModeIndex_: Number, |
- /** Immediate selected mode index value for slider. */ |
- immediateSelectedModeIndex_: {type: Number, value: 0} |
+ /** @private Selected mode index received from chrome. */ |
+ currentSelectedModeIndex_: Number, |
}, |
/** |
@@ -150,15 +150,16 @@ Polymer({ |
/** @private */ |
selectedDisplayChanged_: function() { |
- // Set maxModeIndex first so that the slider updates correctly. |
- if (this.selectedDisplay.modes.length == 0) { |
- this.maxModeIndex_ = 0; |
+ // Set |modeValues_| before |selectedModeIndex_| so that the slider updates |
+ // correctly. |
+ let numModes = this.selectedDisplay.modes.length; |
+ if (numModes == 0) { |
+ this.modeValues_ = []; |
this.selectedModeIndex_ = 0; |
return; |
} |
- this.maxModeIndex_ = this.selectedDisplay.modes.length - 1; |
+ this.modeValues_ = Array.from(Array(numModes).keys()); |
michaelpg
2016/12/22 07:31:32
I think I have a TODO somewhere to add this to cr-
stevenjb
2016/12/22 20:42:18
You do, and I thought about doing it that way, but
|
this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); |
- this.immediateSelectedModeIndex_ = this.selectedModeIndex_; |
}, |
/** |
@@ -249,22 +250,15 @@ Polymer({ |
*/ |
getResolutionText_: function() { |
if (this.selectedDisplay.modes.length == 0) { |
- var widthStr = this.selectedDisplay.bounds.width.toString(); |
- var heightStr = this.selectedDisplay.bounds.height.toString(); |
+ let widthStr = this.selectedDisplay.bounds.width.toString(); |
+ let heightStr = this.selectedDisplay.bounds.height.toString(); |
return this.i18n('displayResolutionText', widthStr, heightStr); |
} |
- // immediateSelectedModeIndex_ is bound to paper-slider.immediate-value |
- // which may not be valid, or may not have updated yet when this is called. |
- if (isNaN(this.immediateSelectedModeIndex_) || |
- this.immediateSelectedModeIndex_ >= this.selectedDisplay.modes.length) { |
- this.immediateSelectedModeIndex_ = |
- this.getSelectedModeIndex_(this.selectedDisplay); |
- } |
- var mode = this.selectedDisplay.modes[this.immediateSelectedModeIndex_]; |
- var best = |
+ let mode = this.selectedDisplay.modes[this.selectedModeIndex_]; |
+ let best = |
this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; |
- var widthStr = mode.width.toString(); |
- var heightStr = mode.height.toString(); |
+ let widthStr = mode.width.toString(); |
+ let heightStr = mode.height.toString(); |
if (best) |
return this.i18n('displayResolutionTextBest', widthStr, heightStr); |
else if (mode.isNative) |
@@ -317,18 +311,20 @@ Polymer({ |
}, |
/** |
- * @param {!{target: !PaperSliderElement}} e |
+ * Triggered when the 'change' event for the selected mode slider is |
+ * triggered. This only occurs when the value is comitted (i.e. not while |
+ * the slider is being dragged). |
* @private |
*/ |
- onChangeMode_: function(e) { |
- var curIndex = this.selectedModeIndex_; |
- var newIndex = parseInt(e.target.value, 10); |
- if (newIndex == curIndex) |
+ onSelectedModeChange_: function() { |
+ if (this.currentSelectedModeIndex_ === undefined || |
michaelpg
2016/12/22 07:31:32
since we remove the listener in detached(), do we
stevenjb
2016/12/22 20:42:18
That's probably a good idea. Done.
|
+ this.currentSelectedModeIndex_ == this.selectedModeIndex_) { |
+ // Don't change the selected display mode until we have received an update |
+ // from Chrome and the mode differs from the current mode. |
return; |
- assert(newIndex >= 0); |
- assert(newIndex < this.selectedDisplay.modes.length); |
+ } |
/** @type {!chrome.system.display.DisplayProperties} */ var properties = { |
- displayMode: this.selectedDisplay.modes[newIndex] |
+ displayMode: this.selectedDisplay.modes[this.selectedModeIndex_] |
}; |
settings.display.systemDisplayApi.setDisplayProperties( |
this.selectedDisplay.id, properties, |
@@ -398,6 +394,11 @@ Polymer({ |
this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; |
this.selectedDisplay = selectedDisplay || primaryDisplay || |
(this.displays && this.displays[0]); |
+ // Save the selected mode index received from Chrome so that we do not |
+ // send an unnecessary setDisplayProperties call (which would log an error). |
+ this.currentSelectedModeIndex_ = |
+ this.getSelectedModeIndex_(this.selectedDisplay); |
+ |
this.$.displayLayout.updateDisplays(this.displays, this.layouts); |
}, |