| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // the tile page padding. | 352 // the tile page padding. |
| 353 var MIN_WIDE_MARGIN = 18; | 353 var MIN_WIDE_MARGIN = 18; |
| 354 | 354 |
| 355 /** | 355 /** |
| 356 * Creates a new TilePage object. This object contains tiles and controls | 356 * Creates a new TilePage object. This object contains tiles and controls |
| 357 * their layout. | 357 * their layout. |
| 358 * @param {Object} gridValues Pixel values that define the size and layout | 358 * @param {Object} gridValues Pixel values that define the size and layout |
| 359 * of the tile grid. | 359 * of the tile grid. |
| 360 * @constructor | 360 * @constructor |
| 361 * @extends {HTMLDivElement} | 361 * @extends {HTMLDivElement} |
| 362 * @implements {cr.ui.DragWrapperDelegate} |
| 362 */ | 363 */ |
| 363 function TilePage(gridValues) { | 364 function TilePage(gridValues) { |
| 364 var el = cr.doc.createElement('div'); | 365 var el = cr.doc.createElement('div'); |
| 365 el.gridValues_ = gridValues; | 366 el.gridValues_ = gridValues; |
| 366 el.__proto__ = TilePage.prototype; | 367 el.__proto__ = TilePage.prototype; |
| 367 el.initialize(); | 368 el.initialize(); |
| 368 | 369 |
| 369 return el; | 370 return el; |
| 370 } | 371 } |
| 371 | 372 |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 heightForWidth: function(width) { | 1139 heightForWidth: function(width) { |
| 1139 return width; | 1140 return width; |
| 1140 }, | 1141 }, |
| 1141 | 1142 |
| 1142 /** Dragging **/ | 1143 /** Dragging **/ |
| 1143 | 1144 |
| 1144 get isCurrentDragTarget() { | 1145 get isCurrentDragTarget() { |
| 1145 return this.dragWrapper_.isCurrentDragTarget; | 1146 return this.dragWrapper_.isCurrentDragTarget; |
| 1146 }, | 1147 }, |
| 1147 | 1148 |
| 1148 /** | 1149 /** @override */ |
| 1149 * Thunk for dragleave events fired on |tileGrid_|. | |
| 1150 * @param {Event} e A MouseEvent for the drag. | |
| 1151 */ | |
| 1152 doDragLeave: function(e) { | 1150 doDragLeave: function(e) { |
| 1153 this.cleanupDrag(); | 1151 this.cleanupDrag(); |
| 1154 }, | 1152 }, |
| 1155 | 1153 |
| 1156 /** | 1154 /** @override */ |
| 1157 * Performs all actions necessary when a drag enters the tile page. | |
| 1158 * @param {Event} e A mouseover event for the drag enter. | |
| 1159 */ | |
| 1160 doDragEnter: function(e) { | 1155 doDragEnter: function(e) { |
| 1161 // Applies the mask so doppleganger tiles disappear into the fog. | 1156 // Applies the mask so doppleganger tiles disappear into the fog. |
| 1162 this.updateMask_(); | 1157 this.updateMask_(); |
| 1163 | 1158 |
| 1164 this.classList.add('animating-tile-page'); | 1159 this.classList.add('animating-tile-page'); |
| 1165 this.withinPageDrag_ = this.contains(currentlyDraggingTile); | 1160 this.withinPageDrag_ = this.contains(currentlyDraggingTile); |
| 1166 this.dragItemIndex_ = this.withinPageDrag_ ? | 1161 this.dragItemIndex_ = this.withinPageDrag_ ? |
| 1167 currentlyDraggingTile.index : this.tileElements_.length; | 1162 currentlyDraggingTile.index : this.tileElements_.length; |
| 1168 this.currentDropIndex_ = this.dragItemIndex_; | 1163 this.currentDropIndex_ = this.dragItemIndex_; |
| 1169 | 1164 |
| 1170 // The new tile may change the number of rows, hence the top margin | 1165 // The new tile may change the number of rows, hence the top margin |
| 1171 // will change. | 1166 // will change. |
| 1172 if (!this.withinPageDrag_) | 1167 if (!this.withinPageDrag_) |
| 1173 this.updateTopMargin_(); | 1168 this.updateTopMargin_(); |
| 1174 | 1169 |
| 1175 this.doDragOver(e); | 1170 this.doDragOver(e); |
| 1176 }, | 1171 }, |
| 1177 | 1172 |
| 1178 /** | 1173 /** @override */ |
| 1179 * Performs all actions necessary when the user moves the cursor during | |
| 1180 * a drag over the tile page. | |
| 1181 * @param {Event} e A mouseover event for the drag over. | |
| 1182 */ | |
| 1183 doDragOver: function(e) { | 1174 doDragOver: function(e) { |
| 1184 e.preventDefault(); | 1175 e.preventDefault(); |
| 1185 | 1176 |
| 1186 this.setDropEffect(e.dataTransfer); | 1177 this.setDropEffect(e.dataTransfer); |
| 1187 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); | 1178 var newDragIndex = this.getWouldBeIndexForPoint_(e.pageX, e.pageY); |
| 1188 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) | 1179 if (newDragIndex < 0 || newDragIndex >= this.tileElements_.length) |
| 1189 newDragIndex = this.dragItemIndex_; | 1180 newDragIndex = this.dragItemIndex_; |
| 1190 this.updateDropIndicator_(newDragIndex); | 1181 this.updateDropIndicator_(newDragIndex); |
| 1191 }, | 1182 }, |
| 1192 | 1183 |
| 1193 /** | 1184 /** @override */ |
| 1194 * Performs all actions necessary when the user completes a drop. | |
| 1195 * @param {Event} e A mouseover event for the drag drop. | |
| 1196 */ | |
| 1197 doDrop: function(e) { | 1185 doDrop: function(e) { |
| 1198 e.stopPropagation(); | 1186 e.stopPropagation(); |
| 1199 e.preventDefault(); | 1187 e.preventDefault(); |
| 1200 | 1188 |
| 1201 var index = this.currentDropIndex_; | 1189 var index = this.currentDropIndex_; |
| 1202 // Only change data if this was not a 'null drag'. | 1190 // Only change data if this was not a 'null drag'. |
| 1203 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { | 1191 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { |
| 1204 var adjustedIndex = this.currentDropIndex_ + | 1192 var adjustedIndex = this.currentDropIndex_ + |
| 1205 (index > this.dragItemIndex_ ? 1 : 0); | 1193 (index > this.dragItemIndex_ ? 1 : 0); |
| 1206 if (this.withinPageDrag_) { | 1194 if (this.withinPageDrag_) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 }; | 1315 }; |
| 1328 | 1316 |
| 1329 return { | 1317 return { |
| 1330 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1318 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1331 setCurrentDropEffect: setCurrentDropEffect, | 1319 setCurrentDropEffect: setCurrentDropEffect, |
| 1332 // Not used outside, just for usage in JSDoc inside this file. | 1320 // Not used outside, just for usage in JSDoc inside this file. |
| 1333 Tile: Tile, | 1321 Tile: Tile, |
| 1334 TilePage: TilePage, | 1322 TilePage: TilePage, |
| 1335 }; | 1323 }; |
| 1336 }); | 1324 }); |
| OLD | NEW |