Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 162 |
| 163 var container = $('display-options-displays-view-host'); | 163 var container = $('display-options-displays-view-host'); |
| 164 container.onmousemove = this.onMouseMove_.bind(this); | 164 container.onmousemove = this.onMouseMove_.bind(this); |
| 165 window.addEventListener('mouseup', this.endDragging_.bind(this), true); | 165 window.addEventListener('mouseup', this.endDragging_.bind(this), true); |
| 166 container.ontouchmove = this.onTouchMove_.bind(this); | 166 container.ontouchmove = this.onTouchMove_.bind(this); |
| 167 container.ontouchend = this.endDragging_.bind(this); | 167 container.ontouchend = this.endDragging_.bind(this); |
| 168 | 168 |
| 169 $('display-options-set-primary').onclick = (function() { | 169 $('display-options-set-primary').onclick = (function() { |
| 170 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]); | 170 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]); |
| 171 }).bind(this); | 171 }).bind(this); |
| 172 | 172 $('display-options-resolution-selection').onchange = (function(ev) { |
| 173 chrome.send('setUIScale', [this.displays_[this.focusedIndex_].id, | |
| 174 ev.target.value]); | |
| 175 }).bind(this); | |
| 176 $('display-options-orientation-selection').onchange = (function(ev) { | |
| 177 chrome.send('setOrientation', [this.displays_[this.focusedIndex_].id, | |
| 178 ev.target.value]); | |
| 179 }).bind(this); | |
|
xiyuan
2013/05/10 22:29:05
nit: wrapping () around function is not necessary.
Jun Mukai
2013/05/10 23:00:06
Done.
| |
| 173 $('selected-display-start-calibrating-overscan').onclick = (function() { | 180 $('selected-display-start-calibrating-overscan').onclick = (function() { |
| 174 // Passes the target display ID. Do not specify it through URL hash, | 181 // Passes the target display ID. Do not specify it through URL hash, |
| 175 // we do not care back/forward. | 182 // we do not care back/forward. |
| 176 var displayOverscan = options.DisplayOverscan.getInstance(); | 183 var displayOverscan = options.DisplayOverscan.getInstance(); |
| 177 displayOverscan.setDisplayId(this.displays_[this.focusedIndex_].id); | 184 displayOverscan.setDisplayId(this.displays_[this.focusedIndex_].id); |
| 178 OptionsPage.navigateToPage('displayOverscan'); | 185 OptionsPage.navigateToPage('displayOverscan'); |
| 179 }).bind(this); | 186 }).bind(this); |
| 180 | 187 |
| 181 chrome.send('getDisplayInfo'); | 188 chrome.send('getDisplayInfo'); |
| 182 }, | 189 }, |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 } | 465 } |
| 459 | 466 |
| 460 for (var i = 0; i < this.displays_.length; i++) { | 467 for (var i = 0; i < this.displays_.length; i++) { |
| 461 var display = this.displays_[i]; | 468 var display = this.displays_[i]; |
| 462 display.div.className = 'displays-display'; | 469 display.div.className = 'displays-display'; |
| 463 this.resizeDisplayRectangle_(display, i); | 470 this.resizeDisplayRectangle_(display, i); |
| 464 if (i != this.focusedIndex_) | 471 if (i != this.focusedIndex_) |
| 465 continue; | 472 continue; |
| 466 | 473 |
| 467 display.div.classList.add('displays-focused'); | 474 display.div.classList.add('displays-focused'); |
| 468 this.dragging_ = { | 475 if (this.displays_.length > 1) { |
| 469 display: display, | 476 this.dragging_ = { |
| 470 originalLocation: { | 477 display: display, |
| 471 x: display.div.offsetLeft, y: display.div.offsetTop | 478 originalLocation: { |
| 472 }, | 479 x: display.div.offsetLeft, y: display.div.offsetTop |
| 473 eventLocation: eventLocation | 480 }, |
| 474 }; | 481 eventLocation: eventLocation |
| 482 }; | |
| 483 } | |
| 475 } | 484 } |
| 476 | 485 |
| 477 this.updateSelectedDisplayDescription_(); | 486 this.updateSelectedDisplayDescription_(); |
| 478 return false; | 487 return false; |
| 479 }, | 488 }, |
| 480 | 489 |
| 481 /** | 490 /** |
| 482 * finish the current dragging of displays. | 491 * finish the current dragging of displays. |
| 483 * @param {Event} e The event which triggers this. | 492 * @param {Event} e The event which triggers this. |
| 484 * @private | 493 * @private |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 } | 525 } |
| 517 this.updateSelectedDisplayDescription_(); | 526 this.updateSelectedDisplayDescription_(); |
| 518 return false; | 527 return false; |
| 519 }, | 528 }, |
| 520 | 529 |
| 521 /** | 530 /** |
| 522 * Updates the description of the selected display section. | 531 * Updates the description of the selected display section. |
| 523 * @private | 532 * @private |
| 524 */ | 533 */ |
| 525 updateSelectedDisplayDescription_: function() { | 534 updateSelectedDisplayDescription_: function() { |
| 535 var resolution = $('display-options-resolution-selection'); | |
| 536 resolution.innerHTML = ''; | |
|
xiyuan
2013/05/10 22:29:05
nit: resolution.textContent = '';
Avoid using inn
Jun Mukai
2013/05/10 23:00:06
Done.
| |
| 537 var orientation = $('display-options-orientation-selection'); | |
| 538 var orientationOptions = orientation.getElementsByTagName('option'); | |
| 539 for (var i = 0; i < orientationOptions.length; i++) { | |
| 540 orientationOptions.selected = false; | |
| 541 } | |
| 542 | |
| 526 if (this.mirroring_) { | 543 if (this.mirroring_) { |
| 527 $('display-configuration-arrow').hidden = true; | 544 $('display-configuration-arrow').hidden = true; |
| 528 $('display-options-set-primary').hidden = true; | 545 $('display-options-set-primary').disabled = true; |
| 529 $('display-options-toggle-mirroring').hidden = false; | 546 $('display-options-toggle-mirroring').disabled = false; |
| 530 $('selected-display-data-container').hidden = false; | 547 $('selected-display-start-calibrating-overscan').disabled = true; |
| 548 orientation.disabled = true; | |
| 531 var display = this.displays_[0]; | 549 var display = this.displays_[0]; |
| 550 $('selected-display-name').textContent = | |
| 551 loadTimeData.getString('mirroringDisplay'); | |
| 552 resolution.appendChild(document.createElement('option')); | |
| 553 resolution.disabled = true; | |
| 554 } else if (this.focusedIndex_ == null || | |
| 555 this.displays_[this.focusedIndex_] == null) { | |
| 556 $('display-configuration-arrow').hidden = true; | |
| 557 $('display-options-set-primary').disabled = true; | |
| 558 $('display-options-toggle-mirroring').disabled = true; | |
| 559 $('selected-display-start-calibrating-overscan').disabled = true; | |
| 560 orientation.disabled = true; | |
| 532 $('selected-display-name').textContent = ''; | 561 $('selected-display-name').textContent = ''; |
| 533 $('selected-display-resolution').textContent = | 562 resolution.appendChild(document.createElement('option')); |
| 534 display.width + 'x' + display.height; | 563 resolution.disabled = true; |
| 535 return; | 564 } else { |
| 565 var display = this.displays_[this.focusedIndex_]; | |
| 566 | |
| 567 var arrow = $('display-configuration-arrow'); | |
| 568 arrow.hidden = false; | |
| 569 // Adding 1 px to the position to fit the border line and the border in | |
| 570 // arrow precisely. | |
| 571 arrow.style.top = $('display-configurations').offsetTop - | |
| 572 arrow.offsetHeight / 2 + 'px'; | |
| 573 arrow.style.left = display.div.offsetLeft + | |
| 574 display.div.offsetWidth / 2 - arrow.offsetWidth / 2 + 'px'; | |
| 575 | |
| 576 $('display-options-set-primary').disabled = display.isPrimary; | |
| 577 $('display-options-toggle-mirroring').disabled = | |
| 578 (this.displays_.length <= 1); | |
| 579 $('selected-display-start-calibrating-overscan').disabled = | |
| 580 display.isInternal; | |
| 581 | |
| 582 orientation.disabled = false; | |
| 583 orientationOptions[display.orientation].selected = true; | |
| 584 | |
| 585 $('selected-display-name').textContent = display.name; | |
| 586 | |
| 587 if (display.ui_scales.length <= 1) { | |
| 588 var option = document.createElement('option'); | |
| 589 option.value = 'default'; | |
| 590 option.textContent = display.width + 'x' + display.height; | |
| 591 option.selected = true; | |
| 592 resolution.appendChild(option); | |
| 593 resolution.disabled = true; | |
| 594 } else { | |
| 595 for (var i = 0; i < display.ui_scales.length; i++) { | |
| 596 var option = document.createElement('option'); | |
| 597 option.value = display.ui_scales[i].scale; | |
| 598 option.textContent = | |
| 599 display.ui_scales[i].width + 'x' + display.ui_scales[i].height; | |
| 600 option.selected = display.ui_scales[i].selected; | |
| 601 resolution.appendChild(option); | |
| 602 } | |
| 603 resolution.disabled = !display.isInternal; | |
| 604 } | |
| 536 } | 605 } |
| 537 | |
| 538 if (this.focusedIndex_ == null || | |
| 539 this.displays_[this.focusedIndex_] == null) { | |
| 540 $('selected-display-data-container').hidden = true; | |
| 541 $('display-configuration-arrow').hidden = true; | |
| 542 $('display-options-set-primary').hidden = true; | |
| 543 $('display-options-toggle-mirroring').hidden = true; | |
| 544 return; | |
| 545 } | |
| 546 | |
| 547 $('selected-display-data-container').hidden = false; | |
| 548 var display = this.displays_[this.focusedIndex_]; | |
| 549 var nameElement = $('selected-display-name'); | |
| 550 nameElement.textContent = display.name; | |
| 551 | |
| 552 var resolutionElement = $('selected-display-resolution'); | |
| 553 resolutionElement.textContent = display.width + 'x' + display.height; | |
| 554 | |
| 555 $('start-calibrating-overscan-control').hidden = display.isInternal; | |
| 556 | |
| 557 var arrow = $('display-configuration-arrow'); | |
| 558 arrow.hidden = false; | |
| 559 // Adding 1 px to the position to fit the border line and the border in | |
| 560 // arrow precisely. | |
| 561 arrow.style.top = $('display-configurations').offsetTop - | |
| 562 arrow.offsetHeight / 2 + 1 + 'px'; | |
| 563 arrow.style.left = display.div.offsetLeft + display.div.offsetWidth / 2 - | |
| 564 arrow.offsetWidth / 2 + 'px'; | |
| 565 | |
| 566 $('display-options-set-primary').hidden = | |
| 567 this.displays_[this.focusedIndex_].isPrimary; | |
| 568 $('display-options-toggle-mirroring').hidden = | |
| 569 (this.displays_.length <= 1 && !this.mirroring_); | |
| 570 }, | 606 }, |
| 571 | 607 |
| 572 /** | 608 /** |
| 573 * Clears the drawing area for display rectangles. | 609 * Clears the drawing area for display rectangles. |
| 574 * @private | 610 * @private |
| 575 */ | 611 */ |
| 576 resetDisplaysView_: function() { | 612 resetDisplaysView_: function() { |
| 577 var displaysViewHost = $('display-options-displays-view-host'); | 613 var displaysViewHost = $('display-options-displays-view-host'); |
| 578 displaysViewHost.removeChild(displaysViewHost.firstChild); | 614 displaysViewHost.removeChild(displaysViewHost.firstChild); |
| 579 this.displaysView_ = document.createElement('div'); | 615 this.displaysView_ = document.createElement('div'); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 if (!this.visible) | 772 if (!this.visible) |
| 737 return; | 773 return; |
| 738 | 774 |
| 739 var hasExternal = false; | 775 var hasExternal = false; |
| 740 for (var i = 0; i < displays.length; i++) { | 776 for (var i = 0; i < displays.length; i++) { |
| 741 if (!displays[i].isInternal) { | 777 if (!displays[i].isInternal) { |
| 742 hasExternal = true; | 778 hasExternal = true; |
| 743 break; | 779 break; |
| 744 } | 780 } |
| 745 } | 781 } |
| 746 if (!hasExternal && !mirroring) { | |
| 747 OptionsPage.showDefaultPage(); | |
| 748 return; | |
| 749 } | |
| 750 | 782 |
| 751 this.mirroring_ = mirroring; | 783 this.mirroring_ = mirroring; |
| 752 this.layout_ = layout; | 784 this.layout_ = layout; |
| 753 this.offset_ = offset; | 785 this.offset_ = offset; |
| 754 this.dirty_ = false; | 786 this.dirty_ = false; |
| 755 | 787 |
| 756 $('display-options-toggle-mirroring').textContent = | 788 $('display-options-toggle-mirroring').textContent = |
| 757 loadTimeData.getString( | 789 loadTimeData.getString( |
| 758 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 790 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
| 759 | 791 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 780 mirroring, displays, layout, offset) { | 812 mirroring, displays, layout, offset) { |
| 781 DisplayOptions.getInstance().onDisplayChanged_( | 813 DisplayOptions.getInstance().onDisplayChanged_( |
| 782 mirroring, displays, layout, offset); | 814 mirroring, displays, layout, offset); |
| 783 }; | 815 }; |
| 784 | 816 |
| 785 // Export | 817 // Export |
| 786 return { | 818 return { |
| 787 DisplayOptions: DisplayOptions | 819 DisplayOptions: DisplayOptions |
| 788 }; | 820 }; |
| 789 }); | 821 }); |
| OLD | NEW |