OLD | NEW |
---|---|
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 Behavior for handling display layout, specifically | 6 * @fileoverview Behavior for handling display layout, specifically |
7 * edge snapping and collisions. | 7 * edge snapping and collisions. |
8 */ | 8 */ |
9 | 9 |
10 /** @polymerBehavior */ | 10 /** @polymerBehavior */ |
11 var LayoutBehavior = { | 11 var LayoutBehavior = { |
12 properties: { | 12 properties: { |
13 /** | 13 /** |
14 * Array of display layouts. | 14 * Array of display layouts. |
15 * @type {!Array<!chrome.system.display.DisplayLayout>} | 15 * @type {!Array<!chrome.system.display.DisplayLayout>} |
16 */ | 16 */ |
17 layouts: Array, | 17 layouts: Array, |
18 | |
19 /** | |
20 * Whether or not mirroring is enabled. | |
21 * @type {boolean} | |
22 */ | |
23 mirroring: false, | |
18 }, | 24 }, |
19 | 25 |
20 /** @private {!Map<string, chrome.system.display.Bounds>} */ | 26 /** @private {!Map<string, chrome.system.display.Bounds>} */ |
21 displayBoundsMap_: new Map(), | 27 displayBoundsMap_: new Map(), |
22 | 28 |
23 /** @private {!Map<string, chrome.system.display.DisplayLayout>} */ | 29 /** @private {!Map<string, chrome.system.display.DisplayLayout>} */ |
24 displayLayoutMap_: new Map(), | 30 displayLayoutMap_: new Map(), |
25 | 31 |
26 /** | 32 /** |
27 * The calculated bounds used for generating the div bounds. | 33 * The calculated bounds used for generating the div bounds. |
(...skipping 14 matching lines...) Expand all Loading... | |
42 dragLayoutPosition_: undefined, | 48 dragLayoutPosition_: undefined, |
43 | 49 |
44 /** | 50 /** |
45 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays | 51 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays |
46 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts | 52 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts |
47 */ | 53 */ |
48 initializeDisplayLayout: function(displays, layouts) { | 54 initializeDisplayLayout: function(displays, layouts) { |
49 this.dragLayoutId = ''; | 55 this.dragLayoutId = ''; |
50 this.dragParentId_ = ''; | 56 this.dragParentId_ = ''; |
51 | 57 |
58 this.mirroring = displays.length > 0 && !!displays[0].mirroringSourceId; | |
59 | |
52 this.displayBoundsMap_.clear(); | 60 this.displayBoundsMap_.clear(); |
53 for (let display of displays) | 61 for (let display of displays) |
54 this.displayBoundsMap_.set(display.id, display.bounds); | 62 this.displayBoundsMap_.set(display.id, display.bounds); |
55 | 63 |
56 this.displayLayoutMap_.clear(); | 64 this.displayLayoutMap_.clear(); |
57 for (let layout of layouts) | 65 for (let layout of layouts) |
58 this.displayLayoutMap_.set(layout.id, layout); | 66 this.displayLayoutMap_.set(layout.id, layout); |
59 | 67 |
60 this.calculatedBoundsMap_.clear(); | 68 this.calculatedBoundsMap_.clear(); |
61 for (let display of displays) { | 69 for (let display of displays) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 chrome.system.display.setDisplayLayout(this.layouts, function() { | 183 chrome.system.display.setDisplayLayout(this.layouts, function() { |
176 if (chrome.runtime.lastError) { | 184 if (chrome.runtime.lastError) { |
177 console.error( | 185 console.error( |
178 'setDisplayLayout Error: ' + chrome.runtime.lastError.message); | 186 'setDisplayLayout Error: ' + chrome.runtime.lastError.message); |
179 } | 187 } |
180 }); | 188 }); |
181 }, | 189 }, |
182 | 190 |
183 /** | 191 /** |
184 * @param {string} displayId | 192 * @param {string} displayId |
193 * @param {boolean=} opt_test | |
michaelpg
2016/07/11 20:41:56
i'd prefer optional params default to false, e.g.
stevenjb
2016/07/11 21:56:23
I inverted the variable to be notest instead. We c
| |
185 * @return {!chrome.system.display.Bounds} bounds | 194 * @return {!chrome.system.display.Bounds} bounds |
186 */ | 195 */ |
187 getCalculatedDisplayBounds: function(displayId) { | 196 getCalculatedDisplayBounds: function(displayId, opt_test) { |
188 var bounds = this.calculatedBoundsMap_.get(displayId); | 197 var bounds = this.calculatedBoundsMap_.get(displayId); |
189 assert(bounds); | 198 assert(opt_test === false || bounds); |
190 return bounds; | 199 return bounds; |
191 }, | 200 }, |
192 | 201 |
193 /** | 202 /** |
194 * @param {string} displayId | 203 * @param {string} displayId |
195 * @param {!chrome.system.display.Bounds|undefined} bounds | 204 * @param {!chrome.system.display.Bounds|undefined} bounds |
196 * @private | 205 * @private |
197 */ | 206 */ |
198 setCalculatedDisplayBounds_: function(displayId, bounds) { | 207 setCalculatedDisplayBounds_: function(displayId, bounds) { |
199 assert(bounds); | 208 assert(bounds); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 * Recursively calculates the absolute bounds of a display. | 310 * Recursively calculates the absolute bounds of a display. |
302 * Caches the display bounds so that parent bounds are only calculated once. | 311 * Caches the display bounds so that parent bounds are only calculated once. |
303 * @param {string} id | 312 * @param {string} id |
304 * @param {number} width | 313 * @param {number} width |
305 * @param {number} height | 314 * @param {number} height |
306 * @private | 315 * @private |
307 */ | 316 */ |
308 calculateBounds_: function(id, width, height) { | 317 calculateBounds_: function(id, width, height) { |
309 var left, top; | 318 var left, top; |
310 var layout = this.displayLayoutMap_.get(id); | 319 var layout = this.displayLayoutMap_.get(id); |
311 if (!layout || !layout.parentId) { | 320 if (this.mirroring || !layout || !layout.parentId) { |
312 left = -width / 2; | 321 left = -width / 2; |
313 top = -height / 2; | 322 top = -height / 2; |
314 } else { | 323 } else { |
315 if (!this.calculatedBoundsMap_.has(layout.parentId)) { | 324 if (!this.calculatedBoundsMap_.has(layout.parentId)) { |
316 var pbounds = this.displayBoundsMap_.get(layout.parentId); | 325 var pbounds = this.displayBoundsMap_.get(layout.parentId); |
317 this.calculateBounds_(layout.parentId, pbounds.width, pbounds.height); | 326 this.calculateBounds_(layout.parentId, pbounds.width, pbounds.height); |
318 } | 327 } |
319 var parentBounds = this.getCalculatedDisplayBounds(layout.parentId); | 328 var parentBounds = this.getCalculatedDisplayBounds(layout.parentId); |
320 left = parentBounds.left; | 329 left = parentBounds.left; |
321 top = parentBounds.top; | 330 top = parentBounds.top; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 highlight == chrome.system.display.LayoutPosition.LEFT); | 698 highlight == chrome.system.display.LayoutPosition.LEFT); |
690 div.classList.toggle( | 699 div.classList.toggle( |
691 'highlight-top', | 700 'highlight-top', |
692 highlight == chrome.system.display.LayoutPosition.TOP); | 701 highlight == chrome.system.display.LayoutPosition.TOP); |
693 div.classList.toggle( | 702 div.classList.toggle( |
694 'highlight-bottom', | 703 'highlight-bottom', |
695 highlight == chrome.system.display.LayoutPosition.BOTTOM); | 704 highlight == chrome.system.display.LayoutPosition.BOTTOM); |
696 } | 705 } |
697 }, | 706 }, |
698 }; | 707 }; |
OLD | NEW |