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

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

Issue 2587913007: MD Settings: cr-slider: Make display consistent and clean up. (Closed)
Patch Set: Add tiny/huge labels Created 4 years 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */ 47 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */
48 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'}, 48 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'},
49 49
50 /** Id passed to the overscan dialog. */ 50 /** Id passed to the overscan dialog. */
51 overscanDisplayId: { 51 overscanDisplayId: {
52 type: String, 52 type: String,
53 notify: true, 53 notify: true,
54 }, 54 },
55 55
56 /** Maximum mode index value for slider. */ 56 /** @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
57 maxModeIndex_: {type: Number, value: 0}, 57 modeValues_: Array,
58 58
59 /** Selected mode index value for slider. */ 59 /** @private Selected mode index value for slider. */
60 selectedModeIndex_: {type: Number}, 60 selectedModeIndex_: Number,
61 61
62 /** Immediate selected mode index value for slider. */ 62 /** @private Selected mode index received from chrome. */
63 immediateSelectedModeIndex_: {type: Number, value: 0} 63 currentSelectedModeIndex_: Number,
64 }, 64 },
65 65
66 /** 66 /**
67 * Listener for chrome.system.display.onDisplayChanged events. 67 * Listener for chrome.system.display.onDisplayChanged events.
68 * @type {function(void)|undefined} 68 * @type {function(void)|undefined}
69 * @private 69 * @private
70 */ 70 */
71 displayChangedListener_: undefined, 71 displayChangedListener_: undefined,
72 72
73 /** @override */ 73 /** @override */
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 getSelectedModeIndex_: function(selectedDisplay) { 143 getSelectedModeIndex_: function(selectedDisplay) {
144 for (var i = 0; i < selectedDisplay.modes.length; ++i) { 144 for (var i = 0; i < selectedDisplay.modes.length; ++i) {
145 if (selectedDisplay.modes[i].isSelected) 145 if (selectedDisplay.modes[i].isSelected)
146 return i; 146 return i;
147 } 147 }
148 return 0; 148 return 0;
149 }, 149 },
150 150
151 /** @private */ 151 /** @private */
152 selectedDisplayChanged_: function() { 152 selectedDisplayChanged_: function() {
153 // Set maxModeIndex first so that the slider updates correctly. 153 // Set |modeValues_| before |selectedModeIndex_| so that the slider updates
154 if (this.selectedDisplay.modes.length == 0) { 154 // correctly.
155 this.maxModeIndex_ = 0; 155 let numModes = this.selectedDisplay.modes.length;
156 if (numModes == 0) {
157 this.modeValues_ = [];
156 this.selectedModeIndex_ = 0; 158 this.selectedModeIndex_ = 0;
157 return; 159 return;
158 } 160 }
159 this.maxModeIndex_ = this.selectedDisplay.modes.length - 1; 161 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
160 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); 162 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay);
161 this.immediateSelectedModeIndex_ = this.selectedModeIndex_;
162 }, 163 },
163 164
164 /** 165 /**
165 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays 166 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays
166 * @return {boolean} 167 * @return {boolean}
167 * @private 168 * @private
168 */ 169 */
169 showDisplayTabMenu_: function(displays) { 170 showDisplayTabMenu_: function(displays) {
170 return displays.length > 1; 171 return displays.length > 1;
171 }, 172 },
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 enableSetResolution_: function(selectedDisplay) { 243 enableSetResolution_: function(selectedDisplay) {
243 return selectedDisplay.modes.length > 1; 244 return selectedDisplay.modes.length > 1;
244 }, 245 },
245 246
246 /** 247 /**
247 * @return {string} 248 * @return {string}
248 * @private 249 * @private
249 */ 250 */
250 getResolutionText_: function() { 251 getResolutionText_: function() {
251 if (this.selectedDisplay.modes.length == 0) { 252 if (this.selectedDisplay.modes.length == 0) {
252 var widthStr = this.selectedDisplay.bounds.width.toString(); 253 let widthStr = this.selectedDisplay.bounds.width.toString();
253 var heightStr = this.selectedDisplay.bounds.height.toString(); 254 let heightStr = this.selectedDisplay.bounds.height.toString();
254 return this.i18n('displayResolutionText', widthStr, heightStr); 255 return this.i18n('displayResolutionText', widthStr, heightStr);
255 } 256 }
256 // immediateSelectedModeIndex_ is bound to paper-slider.immediate-value 257 let mode = this.selectedDisplay.modes[this.selectedModeIndex_];
257 // which may not be valid, or may not have updated yet when this is called. 258 let best =
258 if (isNaN(this.immediateSelectedModeIndex_) ||
259 this.immediateSelectedModeIndex_ >= this.selectedDisplay.modes.length) {
260 this.immediateSelectedModeIndex_ =
261 this.getSelectedModeIndex_(this.selectedDisplay);
262 }
263 var mode = this.selectedDisplay.modes[this.immediateSelectedModeIndex_];
264 var best =
265 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; 259 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative;
266 var widthStr = mode.width.toString(); 260 let widthStr = mode.width.toString();
267 var heightStr = mode.height.toString(); 261 let heightStr = mode.height.toString();
268 if (best) 262 if (best)
269 return this.i18n('displayResolutionTextBest', widthStr, heightStr); 263 return this.i18n('displayResolutionTextBest', widthStr, heightStr);
270 else if (mode.isNative) 264 else if (mode.isNative)
271 return this.i18n('displayResolutionTextNative', widthStr, heightStr); 265 return this.i18n('displayResolutionTextNative', widthStr, heightStr);
272 return this.i18n('displayResolutionText', widthStr, heightStr); 266 return this.i18n('displayResolutionText', widthStr, heightStr);
273 }, 267 },
274 268
275 /** 269 /**
276 * @param {!{detail: string}} e |e.detail| is the id of the selected display. 270 * @param {!{detail: string}} e |e.detail| is the id of the selected display.
277 * @private 271 * @private
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 304
311 /** @type {!chrome.system.display.DisplayProperties} */ var properties = { 305 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {
312 isPrimary: true 306 isPrimary: true
313 }; 307 };
314 settings.display.systemDisplayApi.setDisplayProperties( 308 settings.display.systemDisplayApi.setDisplayProperties(
315 this.selectedDisplay.id, properties, 309 this.selectedDisplay.id, properties,
316 this.setPropertiesCallback_.bind(this)); 310 this.setPropertiesCallback_.bind(this));
317 }, 311 },
318 312
319 /** 313 /**
320 * @param {!{target: !PaperSliderElement}} e 314 * Triggered when the 'change' event for the selected mode slider is
315 * triggered. This only occurs when the value is comitted (i.e. not while
316 * the slider is being dragged).
321 * @private 317 * @private
322 */ 318 */
323 onChangeMode_: function(e) { 319 onSelectedModeChange_: function() {
324 var curIndex = this.selectedModeIndex_; 320 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.
325 var newIndex = parseInt(e.target.value, 10); 321 this.currentSelectedModeIndex_ == this.selectedModeIndex_) {
326 if (newIndex == curIndex) 322 // Don't change the selected display mode until we have received an update
323 // from Chrome and the mode differs from the current mode.
327 return; 324 return;
328 assert(newIndex >= 0); 325 }
329 assert(newIndex < this.selectedDisplay.modes.length);
330 /** @type {!chrome.system.display.DisplayProperties} */ var properties = { 326 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {
331 displayMode: this.selectedDisplay.modes[newIndex] 327 displayMode: this.selectedDisplay.modes[this.selectedModeIndex_]
332 }; 328 };
333 settings.display.systemDisplayApi.setDisplayProperties( 329 settings.display.systemDisplayApi.setDisplayProperties(
334 this.selectedDisplay.id, properties, 330 this.selectedDisplay.id, properties,
335 this.setPropertiesCallback_.bind(this)); 331 this.setPropertiesCallback_.bind(this));
336 }, 332 },
337 333
338 /** 334 /**
339 * @param {!Event} event 335 * @param {!Event} event
340 * @private 336 * @private
341 */ 337 */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 displayIds += display.id; 387 displayIds += display.id;
392 if (display.isPrimary && !primaryDisplay) 388 if (display.isPrimary && !primaryDisplay)
393 primaryDisplay = display; 389 primaryDisplay = display;
394 if (this.selectedDisplay && display.id == this.selectedDisplay.id) 390 if (this.selectedDisplay && display.id == this.selectedDisplay.id)
395 selectedDisplay = display; 391 selectedDisplay = display;
396 } 392 }
397 this.displayIds = displayIds; 393 this.displayIds = displayIds;
398 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; 394 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || '';
399 this.selectedDisplay = selectedDisplay || primaryDisplay || 395 this.selectedDisplay = selectedDisplay || primaryDisplay ||
400 (this.displays && this.displays[0]); 396 (this.displays && this.displays[0]);
397 // Save the selected mode index received from Chrome so that we do not
398 // send an unnecessary setDisplayProperties call (which would log an error).
399 this.currentSelectedModeIndex_ =
400 this.getSelectedModeIndex_(this.selectedDisplay);
401
401 this.$.displayLayout.updateDisplays(this.displays, this.layouts); 402 this.$.displayLayout.updateDisplays(this.displays, this.layouts);
402 }, 403 },
403 404
404 /** @private */ 405 /** @private */
405 setPropertiesCallback_: function() { 406 setPropertiesCallback_: function() {
406 if (chrome.runtime.lastError) { 407 if (chrome.runtime.lastError) {
407 console.error( 408 console.error(
408 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); 409 'setDisplayProperties Error: ' + chrome.runtime.lastError.message);
409 } 410 }
410 }, 411 },
411 }); 412 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698