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

Side by Side Diff: chrome/browser/resources/settings/device_page/display.js

Issue 2789183002: MD Settings: Display: Fix update order (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/display_info_provider_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-display' is the settings subpage for display settings. 7 * 'settings-display' is the settings subpage for display settings.
8 */ 8 */
9 9
10 cr.define('settings.display', function() { 10 cr.define('settings.display', function() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 /** 53 /**
54 * String listing the ids in displays. Used to observe changes to the 54 * String listing the ids in displays. Used to observe changes to the
55 * display configuration (i.e. when a display is added or removed). 55 * display configuration (i.e. when a display is added or removed).
56 */ 56 */
57 displayIds: {type: String, observer: 'onDisplayIdsChanged_'}, 57 displayIds: {type: String, observer: 'onDisplayIdsChanged_'},
58 58
59 /** Primary display id */ 59 /** Primary display id */
60 primaryDisplayId: String, 60 primaryDisplayId: String,
61 61
62 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */ 62 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */
63 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'}, 63 selectedDisplay: Object,
64 64
65 /** Id passed to the overscan dialog. */ 65 /** Id passed to the overscan dialog. */
66 overscanDisplayId: { 66 overscanDisplayId: {
67 type: String, 67 type: String,
68 notify: true, 68 notify: true,
69 }, 69 },
70 70
71 /** @private {!Array<number>} Mode index values for slider. */ 71 /** @private {!Array<number>} Mode index values for slider. */
72 modeValues_: Array, 72 modeValues_: Array,
73 }, 73 },
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 * @private 154 * @private
155 */ 155 */
156 getSelectedModeIndex_: function(selectedDisplay) { 156 getSelectedModeIndex_: function(selectedDisplay) {
157 for (var i = 0; i < selectedDisplay.modes.length; ++i) { 157 for (var i = 0; i < selectedDisplay.modes.length; ++i) {
158 if (selectedDisplay.modes[i].isSelected) 158 if (selectedDisplay.modes[i].isSelected)
159 return i; 159 return i;
160 } 160 }
161 return 0; 161 return 0;
162 }, 162 },
163 163
164 /** @private */ 164 /**
165 selectedDisplayChanged_: function() { 165 * We need to call this explicitly rather than relying on change events
166 // Set |modeValues_| before |selectedModePref_.value| so that the slider 166 * so that we can control the update order.
167 // updates correctly. 167 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay
168 var numModes = this.selectedDisplay.modes.length; 168 * @private
169 */
170 setSelectedDisplay_: function(selectedDisplay) {
171 // Set |currentSelectedModeIndex_| and |modeValues_| first since these
172 // are not used directly in data binding.
173 var numModes = selectedDisplay.modes.length;
169 if (numModes == 0) { 174 if (numModes == 0) {
170 this.modeValues_ = []; 175 this.modeValues_ = [];
171 this.set('selectedModePref_.value', 0);
172 this.currentSelectedModeIndex_ = 0; 176 this.currentSelectedModeIndex_ = 0;
173 return; 177 } else {
178 this.modeValues_ = Array.from(Array(numModes).keys());
179 this.currentSelectedModeIndex_ = this.getSelectedModeIndex_(
180 selectedDisplay);
174 } 181 }
175 this.modeValues_ = Array.from(Array(numModes).keys()); 182 // Set |selectedDisplay| first since only the resolution slider depends
176 this.set('selectedModePref_.value', this.getSelectedModeIndex_( 183 // on |selectedModePref_|.
177 this.selectedDisplay)); 184 this.selectedDisplay = selectedDisplay;
178 this.currentSelectedModeIndex_ = 185 this.set('selectedModePref_.value', this.currentSelectedModeIndex_);
179 /** @type {number} */ (this.selectedModePref_.value);
180 }, 186 },
181 187
182 /** 188 /**
183 * Returns true if the given display has touch support and is not an internal 189 * Returns true if the given display has touch support and is not an internal
184 * display. If the feature is not enabled via the switch, this will return 190 * display. If the feature is not enabled via the switch, this will return
185 * false. 191 * false.
186 * @param {!chrome.system.display.DisplayUnitInfo} display Display being 192 * @param {!chrome.system.display.DisplayUnitInfo} display Display being
187 * checked for touch support. 193 * checked for touch support.
188 * @return {boolean} 194 * @return {boolean}
189 * @private 195 * @private
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (this.selectedDisplay.modes.length == 0 || 289 if (this.selectedDisplay.modes.length == 0 ||
284 this.currentSelectedModeIndex_ == -1) { 290 this.currentSelectedModeIndex_ == -1) {
285 // If currentSelectedModeIndex_ == -1, selectedDisplay and 291 // If currentSelectedModeIndex_ == -1, selectedDisplay and
286 // |selectedModePref_.value| are not in sync. 292 // |selectedModePref_.value| are not in sync.
287 return this.i18n( 293 return this.i18n(
288 'displayResolutionText', this.selectedDisplay.bounds.width.toString(), 294 'displayResolutionText', this.selectedDisplay.bounds.width.toString(),
289 this.selectedDisplay.bounds.height.toString()); 295 this.selectedDisplay.bounds.height.toString());
290 } 296 }
291 var mode = this.selectedDisplay.modes[ 297 var mode = this.selectedDisplay.modes[
292 /** @type {number} */(this.selectedModePref_.value)]; 298 /** @type {number} */(this.selectedModePref_.value)];
299 assert(mode);
293 var best = 300 var best =
294 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; 301 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative;
295 var widthStr = mode.width.toString(); 302 var widthStr = mode.width.toString();
296 var heightStr = mode.height.toString(); 303 var heightStr = mode.height.toString();
297 if (best) 304 if (best)
298 return this.i18n('displayResolutionTextBest', widthStr, heightStr); 305 return this.i18n('displayResolutionTextBest', widthStr, heightStr);
299 else if (mode.isNative) 306 else if (mode.isNative)
300 return this.i18n('displayResolutionTextNative', widthStr, heightStr); 307 return this.i18n('displayResolutionTextNative', widthStr, heightStr);
301 return this.i18n('displayResolutionText', widthStr, heightStr); 308 return this.i18n('displayResolutionText', widthStr, heightStr);
302 }, 309 },
303 310
304 /** 311 /**
305 * @param {!{detail: string}} e |e.detail| is the id of the selected display. 312 * @param {!{detail: string}} e |e.detail| is the id of the selected display.
306 * @private 313 * @private
307 */ 314 */
308 onSelectDisplay_: function(e) { 315 onSelectDisplay_: function(e) {
309 var id = e.detail; 316 var id = e.detail;
310 for (var i = 0; i < this.displays.length; ++i) { 317 for (var i = 0; i < this.displays.length; ++i) {
311 var display = this.displays[i]; 318 var display = this.displays[i];
312 if (id != display.id) 319 if (id == display.id) {
313 continue; 320 if (this.selectedDisplay != display)
314 if (this.selectedDisplay != display) { 321 this.setSelectedDisplay_(display);
315 // Set currentSelectedModeIndex_ to -1 so that getResolutionText_ does 322 return;
316 // not flicker. selectedDisplayChanged will update
317 // |selectedModePref_.value| and currentSelectedModeIndex_ correctly.
318 this.currentSelectedModeIndex_ = -1;
319 this.selectedDisplay = display;
320 } 323 }
321 } 324 }
322 }, 325 },
323 326
324 /** 327 /**
325 * Handles event when a display tab is selected. 328 * Handles event when a display tab is selected.
326 * @param {!{detail: !{item: !{displayId: string}}}} e 329 * @param {!{detail: !{item: !{displayId: string}}}} e
327 * @private 330 * @private
328 */ 331 */
329 onSelectDisplayTab_: function(e) { 332 onSelectDisplayTab_: function(e) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 if (displayIds) 443 if (displayIds)
441 displayIds += ','; 444 displayIds += ',';
442 displayIds += display.id; 445 displayIds += display.id;
443 if (display.isPrimary && !primaryDisplay) 446 if (display.isPrimary && !primaryDisplay)
444 primaryDisplay = display; 447 primaryDisplay = display;
445 if (this.selectedDisplay && display.id == this.selectedDisplay.id) 448 if (this.selectedDisplay && display.id == this.selectedDisplay.id)
446 selectedDisplay = display; 449 selectedDisplay = display;
447 } 450 }
448 this.displayIds = displayIds; 451 this.displayIds = displayIds;
449 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; 452 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || '';
450 this.selectedDisplay = selectedDisplay || primaryDisplay || 453 selectedDisplay = selectedDisplay || primaryDisplay ||
451 (this.displays && this.displays[0]); 454 (this.displays && this.displays[0]);
452 // Save the selected mode index received from Chrome so that we do not 455 this.setSelectedDisplay_(selectedDisplay);
453 // send an unnecessary setDisplayProperties call (which would log an error).
454 this.currentSelectedModeIndex_ =
455 this.getSelectedModeIndex_(this.selectedDisplay);
456 456
457 this.$.displayLayout.updateDisplays(this.displays, this.layouts); 457 this.$.displayLayout.updateDisplays(this.displays, this.layouts);
458 }, 458 },
459 459
460 /** @private */ 460 /** @private */
461 setPropertiesCallback_: function() { 461 setPropertiesCallback_: function() {
462 if (chrome.runtime.lastError) { 462 if (chrome.runtime.lastError) {
463 console.error( 463 console.error(
464 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); 464 'setDisplayProperties Error: ' + chrome.runtime.lastError.message);
465 } 465 }
466 }, 466 },
467 }); 467 });
OLDNEW
« no previous file with comments | « chrome/browser/extensions/display_info_provider_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698