| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 * @private | 148 * @private |
| 149 */ | 149 */ |
| 150 lastTouchLocation_: null, | 150 lastTouchLocation_: null, |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * Initialize the page. | 153 * Initialize the page. |
| 154 */ | 154 */ |
| 155 initializePage: function() { | 155 initializePage: function() { |
| 156 OptionsPage.prototype.initializePage.call(this); | 156 OptionsPage.prototype.initializePage.call(this); |
| 157 | 157 |
| 158 $('display-options-toggle-mirroring').onclick = (function() { | 158 $('display-options-toggle-mirroring').onclick = function() { |
| 159 this.mirroring_ = !this.mirroring_; | 159 this.mirroring_ = !this.mirroring_; |
| 160 chrome.send('setMirroring', [this.mirroring_]); | 160 chrome.send('setMirroring', [this.mirroring_]); |
| 161 }).bind(this); | 161 }.bind(this); |
| 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 $('selected-display-start-calibrating-overscan').onclick = (function() { | 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); |
| 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 }, |
| 183 | 190 |
| 184 /** @override */ | 191 /** @override */ |
| 192 didShowPage: function() { |
| 193 var optionTitles = document.getElementsByClassName( |
| 194 'selected-display-option-title'); |
| 195 var maxSize = 0; |
| 196 for (var i = 0; i < optionTitles.length; i++) |
| 197 maxSize = Math.max(maxSize, optionTitles[i].clientWidth); |
| 198 for (var i = 0; i < optionTitles.length; i++) |
| 199 optionTitles[i].style.width = maxSize + 'px'; |
| 200 }, |
| 201 |
| 202 /** @override */ |
| 185 onVisibilityChanged_: function() { | 203 onVisibilityChanged_: function() { |
| 186 OptionsPage.prototype.onVisibilityChanged_(this); | 204 OptionsPage.prototype.onVisibilityChanged_(this); |
| 187 if (this.visible) | 205 if (this.visible) |
| 188 chrome.send('getDisplayInfo'); | 206 chrome.send('getDisplayInfo'); |
| 189 }, | 207 }, |
| 190 | 208 |
| 191 /** | 209 /** |
| 192 * Mouse move handler for dragging display rectangle. | 210 * Mouse move handler for dragging display rectangle. |
| 193 * @param {Event} e The mouse move event. | 211 * @param {Event} e The mouse move event. |
| 194 * @private | 212 * @private |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 476 } |
| 459 | 477 |
| 460 for (var i = 0; i < this.displays_.length; i++) { | 478 for (var i = 0; i < this.displays_.length; i++) { |
| 461 var display = this.displays_[i]; | 479 var display = this.displays_[i]; |
| 462 display.div.className = 'displays-display'; | 480 display.div.className = 'displays-display'; |
| 463 this.resizeDisplayRectangle_(display, i); | 481 this.resizeDisplayRectangle_(display, i); |
| 464 if (i != this.focusedIndex_) | 482 if (i != this.focusedIndex_) |
| 465 continue; | 483 continue; |
| 466 | 484 |
| 467 display.div.classList.add('displays-focused'); | 485 display.div.classList.add('displays-focused'); |
| 468 this.dragging_ = { | 486 if (this.displays_.length > 1) { |
| 469 display: display, | 487 this.dragging_ = { |
| 470 originalLocation: { | 488 display: display, |
| 471 x: display.div.offsetLeft, y: display.div.offsetTop | 489 originalLocation: { |
| 472 }, | 490 x: display.div.offsetLeft, y: display.div.offsetTop |
| 473 eventLocation: eventLocation | 491 }, |
| 474 }; | 492 eventLocation: eventLocation |
| 493 }; |
| 494 } |
| 475 } | 495 } |
| 476 | 496 |
| 477 this.updateSelectedDisplayDescription_(); | 497 this.updateSelectedDisplayDescription_(); |
| 478 return false; | 498 return false; |
| 479 }, | 499 }, |
| 480 | 500 |
| 481 /** | 501 /** |
| 482 * finish the current dragging of displays. | 502 * finish the current dragging of displays. |
| 483 * @param {Event} e The event which triggers this. | 503 * @param {Event} e The event which triggers this. |
| 484 * @private | 504 * @private |
| (...skipping 27 matching lines...) Expand all Loading... |
| 512 if (originalPosition.x != draggingDiv.offsetLeft || | 532 if (originalPosition.x != draggingDiv.offsetLeft || |
| 513 originalPosition.y != draggingDiv.offsetTop) | 533 originalPosition.y != draggingDiv.offsetTop) |
| 514 this.applyResult_(); | 534 this.applyResult_(); |
| 515 this.dragging_ = null; | 535 this.dragging_ = null; |
| 516 } | 536 } |
| 517 this.updateSelectedDisplayDescription_(); | 537 this.updateSelectedDisplayDescription_(); |
| 518 return false; | 538 return false; |
| 519 }, | 539 }, |
| 520 | 540 |
| 521 /** | 541 /** |
| 542 * Updates the description of selected display section for mirroring mode. |
| 543 * @private |
| 544 */ |
| 545 updateSelectedDisplaySectionMirroring_: function() { |
| 546 $('display-configuration-arrow').hidden = true; |
| 547 $('display-options-set-primary').disabled = true; |
| 548 $('display-options-toggle-mirroring').disabled = false; |
| 549 $('selected-display-start-calibrating-overscan').disabled = true; |
| 550 $('display-options-orientation-selection').disabled = true; |
| 551 var display = this.displays_[0]; |
| 552 $('selected-display-name').textContent = |
| 553 loadTimeData.getString('mirroringDisplay'); |
| 554 var resolution = $('display-options-resolution-selection'); |
| 555 resolution.appendChild(document.createElement('option')); |
| 556 resolution.disabled = true; |
| 557 }, |
| 558 |
| 559 /** |
| 560 * Updates the description of selected display section when no display is |
| 561 * selected. |
| 562 * @private |
| 563 */ |
| 564 updateSelectedDisplaySectionNoSelected_: function() { |
| 565 $('display-configuration-arrow').hidden = true; |
| 566 $('display-options-set-primary').disabled = true; |
| 567 $('display-options-toggle-mirroring').disabled = true; |
| 568 $('selected-display-start-calibrating-overscan').disabled = true; |
| 569 $('display-options-orientation-selection').disabled = true; |
| 570 $('selected-display-name').textContent = ''; |
| 571 var resolution = $('display-options-resolution-selection'); |
| 572 resolution.appendChild(document.createElement('option')); |
| 573 resolution.disabled = true; |
| 574 }, |
| 575 |
| 576 /** |
| 577 * Updates the description of selected display section for the selected |
| 578 * display. |
| 579 * @param {Object} display The selected display object. |
| 580 * @private |
| 581 */ |
| 582 updateSelectedDisplaySectionForDisplay_: function(display) { |
| 583 var arrow = $('display-configuration-arrow'); |
| 584 arrow.hidden = false; |
| 585 // Adding 1 px to the position to fit the border line and the border in |
| 586 // arrow precisely. |
| 587 arrow.style.top = $('display-configurations').offsetTop - |
| 588 arrow.offsetHeight / 2 + 'px'; |
| 589 arrow.style.left = display.div.offsetLeft + |
| 590 display.div.offsetWidth / 2 - arrow.offsetWidth / 2 + 'px'; |
| 591 |
| 592 $('display-options-set-primary').disabled = display.isPrimary; |
| 593 $('display-options-toggle-mirroring').disabled = |
| 594 (this.displays_.length <= 1); |
| 595 $('selected-display-start-calibrating-overscan').disabled = |
| 596 display.isInternal; |
| 597 |
| 598 var orientation = $('display-options-orientation-selection'); |
| 599 orientation.disabled = false; |
| 600 var orientationOptions = orientation.getElementsByTagName('option'); |
| 601 orientationOptions[display.orientation].selected = true; |
| 602 |
| 603 $('selected-display-name').textContent = display.name; |
| 604 |
| 605 var resolution = $('display-options-resolution-selection'); |
| 606 if (display.uiScales.length <= 1) { |
| 607 var option = document.createElement('option'); |
| 608 option.value = 'default'; |
| 609 option.textContent = display.width + 'x' + display.height; |
| 610 option.selected = true; |
| 611 resolution.appendChild(option); |
| 612 resolution.disabled = true; |
| 613 } else { |
| 614 for (var i = 0; i < display.uiScales.length; i++) { |
| 615 var option = document.createElement('option'); |
| 616 option.value = display.uiScales[i].scale; |
| 617 option.textContent = |
| 618 display.uiScales[i].width + 'x' + display.uiScales[i].height; |
| 619 if (display.uiScales[i].scale == 1.0) { |
| 620 option.textContent += ' ' + |
| 621 loadTimeData.getString('annotateBest'); |
| 622 } |
| 623 option.selected = display.uiScales[i].selected; |
| 624 resolution.appendChild(option); |
| 625 } |
| 626 resolution.disabled = !display.isInternal; |
| 627 } |
| 628 }, |
| 629 |
| 630 /** |
| 522 * Updates the description of the selected display section. | 631 * Updates the description of the selected display section. |
| 523 * @private | 632 * @private |
| 524 */ | 633 */ |
| 525 updateSelectedDisplayDescription_: function() { | 634 updateSelectedDisplayDescription_: function() { |
| 635 var resolution = $('display-options-resolution-selection'); |
| 636 resolution.textContent = ''; |
| 637 var orientation = $('display-options-orientation-selection'); |
| 638 var orientationOptions = orientation.getElementsByTagName('option'); |
| 639 for (var i = 0; i < orientationOptions.length; i++) |
| 640 orientationOptions.selected = false; |
| 641 |
| 526 if (this.mirroring_) { | 642 if (this.mirroring_) { |
| 527 $('display-configuration-arrow').hidden = true; | 643 this.updateSelectedDisplaySectionMirroring_(); |
| 528 $('display-options-set-primary').hidden = true; | 644 } else if (this.focusedIndex_ == null || |
| 529 $('display-options-toggle-mirroring').hidden = false; | 645 this.displays_[this.focusedIndex_] == null) { |
| 530 $('selected-display-data-container').hidden = false; | 646 this.updateSelectedDisplaySectionNoSelected_(); |
| 531 var display = this.displays_[0]; | 647 } else { |
| 532 $('selected-display-name').textContent = ''; | 648 this.updateSelectedDisplaySectionForDisplay_( |
| 533 $('selected-display-resolution').textContent = | 649 this.displays_[this.focusedIndex_]); |
| 534 display.width + 'x' + display.height; | |
| 535 return; | |
| 536 } | 650 } |
| 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 }, | 651 }, |
| 571 | 652 |
| 572 /** | 653 /** |
| 573 * Clears the drawing area for display rectangles. | 654 * Clears the drawing area for display rectangles. |
| 574 * @private | 655 * @private |
| 575 */ | 656 */ |
| 576 resetDisplaysView_: function() { | 657 resetDisplaysView_: function() { |
| 577 var displaysViewHost = $('display-options-displays-view-host'); | 658 var displaysViewHost = $('display-options-displays-view-host'); |
| 578 displaysViewHost.removeChild(displaysViewHost.firstChild); | 659 displaysViewHost.removeChild(displaysViewHost.firstChild); |
| 579 this.displaysView_ = document.createElement('div'); | 660 this.displaysView_ = document.createElement('div'); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 if (!this.visible) | 817 if (!this.visible) |
| 737 return; | 818 return; |
| 738 | 819 |
| 739 var hasExternal = false; | 820 var hasExternal = false; |
| 740 for (var i = 0; i < displays.length; i++) { | 821 for (var i = 0; i < displays.length; i++) { |
| 741 if (!displays[i].isInternal) { | 822 if (!displays[i].isInternal) { |
| 742 hasExternal = true; | 823 hasExternal = true; |
| 743 break; | 824 break; |
| 744 } | 825 } |
| 745 } | 826 } |
| 746 if (!hasExternal && !mirroring) { | |
| 747 OptionsPage.showDefaultPage(); | |
| 748 return; | |
| 749 } | |
| 750 | 827 |
| 751 this.mirroring_ = mirroring; | 828 this.mirroring_ = mirroring; |
| 752 this.layout_ = layout; | 829 this.layout_ = layout; |
| 753 this.offset_ = offset; | 830 this.offset_ = offset; |
| 754 this.dirty_ = false; | 831 this.dirty_ = false; |
| 755 | 832 |
| 756 $('display-options-toggle-mirroring').textContent = | 833 $('display-options-toggle-mirroring').textContent = |
| 757 loadTimeData.getString( | 834 loadTimeData.getString( |
| 758 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 835 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
| 759 | 836 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 780 mirroring, displays, layout, offset) { | 857 mirroring, displays, layout, offset) { |
| 781 DisplayOptions.getInstance().onDisplayChanged_( | 858 DisplayOptions.getInstance().onDisplayChanged_( |
| 782 mirroring, displays, layout, offset); | 859 mirroring, displays, layout, offset); |
| 783 }; | 860 }; |
| 784 | 861 |
| 785 // Export | 862 // Export |
| 786 return { | 863 return { |
| 787 DisplayOptions: DisplayOptions | 864 DisplayOptions: DisplayOptions |
| 788 }; | 865 }; |
| 789 }); | 866 }); |
| OLD | NEW |