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

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

Issue 9254023: [NTP4] Track the position of each app that's launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: key board shortcuts fix, misinterpretation of my own class, :/ Created 8 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/most_visited_page.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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('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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 */ 468 */
469 onClick_: function(e) { 469 onClick_: function(e) {
470 var is_promo = this.appsPromoExtras_ && 470 var is_promo = this.appsPromoExtras_ &&
471 window.getComputedStyle(this.appsPromoExtras_).display != 'none'; 471 window.getComputedStyle(this.appsPromoExtras_).display != 'none';
472 var url = !this.appData_.is_webstore ? '' : 472 var url = !this.appData_.is_webstore ? '' :
473 is_promo ? this.appsPromoLink_.href : 473 is_promo ? this.appsPromoLink_.href :
474 appendParam(this.appData_.url, 474 appendParam(this.appData_.url,
475 'utm_source', 475 'utm_source',
476 'chrome-ntp-icon'); 476 'chrome-ntp-icon');
477 477
478 this.recordAppClickIndex_(e.clientX, e.clientY);
478 chrome.send('launchApp', 479 chrome.send('launchApp',
479 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, 480 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url,
480 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); 481 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]);
481 482
482 // Don't allow the click to trigger a link or anything 483 // Don't allow the click to trigger a link or anything
483 e.preventDefault(); 484 e.preventDefault();
484 }, 485 },
485 486
486 /** 487 /**
487 * Invoked when the user presses a key while the app is focused. 488 * Invoked when the user presses a key while the app is focused.
488 * @param {Event} e The key event. 489 * @param {Event} e The key event.
489 * @private 490 * @private
490 */ 491 */
491 onKeydown_: function(e) { 492 onKeydown_: function(e) {
492 if (e.keyIdentifier == 'Enter') { 493 if (e.keyIdentifier == 'Enter') {
494 var rect = this.getBoundingClientRect();
495 this.recordAppClickIndex_(rect.left + rect.width/2,
Evan Stade 2012/01/21 00:44:23 spaces around operators
Dan Beam 2012/01/21 01:49:50 Done.
496 rect.top + rect.height/2);
493 chrome.send('launchApp', 497 chrome.send('launchApp',
494 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '', 498 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '',
495 0, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); 499 0, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]);
496 e.preventDefault(); 500 e.preventDefault();
497 e.stopPropagation(); 501 e.stopPropagation();
498 } 502 }
499 }, 503 },
500 504
501 /** 505 /**
506 * Record app position "clicked" (or when a user presses 'Enter' on an app
507 * using keyboard nav).
508 * @param {number} x The client X at which the app was clicked.
Evan Stade 2012/01/21 00:44:23 you don't specify what units x is in, but it looks
Dan Beam 2012/01/21 01:49:24 Done.
509 * @param {number} y The client Y at which the app was clicked.
510 * @private
511 */
512 recordAppClickIndex_: function(x, y) {
513 var tilePage = this.tile.tilePage;
514 var gridRect = tilePage.tileGrid.getBoundingClientRect();
515
516 var maxWidth = gridRect.width;
517 if (tilePage.tileCount < tilePage.layoutValues.numRowTiles) {
518 var lastTile = tilePage.tiles[tilePage.tiles.length - 1];
519 maxWidth =
520 lastTile.firstChild.getBoundingClientRect().right - gridRect.left;
521 }
522
523 var lastApp = tilePage.tiles[tilePage.tiles.length - 1].firstChild;
524 var maxHeight = lastApp.getBoundingClientRect().bottom - gridRect.top;
525
526 chrome.send('metricsHandler:recordInHistogram',
527 ['NewTabPage.AppClick_X', (x - gridRect.left) / maxWidth * 100, 100]);
528 chrome.send('metricsHandler:recordInHistogram',
529 ['NewTabPage.AppClick_Y', (y - gridRect.top) / maxHeight * 100, 100]);
530 },
531
532 /**
502 * Adds a node to the list of targets that will launch the app. This list 533 * Adds a node to the list of targets that will launch the app. This list
503 * is also used in onMousedown to determine whether the app contents should 534 * is also used in onMousedown to determine whether the app contents should
504 * be shown as active (if we don't do this, then clicking anywhere in 535 * be shown as active (if we don't do this, then clicking anywhere in
505 * appContents, even a part that is outside the ideally clickable region, 536 * appContents, even a part that is outside the ideally clickable region,
506 * will cause the app icon to look active). 537 * will cause the app icon to look active).
507 * @param {HTMLElement} node The node that should be clickable. 538 * @param {HTMLElement} node The node that should be clickable.
508 */ 539 */
509 addLaunchClickTarget_: function(node) { 540 addLaunchClickTarget_: function(node) {
510 node.classList.add('launch-click-target'); 541 node.classList.add('launch-click-target');
511 node.addEventListener('click', this.onClick_.bind(this)); 542 node.addEventListener('click', this.onClick_.bind(this));
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 appNotificationChanged: appNotificationChanged, 925 appNotificationChanged: appNotificationChanged,
895 AppsPage: AppsPage, 926 AppsPage: AppsPage,
896 launchAppAfterEnable: launchAppAfterEnable, 927 launchAppAfterEnable: launchAppAfterEnable,
897 }; 928 };
898 }); 929 });
899 930
900 // TODO(estade): update the content handlers to use ntp namespace instead of 931 // TODO(estade): update the content handlers to use ntp namespace instead of
901 // making these global. 932 // making these global.
902 var appNotificationChanged = ntp4.appNotificationChanged; 933 var appNotificationChanged = ntp4.appNotificationChanged;
903 var launchAppAfterEnable = ntp4.launchAppAfterEnable; 934 var launchAppAfterEnable = ntp4.launchAppAfterEnable;
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/most_visited_page.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698