| OLD | NEW |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 /** @private */ | 151 /** @private */ |
| 152 selectedDisplayChanged_: function() { | 152 selectedDisplayChanged_: function() { |
| 153 // Set maxModeIndex first so that the slider updates correctly. | 153 // Set maxModeIndex first so that the slider updates correctly. |
| 154 if (this.selectedDisplay.modes.length == 0) { | 154 if (this.selectedDisplay.modes.length == 0) { |
| 155 this.maxModeIndex_ = 0; | 155 this.maxModeIndex_ = 0; |
| 156 this.selectedModeIndex_ = 0; | 156 this.selectedModeIndex_ = 0; |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 this.maxModeIndex_ = this.selectedDisplay.modes.length - 1; | 159 this.maxModeIndex_ = this.selectedDisplay.modes.length - 1; |
| 160 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); | 160 this.selectedModeIndex_ = this.getSelectedModeIndex_(this.selectedDisplay); |
| 161 this.immediateSelectedModeIndex_ = this.selectedModeIndex_; |
| 161 }, | 162 }, |
| 162 | 163 |
| 163 /** | 164 /** |
| 164 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays | 165 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays |
| 165 * @return {boolean} | 166 * @return {boolean} |
| 166 * @private | 167 * @private |
| 167 */ | 168 */ |
| 168 showDisplayTabMenu_: function(displays) { | 169 showDisplayTabMenu_: function(displays) { |
| 169 return displays.length > 1; | 170 return displays.length > 1; |
| 170 }, | 171 }, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 /** | 237 /** |
| 237 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay | 238 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay |
| 238 * @return {boolean} | 239 * @return {boolean} |
| 239 * @private | 240 * @private |
| 240 */ | 241 */ |
| 241 enableSetResolution_: function(selectedDisplay) { | 242 enableSetResolution_: function(selectedDisplay) { |
| 242 return selectedDisplay.modes.length > 1; | 243 return selectedDisplay.modes.length > 1; |
| 243 }, | 244 }, |
| 244 | 245 |
| 245 /** | 246 /** |
| 246 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay | |
| 247 * @param {number} immediateSelectedModeIndex | |
| 248 * @return {string} | 247 * @return {string} |
| 249 * @private | 248 * @private |
| 250 */ | 249 */ |
| 251 getResolutionText_: function(selectedDisplay, immediateSelectedModeIndex) { | 250 getResolutionText_: function() { |
| 252 if (this.selectedDisplay.modes.length == 0) { | 251 if (this.selectedDisplay.modes.length == 0) { |
| 253 var widthStr = selectedDisplay.bounds.width.toString(); | 252 var widthStr = this.selectedDisplay.bounds.width.toString(); |
| 254 var heightStr = selectedDisplay.bounds.height.toString(); | 253 var heightStr = this.selectedDisplay.bounds.height.toString(); |
| 255 return this.i18n('displayResolutionText', widthStr, heightStr); | 254 return this.i18n('displayResolutionText', widthStr, heightStr); |
| 256 } | 255 } |
| 257 if (isNaN(immediateSelectedModeIndex)) | 256 // immediateSelectedModeIndex_ is bound to paper-slider.immediate-value |
| 258 immediateSelectedModeIndex = this.getSelectedModeIndex_(selectedDisplay); | 257 // which may not be valid, or may not have updated yet when this is called. |
| 259 var mode = selectedDisplay.modes[immediateSelectedModeIndex]; | 258 if (isNaN(this.immediateSelectedModeIndex_) || |
| 260 var best = selectedDisplay.isInternal ? mode.uiScale == 1.0 : mode.isNative; | 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; |
| 261 var widthStr = mode.width.toString(); | 266 var widthStr = mode.width.toString(); |
| 262 var heightStr = mode.height.toString(); | 267 var heightStr = mode.height.toString(); |
| 263 if (best) | 268 if (best) |
| 264 return this.i18n('displayResolutionTextBest', widthStr, heightStr); | 269 return this.i18n('displayResolutionTextBest', widthStr, heightStr); |
| 265 else if (mode.isNative) | 270 else if (mode.isNative) |
| 266 return this.i18n('displayResolutionTextNative', widthStr, heightStr); | 271 return this.i18n('displayResolutionTextNative', widthStr, heightStr); |
| 267 return this.i18n('displayResolutionText', widthStr, heightStr); | 272 return this.i18n('displayResolutionText', widthStr, heightStr); |
| 268 }, | 273 }, |
| 269 | 274 |
| 270 /** | 275 /** |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 }, | 398 }, |
| 394 | 399 |
| 395 /** @private */ | 400 /** @private */ |
| 396 setPropertiesCallback_: function() { | 401 setPropertiesCallback_: function() { |
| 397 if (chrome.runtime.lastError) { | 402 if (chrome.runtime.lastError) { |
| 398 console.error( | 403 console.error( |
| 399 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); | 404 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); |
| 400 } | 405 } |
| 401 }, | 406 }, |
| 402 }); | 407 }); |
| OLD | NEW |