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 16 matching lines...) Expand all Loading... |
27 * Encapsulated handling of the 'Display' page. | 27 * Encapsulated handling of the 'Display' page. |
28 * @constructor | 28 * @constructor |
29 */ | 29 */ |
30 function DisplayOptions() { | 30 function DisplayOptions() { |
31 OptionsPage.call(this, 'display', | 31 OptionsPage.call(this, 'display', |
32 loadTimeData.getString('displayOptionsPageTabTitle'), | 32 loadTimeData.getString('displayOptionsPageTabTitle'), |
33 'display-options-page'); | 33 'display-options-page'); |
34 this.mirroring_ = false; | 34 this.mirroring_ = false; |
35 this.focusedIndex_ = null; | 35 this.focusedIndex_ = null; |
36 this.displays_ = []; | 36 this.displays_ = []; |
| 37 this.visualScale_ = VISUAL_SCALE; |
37 } | 38 } |
38 | 39 |
39 cr.addSingletonGetter(DisplayOptions); | 40 cr.addSingletonGetter(DisplayOptions); |
40 | 41 |
41 DisplayOptions.prototype = { | 42 DisplayOptions.prototype = { |
42 __proto__: OptionsPage.prototype, | 43 __proto__: OptionsPage.prototype, |
43 | 44 |
44 /** | 45 /** |
45 * Initialize the page. | 46 * Initialize the page. |
46 */ | 47 */ |
(...skipping 24 matching lines...) Expand all Loading... |
71 // Offset is calculated from top or left edge. | 72 // Offset is calculated from top or left edge. |
72 var primary = this.displays_[0]; | 73 var primary = this.displays_[0]; |
73 var secondary = this.displays_[1]; | 74 var secondary = this.displays_[1]; |
74 var offset; | 75 var offset; |
75 if (this.layout_ == SecondaryDisplayLayout.LEFT || | 76 if (this.layout_ == SecondaryDisplayLayout.LEFT || |
76 this.layout_ == SecondaryDisplayLayout.RIGHT) { | 77 this.layout_ == SecondaryDisplayLayout.RIGHT) { |
77 offset = secondary.div.offsetTop - primary.div.offsetTop; | 78 offset = secondary.div.offsetTop - primary.div.offsetTop; |
78 } else { | 79 } else { |
79 offset = secondary.div.offsetLeft - primary.div.offsetLeft; | 80 offset = secondary.div.offsetLeft - primary.div.offsetLeft; |
80 } | 81 } |
81 chrome.send('setDisplayLayout', [this.layout_, offset / VISUAL_SCALE]); | 82 chrome.send('setDisplayLayout', |
| 83 [this.layout_, offset / this.visualScale_]); |
82 }, | 84 }, |
83 | 85 |
84 /** | 86 /** |
85 * Mouse move handler for dragging display rectangle. | 87 * Mouse move handler for dragging display rectangle. |
86 * @private | 88 * @private |
87 * @param {Event} e The mouse move event. | 89 * @param {Event} e The mouse move event. |
88 */ | 90 */ |
89 onMouseMove_: function(e) { | 91 onMouseMove_: function(e) { |
90 if (!this.dragging_) | 92 if (!this.dragging_) |
91 return true; | 93 return true; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 layoutMirroringDisplays_: function() { | 314 layoutMirroringDisplays_: function() { |
313 // Offset pixels for secondary display rectangles. | 315 // Offset pixels for secondary display rectangles. |
314 /** @const */ var MIRRORING_OFFSET_PIXELS = 2; | 316 /** @const */ var MIRRORING_OFFSET_PIXELS = 2; |
315 // Always show two displays because there must be two displays when | 317 // Always show two displays because there must be two displays when |
316 // the display_options is enabled. Don't rely on displays_.length because | 318 // the display_options is enabled. Don't rely on displays_.length because |
317 // there is only one display from chrome's perspective in mirror mode. | 319 // there is only one display from chrome's perspective in mirror mode. |
318 /** @const */ var MIN_NUM_DISPLAYS = 2; | 320 /** @const */ var MIN_NUM_DISPLAYS = 2; |
319 /** @const */ var MIRRORING_VERTICAL_MARGIN = 20; | 321 /** @const */ var MIRRORING_VERTICAL_MARGIN = 20; |
320 | 322 |
321 // The width/height should be same as the primary display: | 323 // The width/height should be same as the primary display: |
322 var width = this.displays_[0].width * VISUAL_SCALE; | 324 var width = this.displays_[0].width * this.visualScale_; |
323 var height = this.displays_[0].height * VISUAL_SCALE; | 325 var height = this.displays_[0].height * this.visualScale_; |
324 | 326 |
325 var numDisplays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); | 327 var numDisplays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); |
326 | 328 |
327 var totalWidth = width + numDisplays * MIRRORING_OFFSET_PIXELS; | 329 var totalWidth = width + numDisplays * MIRRORING_OFFSET_PIXELS; |
328 var totalHeight = height + numDisplays * MIRRORING_OFFSET_PIXELS; | 330 var totalHeight = height + numDisplays * MIRRORING_OFFSET_PIXELS; |
329 | 331 |
330 this.displaysView_.style.height = totalHeight + 'px'; | 332 this.displaysView_.style.height = totalHeight + 'px'; |
331 this.displaysView_.classList.add( | 333 this.displaysView_.classList.add( |
332 'display-options-displays-view-mirroring'); | 334 'display-options-displays-view-mirroring'); |
333 | 335 |
(...skipping 14 matching lines...) Expand all Loading... |
348 div.classList.add('display-mirrored'); | 350 div.classList.add('display-mirrored'); |
349 this.displaysView_.appendChild(div); | 351 this.displaysView_.appendChild(div); |
350 } | 352 } |
351 }, | 353 }, |
352 | 354 |
353 /** | 355 /** |
354 * Layouts the display rectangles according to the current layout_. | 356 * Layouts the display rectangles according to the current layout_. |
355 * @private | 357 * @private |
356 */ | 358 */ |
357 layoutDisplays_: function() { | 359 layoutDisplays_: function() { |
358 var totalHeight = 0; | 360 var maxWidth = 0; |
| 361 var maxHeight = 0; |
359 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; | 362 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; |
360 for (var i = 0; i < this.displays_.length; i++) { | 363 for (var i = 0; i < this.displays_.length; i++) { |
361 var display = this.displays_[i]; | 364 var display = this.displays_[i]; |
362 totalHeight += display.height * VISUAL_SCALE; | 365 boundingBox.left = Math.min(boundingBox.left, display.x); |
363 boundingBox.left = Math.min(boundingBox.left, display.x * VISUAL_SCALE); | |
364 boundingBox.right = Math.max( | 366 boundingBox.right = Math.max( |
365 boundingBox.right, (display.x + display.width) * VISUAL_SCALE); | 367 boundingBox.right, display.x + display.width); |
366 boundingBox.top = Math.min(boundingBox.top, display.y * VISUAL_SCALE); | 368 boundingBox.top = Math.min(boundingBox.top, display.y); |
367 boundingBox.bottom = Math.max( | 369 boundingBox.bottom = Math.max( |
368 boundingBox.bottom, (display.y + display.height) * VISUAL_SCALE); | 370 boundingBox.bottom, display.y + display.height); |
| 371 maxWidth = Math.max(maxWidth, display.width); |
| 372 maxHeight = Math.max(maxHeight, display.height); |
369 } | 373 } |
370 | 374 |
| 375 // Make the margin around the bounding box. |
| 376 var areaWidth = boundingBox.right - boundingBox.left + maxWidth; |
| 377 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight; |
| 378 |
| 379 // Calculates the scale by the width since horizontal size is more strict. |
| 380 // TODO(mukai): Adds the check of vertical size in case. |
| 381 this.visualScale_ = Math.min( |
| 382 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth); |
| 383 |
371 // Prepare enough area for thisplays_view by adding the maximum height. | 384 // Prepare enough area for thisplays_view by adding the maximum height. |
372 this.displaysView_.style.height = totalHeight + 'px'; | 385 this.displaysView_.style.height = areaHeight * this.visualScale_ + 'px'; |
| 386 |
| 387 var boundingCenter = { |
| 388 x: (boundingBox.right + boundingBox.left) * this.visualScale_ / 2, |
| 389 y: (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2}; |
373 | 390 |
374 // Centering the bounding box of the display rectangles. | 391 // Centering the bounding box of the display rectangles. |
375 var offset = {x: $('display-options-displays-view').offsetWidth / 2 - | 392 var offset = { |
376 (boundingBox.left + boundingBox.right) / 2, | 393 x: this.displaysView_.offsetWidth / 2 - |
377 y: totalHeight / 2 - | 394 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2, |
378 (boundingBox.top + boundingBox.bottom) / 2}; | 395 y: this.displaysView_.offsetHeight / 2 - |
379 | 396 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2}; |
380 | 397 |
381 for (var i = 0; i < this.displays_.length; i++) { | 398 for (var i = 0; i < this.displays_.length; i++) { |
382 var display = this.displays_[i]; | 399 var display = this.displays_[i]; |
383 var div = document.createElement('div'); | 400 var div = document.createElement('div'); |
384 display.div = div; | 401 display.div = div; |
385 | 402 |
386 div.className = 'displays-display'; | 403 div.className = 'displays-display'; |
387 if (i == this.focusedIndex_) | 404 var borderWidth = 1; |
| 405 if (i == this.focusedIndex_) { |
388 div.classList.add('displays-focused'); | 406 div.classList.add('displays-focused'); |
389 div.style.width = display.width * VISUAL_SCALE + 'px'; | 407 borderWidth = 2; |
390 div.style.height = display.height * VISUAL_SCALE + 'px'; | 408 } |
| 409 div.style.width = |
| 410 display.width * this.visualScale_ - borderWidth * 2 + 'px'; |
| 411 div.style.height = |
| 412 display.height * this.visualScale_ - borderWidth * 2 + 'px'; |
391 div.style.lineHeight = div.style.height; | 413 div.style.lineHeight = div.style.height; |
392 if (i == 0) { | 414 if (i == 0) { |
393 // Assumes that first display is primary and put a grey rectangle to | 415 // Assumes that first display is primary and put a grey rectangle to |
394 // denote launcher below. | 416 // denote launcher below. |
395 var launcher = document.createElement('div'); | 417 var launcher = document.createElement('div'); |
396 launcher.id = 'display-launcher'; | 418 launcher.id = 'display-launcher'; |
397 launcher.style.width = display.div.style.width; | 419 launcher.style.width = display.div.style.width; |
398 div.appendChild(launcher); | 420 div.appendChild(launcher); |
399 } | 421 } |
400 div.style.left = display.x * VISUAL_SCALE + offset.x + 'px'; | 422 div.style.left = display.x * this.visualScale_ + offset.x + 'px'; |
401 div.style.top = display.y * VISUAL_SCALE + offset.y + 'px'; | 423 div.style.top = display.y * this.visualScale_ + offset.y + 'px'; |
402 | |
403 div.appendChild(document.createTextNode(display.name)); | 424 div.appendChild(document.createTextNode(display.name)); |
404 | 425 |
405 this.displaysView_.appendChild(div); | 426 this.displaysView_.appendChild(div); |
406 } | 427 } |
407 }, | 428 }, |
408 | 429 |
409 /** | 430 /** |
410 * Called when the display arrangement has changed. | 431 * Called when the display arrangement has changed. |
411 * @private | 432 * @private |
412 * @param {boolean} mirroring Whether current mode is mirroring or not. | 433 * @param {boolean} mirroring Whether current mode is mirroring or not. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 mirroring, displays, layout, offset) { | 466 mirroring, displays, layout, offset) { |
446 DisplayOptions.getInstance().onDisplayChanged_( | 467 DisplayOptions.getInstance().onDisplayChanged_( |
447 mirroring, displays, layout, offset); | 468 mirroring, displays, layout, offset); |
448 }; | 469 }; |
449 | 470 |
450 // Export | 471 // Export |
451 return { | 472 return { |
452 DisplayOptions: DisplayOptions | 473 DisplayOptions: DisplayOptions |
453 }; | 474 }; |
454 }); | 475 }); |
OLD | NEW |