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.exportPath('options'); | 5 cr.exportPath('options'); |
6 | 6 |
7 /** | 7 /** |
8 * @typedef {{ | 8 * @typedef {{ |
9 * availableColorProfiles: Array<{profileId: number, name: string}>, | 9 * left: number, |
10 * colorProfile: number, | 10 * top: number, |
| 11 * width: number, |
| 12 * height: number |
| 13 * }} |
| 14 */ |
| 15 options.DisplayBounds; |
| 16 |
| 17 /** |
| 18 * @typedef {{ |
| 19 * width: number, |
11 * height: number, | 20 * height: number, |
| 21 * originalWidth: number, |
| 22 * originalHeight: number, |
| 23 * deviceScaleFactor: number, |
| 24 * scale: number, |
| 25 * refreshRate: number, |
| 26 * isBest: boolean, |
| 27 * selected: boolean |
| 28 * }} |
| 29 */ |
| 30 options.DisplayMode; |
| 31 |
| 32 /** |
| 33 * @typedef {{ |
| 34 * profileId: number, |
| 35 * name: string |
| 36 * }} |
| 37 */ |
| 38 options.ColorProfile; |
| 39 |
| 40 /** |
| 41 * @typedef {{ |
| 42 * availableColorProfiles: !Array<!options.ColorProfile>, |
| 43 * bounds: options.DisplayBounds, |
| 44 * colorProfileId: number, |
| 45 * div: ?Element, |
12 * id: string, | 46 * id: string, |
13 * isInternal: boolean, | 47 * isInternal: boolean, |
14 * isPrimary: boolean, | 48 * isPrimary: boolean, |
15 * resolutions: Array<{width: number, height: number, originalWidth: number, | 49 * resolutions: !Array<!options.DisplayMode>, |
16 * originalHeight: number, deviceScaleFactor: number, scale: number, | |
17 * refreshRate: number, isBest: boolean, selected: boolean}>, | |
18 * name: string, | 50 * name: string, |
19 * orientation: number, | 51 * rotation: number, |
20 * width: number, | 52 * originalPosition: ?{x: number, y: number} |
21 * x: number, | |
22 * y: number | |
23 * }} | 53 * }} |
24 */ | 54 */ |
25 options.DisplayInfo; | 55 options.DisplayInfo; |
26 | 56 |
27 /** | 57 /** |
28 * Enumeration of secondary display layout. The value has to be same as the | 58 * Enumeration of secondary display layout. The value has to be same as the |
29 * values in ash/display/display_controller.cc. | 59 * values in ash/display/display_controller.cc. |
30 * @enum {number} | 60 * @enum {number} |
31 */ | 61 */ |
32 options.SecondaryDisplayLayout = { | 62 options.SecondaryDisplayLayout = { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 171 |
142 /** | 172 /** |
143 * The current secondary display layout. | 173 * The current secondary display layout. |
144 * @private | 174 * @private |
145 */ | 175 */ |
146 layout_: options.SecondaryDisplayLayout.RIGHT, | 176 layout_: options.SecondaryDisplayLayout.RIGHT, |
147 | 177 |
148 /** | 178 /** |
149 * The array of current output displays. It also contains the display | 179 * The array of current output displays. It also contains the display |
150 * rectangles currently rendered on screen. | 180 * rectangles currently rendered on screen. |
151 * @type {Array<options.DisplayInfo>} | 181 * @type {!Array<!options.DisplayInfo>} |
152 * @private | 182 * @private |
153 */ | 183 */ |
154 displays_: [], | 184 displays_: [], |
155 | 185 |
156 /** | 186 /** |
157 * The index for the currently focused display in the options UI. null if | 187 * The index for the currently focused display in the options UI. null if |
158 * no one has focus. | 188 * no one has focus. |
159 * @private | 189 * @private |
160 */ | 190 */ |
161 focusedIndex_: null, | 191 focusedIndex_: null, |
162 | 192 |
163 /** | 193 /** |
164 * The primary display. | 194 * The primary display edit info. |
| 195 * @type {?options.DisplayInfo} |
165 * @private | 196 * @private |
166 */ | 197 */ |
167 primaryDisplay_: null, | 198 primaryDisplay_: null, |
168 | 199 |
169 /** | 200 /** |
170 * The secondary display. | 201 * The secondary display edit info. |
| 202 * @type {?options.DisplayInfo} |
171 * @private | 203 * @private |
172 */ | 204 */ |
173 secondaryDisplay_: null, | 205 secondaryDisplay_: null, |
174 | 206 |
175 /** | 207 /** |
176 * The container div element which contains all of the display rectangles. | 208 * The container div element which contains all of the display rectangles. |
177 * @private | 209 * @private |
178 */ | 210 */ |
179 displaysView_: null, | 211 displaysView_: null, |
180 | 212 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]); | 251 chrome.send('setPrimary', [this.displays_[this.focusedIndex_].id]); |
220 }).bind(this); | 252 }).bind(this); |
221 $('display-options-resolution-selection').onchange = (function(ev) { | 253 $('display-options-resolution-selection').onchange = (function(ev) { |
222 var display = this.displays_[this.focusedIndex_]; | 254 var display = this.displays_[this.focusedIndex_]; |
223 var resolution = display.resolutions[ev.target.value]; | 255 var resolution = display.resolutions[ev.target.value]; |
224 chrome.send('setDisplayMode', [display.id, resolution]); | 256 chrome.send('setDisplayMode', [display.id, resolution]); |
225 }).bind(this); | 257 }).bind(this); |
226 $('display-options-orientation-selection').onchange = (function(ev) { | 258 $('display-options-orientation-selection').onchange = (function(ev) { |
227 var displayIndex = | 259 var displayIndex = |
228 (this.focusedIndex_ === null) ? 0 : this.focusedIndex_; | 260 (this.focusedIndex_ === null) ? 0 : this.focusedIndex_; |
229 chrome.send('setOrientation', [this.displays_[displayIndex].id, | 261 var rotation = parseInt(ev.target.value, 10); |
230 ev.target.value]); | 262 chrome.send('setRotation', [this.displays_[displayIndex].id, rotation]); |
231 }).bind(this); | 263 }).bind(this); |
232 $('display-options-color-profile-selection').onchange = (function(ev) { | 264 $('display-options-color-profile-selection').onchange = (function(ev) { |
233 chrome.send('setColorProfile', [this.displays_[this.focusedIndex_].id, | 265 chrome.send('setColorProfile', [this.displays_[this.focusedIndex_].id, |
234 ev.target.value]); | 266 ev.target.value]); |
235 }).bind(this); | 267 }).bind(this); |
236 $('selected-display-start-calibrating-overscan').onclick = (function() { | 268 $('selected-display-start-calibrating-overscan').onclick = (function() { |
237 // Passes the target display ID. Do not specify it through URL hash, | 269 // Passes the target display ID. Do not specify it through URL hash, |
238 // we do not care back/forward. | 270 // we do not care back/forward. |
239 var displayOverscan = options.DisplayOverscan.getInstance(); | 271 var displayOverscan = options.DisplayOverscan.getInstance(); |
240 displayOverscan.setDisplayId(this.displays_[this.focusedIndex_].id); | 272 displayOverscan.setDisplayId(this.displays_[this.focusedIndex_].id); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 */ | 672 */ |
641 updateSelectedDisplaySectionMirroring_: function() { | 673 updateSelectedDisplaySectionMirroring_: function() { |
642 $('display-configuration-arrow').hidden = true; | 674 $('display-configuration-arrow').hidden = true; |
643 $('display-options-set-primary').disabled = true; | 675 $('display-options-set-primary').disabled = true; |
644 $('display-options-select-mirroring').disabled = false; | 676 $('display-options-select-mirroring').disabled = false; |
645 $('selected-display-start-calibrating-overscan').disabled = true; | 677 $('selected-display-start-calibrating-overscan').disabled = true; |
646 var display = this.displays_[0]; | 678 var display = this.displays_[0]; |
647 var orientation = $('display-options-orientation-selection'); | 679 var orientation = $('display-options-orientation-selection'); |
648 orientation.disabled = false; | 680 orientation.disabled = false; |
649 var orientationOptions = orientation.getElementsByTagName('option'); | 681 var orientationOptions = orientation.getElementsByTagName('option'); |
650 orientationOptions[display.orientation].selected = true; | 682 var orientationIndex = Math.floor(display.rotation / 90); |
| 683 orientationOptions[orientationIndex].selected = true; |
651 $('selected-display-name').textContent = | 684 $('selected-display-name').textContent = |
652 loadTimeData.getString('mirroringDisplay'); | 685 loadTimeData.getString('mirroringDisplay'); |
653 var resolution = $('display-options-resolution-selection'); | 686 var resolution = $('display-options-resolution-selection'); |
654 var option = document.createElement('option'); | 687 var option = document.createElement('option'); |
655 option.value = 'default'; | 688 option.value = 'default'; |
656 option.textContent = display.width + 'x' + display.height; | 689 option.textContent = display.bounds.width + 'x' + display.bounds.height; |
657 resolution.appendChild(option); | 690 resolution.appendChild(option); |
658 resolution.disabled = true; | 691 resolution.disabled = true; |
659 }, | 692 }, |
660 | 693 |
661 /** | 694 /** |
662 * Updates the description of selected display section when no display is | 695 * Updates the description of selected display section when no display is |
663 * selected. | 696 * selected. |
664 * @private | 697 * @private |
665 */ | 698 */ |
666 updateSelectedDisplaySectionNoSelected_: function() { | 699 updateSelectedDisplaySectionNoSelected_: function() { |
(...skipping 27 matching lines...) Expand all Loading... |
694 $('display-options-set-primary').disabled = display.isPrimary; | 727 $('display-options-set-primary').disabled = display.isPrimary; |
695 $('display-options-select-mirroring').disabled = | 728 $('display-options-select-mirroring').disabled = |
696 (this.displays_.length <= 1 && !this.unifiedDesktopEnabled_); | 729 (this.displays_.length <= 1 && !this.unifiedDesktopEnabled_); |
697 $('selected-display-start-calibrating-overscan').disabled = | 730 $('selected-display-start-calibrating-overscan').disabled = |
698 display.isInternal; | 731 display.isInternal; |
699 | 732 |
700 var orientation = $('display-options-orientation-selection'); | 733 var orientation = $('display-options-orientation-selection'); |
701 orientation.disabled = this.unifiedDesktopEnabled_; | 734 orientation.disabled = this.unifiedDesktopEnabled_; |
702 | 735 |
703 var orientationOptions = orientation.getElementsByTagName('option'); | 736 var orientationOptions = orientation.getElementsByTagName('option'); |
704 orientationOptions[display.orientation].selected = true; | 737 var orientationIndex = Math.floor(display.rotation / 90); |
| 738 orientationOptions[orientationIndex].selected = true; |
705 | 739 |
706 $('selected-display-name').textContent = display.name; | 740 $('selected-display-name').textContent = display.name; |
707 | 741 |
708 var resolution = $('display-options-resolution-selection'); | 742 var resolution = $('display-options-resolution-selection'); |
709 if (display.resolutions.length <= 1) { | 743 if (display.resolutions.length <= 1) { |
710 var option = document.createElement('option'); | 744 var option = document.createElement('option'); |
711 option.value = 'default'; | 745 option.value = 'default'; |
712 option.textContent = display.width + 'x' + display.height; | 746 option.textContent = display.bounds.width + 'x' + display.bounds.height; |
713 option.selected = true; | 747 option.selected = true; |
714 resolution.appendChild(option); | 748 resolution.appendChild(option); |
715 resolution.disabled = true; | 749 resolution.disabled = true; |
716 } else { | 750 } else { |
717 var previousOption; | 751 var previousOption; |
718 for (var i = 0; i < display.resolutions.length; i++) { | 752 for (var i = 0; i < display.resolutions.length; i++) { |
719 var option = document.createElement('option'); | 753 var option = document.createElement('option'); |
720 option.value = i; | 754 option.value = i; |
721 option.textContent = display.resolutions[i].width + 'x' + | 755 option.textContent = display.resolutions[i].width + 'x' + |
722 display.resolutions[i].height; | 756 display.resolutions[i].height; |
(...skipping 20 matching lines...) Expand all Loading... |
743 $('selected-display-color-profile-row').hidden = true; | 777 $('selected-display-color-profile-row').hidden = true; |
744 } else { | 778 } else { |
745 $('selected-display-color-profile-row').hidden = false; | 779 $('selected-display-color-profile-row').hidden = false; |
746 var profiles = $('display-options-color-profile-selection'); | 780 var profiles = $('display-options-color-profile-selection'); |
747 profiles.innerHTML = ''; | 781 profiles.innerHTML = ''; |
748 for (var i = 0; i < display.availableColorProfiles.length; i++) { | 782 for (var i = 0; i < display.availableColorProfiles.length; i++) { |
749 var option = document.createElement('option'); | 783 var option = document.createElement('option'); |
750 var colorProfile = display.availableColorProfiles[i]; | 784 var colorProfile = display.availableColorProfiles[i]; |
751 option.value = colorProfile.profileId; | 785 option.value = colorProfile.profileId; |
752 option.textContent = colorProfile.name; | 786 option.textContent = colorProfile.name; |
753 option.selected = ( | 787 option.selected = (display.colorProfileId == colorProfile.profileId); |
754 display.colorProfile == colorProfile.profileId); | |
755 profiles.appendChild(option); | 788 profiles.appendChild(option); |
756 } | 789 } |
757 } | 790 } |
758 }, | 791 }, |
759 | 792 |
760 /** | 793 /** |
761 * Updates the description of the selected display section. | 794 * Updates the description of the selected display section. |
762 * @private | 795 * @private |
763 */ | 796 */ |
764 updateSelectedDisplayDescription_: function() { | 797 updateSelectedDisplayDescription_: function() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 // Offset pixels for secondary display rectangles. The offset includes the | 833 // Offset pixels for secondary display rectangles. The offset includes the |
801 // border width. | 834 // border width. |
802 /** @const */ var MIRRORING_OFFSET_PIXELS = 3; | 835 /** @const */ var MIRRORING_OFFSET_PIXELS = 3; |
803 // Always show two displays because there must be two displays when | 836 // Always show two displays because there must be two displays when |
804 // the display_options is enabled. Don't rely on displays_.length because | 837 // the display_options is enabled. Don't rely on displays_.length because |
805 // there is only one display from chrome's perspective in mirror mode. | 838 // there is only one display from chrome's perspective in mirror mode. |
806 /** @const */ var MIN_NUM_DISPLAYS = 2; | 839 /** @const */ var MIN_NUM_DISPLAYS = 2; |
807 /** @const */ var MIRRORING_VERTICAL_MARGIN = 20; | 840 /** @const */ var MIRRORING_VERTICAL_MARGIN = 20; |
808 | 841 |
809 // The width/height should be same as the first display: | 842 // The width/height should be same as the first display: |
810 var width = Math.ceil(this.displays_[0].width * this.visualScale_); | 843 var width = Math.ceil(this.displays_[0].bounds.width * this.visualScale_); |
811 var height = Math.ceil(this.displays_[0].height * this.visualScale_); | 844 var height = |
| 845 Math.ceil(this.displays_[0].bounds.height * this.visualScale_); |
812 | 846 |
813 var numDisplays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); | 847 var numDisplays = Math.max(MIN_NUM_DISPLAYS, this.displays_.length); |
814 | 848 |
815 var totalWidth = width + numDisplays * MIRRORING_OFFSET_PIXELS; | 849 var totalWidth = width + numDisplays * MIRRORING_OFFSET_PIXELS; |
816 var totalHeight = height + numDisplays * MIRRORING_OFFSET_PIXELS; | 850 var totalHeight = height + numDisplays * MIRRORING_OFFSET_PIXELS; |
817 | 851 |
818 this.displaysView_.style.height = totalHeight + 'px'; | 852 this.displaysView_.style.height = totalHeight + 'px'; |
819 | 853 |
820 // The displays should be centered. | 854 // The displays should be centered. |
821 var offsetX = | 855 var offsetX = |
822 $('display-options-displays-view').offsetWidth / 2 - totalWidth / 2; | 856 $('display-options-displays-view').offsetWidth / 2 - totalWidth / 2; |
823 | 857 |
824 for (var i = 0; i < numDisplays; i++) { | 858 for (var i = 0; i < numDisplays; i++) { |
825 var div = document.createElement('div'); | 859 var div = document.createElement('div'); |
826 div.className = 'displays-display'; | 860 div.className = 'displays-display'; |
827 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; | 861 div.style.top = i * MIRRORING_OFFSET_PIXELS + 'px'; |
828 div.style.left = i * MIRRORING_OFFSET_PIXELS + offsetX + 'px'; | 862 div.style.left = i * MIRRORING_OFFSET_PIXELS + offsetX + 'px'; |
829 div.style.width = width + 'px'; | 863 div.style.width = width + 'px'; |
830 div.style.height = height + 'px'; | 864 div.style.height = height + 'px'; |
831 div.style.zIndex = i; | 865 div.style.zIndex = i; |
832 // set 'display-mirrored' class for the background display rectangles. | 866 // set 'display-mirrored' class for the background display rectangles. |
833 if (i != numDisplays - 1) | 867 if (i != numDisplays - 1) |
834 div.classList.add('display-mirrored'); | 868 div.classList.add('display-mirrored'); |
835 this.displaysView_.appendChild(div); | 869 this.displaysView_.appendChild(div); |
836 } | 870 } |
837 }, | 871 }, |
838 | 872 |
839 /** | 873 /** |
840 * Creates a div element representing the specified display. | 874 * Creates a div element representing the specified display. |
841 * @param {Object} display The display object. | 875 * @param {!options.DisplayInfo} display The display object. |
842 * @param {boolean} focused True if it's focused. | 876 * @param {boolean} focused True if it's focused. |
843 * @private | 877 * @private |
844 */ | 878 */ |
845 createDisplayRectangle_: function(display, focused) { | 879 createDisplayRectangle_: function(display, focused) { |
846 var div = document.createElement('div'); | 880 var div = document.createElement('div'); |
847 display.div = div; | 881 display.div = div; |
848 div.className = 'displays-display'; | 882 div.className = 'displays-display'; |
849 if (focused) | 883 if (focused) |
850 div.classList.add('displays-focused'); | 884 div.classList.add('displays-focused'); |
851 | 885 |
852 // div needs to be added to the DOM tree first, otherwise offsetHeight for | 886 // div needs to be added to the DOM tree first, otherwise offsetHeight for |
853 // nameContainer below cannot be computed. | 887 // nameContainer below cannot be computed. |
854 this.displaysView_.appendChild(div); | 888 this.displaysView_.appendChild(div); |
855 | 889 |
856 var nameContainer = document.createElement('div'); | 890 var nameContainer = document.createElement('div'); |
857 nameContainer.textContent = display.name; | 891 nameContainer.textContent = display.name; |
858 div.appendChild(nameContainer); | 892 div.appendChild(nameContainer); |
859 div.style.width = Math.floor(display.width * this.visualScale_) + 'px'; | 893 div.style.width = |
860 var newHeight = Math.floor(display.height * this.visualScale_); | 894 Math.floor(display.bounds.width * this.visualScale_) + 'px'; |
| 895 var newHeight = Math.floor(display.bounds.height * this.visualScale_); |
861 div.style.height = newHeight + 'px'; | 896 div.style.height = newHeight + 'px'; |
862 nameContainer.style.marginTop = | 897 nameContainer.style.marginTop = |
863 (newHeight - nameContainer.offsetHeight) / 2 + 'px'; | 898 (newHeight - nameContainer.offsetHeight) / 2 + 'px'; |
864 | 899 |
865 div.onmousedown = this.onMouseDown_.bind(this); | 900 div.onmousedown = this.onMouseDown_.bind(this); |
866 div.ontouchstart = this.onTouchStart_.bind(this); | 901 div.ontouchstart = this.onTouchStart_.bind(this); |
867 return div; | 902 return div; |
868 }, | 903 }, |
869 | 904 |
870 /** | 905 /** |
871 * Layouts the display rectangles according to the current layout_. | 906 * Layouts the display rectangles according to the current layout_. |
872 * @private | 907 * @private |
873 */ | 908 */ |
874 layoutDisplays_: function() { | 909 layoutDisplays_: function() { |
875 var maxWidth = 0; | 910 var maxWidth = 0; |
876 var maxHeight = 0; | 911 var maxHeight = 0; |
877 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; | 912 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; |
878 this.primaryDisplay_ = null; | 913 this.primaryDisplay_ = null; |
879 this.secondaryDisplay_ = null; | 914 this.secondaryDisplay_ = null; |
880 var focusedDisplay = null; | 915 var focusedDisplay = null; |
881 for (var i = 0; i < this.displays_.length; i++) { | 916 for (var i = 0; i < this.displays_.length; i++) { |
882 var display = this.displays_[i]; | 917 var display = this.displays_[i]; |
883 if (display.isPrimary) | 918 if (display.isPrimary) |
884 this.primaryDisplay_ = display; | 919 this.primaryDisplay_ = display; |
885 else | 920 else |
886 this.secondaryDisplay_ = display; | 921 this.secondaryDisplay_ = display; |
887 if (i == this.focusedIndex_) | 922 if (i == this.focusedIndex_) |
888 focusedDisplay = display; | 923 focusedDisplay = display; |
889 | 924 |
890 boundingBox.left = Math.min(boundingBox.left, display.x); | 925 var bounds = display.bounds; |
891 boundingBox.right = Math.max( | 926 boundingBox.left = Math.min(boundingBox.left, bounds.left); |
892 boundingBox.right, display.x + display.width); | 927 boundingBox.right = |
893 boundingBox.top = Math.min(boundingBox.top, display.y); | 928 Math.max(boundingBox.right, bounds.left + bounds.width); |
894 boundingBox.bottom = Math.max( | 929 boundingBox.top = Math.min(boundingBox.top, bounds.top); |
895 boundingBox.bottom, display.y + display.height); | 930 boundingBox.bottom = |
896 maxWidth = Math.max(maxWidth, display.width); | 931 Math.max(boundingBox.bottom, bounds.top + bounds.height); |
897 maxHeight = Math.max(maxHeight, display.height); | 932 maxWidth = Math.max(maxWidth, bounds.width); |
| 933 maxHeight = Math.max(maxHeight, bounds.height); |
898 } | 934 } |
899 if (!this.primaryDisplay_) | 935 if (!this.primaryDisplay_) |
900 return; | 936 return; |
901 | 937 |
902 // Make the margin around the bounding box. | 938 // Make the margin around the bounding box. |
903 var areaWidth = boundingBox.right - boundingBox.left + maxWidth; | 939 var areaWidth = boundingBox.right - boundingBox.left + maxWidth; |
904 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight; | 940 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight; |
905 | 941 |
906 // Calculates the scale by the width since horizontal size is more strict. | 942 // Calculates the scale by the width since horizontal size is more strict. |
907 // TODO(mukai): Adds the check of vertical size in case. | 943 // TODO(mukai): Adds the check of vertical size in case. |
908 this.visualScale_ = Math.min( | 944 this.visualScale_ = Math.min( |
909 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth); | 945 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth); |
910 | 946 |
911 // Prepare enough area for thisplays_view by adding the maximum height. | 947 // Prepare enough area for thisplays_view by adding the maximum height. |
912 this.displaysView_.style.height = | 948 this.displaysView_.style.height = |
913 Math.ceil(areaHeight * this.visualScale_) + 'px'; | 949 Math.ceil(areaHeight * this.visualScale_) + 'px'; |
914 | 950 |
915 // Centering the bounding box of the display rectangles. | 951 // Centering the bounding box of the display rectangles. |
916 var offset = { | 952 var offset = { |
917 x: Math.floor(this.displaysView_.offsetWidth / 2 - | 953 x: Math.floor( |
| 954 this.displaysView_.offsetWidth / 2 - |
918 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2), | 955 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2), |
919 y: Math.floor(this.displaysView_.offsetHeight / 2 - | 956 y: Math.floor( |
| 957 this.displaysView_.offsetHeight / 2 - |
920 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2) | 958 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2) |
921 }; | 959 }; |
922 | 960 |
923 // Layouting the display rectangles. First layout the primaryDisplay and | 961 // Layouting the display rectangles. First layout the primaryDisplay and |
924 // then layout the secondary which is attaching to the primary. | 962 // then layout the secondary which is attaching to the primary. |
925 var primaryDiv = this.createDisplayRectangle_( | 963 var primaryDiv = this.createDisplayRectangle_( |
926 this.primaryDisplay_, this.primaryDisplay_ == focusedDisplay); | 964 this.primaryDisplay_, this.primaryDisplay_ == focusedDisplay); |
927 primaryDiv.style.left = | 965 primaryDiv.style.left = |
928 Math.floor(this.primaryDisplay_.x * this.visualScale_) + | 966 Math.floor(this.primaryDisplay_.bounds.left * this.visualScale_) + |
929 offset.x + 'px'; | 967 offset.x + 'px'; |
930 primaryDiv.style.top = | 968 primaryDiv.style.top = |
931 Math.floor(this.primaryDisplay_.y * this.visualScale_) + | 969 Math.floor(this.primaryDisplay_.bounds.top * this.visualScale_) + |
932 offset.y + 'px'; | 970 offset.y + 'px'; |
933 this.primaryDisplay_.originalPosition = { | 971 this.primaryDisplay_.originalPosition = { |
934 x: primaryDiv.offsetLeft, y: primaryDiv.offsetTop}; | 972 x: primaryDiv.offsetLeft, |
| 973 y: primaryDiv.offsetTop |
| 974 }; |
935 | 975 |
936 if (this.secondaryDisplay_) { | 976 if (this.secondaryDisplay_) { |
937 var secondaryDiv = this.createDisplayRectangle_( | 977 var secondaryDiv = this.createDisplayRectangle_( |
938 this.secondaryDisplay_, this.secondaryDisplay_ == focusedDisplay); | 978 this.secondaryDisplay_, this.secondaryDisplay_ == focusedDisplay); |
939 // Don't trust the secondary display's x or y, because it may cause a | 979 // Don't trust the secondary display's x or y, because it may cause a |
940 // 1px gap due to rounding, which will create a fake update on end | 980 // 1px gap due to rounding, which will create a fake update on end |
941 // dragging. See crbug.com/386401 | 981 // dragging. See crbug.com/386401 |
| 982 var bounds = this.secondaryDisplay_.bounds; |
942 switch (this.layout_) { | 983 switch (this.layout_) { |
943 case options.SecondaryDisplayLayout.TOP: | 984 case options.SecondaryDisplayLayout.TOP: |
944 secondaryDiv.style.left = | 985 secondaryDiv.style.left = |
945 Math.floor(this.secondaryDisplay_.x * this.visualScale_) + | 986 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px'; |
946 offset.x + 'px'; | 987 secondaryDiv.style.top = |
947 secondaryDiv.style.top = | 988 primaryDiv.offsetTop - secondaryDiv.offsetHeight + 'px'; |
948 primaryDiv.offsetTop - secondaryDiv.offsetHeight + 'px'; | 989 break; |
949 break; | 990 case options.SecondaryDisplayLayout.RIGHT: |
950 case options.SecondaryDisplayLayout.RIGHT: | 991 secondaryDiv.style.left = |
951 secondaryDiv.style.left = | 992 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px'; |
952 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px'; | 993 secondaryDiv.style.top = |
953 secondaryDiv.style.top = | 994 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px'; |
954 Math.floor(this.secondaryDisplay_.y * this.visualScale_) + | 995 break; |
955 offset.y + 'px'; | 996 case options.SecondaryDisplayLayout.BOTTOM: |
956 break; | 997 secondaryDiv.style.left = |
957 case options.SecondaryDisplayLayout.BOTTOM: | 998 Math.floor(bounds.left * this.visualScale_) + offset.x + 'px'; |
958 secondaryDiv.style.left = | 999 secondaryDiv.style.top = |
959 Math.floor(this.secondaryDisplay_.x * this.visualScale_) + | 1000 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px'; |
960 offset.x + 'px'; | 1001 break; |
961 secondaryDiv.style.top = | 1002 case options.SecondaryDisplayLayout.LEFT: |
962 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px'; | 1003 secondaryDiv.style.left = |
963 break; | 1004 primaryDiv.offsetLeft - secondaryDiv.offsetWidth + 'px'; |
964 case options.SecondaryDisplayLayout.LEFT: | 1005 secondaryDiv.style.top = |
965 secondaryDiv.style.left = | 1006 Math.floor(bounds.top * this.visualScale_) + offset.y + 'px'; |
966 primaryDiv.offsetLeft - secondaryDiv.offsetWidth + 'px'; | 1007 break; |
967 secondaryDiv.style.top = | |
968 Math.floor(this.secondaryDisplay_.y * this.visualScale_) + | |
969 offset.y + 'px'; | |
970 break; | |
971 } | 1008 } |
972 this.secondaryDisplay_.originalPosition = { | 1009 this.secondaryDisplay_.originalPosition = { |
973 x: secondaryDiv.offsetLeft, y: secondaryDiv.offsetTop}; | 1010 x: secondaryDiv.offsetLeft, |
| 1011 y: secondaryDiv.offsetTop |
| 1012 }; |
974 } | 1013 } |
975 }, | 1014 }, |
976 | 1015 |
977 /** | 1016 /** |
978 * Called when the display arrangement has changed. | 1017 * Called when the display arrangement has changed. |
979 * @param {options.MultiDisplayMode} mode multi display mode. | 1018 * @param {options.MultiDisplayMode} mode multi display mode. |
980 * @param {Array<options.DisplayInfo>} displays The list of the display | 1019 * @param {Array<options.DisplayInfo>} displays The list of the display |
981 * information. | 1020 * information. |
982 * @param {options.SecondaryDisplayLayout} layout The layout strategy. | 1021 * @param {options.SecondaryDisplayLayout} layout The layout strategy. |
983 * @param {number} offset The offset of the secondary display. | 1022 * @param {number} offset The offset of the secondary display. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 mode, displays, layout, offset) { | 1084 mode, displays, layout, offset) { |
1046 DisplayOptions.getInstance().onDisplayChanged_( | 1085 DisplayOptions.getInstance().onDisplayChanged_( |
1047 mode, displays, layout, offset); | 1086 mode, displays, layout, offset); |
1048 }; | 1087 }; |
1049 | 1088 |
1050 // Export | 1089 // Export |
1051 return { | 1090 return { |
1052 DisplayOptions: DisplayOptions | 1091 DisplayOptions: DisplayOptions |
1053 }; | 1092 }; |
1054 }); | 1093 }); |
OLD | NEW |