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

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

Issue 7951011: Moving where I'm doing dropEffect normalization. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: code review changes from conversation with estade over chat Created 9 years, 3 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/nav_dot.js ('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;
11 function getCurrentlyDraggingTile() { 11 function getCurrentlyDraggingTile() {
12 return currentlyDraggingTile; 12 return currentlyDraggingTile;
13 } 13 }
14 function setCurrentlyDraggingTile(tile) { 14 function setCurrentlyDraggingTile(tile) {
15 currentlyDraggingTile = tile; 15 currentlyDraggingTile = tile;
16 if (tile) 16 if (tile)
17 ntp4.enterRearrangeMode(); 17 ntp4.enterRearrangeMode();
18 else 18 else
19 ntp4.leaveRearrangeMode(); 19 ntp4.leaveRearrangeMode();
20 } 20 }
csilv 2011/09/20 19:05:34 Add a linefeed here.
Dan Beam 2011/09/20 23:00:21 Done.
21 function setCurrentDropEffect(dataTransfer, effect) {
22 dataTransfer.dropEffect = effect;
23 if (currentlyDraggingTile)
24 currentlyDraggingTile.lastDropEffect = dataTransfer.dropEffect;
Evan Stade 2011/09/21 21:58:29 = effect
Dan Beam 2011/09/21 23:28:38 I did this to filter out bad values. Do you not w
Evan Stade 2011/09/21 23:56:27 oh right, you said that before. I never deleted my
25 }
21 26
22 /** 27 /**
23 * Creates a new Tile object. Tiles wrap content on a TilePage, providing 28 * Creates a new Tile object. Tiles wrap content on a TilePage, providing
24 * some styling and drag functionality. 29 * some styling and drag functionality.
25 * @constructor 30 * @constructor
26 * @extends {HTMLDivElement} 31 * @extends {HTMLDivElement}
27 */ 32 */
28 function Tile(contents) { 33 function Tile(contents) {
29 var tile = cr.doc.createElement('div'); 34 var tile = cr.doc.createElement('div');
30 tile.__proto__ = Tile.prototype; 35 tile.__proto__ = Tile.prototype;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 var tilePage = this.tilePage; 159 var tilePage = this.tilePage;
155 if (tilePage) 160 if (tilePage)
156 tilePage.positionTile_(this.index); 161 tilePage.positionTile_(this.index);
157 162
158 // Take an appropriate action with the drag clone. 163 // Take an appropriate action with the drag clone.
159 if (this.landedOnTrash) { 164 if (this.landedOnTrash) {
160 this.dragClone.classList.add('deleting'); 165 this.dragClone.classList.add('deleting');
161 } else if (tilePage) { 166 } else if (tilePage) {
162 // TODO(dbeam): Until we fix dropEffect to the correct behavior it will 167 // TODO(dbeam): Until we fix dropEffect to the correct behavior it will
163 // differ on windows - crbug.com/39399. That's why we use the custom 168 // differ on windows - crbug.com/39399. That's why we use the custom
164 // tilePage.lastDropEffect_ instead of e.dataTransfer.dropEffect. 169 // this.lastDropEffect instead of e.dataTransfer.dropEffect.
165 if (tilePage.selected && tilePage.lastDropEffect_ != 'copy') { 170 if (tilePage.selected && this.lastDropEffect != 'copy') {
166 // The drag clone can still be hidden from the last drag move event. 171 // The drag clone can still be hidden from the last drag move event.
167 this.dragClone.hidden = false; 172 this.dragClone.hidden = false;
168 // The tile's contents may have moved following the respositioning; 173 // The tile's contents may have moved following the respositioning;
169 // adjust for that. 174 // adjust for that.
170 var contentDiffX = this.dragClone.firstChild.offsetLeft - 175 var contentDiffX = this.dragClone.firstChild.offsetLeft -
171 this.firstChild.offsetLeft; 176 this.firstChild.offsetLeft;
172 var contentDiffY = this.dragClone.firstChild.offsetTop - 177 var contentDiffY = this.dragClone.firstChild.offsetTop -
173 this.firstChild.offsetTop; 178 this.firstChild.offsetTop;
174 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft - 179 this.dragClone.style.left = (this.gridX + this.parentNode.offsetLeft -
175 contentDiffX) + 'px'; 180 contentDiffX) + 'px';
176 this.dragClone.style.top = 181 this.dragClone.style.top =
177 (this.gridY + this.parentNode.getBoundingClientRect().top - 182 (this.gridY + this.parentNode.getBoundingClientRect().top -
178 contentDiffY) + 'px'; 183 contentDiffY) + 'px';
179 } else if (this.dragClone.hidden) { 184 } else if (this.dragClone.hidden) {
180 this.finalizeDrag_(); 185 this.finalizeDrag_();
181 } else { 186 } else {
182 this.dragClone.classList.add('dropped-on-other-page'); 187 this.dragClone.classList.add('dropped-on-other-page');
183 } 188 }
184 } 189 }
185 190
191 delete this.lastDropEffect;
186 this.landedOnTrash = false; 192 this.landedOnTrash = false;
187 }, 193 },
188 194
189 /** 195 /**
190 * Creates a clone of this node offset by the coordinates. Used for the 196 * Creates a clone of this node offset by the coordinates. Used for the
191 * dragging effect where a tile appears to float off one side of the grid 197 * dragging effect where a tile appears to float off one side of the grid
192 * and re-appear on the other. 198 * and re-appear on the other.
193 * @param {number} x x-axis offset, in pixels. 199 * @param {number} x x-axis offset, in pixels.
194 * @param {number} y y-axis offset, in pixels. 200 * @param {number} y y-axis offset, in pixels.
195 */ 201 */
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 * @param {Event} e A mouseover event for the drag over. 933 * @param {Event} e A mouseover event for the drag over.
928 */ 934 */
929 doDragOver: function(e) { 935 doDragOver: function(e) {
930 e.preventDefault(); 936 e.preventDefault();
931 937
932 this.setDropEffect(e.dataTransfer); 938 this.setDropEffect(e.dataTransfer);
933 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); 939 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY);
934 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) 940 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length)
935 newDragIndex = this.dragItemIndex_; 941 newDragIndex = this.dragItemIndex_;
936 this.updateDropIndicator_(newDragIndex); 942 this.updateDropIndicator_(newDragIndex);
937
938 this.lastDropEffect_ = e.dataTransfer.dropEffect;
939 }, 943 },
940 944
941 /** 945 /**
942 * Performs all actions necessary when the user completes a drop. 946 * Performs all actions necessary when the user completes a drop.
943 * @param {Event} e A mouseover event for the drag drop. 947 * @param {Event} e A mouseover event for the drag drop.
944 */ 948 */
945 doDrop: function(e) { 949 doDrop: function(e) {
946 e.stopPropagation(); 950 e.stopPropagation();
947 951
948 var index = this.currentDropIndex_; 952 var index = this.currentDropIndex_;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 * 'copy'). 1071 * 'copy').
1068 * @param {Object} dataTransfer The drag event dataTransfer object. 1072 * @param {Object} dataTransfer The drag event dataTransfer object.
1069 */ 1073 */
1070 setDropEffect: function(dataTransfer) { 1074 setDropEffect: function(dataTransfer) {
1071 assert(false); 1075 assert(false);
1072 }, 1076 },
1073 }; 1077 };
1074 1078
1075 return { 1079 return {
1076 getCurrentlyDraggingTile: getCurrentlyDraggingTile, 1080 getCurrentlyDraggingTile: getCurrentlyDraggingTile,
1081 setCurrentDropEffect: setCurrentDropEffect,
1077 TilePage: TilePage, 1082 TilePage: TilePage,
1078 }; 1083 };
1079 }); 1084 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/nav_dot.js ('k') | chrome/browser/resources/ntp4/trash.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698