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 * | |
9 * @group Chrome Settings Elements | |
10 */ | 8 */ |
11 | 9 |
12 cr.define('settings.display', function() { | 10 cr.define('settings.display', function() { |
13 var systemDisplayApi = /** @type {!SystemDisplay} */ (chrome.system.display); | 11 var systemDisplayApi = /** @type {!SystemDisplay} */ (chrome.system.display); |
14 | 12 |
15 return { | 13 return { |
16 systemDisplayApi: systemDisplayApi, | 14 systemDisplayApi: systemDisplayApi, |
17 }; | 15 }; |
18 }); | 16 }); |
19 | 17 |
20 Polymer({ | 18 Polymer({ |
21 is: 'settings-display', | 19 is: 'settings-display', |
22 | 20 |
23 behaviors: [ | 21 behaviors: [ |
24 I18nBehavior, | 22 I18nBehavior, |
25 ], | 23 ], |
26 | 24 |
27 properties: { | 25 properties: { |
28 /** | 26 /** |
29 * Array of displays. | 27 * Array of displays. |
30 * @type {!Array<!chrome.system.display.DisplayUnitInfo>} | 28 * @type {!Array<!chrome.system.display.DisplayUnitInfo>} |
31 */ | 29 */ |
32 displays: Array, | 30 displays: Array, |
33 | 31 |
34 /** | 32 /** |
| 33 * Array of display layouts. |
| 34 * @type {!Array<!chrome.system.display.DisplayLayout>} |
| 35 */ |
| 36 layouts: Array, |
| 37 |
| 38 /** |
35 * String listing the ids in displays. Used to observe changes to the | 39 * String listing the ids in displays. Used to observe changes to the |
36 * display configuration (i.e. when a display is added or removed). | 40 * display configuration (i.e. when a display is added or removed). |
37 */ | 41 */ |
38 displayIds: {type: String, observer: 'onDisplayIdsChanged_'}, | 42 displayIds: {type: String, observer: 'onDisplayIdsChanged_'}, |
39 | 43 |
40 /** Primary display id */ | 44 /** Primary display id */ |
41 primaryDisplayId: String, | 45 primaryDisplayId: String, |
42 | 46 |
43 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */ | 47 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */ |
44 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'}, | 48 selectedDisplay: {type: Object, observer: 'selectedDisplayChanged_'}, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 /** @private */ | 103 /** @private */ |
100 onDisplayIdsChanged_: function() { | 104 onDisplayIdsChanged_: function() { |
101 // Close any overscan dialog (which will cancel any overscan operation) | 105 // Close any overscan dialog (which will cancel any overscan operation) |
102 // if displayIds changes. | 106 // if displayIds changes. |
103 this.showOverscanDialog_(false); | 107 this.showOverscanDialog_(false); |
104 }, | 108 }, |
105 | 109 |
106 /** @private */ | 110 /** @private */ |
107 getDisplayInfo_: function() { | 111 getDisplayInfo_: function() { |
108 settings.display.systemDisplayApi.getInfo( | 112 settings.display.systemDisplayApi.getInfo( |
109 this.updateDisplayInfo_.bind(this)); | 113 this.displayInfoFetched_.bind(this)); |
110 }, | 114 }, |
111 | 115 |
112 /** | 116 /** |
| 117 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays |
| 118 * @private |
| 119 */ |
| 120 displayInfoFetched_(displays) { |
| 121 if (!displays.length) |
| 122 return; |
| 123 settings.display.systemDisplayApi.getDisplayLayout( |
| 124 this.displayLayoutFetched_.bind(this, displays)); |
| 125 }, |
| 126 |
| 127 /** |
| 128 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays |
| 129 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts |
| 130 * @private |
| 131 */ |
| 132 displayLayoutFetched_(displays, layouts) { |
| 133 this.layouts = layouts; |
| 134 this.displays = displays; |
| 135 this.updateDisplayInfo_(); |
| 136 }, |
| 137 |
| 138 /** |
113 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay | 139 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay |
114 * @return {number} | 140 * @return {number} |
115 * @private | 141 * @private |
116 */ | 142 */ |
117 getSelectedModeIndex_: function(selectedDisplay) { | 143 getSelectedModeIndex_: function(selectedDisplay) { |
118 for (var i = 0; i < selectedDisplay.modes.length; ++i) { | 144 for (var i = 0; i < selectedDisplay.modes.length; ++i) { |
119 if (selectedDisplay.modes[i].isSelected) | 145 if (selectedDisplay.modes[i].isSelected) |
120 return i; | 146 return i; |
121 } | 147 } |
122 return 0; | 148 return 0; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 var widthStr = mode.width.toString(); | 226 var widthStr = mode.width.toString(); |
201 var heightStr = mode.height.toString(); | 227 var heightStr = mode.height.toString(); |
202 if (best) | 228 if (best) |
203 return this.i18n('displayResolutionTextBest', widthStr, heightStr); | 229 return this.i18n('displayResolutionTextBest', widthStr, heightStr); |
204 else if (mode.isNative) | 230 else if (mode.isNative) |
205 return this.i18n('displayResolutionTextNative', widthStr, heightStr); | 231 return this.i18n('displayResolutionTextNative', widthStr, heightStr); |
206 return this.i18n('displayResolutionText', widthStr, heightStr); | 232 return this.i18n('displayResolutionText', widthStr, heightStr); |
207 }, | 233 }, |
208 | 234 |
209 /** | 235 /** |
210 * @param {!{model: !{index: number}, target: !PaperButtonElement}} e | 236 * @param {!{detail: number}} e |
211 * @private | 237 * @private |
212 */ | 238 */ |
213 onSelectDisplayTap_: function(e) { | 239 onSelectDisplay_: function(e) { |
214 this.selectedDisplay = this.displays[e.model.index]; | 240 var index = e.detail; |
| 241 assert(index >= 0); |
| 242 if (index >= this.displays.length) |
| 243 return; |
| 244 this.selectedDisplay = this.displays[e.detail]; |
215 // Force active in case selected display was clicked. | 245 // Force active in case selected display was clicked. |
216 e.target.active = true; | 246 e.target.active = true; |
217 }, | 247 }, |
218 | 248 |
219 /** @private */ | 249 /** @private */ |
220 onMakePrimaryTap_: function() { | 250 onMakePrimaryTap_: function() { |
221 if (!this.selectedDisplay) | 251 if (!this.selectedDisplay) |
222 return; | 252 return; |
223 if (this.selectedDisplay.id == this.primaryDisplayId) | 253 if (this.selectedDisplay.id == this.primaryDisplayId) |
224 return; | 254 return; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 settings.display.systemDisplayApi.setDisplayProperties( | 312 settings.display.systemDisplayApi.setDisplayProperties( |
283 id, properties, this.setPropertiesCallback_.bind(this)); | 313 id, properties, this.setPropertiesCallback_.bind(this)); |
284 }, | 314 }, |
285 | 315 |
286 /** @private */ | 316 /** @private */ |
287 onOverscanTap_: function() { | 317 onOverscanTap_: function() { |
288 this.overscanDisplayId = this.selectedDisplay.id; | 318 this.overscanDisplayId = this.selectedDisplay.id; |
289 this.showOverscanDialog_(true); | 319 this.showOverscanDialog_(true); |
290 }, | 320 }, |
291 | 321 |
292 /** | 322 /** @private */ |
293 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays | 323 updateDisplayInfo_() { |
294 * @private | |
295 */ | |
296 updateDisplayInfo_(displays) { | |
297 this.displays = displays; | |
298 var displayIds = ''; | 324 var displayIds = ''; |
299 var primaryDisplay = undefined; | 325 var primaryDisplay = undefined; |
300 var selectedDisplay = undefined; | 326 var selectedDisplay = undefined; |
301 for (var display of this.displays) { | 327 for (var display of this.displays) { |
302 if (displayIds) | 328 if (displayIds) |
303 displayIds += ','; | 329 displayIds += ','; |
304 displayIds += display.id; | 330 displayIds += display.id; |
305 if (display.isPrimary && !primaryDisplay) | 331 if (display.isPrimary && !primaryDisplay) |
306 primaryDisplay = display; | 332 primaryDisplay = display; |
307 if (this.selectedDisplay && display.id == this.selectedDisplay.id) | 333 if (this.selectedDisplay && display.id == this.selectedDisplay.id) |
308 selectedDisplay = display; | 334 selectedDisplay = display; |
309 } | 335 } |
310 this.displayIds = displayIds; | 336 this.displayIds = displayIds; |
311 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; | 337 this.primaryDisplayId = (primaryDisplay && primaryDisplay.id) || ''; |
312 this.selectedDisplay = selectedDisplay || primaryDisplay || | 338 this.selectedDisplay = selectedDisplay || primaryDisplay || |
313 (this.displays && this.displays[0]); | 339 (this.displays && this.displays[0]); |
| 340 this.$.displayLayout.updateDisplays(this.displays, this.layouts); |
314 }, | 341 }, |
315 | 342 |
316 /** @private */ | 343 /** @private */ |
317 setPropertiesCallback_: function() { | 344 setPropertiesCallback_: function() { |
318 if (chrome.runtime.lastError) { | 345 if (chrome.runtime.lastError) { |
319 console.error( | 346 console.error( |
320 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); | 347 'setDisplayProperties Error: ' + chrome.runtime.lastError.message); |
321 } | 348 } |
322 }, | 349 }, |
323 }); | 350 }); |
OLD | NEW |