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

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

Issue 2737083002: [MD settings] show icon when slider controlled by something (Closed)
Patch Set: touch up Created 3 years, 9 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
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() {
11 var systemDisplayApi = /** @type {!SystemDisplay} */ (chrome.system.display); 11 var systemDisplayApi = /** @type {!SystemDisplay} */ (chrome.system.display);
12 12
13 return { 13 return {
14 systemDisplayApi: systemDisplayApi, 14 systemDisplayApi: systemDisplayApi,
15 }; 15 };
16 }); 16 });
17 17
18 Polymer({ 18 Polymer({
19 is: 'settings-display', 19 is: 'settings-display',
20 20
21 behaviors: [ 21 behaviors: [
22 I18nBehavior, 22 I18nBehavior,
23 ], 23 ],
24 24
25 properties: { 25 properties: {
26 pref: {
stevenjb 2017/03/07 23:11:48 Given that there are many things being set here, c
dschuyler 2017/03/08 21:50:11 Done.
27 type: Object,
28 value: function() {
29 return {
30 key: 'fakeDisplaySliderPref',
31 type: chrome.settingsPrivate.PrefType.NUMBER,
32 value: 0,
33 };
34 },
35 },
36
26 /** 37 /**
27 * Array of displays. 38 * Array of displays.
28 * @type {!Array<!chrome.system.display.DisplayUnitInfo>} 39 * @type {!Array<!chrome.system.display.DisplayUnitInfo>}
29 */ 40 */
30 displays: Array, 41 displays: Array,
31 42
32 /** 43 /**
33 * Array of display layouts. 44 * Array of display layouts.
34 * @type {!Array<!chrome.system.display.DisplayLayout>} 45 * @type {!Array<!chrome.system.display.DisplayLayout>}
35 */ 46 */
(...skipping 12 matching lines...) Expand all
48 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'}, 59 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'},
49 60
50 /** Id passed to the overscan dialog. */ 61 /** Id passed to the overscan dialog. */
51 overscanDisplayId: { 62 overscanDisplayId: {
52 type: String, 63 type: String,
53 notify: true, 64 notify: true,
54 }, 65 },
55 66
56 /** @private {!Array<number>} Mode index values for slider. */ 67 /** @private {!Array<number>} Mode index values for slider. */
57 modeValues_: Array, 68 modeValues_: Array,
58
59 /** @private Selected mode index value for slider. */
60 selectedModeIndex_: Number,
61 }, 69 },
62 70
63 /** @private {number} Selected mode index received from chrome. */ 71 /** @private {number} Selected mode index received from chrome. */
64 currentSelectedModeIndex_: -1, 72 currentSelectedModeIndex_: -1,
65 73
66 /** 74 /**
67 * Listener for chrome.system.display.onDisplayChanged events. 75 * Listener for chrome.system.display.onDisplayChanged events.
68 * @type {function(void)|undefined} 76 * @type {function(void)|undefined}
69 * @private 77 * @private
70 */ 78 */
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 getSelectedModeIndex_: function(selectedDisplay) { 152 getSelectedModeIndex_: function(selectedDisplay) {
145 for (var i = 0; i < selectedDisplay.modes.length; ++i) { 153 for (var i = 0; i < selectedDisplay.modes.length; ++i) {
146 if (selectedDisplay.modes[i].isSelected) 154 if (selectedDisplay.modes[i].isSelected)
147 return i; 155 return i;
148 } 156 }
149 return 0; 157 return 0;
150 }, 158 },
151 159
152 /** @private */ 160 /** @private */
153 selectedDisplayChanged_: function() { 161 selectedDisplayChanged_: function() {
154 // Set |modeValues_| before |selectedModeIndex_| so that the slider updates 162 // Set |modeValues_| before |pref.value| so that the slider updates
155 // correctly. 163 // correctly.
156 var numModes = this.selectedDisplay.modes.length; 164 var numModes = this.selectedDisplay.modes.length;
157 if (numModes == 0) { 165 if (numModes == 0) {
158 this.modeValues_ = []; 166 this.modeValues_ = [];
159 this.selectedModeIndex_ = 0; 167 this.set('pref.value', 0);
160 this.currentSelectedModeIndex_ = 0; 168 this.currentSelectedModeIndex_ = 0;
161 return; 169 return;
162 } 170 }
163 this.modeValues_ = Array.from(Array(numModes).keys()); 171 this.modeValues_ = Array.from(Array(numModes).keys());
164 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); 172 this.set('pref.value', this.getSelectedModeIndex_(this.selectedDisplay));
165 this.currentSelectedModeIndex_ = this.selectedModeIndex_; 173 this.currentSelectedModeIndex_ = this.pref.value;
166 }, 174 },
167 175
168 /** 176 /**
169 * Returns true if the given display has touch support and is not an internal 177 * Returns true if the given display has touch support and is not an internal
170 * display. If the feature is not enabled via the switch, this will return 178 * display. If the feature is not enabled via the switch, this will return
171 * false. 179 * false.
172 * @param {!chrome.system.display.DisplayUnitInfo} display Display being 180 * @param {!chrome.system.display.DisplayUnitInfo} display Display being
173 * checked for touch support. 181 * checked for touch support.
174 * @return {boolean} 182 * @return {boolean}
175 * @private 183 * @private
(...skipping 21 matching lines...) Expand all
197 */ 205 */
198 showDisplaySelectMenu_: function(displays, selectedDisplay) { 206 showDisplaySelectMenu_: function(displays, selectedDisplay) {
199 return displays.length > 1 && !selectedDisplay.isPrimary; 207 return displays.length > 1 && !selectedDisplay.isPrimary;
200 }, 208 },
201 209
202 /** 210 /**
203 * Returns the select menu index indicating whether the display currently is 211 * Returns the select menu index indicating whether the display currently is
204 * primary or extended. 212 * primary or extended.
205 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay 213 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay
206 * @param {string} primaryDisplayId 214 * @param {string} primaryDisplayId
207 * @return {number} Retruns 0 if the display is primary else returns 1. 215 * @return {number} Returns 0 if the display is primary else returns 1.
208 * @private 216 * @private
209 */ 217 */
210 getDisplaySelectMenuIndex_: function(selectedDisplay, primaryDisplayId) { 218 getDisplaySelectMenuIndex_: function(selectedDisplay, primaryDisplayId) {
211 if (selectedDisplay && selectedDisplay.id == primaryDisplayId) 219 if (selectedDisplay && selectedDisplay.id == primaryDisplayId)
212 return 0; 220 return 0;
213 return 1; 221 return 1;
214 }, 222 },
215 223
216 /** 224 /**
217 * Returns the i18n string for the text to be used for mirroring settings. 225 * Returns the i18n string for the text to be used for mirroring settings.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 }, 270 },
263 271
264 /** 272 /**
265 * @return {string} 273 * @return {string}
266 * @private 274 * @private
267 */ 275 */
268 getResolutionText_: function() { 276 getResolutionText_: function() {
269 if (this.selectedDisplay.modes.length == 0 || 277 if (this.selectedDisplay.modes.length == 0 ||
270 this.currentSelectedModeIndex_ == -1) { 278 this.currentSelectedModeIndex_ == -1) {
271 // If currentSelectedModeIndex_ == -1, selectedDisplay and 279 // If currentSelectedModeIndex_ == -1, selectedDisplay and
272 // selectedModeIndex_ are not in sync. 280 // |pref.value| are not in sync.
273 return this.i18n( 281 return this.i18n(
274 'displayResolutionText', this.selectedDisplay.bounds.width.toString(), 282 'displayResolutionText', this.selectedDisplay.bounds.width.toString(),
275 this.selectedDisplay.bounds.height.toString()); 283 this.selectedDisplay.bounds.height.toString());
276 } 284 }
277 var mode = this.selectedDisplay.modes[this.selectedModeIndex_]; 285 var mode = this.selectedDisplay.modes[this.pref.value];
278 var best = 286 var best =
279 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; 287 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative;
280 var widthStr = mode.width.toString(); 288 var widthStr = mode.width.toString();
281 var heightStr = mode.height.toString(); 289 var heightStr = mode.height.toString();
282 if (best) 290 if (best)
283 return this.i18n('displayResolutionTextBest', widthStr, heightStr); 291 return this.i18n('displayResolutionTextBest', widthStr, heightStr);
284 else if (mode.isNative) 292 else if (mode.isNative)
285 return this.i18n('displayResolutionTextNative', widthStr, heightStr); 293 return this.i18n('displayResolutionTextNative', widthStr, heightStr);
286 return this.i18n('displayResolutionText', widthStr, heightStr); 294 return this.i18n('displayResolutionText', widthStr, heightStr);
287 }, 295 },
288 296
289 /** 297 /**
290 * @param {!{detail: string}} e |e.detail| is the id of the selected display. 298 * @param {!{detail: string}} e |e.detail| is the id of the selected display.
291 * @private 299 * @private
292 */ 300 */
293 onSelectDisplay_: function(e) { 301 onSelectDisplay_: function(e) {
294 var id = e.detail; 302 var id = e.detail;
295 for (var i = 0; i < this.displays.length; ++i) { 303 for (var i = 0; i < this.displays.length; ++i) {
296 var display = this.displays[i]; 304 var display = this.displays[i];
297 if (id != display.id) 305 if (id != display.id)
298 continue; 306 continue;
299 if (this.selectedDisplay != display) { 307 if (this.selectedDisplay != display) {
300 // Set currentSelectedModeIndex_ to -1 so that getResolutionText_ does 308 // Set currentSelectedModeIndex_ to -1 so that getResolutionText_ does
301 // not flicker. selectedDisplayChanged will update selectedModeIndex_ 309 // not flicker. selectedDisplayChanged will update |pref.value|
302 // and currentSelectedModeIndex_ correctly. 310 // and currentSelectedModeIndex_ correctly.
303 this.currentSelectedModeIndex_ = -1; 311 this.currentSelectedModeIndex_ = -1;
304 this.selectedDisplay = display; 312 this.selectedDisplay = display;
305 } 313 }
306 } 314 }
307 }, 315 },
308 316
309 /** 317 /**
310 * Handles event when a display tab is selected. 318 * Handles event when a display tab is selected.
311 * @param {!{detail: !{item: !{displayId: string}}}} e 319 * @param {!{detail: !{item: !{displayId: string}}}} e
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 }, 356 },
349 357
350 /** 358 /**
351 * Triggered when the 'change' event for the selected mode slider is 359 * Triggered when the 'change' event for the selected mode slider is
352 * triggered. This only occurs when the value is comitted (i.e. not while 360 * triggered. This only occurs when the value is comitted (i.e. not while
353 * the slider is being dragged). 361 * the slider is being dragged).
354 * @private 362 * @private
355 */ 363 */
356 onSelectedModeChange_: function() { 364 onSelectedModeChange_: function() {
357 if (this.currentSelectedModeIndex_ == -1 || 365 if (this.currentSelectedModeIndex_ == -1 ||
358 this.currentSelectedModeIndex_ == this.selectedModeIndex_) { 366 this.currentSelectedModeIndex_ == this.pref.value) {
359 // Don't change the selected display mode until we have received an update 367 // Don't change the selected display mode until we have received an update
360 // from Chrome and the mode differs from the current mode. 368 // from Chrome and the mode differs from the current mode.
361 return; 369 return;
362 } 370 }
363 /** @type {!chrome.system.display.DisplayProperties} */ var properties = { 371 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {
364 displayMode: this.selectedDisplay.modes[this.selectedModeIndex_] 372 displayMode: this.selectedDisplay.modes[this.pref.value]
365 }; 373 };
366 settings.display.systemDisplayApi.setDisplayProperties( 374 settings.display.systemDisplayApi.setDisplayProperties(
367 this.selectedDisplay.id, properties, 375 this.selectedDisplay.id, properties,
368 this.setPropertiesCallback_.bind(this)); 376 this.setPropertiesCallback_.bind(this));
369 }, 377 },
370 378
371 /** 379 /**
372 * @param {!Event} event 380 * @param {!Event} event
373 * @private 381 * @private
374 */ 382 */
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 }, 450 },
443 451
444 /** @private */ 452 /** @private */
445 setPropertiesCallback_: function() { 453 setPropertiesCallback_: function() {
446 if (chrome.runtime.lastError) { 454 if (chrome.runtime.lastError) {
447 console.error( 455 console.error(
448 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); 456 'setDisplayProperties Error: ' + chrome.runtime.lastError.message);
449 } 457 }
450 }, 458 },
451 }); 459 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698