OLD | NEW |
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 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 * Returns a pointer to the context menu for this app. All apps share the | 320 * Returns a pointer to the context menu for this app. All apps share the |
321 * singleton AppContextMenu. This function is called by the | 321 * singleton AppContextMenu. This function is called by the |
322 * ContextMenuHandler in response to the 'contextmenu' event. | 322 * ContextMenuHandler in response to the 'contextmenu' event. |
323 * @type {cr.ui.Menu} | 323 * @type {cr.ui.Menu} |
324 */ | 324 */ |
325 get contextMenu() { | 325 get contextMenu() { |
326 var menu = AppContextMenu.getInstance(); | 326 var menu = AppContextMenu.getInstance(); |
327 menu.setupForApp(this); | 327 menu.setupForApp(this); |
328 return menu.menu; | 328 return menu.menu; |
329 }, | 329 }, |
| 330 |
| 331 /** |
| 332 * Returns whether this element can be 'removed' from chrome (i.e. whether |
| 333 * the user can drag it onto the trash and expect something to happen). |
| 334 * @return {boolean} True if the app can be uninstalled. |
| 335 */ |
| 336 canBeRemoved: function() { |
| 337 return this.appData_.can_uninstall; |
| 338 }, |
| 339 |
| 340 /** |
| 341 * Uninstalls the app after it's been dropped on the trash. |
| 342 */ |
| 343 removeFromChrome: function() { |
| 344 chrome.send('uninstallApp', [this.appData_.id, true]); |
| 345 |
| 346 var tile = this.parentNode; |
| 347 tile.tilePage.cleanupDrag(); |
| 348 tile.parentNode.removeChild(tile); |
| 349 }, |
330 }; | 350 }; |
331 | 351 |
332 var TilePage = ntp4.TilePage; | 352 var TilePage = ntp4.TilePage; |
333 | 353 |
334 // The fraction of the app tile size that the icon uses. | 354 // The fraction of the app tile size that the icon uses. |
335 var APP_IMG_SIZE_FRACTION = 4 / 5; | 355 var APP_IMG_SIZE_FRACTION = 4 / 5; |
336 | 356 |
337 var appsPageGridValues = { | 357 var appsPageGridValues = { |
338 // The fewest tiles we will show in a row. | 358 // The fewest tiles we will show in a row. |
339 minColCount: 3, | 359 minColCount: 3, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 this.appendTile(new App(appData), animate); | 397 this.appendTile(new App(appData), animate); |
378 }, | 398 }, |
379 | 399 |
380 /** @inheritDoc */ | 400 /** @inheritDoc */ |
381 shouldAcceptDrag: function(e) { | 401 shouldAcceptDrag: function(e) { |
382 return ntp4.getCurrentlyDraggingTile() || | 402 return ntp4.getCurrentlyDraggingTile() || |
383 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); | 403 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); |
384 }, | 404 }, |
385 | 405 |
386 /** @inheritDoc */ | 406 /** @inheritDoc */ |
387 addOutsideData: function(dataTransfer, index) { | 407 addDragData: function(dataTransfer, index) { |
| 408 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); |
| 409 if (currentlyDraggingTile) { |
| 410 var tileContents = currentlyDraggingTile.firstChild; |
| 411 if (tileContents.classList.contains('app')) { |
| 412 this.tileGrid_.insertBefore( |
| 413 currentlyDraggingTile, |
| 414 this.tileElements_[index]); |
| 415 this.tileMoved(currentlyDraggingTile); |
| 416 } else if (tileContents.classList.contains('most-visited')) { |
| 417 this.generateAppForLink(tileContents.data); |
| 418 } |
| 419 } else { |
| 420 this.addOutsideData_(e.dataTransfer, index); |
| 421 } |
| 422 }, |
| 423 |
| 424 /** |
| 425 * Adds drag data that has been dropped from a source that is not a tile. |
| 426 * @param {Object} dataTransfer The data transfer object that holds drop |
| 427 * data. |
| 428 * @param {number} index The index for the new data. |
| 429 * @private |
| 430 */ |
| 431 addOutsideData_: function(dataTransfer, index) { |
388 var url = dataTransfer.getData('url'); | 432 var url = dataTransfer.getData('url'); |
389 assert(url); | 433 assert(url); |
390 if (!url) | 434 if (!url) |
391 return; | 435 return; |
392 | 436 |
393 // If the dataTransfer has html data, use that html's text contents as the | 437 // If the dataTransfer has html data, use that html's text contents as the |
394 // title of the new link. | 438 // title of the new link. |
395 var html = dataTransfer.getData('text/html'); | 439 var html = dataTransfer.getData('text/html'); |
396 var title; | 440 var title; |
397 if (html) { | 441 if (html) { |
(...skipping 12 matching lines...) Expand all Loading... |
410 if (data.title.length > 45) | 454 if (data.title.length > 45) |
411 data.title = data.title.substring(0,45); | 455 data.title = data.title.substring(0,45); |
412 if (data.title.length == 0) | 456 if (data.title.length == 0) |
413 data.title = data.url; | 457 data.title = data.url; |
414 this.generateAppForLink(data); | 458 this.generateAppForLink(data); |
415 }, | 459 }, |
416 | 460 |
417 /** | 461 /** |
418 * Creates a new crx-less app manifest and installs it. | 462 * Creates a new crx-less app manifest and installs it. |
419 * @param {Object} data The data object describing the link. Must have |url| | 463 * @param {Object} data The data object describing the link. Must have |url| |
420 * and |title| members. | 464 * and |title| members. |
| 465 * TODO(estade): pass along an index. |
421 */ | 466 */ |
422 generateAppForLink: function(data) { | 467 generateAppForLink: function(data) { |
| 468 assert(data.url != undefined); |
| 469 assert(data.title != undefined); |
423 chrome.send('generateAppForLink', [data.url, data.title]); | 470 chrome.send('generateAppForLink', [data.url, data.title]); |
424 }, | 471 }, |
425 | 472 |
426 /** @inheritDoc */ | 473 /** @inheritDoc */ |
427 tileMoved: function(draggedTile) { | 474 tileMoved: function(draggedTile) { |
428 if (!(draggedTile.firstChild instanceof App)) | 475 if (!(draggedTile.firstChild instanceof App)) |
429 return; | 476 return; |
430 | 477 |
431 var pageIndex = ntp4.getAppsPageIndex(this); | 478 var pageIndex = ntp4.getAppsPageIndex(this); |
432 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]); | 479 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]); |
(...skipping 13 matching lines...) Expand all Loading... |
446 var store = document.querySelector('.webstore'); | 493 var store = document.querySelector('.webstore'); |
447 if (store) | 494 if (store) |
448 store.setAppsPromoData(data); | 495 store.setAppsPromoData(data); |
449 }; | 496 }; |
450 | 497 |
451 return { | 498 return { |
452 APP_LAUNCH: APP_LAUNCH, | 499 APP_LAUNCH: APP_LAUNCH, |
453 AppsPage: AppsPage, | 500 AppsPage: AppsPage, |
454 }; | 501 }; |
455 }); | 502 }); |
OLD | NEW |