OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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('ntp', function() { | 5 cr.define('ntp', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 | 8 |
9 /** | 9 /** |
10 * The maximum gap from the edge of the scrolling area which will display | 10 * The maximum gap from the edge of the scrolling area which will display |
11 * the shadow with transparency. After this point the shadow will become | 11 * the shadow with transparency. After this point the shadow will become |
12 * 100% opaque. | 12 * 100% opaque. |
13 * @type {number} | 13 * @type {number} |
14 * @const | 14 * @const |
15 */ | 15 */ |
16 var MAX_SCROLL_SHADOW_GAP = 16; | 16 var MAX_SCROLL_SHADOW_GAP = 16; |
17 | 17 |
18 /** | 18 /** |
19 * @type {number} | 19 * @type {number} |
20 * @const | 20 * @const |
21 */ | 21 */ |
22 var TILE_ROW_HEIGHT = 92; | |
23 | |
24 /** | |
25 * @type {number} | |
26 * @const | |
27 */ | |
28 var SCROLL_BAR_WIDTH = 12; | 22 var SCROLL_BAR_WIDTH = 12; |
29 | 23 |
30 //---------------------------------------------------------------------------- | 24 //---------------------------------------------------------------------------- |
31 // Tile | 25 // Tile |
32 //---------------------------------------------------------------------------- | 26 //---------------------------------------------------------------------------- |
33 | 27 |
34 /** | 28 /** |
35 * A virtual Tile class. Each TilePage subclass should have its own Tile | 29 * A virtual Tile class. Each TilePage subclass should have its own Tile |
36 * subclass implemented too (e.g. MostVisitedPage contains MostVisited | 30 * subclass implemented too (e.g. MostVisitedPage contains MostVisited |
37 * tiles, and MostVisited is a Tile subclass). | 31 * tiles, and MostVisited is a Tile subclass). |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 * @private | 563 * @private |
570 * @return {!{top: number, left: number}} Position. | 564 * @return {!{top: number, left: number}} Position. |
571 */ | 565 */ |
572 getTilePosition_: function(index) { | 566 getTilePosition_: function(index) { |
573 var colCount = this.colCount_; | 567 var colCount = this.colCount_; |
574 var row = Math.floor(index / colCount); | 568 var row = Math.floor(index / colCount); |
575 var col = index % colCount; | 569 var col = index % colCount; |
576 if (isRTL()) | 570 if (isRTL()) |
577 col = colCount - col - 1; | 571 col = colCount - col - 1; |
578 var config = this.config; | 572 var config = this.config; |
579 var top = TILE_ROW_HEIGHT * row; | 573 var top = ntp.TILE_ROW_HEIGHT * row; |
580 var left = col * (config.cellWidth + config.cellMarginStart); | 574 var left = col * (config.cellWidth + config.cellMarginStart); |
581 return {top: top, left: left}; | 575 return {top: top, left: left}; |
582 }, | 576 }, |
583 | 577 |
584 // rendering | 578 // rendering |
585 // ------------------------------------------------------------------------- | 579 // ------------------------------------------------------------------------- |
586 | 580 |
587 /** | 581 /** |
588 * Renders the tile grid, and the individual tiles. Rendering the grid | 582 * Renders the tile grid, and the individual tiles. Rendering the grid |
589 * consists of adding/removing tile rows and tile cells according to the | 583 * consists of adding/removing tile rows and tile cells according to the |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 * Panel's size. This method will resize the containers of the tile page, | 677 * Panel's size. This method will resize the containers of the tile page, |
684 * and re-render the grid when its dimension changes (number of columns or | 678 * and re-render the grid when its dimension changes (number of columns or |
685 * visible rows changes). This method also sets the private properties | 679 * visible rows changes). This method also sets the private properties |
686 * |numOfVisibleRows_| and |animatingColCount_|. | 680 * |numOfVisibleRows_| and |animatingColCount_|. |
687 * | 681 * |
688 * This method should be called every time the dimension of the grid changes | 682 * This method should be called every time the dimension of the grid changes |
689 * or when you need to reinforce its dimension. | 683 * or when you need to reinforce its dimension. |
690 * @param {boolean=} opt_animate Whether the layout be animated. | 684 * @param {boolean=} opt_animate Whether the layout be animated. |
691 */ | 685 */ |
692 layout: function(opt_animate) { | 686 layout: function(opt_animate) { |
| 687 var contentHeight = ntp.getContentHeight(); |
| 688 this.content_.style.height = contentHeight + 'px'; |
| 689 |
693 var contentWidth = ntp.getContentWidth(); | 690 var contentWidth = ntp.getContentWidth(); |
694 var colCount = this.getColCountForWidth_(contentWidth); | 691 var colCount = this.getColCountForWidth_(contentWidth); |
695 var lastColCount = this.colCount_; | 692 var lastColCount = this.colCount_; |
696 var animatingColCount = this.animatingColCount_; | 693 var animatingColCount = this.animatingColCount_; |
697 if (colCount != animatingColCount) { | 694 if (colCount != animatingColCount) { |
698 if (opt_animate) | 695 if (opt_animate) |
699 this.tileGrid_.classList.add('animate-grid-width'); | 696 this.tileGrid_.classList.add('animate-grid-width'); |
700 | 697 |
701 if (colCount > animatingColCount) { | 698 if (colCount > animatingColCount) { |
702 // If the grid is expanding, it needs to be rendered first so the | 699 // If the grid is expanding, it needs to be rendered first so the |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 tile.scrollTop; | 1098 tile.scrollTop; |
1102 tile.classList.remove(className); | 1099 tile.classList.remove(className); |
1103 } | 1100 } |
1104 } | 1101 } |
1105 | 1102 |
1106 return { | 1103 return { |
1107 Tile: Tile, | 1104 Tile: Tile, |
1108 TilePage: TilePage, | 1105 TilePage: TilePage, |
1109 }; | 1106 }; |
1110 }); | 1107 }); |
OLD | NEW |