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 // 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 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 // leftMargin centers the grid within the avaiable space. | 812 // leftMargin centers the grid within the avaiable space. |
813 var minMargin = wide ? MIN_WIDE_MARGIN : 0; | 813 var minMargin = wide ? MIN_WIDE_MARGIN : 0; |
814 var leftMargin = | 814 var leftMargin = |
815 Math.max(minMargin, | 815 Math.max(minMargin, |
816 (this.tileGrid_.clientWidth - effectiveGridWidth) / 2); | 816 (this.tileGrid_.clientWidth - effectiveGridWidth) / 2); |
817 | 817 |
818 var rowHeight = this.heightForWidth(realTileValues.tileWidth) + | 818 var rowHeight = this.heightForWidth(realTileValues.tileWidth) + |
819 realTileValues.interTileSpacing; | 819 realTileValues.interTileSpacing; |
820 | 820 |
821 this.layoutValues_ = { | 821 this.layoutValues_ = { |
822 colWidth: realTileValues.offsetX, | |
823 gridWidth: effectiveGridWidth, | |
824 leftMargin: leftMargin, | |
822 numRowTiles: numRowTiles, | 825 numRowTiles: numRowTiles, |
823 leftMargin: leftMargin, | |
824 colWidth: realTileValues.offsetX, | |
825 rowHeight: rowHeight, | 826 rowHeight: rowHeight, |
826 tileWidth: realTileValues.tileWidth, | 827 tileWidth: realTileValues.tileWidth, |
827 wide: wide, | 828 wide: wide, |
828 }; | 829 }; |
829 | 830 |
830 // We need to update the top margin as well. | 831 // We need to update the top margin as well. |
831 this.updateTopMargin_(); | 832 this.updateTopMargin_(); |
832 | 833 |
833 this.firePageLayoutEvent_(); | 834 this.firePageLayoutEvent_(); |
834 }, | 835 }, |
835 | 836 |
836 /** | 837 /** |
837 * Dispatches the custom pagelayout event. | 838 * Dispatches the custom pagelayout event. |
838 * @private | 839 * @private |
839 */ | 840 */ |
840 firePageLayoutEvent_: function() { | 841 firePageLayoutEvent_: function() { |
841 cr.dispatchSimpleEvent(this, 'pagelayout', true, true); | 842 cr.dispatchSimpleEvent(this, 'pagelayout', true, true); |
842 }, | 843 }, |
843 | 844 |
844 /** | 845 /** |
846 * @return {number} The animated left margin for the current layout. | |
Evan Stade
2012/07/23 21:51:15
needs better English description of "animated left
Dan Beam
2012/07/24 00:52:56
Done.
| |
847 */ | |
848 getAnimatedLeftMargin_: function() { | |
849 if (this.layoutValues_.wide) | |
850 return 0; | |
851 | |
852 var grid = this.gridValues_; | |
853 return (grid.minWideWidth - MIN_WIDE_MARGIN - grid.narrowWidth) / 2; | |
854 }, | |
855 | |
856 /** | |
845 * Calculates the x/y coordinates for an element and moves it there. | 857 * Calculates the x/y coordinates for an element and moves it there. |
846 * @param {number} index The index of the element to be positioned. | 858 * @param {number} index The index of the element to be positioned. |
847 * @param {number} indexOffset If provided, this is added to |index| when | 859 * @param {number} indexOffset If provided, this is added to |index| when |
848 * positioning the tile. The effect is that the tile will be positioned | 860 * positioning the tile. The effect is that the tile will be positioned |
849 * in a non-default location. | 861 * in a non-default location. |
850 * @private | 862 * @private |
851 */ | 863 */ |
852 positionTile_: function(index, indexOffset) { | 864 positionTile_: function(index, indexOffset) { |
853 var grid = this.gridValues_; | 865 var grid = this.gridValues_; |
854 var layout = this.layoutValues_; | 866 var layout = this.layoutValues_; |
855 | 867 |
856 indexOffset = typeof indexOffset != 'undefined' ? indexOffset : 0; | 868 indexOffset = typeof indexOffset != 'undefined' ? indexOffset : 0; |
857 // Add the offset _after_ the modulus division. We might want to show the | 869 // Add the offset _after_ the modulus division. We might want to show the |
858 // tile off the side of the grid. | 870 // tile off the side of the grid. |
859 var col = index % layout.numRowTiles + indexOffset; | 871 var col = index % layout.numRowTiles + indexOffset; |
860 var row = Math.floor(index / layout.numRowTiles); | 872 var row = Math.floor(index / layout.numRowTiles); |
861 // Calculate the final on-screen position for the tile. | 873 // Calculate the final on-screen position for the tile. |
862 var realX = col * layout.colWidth + layout.leftMargin; | 874 var realX = col * layout.colWidth + layout.leftMargin; |
863 var realY = row * layout.rowHeight; | 875 var realY = row * layout.rowHeight; |
864 | 876 |
865 // Calculate the portion of the tile's position that should be animated. | 877 // Calculate the portion of the tile's position that should be animated. |
866 var animatedTileValues = layout.wide ? | 878 var animatedTileValues = layout.wide ? |
867 grid.wideTileValues : grid.narrowTileValues; | 879 grid.wideTileValues : grid.narrowTileValues; |
868 // Animate the difference between three-wide and six-wide. | 880 // Animate the difference between three-wide and six-wide. |
869 var animatedLeftMargin = layout.wide ? | 881 var animatedLeftMargin = this.getAnimatedLeftMargin_(); |
870 0 : (grid.minWideWidth - MIN_WIDE_MARGIN - grid.narrowWidth) / 2; | |
871 var animatedX = col * animatedTileValues.offsetX + animatedLeftMargin; | 882 var animatedX = col * animatedTileValues.offsetX + animatedLeftMargin; |
872 var animatedY = row * (this.heightForWidth(animatedTileValues.tileWidth) + | 883 var animatedY = row * (this.heightForWidth(animatedTileValues.tileWidth) + |
873 animatedTileValues.interTileSpacing); | 884 animatedTileValues.interTileSpacing); |
874 | 885 |
875 var tile = this.tileElements_[index]; | 886 var tile = this.tileElements_[index]; |
876 tile.setGridPosition(animatedX, animatedY); | 887 tile.setGridPosition(animatedX, animatedY); |
877 tile.firstChild.setBounds(layout.tileWidth, | 888 tile.firstChild.setBounds(layout.tileWidth, |
878 realX - animatedX, | 889 realX - animatedX, |
879 realY - animatedY); | 890 realY - animatedY); |
880 | 891 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 this.topMarginIsForWide_ = layout.wide; | 1025 this.topMarginIsForWide_ = layout.wide; |
1015 this.topMarginPx_ = newMargin; | 1026 this.topMarginPx_ = newMargin; |
1016 this.topMargin_.style.marginTop = | 1027 this.topMargin_.style.marginTop = |
1017 toCssPx(this.topMarginPx_ - this.animatedTopMarginPx_); | 1028 toCssPx(this.topMarginPx_ - this.animatedTopMarginPx_); |
1018 }, | 1029 }, |
1019 | 1030 |
1020 /** | 1031 /** |
1021 * Position the notification if there's one showing. | 1032 * Position the notification if there's one showing. |
1022 */ | 1033 */ |
1023 positionNotification_: function() { | 1034 positionNotification_: function() { |
1024 if (this.notification && !this.notification.hidden) { | 1035 var notification = this.notification; |
1025 this.notification.style.margin = | 1036 if (!notification || notification.hidden) |
1026 -this.notification.offsetHeight + 'px ' + | 1037 return; |
1027 this.layoutValues_.leftMargin + 'px 0'; | 1038 |
1028 } | 1039 // Update the top position. |
1040 notification.style.marginTop = -notification.offsetHeight + 'px'; | |
1041 | |
1042 // Update the horizontal position. | |
1043 var animatedLeftMargin = this.getAnimatedLeftMargin_(); | |
1044 notification.style.WebkitMarginStart = animatedLeftMargin + 'px'; | |
1045 var leftOffset = (this.layoutValues_.leftMargin - animatedLeftMargin) * | |
1046 (isRTL() ? -1 : 1); | |
1047 notification.style.WebkitTransform = 'translateX(' + leftOffset + 'px)'; | |
1048 | |
1049 // Update the allowable widths of the text. | |
1050 var buttonWidth = notification.querySelector('button').offsetWidth + 8; | |
1051 notification.querySelector('span').style.maxWidth = | |
1052 this.layoutValues_.gridWidth - buttonWidth + 'px'; | |
1053 | |
1054 // This makes sure the text doesn't condense smaller than the narrow size | |
1055 // of the grid (e.g. when a user makes the window really small). | |
1056 notification.style.minWidth = | |
1057 this.gridValues_.narrowWidth - buttonWidth + 'px'; | |
1029 }, | 1058 }, |
1030 | 1059 |
1031 /** | 1060 /** |
1032 * Handles final setup that can only happen after |this| is inserted into | 1061 * Handles final setup that can only happen after |this| is inserted into |
1033 * the page. | 1062 * the page. |
1034 * @private | 1063 * @private |
1035 */ | 1064 */ |
1036 onNodeInsertedIntoDocument_: function(e) { | 1065 onNodeInsertedIntoDocument_: function(e) { |
1037 this.calculateLayoutValues_(); | 1066 this.calculateLayoutValues_(); |
1038 this.heightChanged_(); | 1067 this.heightChanged_(); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1338 assert(false); | 1367 assert(false); |
1339 }, | 1368 }, |
1340 }; | 1369 }; |
1341 | 1370 |
1342 return { | 1371 return { |
1343 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1372 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
1344 setCurrentDropEffect: setCurrentDropEffect, | 1373 setCurrentDropEffect: setCurrentDropEffect, |
1345 TilePage: TilePage, | 1374 TilePage: TilePage, |
1346 }; | 1375 }; |
1347 }); | 1376 }); |
OLD | NEW |