| 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 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 /** @private {!Map<string, chrome.system.display.DisplayLayout>} */ | 29 /** @private {!Map<string, chrome.system.display.DisplayLayout>} */ |
| 30 displayLayoutMap_: new Map(), | 30 displayLayoutMap_: new Map(), |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * The calculated bounds used for generating the div bounds. | 33 * The calculated bounds used for generating the div bounds. |
| 34 * @private {!Map<string, chrome.system.display.Bounds>} | 34 * @private {!Map<string, chrome.system.display.Bounds>} |
| 35 */ | 35 */ |
| 36 calculatedBoundsMap_: new Map(), | 36 calculatedBoundsMap_: new Map(), |
| 37 | 37 |
| 38 /** @private {string} */ | 38 /** @private {string} */ |
| 39 dragLayoutId: '', | 39 dragLayoutId_: '', |
| 40 | 40 |
| 41 /** @private {string} */ | 41 /** @private {string} */ |
| 42 dragParentId_: '', | 42 dragParentId_: '', |
| 43 | 43 |
| 44 /** @private {!chrome.system.display.Bounds|undefined} */ | 44 /** @private {!chrome.system.display.Bounds|undefined} */ |
| 45 dragBounds_: undefined, | 45 dragBounds_: undefined, |
| 46 | 46 |
| 47 /** @private {!chrome.system.display.LayoutPosition|undefined} */ | 47 /** @private {!chrome.system.display.LayoutPosition|undefined} */ |
| 48 dragLayoutPosition_: undefined, | 48 dragLayoutPosition_: undefined, |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays | 51 * @param {!Array<!chrome.system.display.DisplayUnitInfo>} displays |
| 52 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts | 52 * @param {!Array<!chrome.system.display.DisplayLayout>} layouts |
| 53 */ | 53 */ |
| 54 initializeDisplayLayout: function(displays, layouts) { | 54 initializeDisplayLayout: function(displays, layouts) { |
| 55 this.dragLayoutId = ''; | 55 this.dragLayoutId_ = ''; |
| 56 this.dragParentId_ = ''; | 56 this.dragParentId_ = ''; |
| 57 | 57 |
| 58 this.mirroring = displays.length > 0 && !!displays[0].mirroringSourceId; | 58 this.mirroring = displays.length > 0 && !!displays[0].mirroringSourceId; |
| 59 | 59 |
| 60 this.displayBoundsMap_.clear(); | 60 this.displayBoundsMap_.clear(); |
| 61 for (var i = 0; i < displays.length; ++i) { | 61 for (var i = 0; i < displays.length; ++i) { |
| 62 var display = displays[i]; | 62 var display = displays[i]; |
| 63 this.displayBoundsMap_.set(display.id, display.bounds); | 63 this.displayBoundsMap_.set(display.id, display.bounds); |
| 64 } | 64 } |
| 65 this.displayLayoutMap_.clear(); | 65 this.displayLayoutMap_.clear(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 78 }, | 78 }, |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Called when a drag event occurs. Checks collisions and updates the layout. | 81 * Called when a drag event occurs. Checks collisions and updates the layout. |
| 82 * @param {string} id | 82 * @param {string} id |
| 83 * @param {!chrome.system.display.Bounds} newBounds The new calculated | 83 * @param {!chrome.system.display.Bounds} newBounds The new calculated |
| 84 * bounds for the display. | 84 * bounds for the display. |
| 85 * @return {!chrome.system.display.Bounds} | 85 * @return {!chrome.system.display.Bounds} |
| 86 */ | 86 */ |
| 87 updateDisplayBounds: function(id, newBounds) { | 87 updateDisplayBounds: function(id, newBounds) { |
| 88 this.dragLayoutId = id; | 88 this.dragLayoutId_ = id; |
| 89 | 89 |
| 90 // Find the closest parent. | 90 // Find the closest parent. |
| 91 var closestId = this.findClosest_(id, newBounds); | 91 var closestId = this.findClosest_(id, newBounds); |
| 92 assert(closestId); | 92 assert(closestId); |
| 93 | 93 |
| 94 // Find the closest edge. | 94 // Find the closest edge. |
| 95 var closestBounds = this.getCalculatedDisplayBounds(closestId); | 95 var closestBounds = this.getCalculatedDisplayBounds(closestId); |
| 96 var layoutPosition = | 96 var layoutPosition = |
| 97 this.getLayoutPositionForBounds_(newBounds, closestBounds); | 97 this.getLayoutPositionForBounds_(newBounds, closestBounds); |
| 98 | 98 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 127 | 127 |
| 128 return newBounds; | 128 return newBounds; |
| 129 }, | 129 }, |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * Called when dragging ends. Sends the updated layout to chrome. | 132 * Called when dragging ends. Sends the updated layout to chrome. |
| 133 * @param {string} id | 133 * @param {string} id |
| 134 */ | 134 */ |
| 135 finishUpdateDisplayBounds: function(id) { | 135 finishUpdateDisplayBounds: function(id) { |
| 136 this.highlightEdge_('', undefined); // Remove any highlights. | 136 this.highlightEdge_('', undefined); // Remove any highlights. |
| 137 if (id != this.dragLayoutId || !this.dragBounds_ || | 137 if (id != this.dragLayoutId_ || !this.dragBounds_ || |
| 138 !this.dragLayoutPosition_) { | 138 !this.dragLayoutPosition_) { |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 var layout = this.displayLayoutMap_.get(id); | 142 var layout = this.displayLayoutMap_.get(id); |
| 143 | 143 |
| 144 var orphanIds; | 144 var orphanIds; |
| 145 if (!layout || layout.parentId == '') { | 145 if (!layout || layout.parentId == '') { |
| 146 // Primary display. Set the calculated position to |dragBounds_|. | 146 // Primary display. Set the calculated position to |dragBounds_|. |
| 147 this.setCalculatedDisplayBounds_(id, this.dragBounds_); | 147 this.setCalculatedDisplayBounds_(id, this.dragBounds_); |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 highlight == chrome.system.display.LayoutPosition.LEFT); | 705 highlight == chrome.system.display.LayoutPosition.LEFT); |
| 706 div.classList.toggle( | 706 div.classList.toggle( |
| 707 'highlight-top', | 707 'highlight-top', |
| 708 highlight == chrome.system.display.LayoutPosition.TOP); | 708 highlight == chrome.system.display.LayoutPosition.TOP); |
| 709 div.classList.toggle( | 709 div.classList.toggle( |
| 710 'highlight-bottom', | 710 'highlight-bottom', |
| 711 highlight == chrome.system.display.LayoutPosition.BOTTOM); | 711 highlight == chrome.system.display.LayoutPosition.BOTTOM); |
| 712 } | 712 } |
| 713 }, | 713 }, |
| 714 }; | 714 }; |
| OLD | NEW |