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

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

Powered by Google App Engine
This is Rietveld 408576698