Chromium Code Reviews| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 312 |
| 313 // The proportion of the tile width which will be used as spacing between | 313 // The proportion of the tile width which will be used as spacing between |
| 314 // tiles. | 314 // tiles. |
| 315 var TILE_SPACING_FRACTION = 1 / 8; | 315 var TILE_SPACING_FRACTION = 1 / 8; |
| 316 | 316 |
| 317 // The smallest amount of horizontal blank space to display on the sides when | 317 // The smallest amount of horizontal blank space to display on the sides when |
| 318 // displaying a wide arrangement. There is an additional 26px of margin from | 318 // displaying a wide arrangement. There is an additional 26px of margin from |
| 319 // the tile page padding. | 319 // the tile page padding. |
| 320 var MIN_WIDE_MARGIN = 18; | 320 var MIN_WIDE_MARGIN = 18; |
| 321 | 321 |
| 322 // Extra space to allow at the bottom of a tilegrid when setting the | |
| 323 // min-height property. This is a bit of a hack to allow pages to insert | |
| 324 // small content at the bottom. | |
| 325 // TODO(csilv): Remove the need for this. | |
| 326 var TILE_GRID_EXTRA_PADDING = 40; | |
|
Evan Stade
2011/09/05 01:59:20
can you do this as a function on TilePage which ch
csilv
2011/09/06 05:33:33
Done.
| |
| 327 | |
| 322 /** | 328 /** |
| 323 * Creates a new TilePage object. This object contains tiles and controls | 329 * Creates a new TilePage object. This object contains tiles and controls |
| 324 * their layout. | 330 * their layout. |
| 325 * @param {Object} gridValues Pixel values that define the size and layout | 331 * @param {Object} gridValues Pixel values that define the size and layout |
| 326 * of the tile grid. | 332 * of the tile grid. |
| 327 * @constructor | 333 * @constructor |
| 328 * @extends {HTMLDivElement} | 334 * @extends {HTMLDivElement} |
| 329 */ | 335 */ |
| 330 function TilePage(gridValues) { | 336 function TilePage(gridValues) { |
| 331 var el = cr.doc.createElement('div'); | 337 var el = cr.doc.createElement('div'); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 if (animate) | 485 if (animate) |
| 480 tileElement.classList.add('new-tile-contents'); | 486 tileElement.classList.add('new-tile-contents'); |
| 481 var wrapperDiv = new Tile(tileElement); | 487 var wrapperDiv = new Tile(tileElement); |
| 482 if (index == this.tileElements_.length) { | 488 if (index == this.tileElements_.length) { |
| 483 this.tileGrid_.appendChild(wrapperDiv); | 489 this.tileGrid_.appendChild(wrapperDiv); |
| 484 } else { | 490 } else { |
| 485 this.tileGrid_.insertBefore(wrapperDiv, | 491 this.tileGrid_.insertBefore(wrapperDiv, |
| 486 this.tileElements_[index]); | 492 this.tileElements_[index]); |
| 487 } | 493 } |
| 488 this.calculateLayoutValues_(); | 494 this.calculateLayoutValues_(); |
| 495 this.heightChanged_(); | |
| 489 | 496 |
| 490 this.positionTile_(index); | 497 this.positionTile_(index); |
| 491 }, | 498 }, |
| 492 | 499 |
| 493 /** | 500 /** |
| 494 * Removes the given tile and animates the respositioning of the other | 501 * Removes the given tile and animates the respositioning of the other |
| 495 * tiles. | 502 * tiles. |
| 496 * @param {HTMLElement} tile The tile to remove from |tileGrid_|. | 503 * @param {HTMLElement} tile The tile to remove from |tileGrid_|. |
| 497 * @param {?boolean} animate If true, tiles will animate. | 504 * @param {?boolean} animate If true, tiles will animate. |
| 498 */ | 505 */ |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 * Called when the height of |this| has changed: update the size of | 755 * Called when the height of |this| has changed: update the size of |
| 749 * tileGrid. | 756 * tileGrid. |
| 750 * @private | 757 * @private |
| 751 */ | 758 */ |
| 752 heightChanged_: function() { | 759 heightChanged_: function() { |
| 753 // The tile grid will expand to the bottom footer, or enough to hold all | 760 // The tile grid will expand to the bottom footer, or enough to hold all |
| 754 // the tiles, whichever is greater. It would be nicer if tilePage were | 761 // the tiles, whichever is greater. It would be nicer if tilePage were |
| 755 // a flex box, and the tile grid could be box-flex: 1, but this exposes a | 762 // a flex box, and the tile grid could be box-flex: 1, but this exposes a |
| 756 // bug where repositioning tiles will cause the scroll position to reset. | 763 // bug where repositioning tiles will cause the scroll position to reset. |
| 757 this.tileGrid_.style.minHeight = (this.clientHeight - | 764 this.tileGrid_.style.minHeight = (this.clientHeight - |
| 758 this.tileGrid_.offsetTop) + 'px'; | 765 this.tileGrid_.offsetTop - this.content_.offsetTop - |
| 766 TILE_GRID_EXTRA_PADDING) + 'px'; | |
| 759 }, | 767 }, |
| 760 | 768 |
| 761 /** | 769 /** |
| 762 * Scrolls the page in response to a mousewheel event. | 770 * Scrolls the page in response to a mousewheel event. |
| 763 * @param {Event} e The mousewheel event. | 771 * @param {Event} e The mousewheel event. |
| 764 */ | 772 */ |
| 765 handleMouseWheel: function(e) { | 773 handleMouseWheel: function(e) { |
| 766 this.content_.scrollTop -= e.wheelDeltaY / 3; | 774 this.content_.scrollTop -= e.wheelDeltaY / 3; |
| 767 }, | 775 }, |
| 768 | 776 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 setDropEffect: function(dataTransfer) { | 1049 setDropEffect: function(dataTransfer) { |
| 1042 assert(false); | 1050 assert(false); |
| 1043 }, | 1051 }, |
| 1044 }; | 1052 }; |
| 1045 | 1053 |
| 1046 return { | 1054 return { |
| 1047 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1055 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1048 TilePage: TilePage, | 1056 TilePage: TilePage, |
| 1049 }; | 1057 }; |
| 1050 }); | 1058 }); |
| OLD | NEW |