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

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: 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() {
michaelpg 2016/07/11 13:37:55 var interval = setInterval(function() { if (self
stevenjb 2016/07/11 19:45:35 The problem with setInterval is that it delays bef
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
153 * @return {string} The style string for the div. 138 * @return {string} The style string for the div.
154 * @private 139 * @private
155 */ 140 */
156 getDivStyle_: function(id, displayBounds, visualScale) { 141 getDivStyle_: function(id, displayBounds, visualScale) {
157 // This matches the size of the box-shadow or border in CSS. 142 // This matches the size of the box-shadow or border in CSS.
158 /** @const {number} */ var BORDER = 2; 143 /** @const {number} */ var BORDER = 2;
159 var bounds = this.getCalculatedDisplayBounds(id); 144 var bounds = this.getCalculatedDisplayBounds(id, false);
145 if (!bounds)
146 return '';
160 var height = Math.round(bounds.height * this.visualScale) - BORDER * 2; 147 var height = Math.round(bounds.height * this.visualScale) - BORDER * 2;
161 var width = Math.round(bounds.width * this.visualScale) - BORDER * 2; 148 var width = Math.round(bounds.width * this.visualScale) - BORDER * 2;
162 var left = 149 var left =
163 Math.round(this.visualOffset_.left + (bounds.left * this.visualScale)); 150 Math.round(this.visualOffset_.left + (bounds.left * this.visualScale));
164 var top = 151 var top =
165 Math.round(this.visualOffset_.top + (bounds.top * this.visualScale)); 152 Math.round(this.visualOffset_.top + (bounds.top * this.visualScale));
166 return `height: ${height}px; width: ${width}px;` + 153 return `height: ${height}px; width: ${width}px;` +
167 ` left: ${left}px; top: ${top}px`; 154 ` left: ${left}px; top: ${top}px`;
168 }, 155 },
169 156
170 /** 157 /**
158 * @param {string} id
159 * @param {!chrome.system.display.Bounds} displayBounds
160 * @param {number} visualScale
161 * @return {string} The style string for the mirror div.
162 * @private
163 */
164 getMirrorDivStyle_: function(id, displayBounds, visualScale) {
165 // This matches the size of the mirrored border in CSS.
166 /** @const {number} */ var BORDER = 1;
167 /** @const {number} */ var OFFSET = -4;
168 var bounds = this.getCalculatedDisplayBounds(id, false);
michaelpg 2016/07/11 13:37:55 can you factor out the majority of this function a
stevenjb 2016/07/11 19:45:35 Done.
169 if (!bounds)
170 return '';
171 var height = Math.round(bounds.height * this.visualScale) - BORDER * 2;
172 var width = Math.round(bounds.width * this.visualScale) - BORDER * 2;
173 var left = OFFSET +
174 Math.round(this.visualOffset_.left + (bounds.left * this.visualScale));
175 var top = OFFSET +
176 Math.round(this.visualOffset_.top + (bounds.top * this.visualScale));
177 return `height: ${height}px; width: ${width}px;` +
178 ` left: ${left}px; top: ${top}px`;
179 },
180
181 /**
171 * @param {!chrome.system.display.DisplayUnitInfo} display 182 * @param {!chrome.system.display.DisplayUnitInfo} display
172 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay 183 * @param {!chrome.system.display.DisplayUnitInfo} selectedDisplay
173 * @return {boolean} 184 * @return {boolean}
174 * @private 185 * @private
175 */ 186 */
176 isSelected_: function(display, selectedDisplay) { 187 isSelected_: function(display, selectedDisplay) {
177 return display.id == selectedDisplay.id; 188 return display.id == selectedDisplay.id;
178 }, 189 },
179 190
180 /** 191 /**
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 var top = 228 var top =
218 this.visualOffset_.top + Math.round(newBounds.top * this.visualScale); 229 this.visualOffset_.top + Math.round(newBounds.top * this.visualScale);
219 var div = this.$$('#_' + id); 230 var div = this.$$('#_' + id);
220 div.style.left = '' + left + 'px'; 231 div.style.left = '' + left + 'px';
221 div.style.top = '' + top + 'px'; 232 div.style.top = '' + top + 'px';
222 }, 233 },
223 234
224 }); 235 });
225 236
226 })(); 237 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698