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

Side by Side Diff: chrome/browser/resources/settings/device_page/display_layout.js

Issue 2128773004: MD Settings: Display: Add mirroring and other fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_625106_settings_dropdown_style
Patch Set: Fix drag + mirrored, cleanup, feedback Created 4 years, 5 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'display-layout' presents a visual representation of the layout of one or 7 * 'display-layout' presents a visual representation of the layout of one or
8 * more displays and allows them to be arranged. 8 * more displays and allows them to be arranged.
9 */ 9 */
10 10
(...skipping 10 matching lines...) Expand all
21 LayoutBehavior, 21 LayoutBehavior,
22 ], 22 ],
23 23
24 properties: { 24 properties: {
25 /** 25 /**
26 * Array of displays. 26 * Array of displays.
27 * @type {!Array<!chrome.system.display.DisplayUnitInfo>} 27 * @type {!Array<!chrome.system.display.DisplayUnitInfo>}
28 */ 28 */
29 displays: Array, 29 displays: Array,
30 30
31 /**
32 * Whether or not mirroring is enabled.
33 * @type {boolean}
34 */
35 mirroring: false,
36
37 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */ 31 /** @type {!chrome.system.display.DisplayUnitInfo|undefined} */
38 selectedDisplay: Object, 32 selectedDisplay: Object,
39 33
40 /** 34 /**
41 * The ratio of the display area div (in px) to DisplayUnitInfo.bounds. 35 * The ratio of the display area div (in px) to DisplayUnitInfo.bounds.
42 * @type {number} 36 * @type {number}
43 */ 37 */
44 visualScale: 1, 38 visualScale: 1,
45 }, 39 },
46 40
47 /** @private {!{left: number, top: number}} */ 41 /** @private {!{left: number, top: number}} */
48 visualOffset_: {left: 0, top: 0}, 42 visualOffset_: {left: 0, top: 0},
49 43
50 /** @override */ 44 /** @override */
51 attached: function() {
52 // TODO(stevenjb): Remove retry once fixed:
53 // https://github.com/Polymer/polymer/issues/3629
54 var self = this;
55 var retry = 100; // ms
56 function tryCalcVisualScale() {
57 if (!self.calculateVisualScale_())
58 setTimeout(tryCalcVisualScale, retry);
59 }
60 tryCalcVisualScale();
61 },
62
63 /** @override */
64 detached: function() { this.initializeDrag(false); }, 45 detached: function() { this.initializeDrag(false); },
65 46
66 /** 47 /**
67 * Called explicitly when |this.displays| and their associated |this.layouts| 48 * Called explicitly when |this.displays| and their associated |this.layouts|
68 * have been fetched from chrome. 49 * have been fetched from chrome.
69 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays 50 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays
70 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts 51 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts
71 */ 52 */
72 updateDisplays: function(displays, layouts) { 53 updateDisplays: function(displays, layouts) {
73 this.displays = displays; 54 this.displays = displays;
74 this.layouts = layouts; 55 this.layouts = layouts;
75 56
76 this.mirroring = displays.length > 0 && !!displays[0].mirroringSourceId;
77
78 this.initializeDisplayLayout(displays, layouts); 57 this.initializeDisplayLayout(displays, layouts);
79 58
80 this.calculateVisualScale_(); 59 var self = this;
60 var retry = 100; // ms
61 function tryCalcVisualScale() {
62 if (!self.calculateVisualScale_())
63 setTimeout(tryCalcVisualScale, retry);
64 }
65 tryCalcVisualScale();
81 66
82 this.initializeDrag( 67 this.initializeDrag(
83 !this.mirroring, this.$.displayArea, this.onDrag_.bind(this)); 68 !this.mirroring, this.$.displayArea, this.onDrag_.bind(this));
84 }, 69 },
85 70
86 /** 71 /**
87 * Calculates the visual offset and scale for the display area 72 * Calculates the visual offset and scale for the display area
88 * (i.e. the ratio of the display area div size to the area required to 73 * (i.e. the ratio of the display area div size to the area required to
89 * contain the DisplayUnitInfo bounding boxes). 74 * contain the DisplayUnitInfo bounding boxes).
90 * @return {boolean} Whether the calculation was successful. 75 * @return {boolean} Whether the calculation was successful.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Update the scale which will trigger calls to getDivStyle_. 128 // Update the scale which will trigger calls to getDivStyle_.
144 this.visualScale = Math.max(MIN_VISUAL_SCALE, scale); 129 this.visualScale = Math.max(MIN_VISUAL_SCALE, scale);
145 130
146 return true; 131 return true;
147 }, 132 },
148 133
149 /** 134 /**
150 * @param {string} id 135 * @param {string} id
151 * @param {!chrome.system.display.Bounds} displayBounds 136 * @param {!chrome.system.display.Bounds} displayBounds
152 * @param {number} visualScale 137 * @param {number} visualScale
138 * @param {boolean=} opt_mirrored
153 * @return {string} The style string for the div. 139 * @return {string} The style string for the div.
154 * @private 140 * @private
155 */ 141 */
156 getDivStyle_: function(id, displayBounds, visualScale) { 142 getDivStyle_: function(id, displayBounds, visualScale, opt_mirrored) {
157 // This matches the size of the box-shadow or border in CSS. 143 // This matches the size of the box-shadow or border in CSS.
158 /** @const {number} */ var BORDER = 2; 144 /** @const {number} */ var BORDER = opt_mirrored ? 1 : 2;
159 var bounds = this.getCalculatedDisplayBounds(id); 145 /** @const {number} */ var OFFSET = opt_mirrored ? -4 : 0;
146 var bounds = this.getCalculatedDisplayBounds(id, true /* notest */);
147 if (!bounds)
148 return '';
160 var height = Math.round(bounds.height * this.visualScale) - BORDER * 2; 149 var height = Math.round(bounds.height * this.visualScale) - BORDER * 2;
161 var width = Math.round(bounds.width * this.visualScale) - BORDER * 2; 150 var width = Math.round(bounds.width * this.visualScale) - BORDER * 2;
162 var left = 151 var left = OFFSET +
163 Math.round(this.visualOffset_.left + (bounds.left * this.visualScale)); 152 Math.round(this.visualOffset_.left + (bounds.left * this.visualScale));
164 var top = 153 var top = OFFSET +
165 Math.round(this.visualOffset_.top + (bounds.top * this.visualScale)); 154 Math.round(this.visualOffset_.top + (bounds.top * this.visualScale));
166 return `height: ${height}px; width: ${width}px;` + 155 return `height: ${height}px; width: ${width}px;` +
167 ` left: ${left}px; top: ${top}px`; 156 ` left: ${left}px; top: ${top}px`;
168 }, 157 },
169 158
170 /** 159 /**
160 * @param {string} id
161 * @param {!chrome.system.display.Bounds} displayBounds
162 * @param {number} visualScale
163 * @return {string} The style string for the mirror div.
164 * @private
165 */
166 getMirrorDivStyle_: function(id, displayBounds, visualScale) {
167 return this.getDivStyle_(id, displayBounds, visualScale, true);
168 },
169
170 /**
171 * @param {!chrome.system.display.DisplayUnitInfo} display 171 * @param {!chrome.system.display.DisplayUnitInfo} display
172 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay 172 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay
173 * @return {boolean} 173 * @return {boolean}
174 * @private 174 * @private
175 */ 175 */
176 isSelected_: function(display, selectedDisplay) { 176 isSelected_: function(display, selectedDisplay) {
177 return display.id == selectedDisplay.id; 177 return display.id == selectedDisplay.id;
178 }, 178 },
179 179
180 /** 180 /**
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 var top = 217 var top =
218 this.visualOffset_.top + Math.round(newBounds.top * this.visualScale); 218 this.visualOffset_.top + Math.round(newBounds.top * this.visualScale);
219 var div = this.$$('#_' + id); 219 var div = this.$$('#_' + id);
220 div.style.left = '' + left + 'px'; 220 div.style.left = '' + left + 'px';
221 div.style.top = '' + top + 'px'; 221 div.style.top = '' + top + 'px';
222 }, 222 },
223 223
224 }); 224 });
225 225
226 })(); 226 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698