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 $('display-options-orientation-selection').disabled = false; |
| 599 orientationOptions[display.orientation].selected = true; |
| 600 |
| 601 $('selected-display-name').textContent = display.name; |
| 602 |
| 603 var resolution = $('display-options-resolution-selection'); |
| 604 if (display.uiScales.length <= 1) { |
| 605 var option = document.createElement('option'); |
| 606 option.value = 'default'; |
| 607 option.textContent = display.width + 'x' + display.height; |
| 608 option.selected = true; |
| 609 resolution.appendChild(option); |
| 610 resolution.disabled = true; |
| 611 } else { |
| 612 for (var i = 0; i < display.uiScales.length; i++) { |
| 613 var option = document.createElement('option'); |
| 614 option.value = display.uiScales[i].scale; |
| 615 option.textContent = |
| 616 display.uiScales[i].width + 'x' + display.uiScales[i].height; |
| 617 if (display.uiScales[i].scale == 1.0) { |
| 618 option.textContent += ' ' + |
| 619 loadTimeData.getString('annotateBest'); |
| 620 } |
| 621 option.selected = display.uiScales[i].selected; |
| 622 resolution.appendChild(option); |
| 623 } |
| 624 resolution.disabled = !display.isInternal; |
| 625 } |
| 626 }, |
| 627 |
| 628 /** |
522 * Updates the description of the selected display section. | 629 * Updates the description of the selected display section. |
523 * @private | 630 * @private |
524 */ | 631 */ |
525 updateSelectedDisplayDescription_: function() { | 632 updateSelectedDisplayDescription_: function() { |
| 633 var resolution = $('display-options-resolution-selection'); |
| 634 resolution.textContent = ''; |
| 635 var orientation = $('display-options-orientation-selection'); |
| 636 var orientationOptions = orientation.getElementsByTagName('option'); |
| 637 for (var i = 0; i < orientationOptions.length; i++) |
| 638 orientationOptions.selected = false; |
| 639 |
526 if (this.mirroring_) { | 640 if (this.mirroring_) { |
527 $('display-configuration-arrow').hidden = true; | 641 this.updateSelectedDisplaySectionMirroring_(); |
528 $('display-options-set-primary').hidden = true; | 642 } else if (this.focusedIndex_ == null || |
529 $('display-options-toggle-mirroring').hidden = false; | 643 this.displays_[this.focusedIndex_] == null) { |
530 $('selected-display-data-container').hidden = false; | 644 this.updateSelectedDisplaySectionNoSelected_(); |
531 var display = this.displays_[0]; | 645 } else { |
532 $('selected-display-name').textContent = ''; | 646 this.updateSelectedDisplaySectionForDisplay_( |
533 $('selected-display-resolution').textContent = | 647 this.displays_[this.focusedIndex_]); |
534 display.width + 'x' + display.height; | |
535 return; | |
536 } | 648 } |
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 }, | 649 }, |
571 | 650 |
572 /** | 651 /** |
573 * Clears the drawing area for display rectangles. | 652 * Clears the drawing area for display rectangles. |
574 * @private | 653 * @private |
575 */ | 654 */ |
576 resetDisplaysView_: function() { | 655 resetDisplaysView_: function() { |
577 var displaysViewHost = $('display-options-displays-view-host'); | 656 var displaysViewHost = $('display-options-displays-view-host'); |
578 displaysViewHost.removeChild(displaysViewHost.firstChild); | 657 displaysViewHost.removeChild(displaysViewHost.firstChild); |
579 this.displaysView_ = document.createElement('div'); | 658 this.displaysView_ = document.createElement('div'); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 if (!this.visible) | 815 if (!this.visible) |
737 return; | 816 return; |
738 | 817 |
739 var hasExternal = false; | 818 var hasExternal = false; |
740 for (var i = 0; i < displays.length; i++) { | 819 for (var i = 0; i < displays.length; i++) { |
741 if (!displays[i].isInternal) { | 820 if (!displays[i].isInternal) { |
742 hasExternal = true; | 821 hasExternal = true; |
743 break; | 822 break; |
744 } | 823 } |
745 } | 824 } |
746 if (!hasExternal && !mirroring) { | |
747 OptionsPage.showDefaultPage(); | |
748 return; | |
749 } | |
750 | 825 |
751 this.mirroring_ = mirroring; | 826 this.mirroring_ = mirroring; |
752 this.layout_ = layout; | 827 this.layout_ = layout; |
753 this.offset_ = offset; | 828 this.offset_ = offset; |
754 this.dirty_ = false; | 829 this.dirty_ = false; |
755 | 830 |
756 $('display-options-toggle-mirroring').textContent = | 831 $('display-options-toggle-mirroring').textContent = |
757 loadTimeData.getString( | 832 loadTimeData.getString( |
758 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); | 833 this.mirroring_ ? 'stopMirroring' : 'startMirroring'); |
759 | 834 |
(...skipping 20 matching lines...) Expand all Loading... |
780 mirroring, displays, layout, offset) { | 855 mirroring, displays, layout, offset) { |
781 DisplayOptions.getInstance().onDisplayChanged_( | 856 DisplayOptions.getInstance().onDisplayChanged_( |
782 mirroring, displays, layout, offset); | 857 mirroring, displays, layout, offset); |
783 }; | 858 }; |
784 | 859 |
785 // Export | 860 // Export |
786 return { | 861 return { |
787 DisplayOptions: DisplayOptions | 862 DisplayOptions: DisplayOptions |
788 }; | 863 }; |
789 }); | 864 }); |
OLD | NEW |