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')) |
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; | |
414 var y = coordinates.y; | |
415 | |
416 var w = this.dimensions.width; | 413 var w = this.dimensions.width; |
417 var h = this.dimensions.height; | 414 var h = this.dimensions.height; |
418 | 415 |
419 var availableWidth = this.dragContainer.offsetWidth; | 416 var availableWidth = this.dragContainer.offsetWidth; |
420 | 417 |
421 var row = Math.floor(y / h); | 418 var row = Math.floor(coordinates.y / h); |
422 var col = Math.floor(x / w); | 419 var col = Math.floor(coordinates.x / w); |
423 var index = Math.floor(availableWidth / w) * row + col; | 420 var index = Math.floor(availableWidth / w) * row + col; |
424 | 421 |
| 422 var appCount = this.data.length; |
| 423 var cols = MAX_APPS_PER_ROW[layoutMode]; |
| 424 var rows = Math.ceil(appCount / cols); |
| 425 |
| 426 // Rather than making the free space on the last row invalid, we |
| 427 // map it to the last valid position. |
| 428 if (index >= appCount && index < cols * rows) |
| 429 return appCount-1; |
| 430 |
425 return index; | 431 return index; |
426 }, | 432 }, |
427 | 433 |
428 saveDrag: function() { | 434 saveDrag: function() { |
429 this.invalidate_(); | 435 this.invalidate_(); |
430 this.layout(); | 436 this.layout(); |
431 | 437 |
432 var appIds = this.data.filter(function(id) { | 438 var appIds = this.data.filter(function(id) { |
433 return id != 'web-store-entry'; | 439 return id != 'web-store-entry'; |
434 }); | 440 }); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 a.href = localStrings.getString('web_store_url'); | 608 a.href = localStrings.getString('web_store_url'); |
603 a.style.backgroundImage = url('chrome://theme/IDR_PRODUCT_LOGO_16'); | 609 a.style.backgroundImage = url('chrome://theme/IDR_PRODUCT_LOGO_16'); |
604 a.className = 'item'; | 610 a.className = 'item'; |
605 return a; | 611 return a; |
606 } | 612 } |
607 }; | 613 }; |
608 })(); | 614 })(); |
609 | 615 |
610 // Enable drag and drop reordering of the app launcher. | 616 // Enable drag and drop reordering of the app launcher. |
611 var appDragAndDrop = new DragAndDropController(apps); | 617 var appDragAndDrop = new DragAndDropController(apps); |
OLD | NEW |