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

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

Issue 7592001: ntp4: most visited dragging onto apps page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: most visited polish Created 9 years, 4 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
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 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
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 * @return {boolean} True if the app can be uninstalled.
Rick Byers 2011/08/08 15:24:15 Remove - doesn't return anything
Evan Stade 2011/08/08 18:26:58 Done.
343 */
344 removeFromChrome: function() {
345 chrome.send('uninstallApp', [this.appData_.id, true]);
346
347 var tile = this.parentNode;
348 tile.tilePage.cleanupDrag();
349 tile.parentNode.removeChild(tile);
350 },
330 }; 351 };
331 352
332 var TilePage = ntp4.TilePage; 353 var TilePage = ntp4.TilePage;
333 354
334 // The fraction of the app tile size that the icon uses. 355 // The fraction of the app tile size that the icon uses.
335 var APP_IMG_SIZE_FRACTION = 4 / 5; 356 var APP_IMG_SIZE_FRACTION = 4 / 5;
336 357
337 var appsPageGridValues = { 358 var appsPageGridValues = {
338 // The fewest tiles we will show in a row. 359 // The fewest tiles we will show in a row.
339 minColCount: 3, 360 minColCount: 3,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 this.appendTile(new App(appData), animate); 398 this.appendTile(new App(appData), animate);
378 }, 399 },
379 400
380 /** @inheritDoc */ 401 /** @inheritDoc */
381 shouldAcceptDrag: function(e) { 402 shouldAcceptDrag: function(e) {
382 return ntp4.getCurrentlyDraggingTile() || 403 return ntp4.getCurrentlyDraggingTile() ||
383 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); 404 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1);
384 }, 405 },
385 406
386 /** @inheritDoc */ 407 /** @inheritDoc */
387 addOutsideData: function(dataTransfer, index) { 408 addDragData: function(dataTransfer, index) {
409 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile();
410 if (currentlyDraggingTile) {
411 var tileContents = currentlyDraggingTile.firstChild;
412 if (tileContents.classList.contains('app')) {
413 this.tileGrid_.insertBefore(
414 currentlyDraggingTile,
415 this.tileElements_[index]);
416 this.tileMoved(currentlyDraggingTile);
417 } else if (tileContents.classList.contains('most-visited')) {
418 this.generateAppForLink(tileContents.data);
419 }
420 } else {
421 this.addOutsideData_(e.dataTransfer, index);
422 }
423 },
424
425 /**
426 * Adds drag data that has been dropped from a source that is not a tile.
427 * @param {Object} dataTransfer The data transfer object that holds drop
428 * data.
429 * @param {number} index The index for the new data.
430 * @private
431 */
432 addOutsideData_: function(dataTransfer, index) {
388 var url = dataTransfer.getData('url'); 433 var url = dataTransfer.getData('url');
389 assert(url); 434 assert(url);
390 if (!url) 435 if (!url)
391 return; 436 return;
392 437
393 // If the dataTransfer has html data, use that html's text contents as the 438 // If the dataTransfer has html data, use that html's text contents as the
394 // title of the new link. 439 // title of the new link.
395 var html = dataTransfer.getData('text/html'); 440 var html = dataTransfer.getData('text/html');
396 var title; 441 var title;
397 if (html) { 442 if (html) {
(...skipping 12 matching lines...) Expand all
410 if (data.title.length > 45) 455 if (data.title.length > 45)
411 data.title = data.title.substring(0,45); 456 data.title = data.title.substring(0,45);
412 if (data.title.length == 0) 457 if (data.title.length == 0)
413 data.title = data.url; 458 data.title = data.url;
414 this.generateAppForLink(data); 459 this.generateAppForLink(data);
415 }, 460 },
416 461
417 /** 462 /**
418 * Creates a new crx-less app manifest and installs it. 463 * Creates a new crx-less app manifest and installs it.
419 * @param {Object} data The data object describing the link. Must have |url| 464 * @param {Object} data The data object describing the link. Must have |url|
420 * and |title| members. 465 * and |title| members.
466 * TODO(estade): pass along an index.
421 */ 467 */
422 generateAppForLink: function(data) { 468 generateAppForLink: function(data) {
469 assert(data.url != undefined);
470 assert(data.title != undefined);
423 chrome.send('generateAppForLink', [data.url, data.title]); 471 chrome.send('generateAppForLink', [data.url, data.title]);
424 }, 472 },
425 473
426 /** @inheritDoc */ 474 /** @inheritDoc */
427 tileMoved: function(draggedTile) { 475 tileMoved: function(draggedTile) {
428 if (!(draggedTile.firstChild instanceof App)) 476 if (!(draggedTile.firstChild instanceof App))
429 return; 477 return;
430 478
431 var pageIndex = ntp4.getAppsPageIndex(this); 479 var pageIndex = ntp4.getAppsPageIndex(this);
432 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]); 480 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]);
(...skipping 13 matching lines...) Expand all
446 var store = document.querySelector('.webstore'); 494 var store = document.querySelector('.webstore');
447 if (store) 495 if (store)
448 store.setAppsPromoData(data); 496 store.setAppsPromoData(data);
449 }; 497 };
450 498
451 return { 499 return {
452 APP_LAUNCH: APP_LAUNCH, 500 APP_LAUNCH: APP_LAUNCH,
453 AppsPage: AppsPage, 501 AppsPage: AppsPage,
454 }; 502 };
455 }); 503 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698