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

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: most visited polish 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
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.
157 if (this.tilePage)
158 this.tilePage.positionTile_(this.index);
159
160 // Take an appropriate action with the drag clone.
161 if (this.landedOnTrash) {
165 this.dragClone.firstChild.classList.add('deleting'); 162 this.dragClone.firstChild.classList.add('deleting');
166 return; 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 // When we're showing another page and a drag fails or gets cancelled,
178 // the tile shrinks to a dot.
179 this.dragClone.firstChild.style.webkitTransform = 'scale(0)';
Rick Byers 2011/08/08 15:24:15 shouldn't you really leave this presentation detai
Evan Stade 2011/08/08 18:26:58 Done.
180 }
167 } 181 }
168 182
169 this.tilePage.positionTile_(this.index); 183 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 }, 184 },
189 185
190 /** 186 /**
191 * Creates a clone of this node offset by the coordinates. Used for the 187 * 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 188 * dragging effect where a tile appears to float off one side of the grid
193 * and re-appear on the other. 189 * and re-appear on the other.
194 * @param {number} x x-axis offset, in pixels. 190 * @param {number} x x-axis offset, in pixels.
195 * @param {number} y y-axis offset, in pixels. 191 * @param {number} y y-axis offset, in pixels.
196 */ 192 */
197 showDoppleganger: function(x, y) { 193 showDoppleganger: function(x, y) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 */ 239 */
244 finalizeDrag_: function() { 240 finalizeDrag_: function() {
245 assert(this.classList.contains('dragging')); 241 assert(this.classList.contains('dragging'));
246 242
247 var clone = this.dragClone; 243 var clone = this.dragClone;
248 this.dragClone = null; 244 this.dragClone = null;
249 245
250 clone.parentNode.removeChild(clone); 246 clone.parentNode.removeChild(clone);
251 this.eventTracker.remove(clone, 'webkitTransitionEnd'); 247 this.eventTracker.remove(clone, 'webkitTransitionEnd');
252 this.classList.remove('dragging'); 248 this.classList.remove('dragging');
249 if (this.firstChild.finalizeDrag)
250 this.firstChild.finalizeDrag();
253 }, 251 },
254 252
255 /** 253 /**
256 * Called when the drag representation node is done migrating to its final 254 * Called when the drag representation node is done migrating to its final
257 * resting spot. 255 * resting spot.
258 * @param {Event} e The transition end event. 256 * @param {Event} e The transition end event.
259 */ 257 */
260 onDragCloneTransitionEnd_: function(e) { 258 onDragCloneTransitionEnd_: function(e) {
261 if (this.classList.contains('dragging') && 259 if (this.classList.contains('dragging') &&
262 (e.propertyName == 'left' || e.propertyName == 'top' || 260 (e.propertyName == 'left' || e.propertyName == 'top' ||
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 * @private 886 * @private
889 */ 887 */
890 doDrop: function(e) { 888 doDrop: function(e) {
891 e.stopPropagation(); 889 e.stopPropagation();
892 890
893 var index = this.currentDropIndex_; 891 var index = this.currentDropIndex_;
894 // Only change data if this was not a 'null drag'. 892 // Only change data if this was not a 'null drag'.
895 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { 893 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) {
896 var adjustedIndex = this.currentDropIndex_ + 894 var adjustedIndex = this.currentDropIndex_ +
897 (index > this.dragItemIndex_ ? 1 : 0); 895 (index > this.dragItemIndex_ ? 1 : 0);
898 if (currentlyDraggingTile) { 896 if (this.withinPageDrag_) {
899 var originalPage = currentlyDraggingTile.tilePage;
900 this.tileGrid_.insertBefore( 897 this.tileGrid_.insertBefore(
901 currentlyDraggingTile, 898 currentlyDraggingTile,
902 this.tileElements_[adjustedIndex]); 899 this.tileElements_[adjustedIndex]);
900 this.tileMoved(currentlyDraggingTile);
901 } else {
902 this.addDragData(e.dataTransfer, adjustedIndex);
903 currentlyDraggingTile.tilePage.cleanupDrag();
904 }
903 905
904 if (originalPage != this) 906 // Dropping the icon may cause topMargin to change, but changing it
905 originalPage.cleanupDrag(); 907 // now would cause everything to move (annoying), so we leave it
906 this.tileMoved(currentlyDraggingTile); 908 // alone. The top margin will be re-calculated next time the window is
907 909 // 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 } 910 }
916 911
917 this.classList.remove('animating-tile-page'); 912 this.classList.remove('animating-tile-page');
918 this.cleanupDrag(); 913 this.cleanupDrag();
919 }, 914 },
920 915
921 /** 916 /**
922 * Appends the currently dragged tile to the end of the page. Called 917 * 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. 918 * from outside the page, e.g. when dropping on a nav dot.
924 */ 919 */
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 * Checks if a page can accept a drag with the given data. 973 * 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 974 * @param {Event} e The drag event if the drag object. Implementations will
980 * likely want to check |e.dataTransfer|. 975 * likely want to check |e.dataTransfer|.
981 * @return {boolean} True if this page can handle the drag. 976 * @return {boolean} True if this page can handle the drag.
982 */ 977 */
983 shouldAcceptDrag: function(e) { 978 shouldAcceptDrag: function(e) {
984 return false; 979 return false;
985 }, 980 },
986 981
987 /** 982 /**
988 * Called to accept a drag drop. 983 * 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 984 * @param {Object} dataTransfer The data transfer object that holds the drop
990 * data. 985 * data.
991 * @param {number} index The tile index at which the drop occurred. 986 * @param {number} index The tile index at which the drop occurred.
992 */ 987 */
993 addOutsideData: function(dataTransfer, index) { 988 addDragData: function(dataTransfer, index) {
994 // This should not get called unless there is a non-default
995 // implementation.
996 assert(false); 989 assert(false);
997 }, 990 },
998 991
999 /** 992 /**
1000 * Called when a tile has been moved (via dragging). Override this to make 993 * Called when a tile has been moved (via dragging). Override this to make
1001 * backend updates. 994 * backend updates.
1002 * @param {Node} draggedTile The tile that was dropped. 995 * @param {Node} draggedTile The tile that was dropped.
1003 */ 996 */
1004 tileMoved: function(draggedTile) { 997 tileMoved: function(draggedTile) {
1005 }, 998 },
1006 }; 999 };
1007 1000
1008 return { 1001 return {
1009 getCurrentlyDraggingTile: getCurrentlyDraggingTile, 1002 getCurrentlyDraggingTile: getCurrentlyDraggingTile,
1010 TilePage: TilePage, 1003 TilePage: TilePage,
1011 }; 1004 };
1012 }); 1005 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698