| 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 /** | 7 /** |
| 8 * Enumeration of display layout. These values must match the C++ values in | 8 * Enumeration of display layout. These values must match the C++ values in |
| 9 * ash::DisplayController. | 9 * ash::DisplayController. |
| 10 * @enum {number} | 10 * @enum {number} |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 * 0 means snap from any distance. | 388 * 0 means snap from any distance. |
| 389 * @return {number} | 389 * @return {number} |
| 390 */ | 390 */ |
| 391 snapToY: function(y, parentDiv, opt_snapDistance) { | 391 snapToY: function(y, parentDiv, opt_snapDistance) { |
| 392 return snapToEdge_( | 392 return snapToEdge_( |
| 393 y, this.div.offsetHeight, parentDiv.offsetTop, parentDiv.offsetHeight, | 393 y, this.div.offsetHeight, parentDiv.offsetTop, parentDiv.offsetHeight, |
| 394 opt_snapDistance); | 394 opt_snapDistance); |
| 395 }, | 395 }, |
| 396 | 396 |
| 397 /** | 397 /** |
| 398 * Intersects this.div with |otherDiv|. If there is a collision, modifies | 398 * Intersects this.div at |pos| with |otherDiv|. If there is a collision, |
| 399 * |deltaPos| to limit movement to a single axis and avoid the collision | 399 * modifies |deltaPos| to limit movement to a single axis and avoid the |
| 400 * and returns true. | 400 * collision and returns true. |
| 401 * @param {!options.DisplayPosition} pos |
| 401 * @param {?HTMLElement} otherDiv | 402 * @param {?HTMLElement} otherDiv |
| 402 * @param {!options.DisplayPosition} deltaPos | 403 * @param {!options.DisplayPosition} deltaPos |
| 403 * @return {boolean} Whether there was a collision. | 404 * @return {boolean} Whether there was a collision. |
| 404 */ | 405 */ |
| 405 collideWithDivAndModifyDelta: function(otherDiv, deltaPos) { | 406 collideWithDivAndModifyDelta: function(pos, otherDiv, deltaPos) { |
| 406 var div = this.div; | 407 var div = this.div; |
| 407 var newX = div.offsetLeft + deltaPos.x; | 408 var newX = pos.x + deltaPos.x; |
| 408 var newY = div.offsetTop + deltaPos.y; | 409 var newY = pos.y + deltaPos.y; |
| 409 | 410 |
| 410 if ((newX + div.offsetWidth <= otherDiv.offsetLeft) || | 411 if ((newX + div.offsetWidth <= otherDiv.offsetLeft) || |
| 411 (newX >= otherDiv.offsetLeft + otherDiv.offsetWidth) || | 412 (newX >= otherDiv.offsetLeft + otherDiv.offsetWidth) || |
| 412 (newY + div.offsetHeight <= otherDiv.offsetTop) || | 413 (newY + div.offsetHeight <= otherDiv.offsetTop) || |
| 413 (newY >= otherDiv.offsetTop + otherDiv.offsetHeight)) { | 414 (newY >= otherDiv.offsetTop + otherDiv.offsetHeight)) { |
| 414 return false; | 415 return false; |
| 415 } | 416 } |
| 416 | 417 |
| 417 if (Math.abs(deltaPos.x) > Math.abs(deltaPos.y)) { | 418 if (Math.abs(deltaPos.x) > Math.abs(deltaPos.y)) { |
| 418 if (deltaPos.x > 0) { | 419 if (deltaPos.x > 0) { |
| 419 var x = otherDiv.offsetLeft - div.offsetWidth; | 420 var x = otherDiv.offsetLeft - div.offsetWidth; |
| 420 if (x > div.offsetLeft) | 421 if (x > pos.x) |
| 421 deltaPos.x = x - div.offsetLeft; | 422 deltaPos.x = x - pos.x; |
| 422 else | 423 else |
| 423 deltaPos.x = 0; | 424 deltaPos.x = 0; |
| 424 } else { | 425 } else { |
| 425 var x = otherDiv.offsetLeft + otherDiv.offsetWidth; | 426 var x = otherDiv.offsetLeft + otherDiv.offsetWidth; |
| 426 if (x < div.offsetLeft) | 427 if (x < pos.x) |
| 427 deltaPos.x = x - div.offsetLeft; | 428 deltaPos.x = x - pos.x; |
| 428 else | 429 else |
| 429 deltaPos.x = 0; | 430 deltaPos.x = 0; |
| 430 } | 431 } |
| 431 deltaPos.y = 0; | 432 deltaPos.y = 0; |
| 432 } else { | 433 } else { |
| 433 deltaPos.x = 0; | 434 deltaPos.x = 0; |
| 434 if (deltaPos.y > 0) { | 435 if (deltaPos.y > 0) { |
| 435 var y = otherDiv.offsetTop - div.offsetHeight; | 436 var y = otherDiv.offsetTop - div.offsetHeight; |
| 436 if (y > div.offsetTop) | 437 if (y > pos.y) |
| 437 deltaPos.y = y - div.offsetTop; | 438 deltaPos.y = y - pos.y; |
| 438 else | 439 else |
| 439 deltaPos.y = 0; | 440 deltaPos.y = 0; |
| 440 } else if (deltaPos.y < 0) { | 441 } else if (deltaPos.y < 0) { |
| 441 var y = otherDiv.offsetTop + otherDiv.offsetTop; | 442 var y = otherDiv.offsetTop + otherDiv.offsetTop; |
| 442 if (y < div.offsetTop) | 443 if (y < pos.y) |
| 443 deltaPos.y = y - div.offsetTop; | 444 deltaPos.y = y - pos.y; |
| 444 else | 445 else |
| 445 deltaPos.y = 0; | 446 deltaPos.y = 0; |
| 446 } | 447 } |
| 447 } | 448 } |
| 448 | 449 |
| 449 return true; | 450 return true; |
| 450 } | 451 } |
| 451 }; | 452 }; |
| 452 | 453 |
| 453 // Export | 454 // Export |
| 454 return {DisplayLayout: DisplayLayout}; | 455 return {DisplayLayout: DisplayLayout}; |
| 455 }); | 456 }); |
| OLD | NEW |