OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 var MAX_APPS_PER_ROW = []; | 5 var MAX_APPS_PER_ROW = []; |
6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; | 6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; |
7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; | 7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; |
8 | 8 |
9 // The URL prefix used in the app link 'ping' attributes. | 9 // The URL prefix used in the app link 'ping' attributes. |
10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; | 10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 | 360 |
361 return this.dimensions_; | 361 return this.dimensions_; |
362 }, | 362 }, |
363 | 363 |
364 // Gets the item under the mouse event |e|. Returns null if there is no | 364 // Gets the item under the mouse event |e|. Returns null if there is no |
365 // item or if the item is not draggable. | 365 // item or if the item is not draggable. |
366 getItem: function(e) { | 366 getItem: function(e) { |
367 var item = findAncestorByClass(e.target, 'app'); | 367 var item = findAncestorByClass(e.target, 'app'); |
368 | 368 |
369 // You can't drag the web store launcher. | 369 // You can't drag the web store launcher. |
370 if (item.classList.contains('web-store-entry')) | 370 if (!item || item.classList.contains('web-store-entry')) |
Aaron Boodman
2011/01/24 19:22:42
Can the second half of this check happen now? If n
| |
371 return null; | 371 return null; |
372 | 372 |
373 return item; | 373 return item; |
374 }, | 374 }, |
375 | 375 |
376 // Returns true if |coordinates| point to a valid drop location. The | 376 // Returns true if |coordinates| point to a valid drop location. The |
377 // coordinates are relative to the drag container and the object should | 377 // coordinates are relative to the drag container and the object should |
378 // have the 'x' and 'y' properties set. | 378 // have the 'x' and 'y' properties set. |
379 canDropOn: function(coordinates) { | 379 canDropOn: function(coordinates) { |
380 var cols = MAX_APPS_PER_ROW[layoutMode]; | 380 var cols = MAX_APPS_PER_ROW[layoutMode]; |
(...skipping 22 matching lines...) Expand all Loading... | |
403 | 403 |
404 if (current == position || current < 0) | 404 if (current == position || current < 0) |
405 return; | 405 return; |
406 | 406 |
407 arrayMove(this.data, current, position); | 407 arrayMove(this.data, current, position); |
408 this.invalidate_(); | 408 this.invalidate_(); |
409 this.layout(); | 409 this.layout(); |
410 }, | 410 }, |
411 | 411 |
412 getIndexAt_: function(coordinates) { | 412 getIndexAt_: function(coordinates) { |
413 var x = coordinates.x; | 413 // We need to adjust for the page offsets because scrolling the window |
414 var y = coordinates.y; | 414 // actually scrolls the app section. |
415 var x = coordinates.x - window.pageXOffset; | |
416 var y = coordinates.y - window.pageYOffset; | |
415 | 417 |
416 var w = this.dimensions.width; | 418 var w = this.dimensions.width; |
417 var h = this.dimensions.height; | 419 var h = this.dimensions.height; |
418 | 420 |
419 var availableWidth = this.dragContainer.offsetWidth; | 421 var availableWidth = this.dragContainer.offsetWidth; |
420 | 422 |
421 var row = Math.floor(y / h); | 423 var row = Math.floor(y / h); |
422 var col = Math.floor(x / w); | 424 var col = Math.floor(x / w); |
423 var index = Math.floor(availableWidth / w) * row + col; | 425 var index = Math.floor(availableWidth / w) * row + col; |
424 | 426 |
427 var appCount = this.data.length; | |
428 var cols = MAX_APPS_PER_ROW[layoutMode]; | |
429 var rows = Math.ceil(appCount / cols); | |
430 | |
431 // Rather than making the free space on the last row invalid, we | |
432 // map it to the last valid position. | |
433 if (index >= appCount && index < cols * rows) | |
Aaron Boodman
2011/01/24 19:22:42
Cool. This was a good benefit of moving getIndexAt
| |
434 return appCount-1; | |
435 | |
425 return index; | 436 return index; |
426 }, | 437 }, |
427 | 438 |
428 saveDrag: function() { | 439 saveDrag: function() { |
429 this.invalidate_(); | 440 this.invalidate_(); |
430 this.layout(); | 441 this.layout(); |
431 | 442 |
432 var appIds = this.data.filter(function(id) { | 443 var appIds = this.data.filter(function(id) { |
433 return id != 'web-store-entry'; | 444 return id != 'web-store-entry'; |
434 }); | 445 }); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 a.href = localStrings.getString('web_store_url'); | 613 a.href = localStrings.getString('web_store_url'); |
603 a.style.backgroundImage = url('chrome://theme/IDR_PRODUCT_LOGO_16'); | 614 a.style.backgroundImage = url('chrome://theme/IDR_PRODUCT_LOGO_16'); |
604 a.className = 'item'; | 615 a.className = 'item'; |
605 return a; | 616 return a; |
606 } | 617 } |
607 }; | 618 }; |
608 })(); | 619 })(); |
609 | 620 |
610 // Enable drag and drop reordering of the app launcher. | 621 // Enable drag and drop reordering of the app launcher. |
611 var appDragAndDrop = new DragAndDropController(apps); | 622 var appDragAndDrop = new DragAndDropController(apps); |
OLD | NEW |