| 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 cr.exportPath('options'); | 5 cr.exportPath('options'); |
| 6 | 6 |
| 7 cr.define('options', function() { | 7 cr.define('options', function() { |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 var DisplayLayoutManager = options.DisplayLayoutManager; | 10 var DisplayLayoutManager = options.DisplayLayoutManager; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // Find the closest edge. | 50 // Find the closest edge. |
| 51 var layoutType = layout.getLayoutTypeForPosition(parent.div, newPosition); | 51 var layoutType = layout.getLayoutTypeForPosition(parent.div, newPosition); |
| 52 | 52 |
| 53 // Calculate the new position and delta. | 53 // Calculate the new position and delta. |
| 54 var oldPos = {x: layout.div.offsetLeft, y: layout.div.offsetTop}; | 54 var oldPos = {x: layout.div.offsetLeft, y: layout.div.offsetTop}; |
| 55 var newPos = layout.getSnapPosition(newPosition, parent.div, layoutType); | 55 var newPos = layout.getSnapPosition(newPosition, parent.div, layoutType); |
| 56 var deltaPos = {x: newPos.x - oldPos.x, y: newPos.y - oldPos.y}; | 56 var deltaPos = {x: newPos.x - oldPos.x, y: newPos.y - oldPos.y}; |
| 57 | 57 |
| 58 // Check for collisions. | 58 // Check for collisions. |
| 59 this.collideAndModifyDelta_(layout, deltaPos); | 59 this.collideAndModifyDelta_(layout, oldPos, deltaPos); |
| 60 if (deltaPos.x == 0 && deltaPos.y == 0) | 60 if (deltaPos.x == 0 && deltaPos.y == 0) |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 // Update the div (but not the actual layout type or offset yet), | 63 // Update the div (but not the actual layout type or offset yet), |
| 64 newPos = {x: oldPos.x + deltaPos.x, y: oldPos.y + deltaPos.y}; | 64 newPos = {x: oldPos.x + deltaPos.x, y: oldPos.y + deltaPos.y}; |
| 65 layout.setDivPosition(newPos, parent.div, layoutType); | 65 layout.setDivPosition(newPos, parent.div, layoutType); |
| 66 | 66 |
| 67 // If the edge changed, update and highlight it. | 67 // If the edge changed, update and highlight it. |
| 68 if (layoutType != this.dragLayoutType_ || | 68 if (layoutType != this.dragLayoutType_ || |
| 69 parentId != this.dragParentId_) { | 69 parentId != this.dragParentId_) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 // Find the closest edge. | 188 // Find the closest edge. |
| 189 var layoutType = orphan.getLayoutTypeForPosition(parent.div, pos); | 189 var layoutType = orphan.getLayoutTypeForPosition(parent.div, pos); |
| 190 | 190 |
| 191 // Snap from the nearest corner to the desired locaiton and get the delta. | 191 // Snap from the nearest corner to the desired locaiton and get the delta. |
| 192 var cornerPos = orphan.getCornerPos(parent.div, pos); | 192 var cornerPos = orphan.getCornerPos(parent.div, pos); |
| 193 pos = orphan.getSnapPosition(pos, parent.div, layoutType); | 193 pos = orphan.getSnapPosition(pos, parent.div, layoutType); |
| 194 var deltaPos = {x: pos.x - cornerPos.x, y: pos.y - cornerPos.y}; | 194 var deltaPos = {x: pos.x - cornerPos.x, y: pos.y - cornerPos.y}; |
| 195 | 195 |
| 196 // Check for collisions. | 196 // Check for collisions. |
| 197 this.collideAndModifyDelta_(orphan, deltaPos); | 197 this.collideAndModifyDelta_(orphan, cornerPos, deltaPos); |
| 198 pos = {x: cornerPos.x + deltaPos.x, y: cornerPos.y + deltaPos.y}; | 198 pos = {x: cornerPos.x + deltaPos.x, y: cornerPos.y + deltaPos.y}; |
| 199 | 199 |
| 200 // Update the div and adjust the corners. | 200 // Update the div and adjust the corners. |
| 201 orphan.layoutType = layoutType; | 201 orphan.layoutType = layoutType; |
| 202 orphan.setDivPosition(pos, parent.div, layoutType); | 202 orphan.setDivPosition(pos, parent.div, layoutType); |
| 203 orphan.adjustCorners(parent.div, layoutType); | 203 orphan.adjustCorners(parent.div, layoutType); |
| 204 | 204 |
| 205 // Calculate the bounds from the new div position. | 205 // Calculate the bounds from the new div position. |
| 206 orphan.calculateOffset(this.visualScale_, parent); | 206 orphan.calculateOffset(this.visualScale_, parent); |
| 207 | 207 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 var delta2 = dx * dx + dy * dy; | 272 var delta2 = dx * dx + dy * dy; |
| 273 if (closestId == '' || delta2 < closestDelta2) { | 273 if (closestId == '' || delta2 < closestDelta2) { |
| 274 closestId = id; | 274 closestId = id; |
| 275 closestDelta2 = delta2; | 275 closestDelta2 = delta2; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 return closestId; | 278 return closestId; |
| 279 }, | 279 }, |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * Intersects |layout| with each other layout and reduces |deltaPos| to | 282 * Intersects |layout| at |pos| with each other layout and reduces |
| 283 * avoid any collisions (or sets it to [0,0] if the div can not be moved | 283 * |deltaPos| to avoid any collisions (or sets it to [0,0] if the div can |
| 284 * in the direction of |deltaPos|). | 284 * not be moved in the direction of |deltaPos|). |
| 285 * @param {!options.DisplayLayout} layout | 285 * @param {!options.DisplayLayout} layout |
| 286 * @param {!options.DisplayPosition} pos |
| 286 * @param {!options.DisplayPosition} deltaPos | 287 * @param {!options.DisplayPosition} deltaPos |
| 287 */ | 288 */ |
| 288 collideAndModifyDelta_: function(layout, deltaPos) { | 289 collideAndModifyDelta_: function(layout, pos, deltaPos) { |
| 289 var keys = Object.keys( | 290 var keys = Object.keys( |
| 290 /** @type {!Object<!options.DisplayLayout>}*/ ( | 291 /** @type {!Object<!options.DisplayLayout>}*/ ( |
| 291 this.displayLayoutMap_)); | 292 this.displayLayoutMap_)); |
| 292 var others = new Set(keys); | 293 var others = new Set(keys); |
| 293 others.delete(layout.id); | 294 others.delete(layout.id); |
| 294 var checkCollisions = true; | 295 var checkCollisions = true; |
| 295 while (checkCollisions) { | 296 while (checkCollisions) { |
| 296 checkCollisions = false; | 297 checkCollisions = false; |
| 297 for (var tid of others) { | 298 for (var tid of others) { |
| 298 var tlayout = this.displayLayoutMap_[tid]; | 299 var tlayout = this.displayLayoutMap_[tid]; |
| 299 if (layout.collideWithDivAndModifyDelta(tlayout.div, deltaPos)) { | 300 if (layout.collideWithDivAndModifyDelta(pos, tlayout.div, deltaPos)) { |
| 300 if (deltaPos.x == 0 && deltaPos.y == 0) | 301 if (deltaPos.x == 0 && deltaPos.y == 0) |
| 301 return; | 302 return; |
| 302 others.delete(tid); | 303 others.delete(tid); |
| 303 checkCollisions = true; | 304 checkCollisions = true; |
| 304 break; | 305 break; |
| 305 } | 306 } |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 }, | 309 }, |
| 309 | 310 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Parent layout bounds may not be calculated yet, so calculate (but | 359 // Parent layout bounds may not be calculated yet, so calculate (but |
| 359 // do not set) them. | 360 // do not set) them. |
| 360 var parentBounds = this.calcLayoutBounds_(parent); | 361 var parentBounds = this.calcLayoutBounds_(parent); |
| 361 return layout.calculateBounds(parentBounds); | 362 return layout.calculateBounds(parentBounds); |
| 362 }, | 363 }, |
| 363 }; | 364 }; |
| 364 | 365 |
| 365 // Export | 366 // Export |
| 366 return {DisplayLayoutManagerMulti: DisplayLayoutManagerMulti}; | 367 return {DisplayLayoutManagerMulti: DisplayLayoutManagerMulti}; |
| 367 }); | 368 }); |
| OLD | NEW |