Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/resources/options/chromeos/display_options.js

Issue 739413002: Fixes a minor rearrangement of rectangles for display settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * availableColorProfiles: Array.<{profileId: number, name: string}>,
10 * colorProfile: number, 10 * colorProfile: number,
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 div.style.height = height + 'px'; 759 div.style.height = height + 'px';
760 div.style.zIndex = i; 760 div.style.zIndex = i;
761 // set 'display-mirrored' class for the background display rectangles. 761 // set 'display-mirrored' class for the background display rectangles.
762 if (i != numDisplays - 1) 762 if (i != numDisplays - 1)
763 div.classList.add('display-mirrored'); 763 div.classList.add('display-mirrored');
764 this.displaysView_.appendChild(div); 764 this.displaysView_.appendChild(div);
765 } 765 }
766 }, 766 },
767 767
768 /** 768 /**
769 * Creates a div element representing the specified display.
770 * @param {Object} display The display object.
771 * @param {boolean} focused True if it's focused.
772 * @private
773 */
774 createDisplayRectangle_: function(display, focused) {
775 var div = document.createElement('div');
776 display.div = div;
777 div.className = 'displays-display';
778 if (focused)
779 div.classList.add('displays-focused');
780
781 // div needs to be added to the DOM tree first, otherwise offsetHeight for
782 // nameContainer below cannot be computed.
783 this.displaysView_.appendChild(div);
784
785 var nameContainer = document.createElement('div');
786 nameContainer.textContent = display.name;
787 div.appendChild(nameContainer);
788 display.div.style.width =
xiyuan 2014/11/20 02:21:31 nit: display.div is |div|, why not just use that?
Jun Mukai 2014/11/20 02:31:41 Done. I copied from the old code which somehow us
789 Math.floor(display.width * this.visualScale_) + 'px';
790 var newHeight = Math.floor(display.height * this.visualScale_);
791 display.div.style.height = newHeight + 'px';
xiyuan 2014/11/20 02:21:31 nit: same here.
Jun Mukai 2014/11/20 02:31:41 Done.
792 nameContainer.style.marginTop =
793 (newHeight - nameContainer.offsetHeight) / 2 + 'px';
794
795 div.onmousedown = this.onMouseDown_.bind(this);
796 div.ontouchstart = this.onTouchStart_.bind(this);
797 return div;
798 },
799
800 /**
769 * Layouts the display rectangles according to the current layout_. 801 * Layouts the display rectangles according to the current layout_.
770 * @private 802 * @private
771 */ 803 */
772 layoutDisplays_: function() { 804 layoutDisplays_: function() {
773 var maxWidth = 0; 805 var maxWidth = 0;
774 var maxHeight = 0; 806 var maxHeight = 0;
775 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0}; 807 var boundingBox = {left: 0, right: 0, top: 0, bottom: 0};
808 this.primaryDisplay_ = null;
809 this.secondaryDisplay_ = null;
810 var focusedDisplay = null;
776 for (var i = 0; i < this.displays_.length; i++) { 811 for (var i = 0; i < this.displays_.length; i++) {
777 var display = this.displays_[i]; 812 var display = this.displays_[i];
813 if (display.isPrimary)
814 this.primaryDisplay_ = display;
815 else
816 this.secondaryDisplay_ = display;
817 if (i == this.focusedIndex_)
818 focusedDisplay = display;
819
778 boundingBox.left = Math.min(boundingBox.left, display.x); 820 boundingBox.left = Math.min(boundingBox.left, display.x);
779 boundingBox.right = Math.max( 821 boundingBox.right = Math.max(
780 boundingBox.right, display.x + display.width); 822 boundingBox.right, display.x + display.width);
781 boundingBox.top = Math.min(boundingBox.top, display.y); 823 boundingBox.top = Math.min(boundingBox.top, display.y);
782 boundingBox.bottom = Math.max( 824 boundingBox.bottom = Math.max(
783 boundingBox.bottom, display.y + display.height); 825 boundingBox.bottom, display.y + display.height);
784 maxWidth = Math.max(maxWidth, display.width); 826 maxWidth = Math.max(maxWidth, display.width);
785 maxHeight = Math.max(maxHeight, display.height); 827 maxHeight = Math.max(maxHeight, display.height);
786 } 828 }
829 if (!this.primaryDisplay_)
830 return;
787 831
788 // Make the margin around the bounding box. 832 // Make the margin around the bounding box.
789 var areaWidth = boundingBox.right - boundingBox.left + maxWidth; 833 var areaWidth = boundingBox.right - boundingBox.left + maxWidth;
790 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight; 834 var areaHeight = boundingBox.bottom - boundingBox.top + maxHeight;
791 835
792 // Calculates the scale by the width since horizontal size is more strict. 836 // Calculates the scale by the width since horizontal size is more strict.
793 // TODO(mukai): Adds the check of vertical size in case. 837 // TODO(mukai): Adds the check of vertical size in case.
794 this.visualScale_ = Math.min( 838 this.visualScale_ = Math.min(
795 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth); 839 VISUAL_SCALE, this.displaysView_.offsetWidth / areaWidth);
796 840
797 // Prepare enough area for thisplays_view by adding the maximum height. 841 // Prepare enough area for thisplays_view by adding the maximum height.
798 this.displaysView_.style.height = 842 this.displaysView_.style.height =
799 Math.ceil(areaHeight * this.visualScale_) + 'px'; 843 Math.ceil(areaHeight * this.visualScale_) + 'px';
800 844
801 var boundingCenter = {
802 x: Math.floor((boundingBox.right + boundingBox.left) *
803 this.visualScale_ / 2),
804 y: Math.floor((boundingBox.bottom + boundingBox.top) *
805 this.visualScale_ / 2)
806 };
807
808 // Centering the bounding box of the display rectangles. 845 // Centering the bounding box of the display rectangles.
809 var offset = { 846 var offset = {
810 x: Math.floor(this.displaysView_.offsetWidth / 2 - 847 x: Math.floor(this.displaysView_.offsetWidth / 2 -
811 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2), 848 (boundingBox.right + boundingBox.left) * this.visualScale_ / 2),
812 y: Math.floor(this.displaysView_.offsetHeight / 2 - 849 y: Math.floor(this.displaysView_.offsetHeight / 2 -
813 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2) 850 (boundingBox.bottom + boundingBox.top) * this.visualScale_ / 2)
814 }; 851 };
815 852
816 for (var i = 0; i < this.displays_.length; i++) { 853 // Layouting the display rectangles. First layout the primaryDisplay and
817 var display = this.displays_[i]; 854 // then layout the secondary which is attaching to the primary.
818 var div = document.createElement('div'); 855 var primaryDiv = this.createDisplayRectangle_(
819 display.div = div; 856 this.primaryDisplay_, this.primaryDisplay_ == focusedDisplay);
857 primaryDiv.style.left =
858 Math.floor(this.primaryDisplay_.x * this.visualScale_) +
859 offset.x + 'px';
860 primaryDiv.style.top =
861 Math.floor(this.primaryDisplay_.y * this.visualScale_) +
862 offset.y + 'px';
863 this.primaryDisplay_.originalPosition = {
864 x: primaryDiv.offsetLeft, y: primaryDiv.offsetTop};
820 865
821 div.className = 'displays-display'; 866 if (this.secondaryDisplay_) {
822 if (i == this.focusedIndex_) 867 var secondaryDiv = this.createDisplayRectangle_(
823 div.classList.add('displays-focused'); 868 this.secondaryDisplay_, this.secondaryDisplay_ == focusedDisplay);
824 869 // Don't trust the secondary display's x or y, because it may cause a
825 if (display.isPrimary) { 870 // 1px gap due to rounding, which will create a fake update on end
826 this.primaryDisplay_ = display; 871 // dragging. See crbug.com/386401
827 } else { 872 switch (this.layout_) {
828 this.secondaryDisplay_ = display; 873 case options.SecondaryDisplayLayout.TOP:
874 secondaryDiv.style.left =
875 Math.floor(this.secondaryDisplay_.x * this.visualScale_) +
876 offset.x + 'px';
877 secondaryDiv.style.top =
878 primaryDiv.offsetTop - secondaryDiv.offsetHeight + 'px';
879 break;
880 case options.SecondaryDisplayLayout.RIGHT:
881 secondaryDiv.style.left =
882 primaryDiv.offsetLeft + primaryDiv.offsetWidth + 'px';
883 secondaryDiv.style.top =
884 Math.floor(this.secondaryDisplay_.y * this.visualScale_) +
885 offset.y + 'px';
886 break;
887 case options.SecondaryDisplayLayout.BOTTOM:
888 secondaryDiv.style.left =
889 Math.floor(this.secondaryDisplay_.x * this.visualScale_) +
890 offset.x + 'px';
891 secondaryDiv.style.top =
892 primaryDiv.offsetTop + primaryDiv.offsetHeight + 'px';
893 break;
894 case options.SecondaryDisplayLayout.LEFT:
895 secondaryDiv.style.left =
896 primaryDiv.offsetLeft - secondaryDiv.offsetWidth + 'px';
897 secondaryDiv.style.top =
898 Math.floor(this.secondaryDisplay_.y * this.visualScale_) +
899 offset.y + 'px';
900 break;
829 } 901 }
830 var displayNameContainer = document.createElement('div'); 902 this.secondaryDisplay_.originalPosition = {
831 displayNameContainer.textContent = display.name; 903 x: secondaryDiv.offsetLeft, y: secondaryDiv.offsetTop};
832 div.appendChild(displayNameContainer);
833 display.nameContainer = displayNameContainer;
834 display.div.style.width =
835 Math.floor(display.width * this.visualScale_) + 'px';
836 var newHeight = Math.floor(display.height * this.visualScale_);
837 display.div.style.height = newHeight + 'px';
838 div.style.left =
839 Math.floor(display.x * this.visualScale_) + offset.x + 'px';
840 div.style.top =
841 Math.floor(display.y * this.visualScale_) + offset.y + 'px';
842 display.nameContainer.style.marginTop =
843 (newHeight - display.nameContainer.offsetHeight) / 2 + 'px';
844
845 div.onmousedown = this.onMouseDown_.bind(this);
846 div.ontouchstart = this.onTouchStart_.bind(this);
847
848 this.displaysView_.appendChild(div);
849
850 // Set the margin top to place the display name at the middle of the
851 // rectangle. Note that this has to be done after it's added into the
852 // |displaysView_|. Otherwise its offsetHeight is yet 0.
853 displayNameContainer.style.marginTop =
854 (div.offsetHeight - displayNameContainer.offsetHeight) / 2 + 'px';
855 display.originalPosition = {x: div.offsetLeft, y: div.offsetTop};
856 } 904 }
857 }, 905 },
858 906
859 /** 907 /**
860 * Called when the display arrangement has changed. 908 * Called when the display arrangement has changed.
861 * @param {boolean} mirroring Whether current mode is mirroring or not. 909 * @param {boolean} mirroring Whether current mode is mirroring or not.
862 * @param {Array.<options.DisplayInfo>} displays The list of the display 910 * @param {Array.<options.DisplayInfo>} displays The list of the display
863 * information. 911 * information.
864 * @param {options.SecondaryDisplayLayout} layout The layout strategy. 912 * @param {options.SecondaryDisplayLayout} layout The layout strategy.
865 * @param {number} offset The offset of the secondary display. 913 * @param {number} offset The offset of the secondary display.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 mirroring, displays, layout, offset) { 957 mirroring, displays, layout, offset) {
910 DisplayOptions.getInstance().onDisplayChanged_( 958 DisplayOptions.getInstance().onDisplayChanged_(
911 mirroring, displays, layout, offset); 959 mirroring, displays, layout, offset);
912 }; 960 };
913 961
914 // Export 962 // Export
915 return { 963 return {
916 DisplayOptions: DisplayOptions 964 DisplayOptions: DisplayOptions
917 }; 965 };
918 }); 966 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698