| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.define('ntp4', function() { | 5 cr.define('ntp4', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 // We can't pass the currently dragging tile via dataTransfer because of | 8 // We can't pass the currently dragging tile via dataTransfer because of |
| 9 // http://crbug.com/31037 | 9 // http://crbug.com/31037 |
| 10 var currentlyDraggingTile = null; | 10 var currentlyDraggingTile = null; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 384 |
| 385 // Div that sets the vertical position of the tile grid. | 385 // Div that sets the vertical position of the tile grid. |
| 386 this.topMargin_ = this.ownerDocument.createElement('div'); | 386 this.topMargin_ = this.ownerDocument.createElement('div'); |
| 387 this.topMargin_.className = 'top-margin'; | 387 this.topMargin_.className = 'top-margin'; |
| 388 this.content_.appendChild(this.topMargin_); | 388 this.content_.appendChild(this.topMargin_); |
| 389 | 389 |
| 390 // Div that holds the tiles. | 390 // Div that holds the tiles. |
| 391 this.tileGrid_ = this.ownerDocument.createElement('div'); | 391 this.tileGrid_ = this.ownerDocument.createElement('div'); |
| 392 this.tileGrid_.className = 'tile-grid'; | 392 this.tileGrid_.className = 'tile-grid'; |
| 393 this.tileGrid_.style.minWidth = (this.gridValues_.minColCount * | 393 this.tileGrid_.style.minWidth = (this.gridValues_.minColCount * |
| 394 this.gridValues_.minTileWidth) + 'px'; | 394 tileWidthFraction(this.gridValues_.minTileWidth)) + 'px'; |
| 395 this.content_.appendChild(this.tileGrid_); | 395 this.content_.appendChild(this.tileGrid_); |
| 396 | 396 |
| 397 // Ordered list of our tiles. | 397 // Ordered list of our tiles. |
| 398 this.tileElements_ = this.tileGrid_.getElementsByClassName('tile real'); | 398 this.tileElements_ = this.tileGrid_.getElementsByClassName('tile real'); |
| 399 | 399 |
| 400 // These are properties used in updateTopMargin. | 400 // These are properties used in updateTopMargin. |
| 401 this.animatedTopMarginPx_ = 0; | 401 this.animatedTopMarginPx_ = 0; |
| 402 this.topMarginPx_ = 0; | 402 this.topMarginPx_ = 0; |
| 403 | 403 |
| 404 this.eventTracker = new EventTracker(); | 404 this.eventTracker = new EventTracker(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 this.tileGrid_.style.height = (realY + layout.rowHeight) + 'px'; | 605 this.tileGrid_.style.height = (realY + layout.rowHeight) + 'px'; |
| 606 this.queueUpdateScrollbars_(); | 606 this.queueUpdateScrollbars_(); |
| 607 } | 607 } |
| 608 }, | 608 }, |
| 609 | 609 |
| 610 /** | 610 /** |
| 611 * Gets the index of the tile that should occupy coordinate (x, y). Note | 611 * Gets the index of the tile that should occupy coordinate (x, y). Note |
| 612 * that this function doesn't care where the tiles actually are, and will | 612 * that this function doesn't care where the tiles actually are, and will |
| 613 * return an index even for the space between two tiles. This function is | 613 * return an index even for the space between two tiles. This function is |
| 614 * effectively the inverse of |positionTile_|. | 614 * effectively the inverse of |positionTile_|. |
| 615 * @param {number} x The x coordinate, in pixels, relative to the top left | 615 * @param {number} x The x coordinate, in pixels, relative to the left of |
| 616 * of tileGrid_. | 616 * |this|. |
| 617 * @param {number} y The y coordinate. | 617 * @param {number} y The y coordinate, in pixels, relative to the top of |
| 618 * |this|. |
| 618 * @private | 619 * @private |
| 619 */ | 620 */ |
| 620 getWouldBeIndexForPoint_: function(x, y) { | 621 getWouldBeIndexForPoint_: function(x, y) { |
| 621 var grid = this.gridValues_; | 622 var grid = this.gridValues_; |
| 622 var layout = this.layoutValues_; | 623 var layout = this.layoutValues_; |
| 623 | 624 |
| 624 var col = Math.floor((x - layout.leftMargin) / layout.colWidth); | 625 var gridClientRect = this.tileGrid_.getBoundingClientRect(); |
| 626 var col = Math.floor((x - gridClientRect.left - layout.leftMargin) / |
| 627 layout.colWidth); |
| 625 if (col < 0 || col >= layout.numRowTiles) | 628 if (col < 0 || col >= layout.numRowTiles) |
| 626 return -1; | 629 return -1; |
| 627 | 630 |
| 628 if (ntp4.isRTL()) | 631 if (ntp4.isRTL()) |
| 629 col = layout.numRowTiles - 1 - col; | 632 col = layout.numRowTiles - 1 - col; |
| 630 | 633 |
| 631 var row = Math.floor( | 634 var row = Math.floor((y - gridClientRect.top) / layout.rowHeight); |
| 632 (y - this.tileGrid_.getBoundingClientRect().top) / layout.rowHeight); | |
| 633 return row * layout.numRowTiles + col; | 635 return row * layout.numRowTiles + col; |
| 634 }, | 636 }, |
| 635 | 637 |
| 636 /** | 638 /** |
| 637 * Window resize event handler. Window resizes may trigger re-layouts. | 639 * Window resize event handler. Window resizes may trigger re-layouts. |
| 638 * @param {Object} e The resize event. | 640 * @param {Object} e The resize event. |
| 639 */ | 641 */ |
| 640 onResize_: function(e) { | 642 onResize_: function(e) { |
| 641 if (this.lastWidth_ == this.clientWidth && | 643 if (this.lastWidth_ == this.clientWidth && |
| 642 this.lastHeight_ == this.clientHeight) { | 644 this.lastHeight_ == this.clientHeight) { |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 */ | 997 */ |
| 996 tileMoved: function(draggedTile) { | 998 tileMoved: function(draggedTile) { |
| 997 }, | 999 }, |
| 998 }; | 1000 }; |
| 999 | 1001 |
| 1000 return { | 1002 return { |
| 1001 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1003 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1002 TilePage: TilePage, | 1004 TilePage: TilePage, |
| 1003 }; | 1005 }; |
| 1004 }); | 1006 }); |
| OLD | NEW |