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

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

Issue 2651483002: MD Settings: Eliminate use of ES6 for Chrome OS (Closed)
Patch Set: Feedback Created 3 years, 11 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() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (selectedDisplay.modes[i].isSelected) 146 if (selectedDisplay.modes[i].isSelected)
147 return i; 147 return i;
148 } 148 }
149 return 0; 149 return 0;
150 }, 150 },
151 151
152 /** @private */ 152 /** @private */
153 selectedDisplayChanged_: function() { 153 selectedDisplayChanged_: function() {
154 // Set |modeValues_| before |selectedModeIndex_| so that the slider updates 154 // Set |modeValues_| before |selectedModeIndex_| so that the slider updates
155 // correctly. 155 // correctly.
156 let numModes = this.selectedDisplay.modes.length; 156 var numModes = this.selectedDisplay.modes.length;
157 if (numModes == 0) { 157 if (numModes == 0) {
158 this.modeValues_ = []; 158 this.modeValues_ = [];
159 this.selectedModeIndex_ = 0; 159 this.selectedModeIndex_ = 0;
160 this.currentSelectedModeIndex_ = 0; 160 this.currentSelectedModeIndex_ = 0;
161 return; 161 return;
162 } 162 }
163 this.modeValues_ = Array.from(Array(numModes).keys()); 163 this.modeValues_ = Array.from(Array(numModes).keys());
164 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); 164 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay);
165 this.currentSelectedModeIndex_ = this.selectedModeIndex_; 165 this.currentSelectedModeIndex_ = this.selectedModeIndex_;
166 }, 166 },
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 /** 264 /**
265 * @return {string} 265 * @return {string}
266 * @private 266 * @private
267 */ 267 */
268 getResolutionText_: function() { 268 getResolutionText_: function() {
269 if (this.selectedDisplay.modes.length == 0 || 269 if (this.selectedDisplay.modes.length == 0 ||
270 this.currentSelectedModeIndex_ == -1) { 270 this.currentSelectedModeIndex_ == -1) {
271 // If currentSelectedModeIndex_ == -1, selectedDisplay and 271 // If currentSelectedModeIndex_ == -1, selectedDisplay and
272 // selectedModeIndex_ are not in sync. 272 // selectedModeIndex_ are not in sync.
273 let widthStr = this.selectedDisplay.bounds.width.toString(); 273 return this.i18n(
274 let heightStr = this.selectedDisplay.bounds.height.toString(); 274 'displayResolutionText', this.selectedDisplay.bounds.width.toString(),
275 return this.i18n('displayResolutionText', widthStr, heightStr); 275 this.selectedDisplay.bounds.height.toString());
276 } 276 }
277 let mode = this.selectedDisplay.modes[this.selectedModeIndex_]; 277 var mode = this.selectedDisplay.modes[this.selectedModeIndex_];
278 let best = 278 var best =
279 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; 279 this.selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative;
280 let widthStr = mode.width.toString(); 280 var widthStr = mode.width.toString();
281 let heightStr = mode.height.toString(); 281 var heightStr = mode.height.toString();
282 if (best) 282 if (best)
283 return this.i18n('displayResolutionTextBest', widthStr, heightStr); 283 return this.i18n('displayResolutionTextBest', widthStr, heightStr);
284 else if (mode.isNative) 284 else if (mode.isNative)
285 return this.i18n('displayResolutionTextNative', widthStr, heightStr); 285 return this.i18n('displayResolutionTextNative', widthStr, heightStr);
286 return this.i18n('displayResolutionText', widthStr, heightStr); 286 return this.i18n('displayResolutionText', widthStr, heightStr);
287 }, 287 },
288 288
289 /** 289 /**
290 * @param {!{detail: string}} e |e.detail| is the id of the selected display. 290 * @param {!{detail: string}} e |e.detail| is the id of the selected display.
291 * @private 291 * @private
292 */ 292 */
293 onSelectDisplay_: function(e) { 293 onSelectDisplay_: function(e) {
294 var id = e.detail; 294 var id = e.detail;
295 for (let display of this.displays) { 295 for (var i = 0; i < this.displays.length; ++i) {
296 var display = this.displays[i];
296 if (id != display.id) 297 if (id != display.id)
297 continue; 298 continue;
298 this.currentSelectedModeIndex_ = -1; 299 this.currentSelectedModeIndex_ = -1;
299 this.selectedDisplay = display; 300 this.selectedDisplay = display;
300 } 301 }
301 }, 302 },
302 303
303 /** 304 /**
304 * Handles event when a display tab is selected. 305 * Handles event when a display tab is selected.
305 * @param {!{detail: !{item: !{displayId: string}}}} e 306 * @param {!{detail: !{item: !{displayId: string}}}} e
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 settings.display.systemDisplayApi.setDisplayProperties( 361 settings.display.systemDisplayApi.setDisplayProperties(
361 this.selectedDisplay.id, properties, 362 this.selectedDisplay.id, properties,
362 this.setPropertiesCallback_.bind(this)); 363 this.setPropertiesCallback_.bind(this));
363 }, 364 },
364 365
365 /** 366 /**
366 * @param {!Event} event 367 * @param {!Event} event
367 * @private 368 * @private
368 */ 369 */
369 onOrientationChange_: function(event) { 370 onOrientationChange_: function(event) {
370 let target = /** @type {!HTMLSelectElement} */ (event.target); 371 var target = /** @type {!HTMLSelectElement} */ (event.target);
371 /** @type {!chrome.system.display.DisplayProperties} */ var properties = { 372 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {
372 rotation: parseInt(target.value, 10) 373 rotation: parseInt(target.value, 10)
373 }; 374 };
374 settings.display.systemDisplayApi.setDisplayProperties( 375 settings.display.systemDisplayApi.setDisplayProperties(
375 this.selectedDisplay.id, properties, 376 this.selectedDisplay.id, properties,
376 this.setPropertiesCallback_.bind(this)); 377 this.setPropertiesCallback_.bind(this));
377 }, 378 },
378 379
379 /** @private */ 380 /** @private */
380 onMirroredTap_: function() { 381 onMirroredTap_: function() {
381 var id = ''; 382 var id = '';
382 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {}; 383 /** @type {!chrome.system.display.DisplayProperties} */ var properties = {};
383 if (this.isMirrored_(this.displays)) { 384 if (this.isMirrored_(this.displays)) {
384 id = this.primaryDisplayId; 385 id = this.primaryDisplayId;
385 properties.mirroringSourceId = ''; 386 properties.mirroringSourceId = '';
386 } else { 387 } else {
387 // Set the mirroringSourceId of the secondary (first non-primary) display. 388 // Set the mirroringSourceId of the secondary (first non-primary) display.
388 for (var display of this.displays) { 389 for (var i = 0; i < this.displays.length; ++i) {
390 var display = this.displays[i];
389 if (display.id != this.primaryDisplayId) { 391 if (display.id != this.primaryDisplayId) {
390 id = display.id; 392 id = display.id;
391 break; 393 break;
392 } 394 }
393 } 395 }
394 properties.mirroringSourceId = this.primaryDisplayId; 396 properties.mirroringSourceId = this.primaryDisplayId;
395 } 397 }
396 settings.display.systemDisplayApi.setDisplayProperties( 398 settings.display.systemDisplayApi.setDisplayProperties(
397 id, properties, this.setPropertiesCallback_.bind(this)); 399 id, properties, this.setPropertiesCallback_.bind(this));
398 }, 400 },
399 401
400 /** 402 /**
401 * @param {!Event} e 403 * @param {!Event} e
402 * @private 404 * @private
403 */ 405 */
404 onOverscanTap_: function(e) { 406 onOverscanTap_: function(e) {
405 e.preventDefault(); 407 e.preventDefault();
406 this.overscanDisplayId = this.selectedDisplay.id; 408 this.overscanDisplayId = this.selectedDisplay.id;
407 this.showOverscanDialog_(true); 409 this.showOverscanDialog_(true);
408 }, 410 },
409 411
410 /** @private */ 412 /** @private */
411 updateDisplayInfo_: function() { 413 updateDisplayInfo_: function() {
412 var displayIds = ''; 414 var displayIds = '';
413 var primaryDisplay = undefined; 415 var primaryDisplay = undefined;
414 var selectedDisplay = undefined; 416 var selectedDisplay = undefined;
415 for (var display of this.displays) { 417 for (var i = 0; i < this.displays.length; ++i) {
418 var display = this.displays[i];
416 if (displayIds) 419 if (displayIds)
417 displayIds += ','; 420 displayIds += ',';
418 displayIds += display.id; 421 displayIds += display.id;
419 if (display.isPrimary && !primaryDisplay) 422 if (display.isPrimary && !primaryDisplay)
420 primaryDisplay = display; 423 primaryDisplay = display;
421 if (this.selectedDisplay && display.id == this.selectedDisplay.id) 424 if (this.selectedDisplay && display.id == this.selectedDisplay.id)
422 selectedDisplay = display; 425 selectedDisplay = display;
423 } 426 }
424 this.displayIds = displayIds; 427 this.displayIds = displayIds;
425 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; 428 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || '';
426 this.selectedDisplay = selectedDisplay || primaryDisplay || 429 this.selectedDisplay = selectedDisplay || primaryDisplay ||
427 (this.displays && this.displays[0]); 430 (this.displays && this.displays[0]);
428 // Save the selected mode index received from Chrome so that we do not 431 // Save the selected mode index received from Chrome so that we do not
429 // send an unnecessary setDisplayProperties call (which would log an error). 432 // send an unnecessary setDisplayProperties call (which would log an error).
430 this.currentSelectedModeIndex_ = 433 this.currentSelectedModeIndex_ =
431 this.getSelectedModeIndex_(this.selectedDisplay); 434 this.getSelectedModeIndex_(this.selectedDisplay);
432 435
433 this.$.displayLayout.updateDisplays(this.displays, this.layouts); 436 this.$.displayLayout.updateDisplays(this.displays, this.layouts);
434 }, 437 },
435 438
436 /** @private */ 439 /** @private */
437 setPropertiesCallback_: function() { 440 setPropertiesCallback_: function() {
438 if (chrome.runtime.lastError) { 441 if (chrome.runtime.lastError) {
439 console.error( 442 console.error(
440 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); 443 'setDisplayProperties Error: ' + chrome.runtime.lastError.message);
441 } 444 }
442 }, 445 },
443 }); 446 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698