OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 | 7 |
8 // The scale ratio of the display rectangle to its original size. | 8 // The scale ratio of the display rectangle to its original size. |
9 /** @const */ var VISUAL_SCALE = 1 / 10; | 9 /** @const */ var VISUAL_SCALE = 1 / 10; |
10 | 10 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 this.displays_view_.onmousedown = this.onMouseDown_.bind(this); | 219 this.displays_view_.onmousedown = this.onMouseDown_.bind(this); |
220 this.displays_view_.onmouseup = this.onMouseUp_.bind(this); | 220 this.displays_view_.onmouseup = this.onMouseUp_.bind(this); |
221 displays_view_host.appendChild(this.displays_view_); | 221 displays_view_host.appendChild(this.displays_view_); |
222 }, | 222 }, |
223 | 223 |
224 /** | 224 /** |
225 * Lays out the display rectangles for mirroring. | 225 * Lays out the display rectangles for mirroring. |
226 * @private | 226 * @private |
227 */ | 227 */ |
228 layoutMirroringDisplays_: function() { | 228 layoutMirroringDisplays_: function() { |
| 229 // Offset pixels for secondary display rectangles. |
| 230 /** @const */ var MIRRORING_OFFSET_PIXELS = 2; |
| 231 // Always show two displays because there must be two displays when |
| 232 // the display_options is enabled. Don't rely on displays_.length because |
| 233 // there is only one display from chrome's perspective in mirror mode. |
| 234 /** @const */ var MIN_NUM_DISPLAYS = 2; |
| 235 |
229 // The width/height should be same as the primary display: | 236 // The width/height should be same as the primary display: |
230 var width = this.displays_[0].width * VISUAL_SCALE; | 237 var width = this.displays_[0].width * VISUAL_SCALE; |
231 var height = this.displays_[0].height * VISUAL_SCALE; | 238 var height = this.displays_[0].height * VISUAL_SCALE; |
232 | 239 |
| 240 var num_displays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); |
| 241 |
233 this.displays_view_.style.height = | 242 this.displays_view_.style.height = |
234 height + this.displays_.length * 2 + 'px'; | 243 height + num_displays * MIRRORING_OFFSET_PIXELS + 'px'; |
235 | 244 |
236 for (var i = 0; i < this.displays_.length; i++) { | 245 for (var i = 0; i < num_displays; i++) { |
237 var div = document.createElement('div'); | 246 var div = document.createElement('div'); |
238 this.displays_[i].div = div; | |
239 div.className = 'displays-display'; | 247 div.className = 'displays-display'; |
240 div.style.top = i * 2 + 'px'; | 248 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; |
241 div.style.left = i * 2 + 'px'; | 249 div.style.left = i * MIRRORING_OFFSET_PIXELS + 'px'; |
242 div.style.width = width + 'px'; | 250 div.style.width = width + 'px'; |
243 div.style.height = height + 'px'; | 251 div.style.height = height + 'px'; |
244 div.style.zIndex = i; | 252 div.style.zIndex = i; |
245 if (i == this.displays_.length - 1) | 253 if (i == num_displays - 1) |
246 div.className += ' displays-primary'; | 254 div.className += ' displays-primary'; |
247 this.displays_view_.appendChild(div); | 255 this.displays_view_.appendChild(div); |
248 } | 256 } |
249 }, | 257 }, |
250 | 258 |
251 /** | 259 /** |
252 * Layouts the display rectangles according to the current layout_. | 260 * Layouts the display rectangles according to the current layout_. |
253 * @private | 261 * @private |
254 */ | 262 */ |
255 layoutDisplays_: function() { | 263 layoutDisplays_: function() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 loadTimeData.getString( | 331 loadTimeData.getString( |
324 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 332 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
325 | 333 |
326 // Focus to the first display next to the primary one when |displays| list | 334 // Focus to the first display next to the primary one when |displays| list |
327 // is updated. | 335 // is updated. |
328 if (this.displays_.length != displays.length) | 336 if (this.displays_.length != displays.length) |
329 this.focused_index_ = 1; | 337 this.focused_index_ = 1; |
330 | 338 |
331 this.displays_ = displays; | 339 this.displays_ = displays; |
332 | 340 |
333 if (this.displays_.length <= 1) | |
334 return; | |
335 | |
336 this.resetDisplaysView_(); | 341 this.resetDisplaysView_(); |
337 if (this.mirroring_) | 342 if (this.mirroring_) |
338 this.layoutMirroringDisplays_(); | 343 this.layoutMirroringDisplays_(); |
339 else | 344 else |
340 this.layoutDisplays_(); | 345 this.layoutDisplays_(); |
341 }, | 346 }, |
342 }; | 347 }; |
343 | 348 |
344 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { | 349 DisplayOptions.setDisplayInfo = function(mirroring, displays, layout) { |
345 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); | 350 DisplayOptions.getInstance().onDisplayChanged_(mirroring, displays, layout); |
346 }; | 351 }; |
347 | 352 |
348 // Export | 353 // Export |
349 return { | 354 return { |
350 DisplayOptions: DisplayOptions | 355 DisplayOptions: DisplayOptions |
351 }; | 356 }; |
352 }); | 357 }); |
OLD | NEW |