Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/resources/ntp4/tile_page.js

Issue 7592001: ntp4: most visited dragging onto apps page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/ntp4/tile_page.css ('k') | chrome/browser/resources/ntp4/trash.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 this.style.right = x + 'px'; 83 this.style.right = x + 'px';
84 this.style.top = y + 'px'; 84 this.style.top = y + 'px';
85 }, 85 },
86 86
87 /** 87 /**
88 * The handler for dragstart events fired on |this|. 88 * The handler for dragstart events fired on |this|.
89 * @param {Event} e The event for the drag. 89 * @param {Event} e The event for the drag.
90 * @private 90 * @private
91 */ 91 */
92 onDragStart_: function(e) { 92 onDragStart_: function(e) {
93 // TODO(estade): most visited dragging is disabled for now, remove this
94 // when it does something useful.
95 if (this.querySelector('.most-visited')) {
96 e.preventDefault();
97 e.stopPropagation();
98 return;
99 }
100
101 // The user may start dragging again during a previous drag's finishing 93 // The user may start dragging again during a previous drag's finishing
102 // animation. 94 // animation.
103 if (this.classList.contains('dragging')) 95 if (this.classList.contains('dragging'))
104 this.finalizeDrag_(); 96 this.finalizeDrag_();
105 97
106 setCurrentlyDraggingTile(this); 98 setCurrentlyDraggingTile(this);
107 99
108 e.dataTransfer.effectAllowed = 'copyMove'; 100 e.dataTransfer.effectAllowed = 'copyMove';
109 // TODO(estade): fill this in. 101 // TODO(estade): fill this in.
110 e.dataTransfer.setData('text/plain', 'foo'); 102 e.dataTransfer.setData('text/plain', 'foo');
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 * @param {Event} e The event for the drag. 146 * @param {Event} e The event for the drag.
155 * @private 147 * @private
156 */ 148 */
157 onDragEnd_: function(e) { 149 onDragEnd_: function(e) {
158 // The drag clone can still be hidden from the last drag move event. 150 // The drag clone can still be hidden from the last drag move event.
159 this.dragClone.classList.remove('hidden'); 151 this.dragClone.classList.remove('hidden');
160 this.dragClone.classList.add('placing'); 152 this.dragClone.classList.add('placing');
161 153
162 setCurrentlyDraggingTile(null); 154 setCurrentlyDraggingTile(null);
163 155
164 if (!this.tilePage) { 156 // tilePage will be null if we've already been removed.
165 this.dragClone.firstChild.classList.add('deleting'); 157 if (this.tilePage)
166 return; 158 this.tilePage.positionTile_(this.index);
159
160 // Take an appropriate action with the drag clone.
161 if (this.landedOnTrash) {
162 this.dragClone.classList.add('deleting');
163 } else if (this.tilePage) {
164 if (this.tilePage.selected) {
165 // The tile's contents may have moved following the respositioning;
166 // adjust for that.
167 var contentDiffX = this.dragClone.firstChild.offsetLeft -
168 this.firstChild.offsetLeft;
169 var contentDiffY = this.dragClone.firstChild.offsetTop -
170 this.firstChild.offsetTop;
171 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft -
172 contentDiffX) + 'px';
173 this.dragClone.style.top =
174 (this.gridY + this.parentNode.getBoundingClientRect().top -
175 contentDiffY) + 'px';
176 } else {
177 this.dragClone.classList.add('dropped-on-other-page');
178 }
167 } 179 }
168 180
169 this.tilePage.positionTile_(this.index); 181 this.landedOnTrash = false;
170
171 if (this.tilePage.selected) {
172 // The tile's contents may have moved following the respositioning;
173 // adjust for that.
174 var contentDiffX = this.dragClone.firstChild.offsetLeft -
175 this.firstChild.offsetLeft;
176 var contentDiffY = this.dragClone.firstChild.offsetTop -
177 this.firstChild.offsetTop;
178 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft -
179 contentDiffX) + 'px';
180 this.dragClone.style.top =
181 (this.gridY + this.parentNode.getBoundingClientRect().top -
182 contentDiffY) + 'px';
183 } else {
184 // When we're showing another page and a drag fails or gets cancelled,
185 // the tile shrinks to a dot.
186 this.dragClone.firstChild.style.webkitTransform = 'scale(0)';
187 }
188 }, 182 },
189 183
190 /** 184 /**
191 * Creates a clone of this node offset by the coordinates. Used for the 185 * Creates a clone of this node offset by the coordinates. Used for the
192 * dragging effect where a tile appears to float off one side of the grid 186 * dragging effect where a tile appears to float off one side of the grid
193 * and re-appear on the other. 187 * and re-appear on the other.
194 * @param {number} x x-axis offset, in pixels. 188 * @param {number} x x-axis offset, in pixels.
195 * @param {number} y y-axis offset, in pixels. 189 * @param {number} y y-axis offset, in pixels.
196 */ 190 */
197 showDoppleganger: function(x, y) { 191 showDoppleganger: function(x, y) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 */ 237 */
244 finalizeDrag_: function() { 238 finalizeDrag_: function() {
245 assert(this.classList.contains('dragging')); 239 assert(this.classList.contains('dragging'));
246 240
247 var clone = this.dragClone; 241 var clone = this.dragClone;
248 this.dragClone = null; 242 this.dragClone = null;
249 243
250 clone.parentNode.removeChild(clone); 244 clone.parentNode.removeChild(clone);
251 this.eventTracker.remove(clone, 'webkitTransitionEnd'); 245 this.eventTracker.remove(clone, 'webkitTransitionEnd');
252 this.classList.remove('dragging'); 246 this.classList.remove('dragging');
247 if (this.firstChild.finalizeDrag)
248 this.firstChild.finalizeDrag();
253 }, 249 },
254 250
255 /** 251 /**
256 * Called when the drag representation node is done migrating to its final 252 * Called when the drag representation node is done migrating to its final
257 * resting spot. 253 * resting spot.
258 * @param {Event} e The transition end event. 254 * @param {Event} e The transition end event.
259 */ 255 */
260 onDragCloneTransitionEnd_: function(e) { 256 onDragCloneTransitionEnd_: function(e) {
261 if (this.classList.contains('dragging') && 257 if (this.classList.contains('dragging') &&
262 (e.propertyName == 'left' || e.propertyName == 'top' || 258 (e.propertyName == 'left' || e.propertyName == 'top' ||
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 * @private 884 * @private
889 */ 885 */
890 doDrop: function(e) { 886 doDrop: function(e) {
891 e.stopPropagation(); 887 e.stopPropagation();
892 888
893 var index = this.currentDropIndex_; 889 var index = this.currentDropIndex_;
894 // Only change data if this was not a 'null drag'. 890 // Only change data if this was not a 'null drag'.
895 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { 891 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) {
896 var adjustedIndex = this.currentDropIndex_ + 892 var adjustedIndex = this.currentDropIndex_ +
897 (index > this.dragItemIndex_ ? 1 : 0); 893 (index > this.dragItemIndex_ ? 1 : 0);
898 if (currentlyDraggingTile) { 894 if (this.withinPageDrag_) {
899 var originalPage = currentlyDraggingTile.tilePage;
900 this.tileGrid_.insertBefore( 895 this.tileGrid_.insertBefore(
901 currentlyDraggingTile, 896 currentlyDraggingTile,
902 this.tileElements_[adjustedIndex]); 897 this.tileElements_[adjustedIndex]);
898 this.tileMoved(currentlyDraggingTile);
899 } else {
900 this.addDragData(e.dataTransfer, adjustedIndex);
901 currentlyDraggingTile.tilePage.cleanupDrag();
902 }
903 903
904 if (originalPage != this) 904 // Dropping the icon may cause topMargin to change, but changing it
905 originalPage.cleanupDrag(); 905 // now would cause everything to move (annoying), so we leave it
906 this.tileMoved(currentlyDraggingTile); 906 // alone. The top margin will be re-calculated next time the window is
907 907 // resized or the page is selected.
908 // Dropping the icon may cause topMargin to change, but changing it
909 // now would cause everything to move (annoying), so we leave it
910 // alone. The top margin will be re-calculated next time the window is
911 // resized or the page is selected.
912 } else {
913 this.addOutsideData(e.dataTransfer, adjustedIndex);
914 }
915 } 908 }
916 909
917 this.classList.remove('animating-tile-page'); 910 this.classList.remove('animating-tile-page');
918 this.cleanupDrag(); 911 this.cleanupDrag();
919 }, 912 },
920 913
921 /** 914 /**
922 * Appends the currently dragged tile to the end of the page. Called 915 * Appends the currently dragged tile to the end of the page. Called
923 * from outside the page, e.g. when dropping on a nav dot. 916 * from outside the page, e.g. when dropping on a nav dot.
924 */ 917 */
925 appendDraggingTile: function() { 918 appendDraggingTile: function() {
926 var originalPage = currentlyDraggingTile.tilePage; 919 var originalPage = currentlyDraggingTile.tilePage;
927 if (originalPage == this) 920 if (originalPage == this)
928 return; 921 return;
929 922
930 this.tileGrid_.appendChild(currentlyDraggingTile); 923 this.addDragData(null, this.tileElements_.length - 1);
931 originalPage.cleanupDrag(); 924 originalPage.cleanupDrag();
932 this.tileMoved(currentlyDraggingTile);
933 }, 925 },
934 926
935 /** 927 /**
936 * Makes sure all the tiles are in the right place after a drag is over. 928 * Makes sure all the tiles are in the right place after a drag is over.
937 * @private 929 * @private
938 */ 930 */
939 cleanupDrag: function() { 931 cleanupDrag: function() {
940 for (var i = 0; i < this.tileElements_.length; i++) { 932 for (var i = 0; i < this.tileElements_.length; i++) {
941 // The current drag tile will be positioned in its dragend handler. 933 // The current drag tile will be positioned in its dragend handler.
942 if (this.tileElements_[i] == currentlyDraggingTile) 934 if (this.tileElements_[i] == currentlyDraggingTile)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 * Checks if a page can accept a drag with the given data. 970 * Checks if a page can accept a drag with the given data.
979 * @param {Event} e The drag event if the drag object. Implementations will 971 * @param {Event} e The drag event if the drag object. Implementations will
980 * likely want to check |e.dataTransfer|. 972 * likely want to check |e.dataTransfer|.
981 * @return {boolean} True if this page can handle the drag. 973 * @return {boolean} True if this page can handle the drag.
982 */ 974 */
983 shouldAcceptDrag: function(e) { 975 shouldAcceptDrag: function(e) {
984 return false; 976 return false;
985 }, 977 },
986 978
987 /** 979 /**
988 * Called to accept a drag drop. 980 * Called to accept a drag drop. Will not be called for in-page drops.
989 * @param {Object} dataTransfer The data transfer object that holds the drop 981 * @param {Object} dataTransfer The data transfer object that holds the drop
990 * data. 982 * data. This should only be used if currentlyDraggingTile is null.
991 * @param {number} index The tile index at which the drop occurred. 983 * @param {number} index The tile index at which the drop occurred.
992 */ 984 */
993 addOutsideData: function(dataTransfer, index) { 985 addDragData: function(dataTransfer, index) {
994 // This should not get called unless there is a non-default
995 // implementation.
996 assert(false); 986 assert(false);
997 }, 987 },
998 988
999 /** 989 /**
1000 * Called when a tile has been moved (via dragging). Override this to make 990 * Called when a tile has been moved (via dragging). Override this to make
1001 * backend updates. 991 * backend updates.
1002 * @param {Node} draggedTile The tile that was dropped. 992 * @param {Node} draggedTile The tile that was dropped.
1003 */ 993 */
1004 tileMoved: function(draggedTile) { 994 tileMoved: function(draggedTile) {
1005 }, 995 },
1006 }; 996 };
1007 997
1008 return { 998 return {
1009 getCurrentlyDraggingTile: getCurrentlyDraggingTile, 999 getCurrentlyDraggingTile: getCurrentlyDraggingTile,
1010 TilePage: TilePage, 1000 TilePage: TilePage,
1011 }; 1001 };
1012 }); 1002 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/tile_page.css ('k') | chrome/browser/resources/ntp4/trash.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698