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

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

Issue 2891873002: ntp4: Fix some closure compiler annotations in apps_page.js (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | 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('ntp', function() { 5 cr.define('ntp', function() {
6 'use strict'; 6 'use strict';
7 7
8 var APP_LAUNCH = { 8 var APP_LAUNCH = {
9 // The histogram buckets (keep in sync with extension_constants.h). 9 // The histogram buckets (keep in sync with extension_constants.h).
10 NTP_APPS_MAXIMIZED: 0, 10 NTP_APPS_MAXIMIZED: 0,
(...skipping 27 matching lines...) Expand all
38 cr.addSingletonGetter(AppContextMenu); 38 cr.addSingletonGetter(AppContextMenu);
39 39
40 AppContextMenu.prototype = { 40 AppContextMenu.prototype = {
41 initialize: function() { 41 initialize: function() {
42 var menu = new cr.ui.Menu; 42 var menu = new cr.ui.Menu;
43 cr.ui.decorate(menu, cr.ui.Menu); 43 cr.ui.decorate(menu, cr.ui.Menu);
44 menu.classList.add('app-context-menu'); 44 menu.classList.add('app-context-menu');
45 this.menu = menu; 45 this.menu = menu;
46 46
47 this.launch_ = this.appendMenuItem_(); 47 this.launch_ = this.appendMenuItem_();
48 this.launch_.addEventListener('activate', this.onLaunch_.bind(this)); 48 this.launch_.addEventListener('activate', this.onActivate_.bind(this));
49 49
50 menu.appendChild(cr.ui.MenuItem.createSeparator()); 50 menu.appendChild(cr.ui.MenuItem.createSeparator());
51 this.launchRegularTab_ = this.appendMenuItem_('applaunchtyperegular'); 51 this.launchRegularTab_ = this.appendMenuItem_('applaunchtyperegular');
52 this.launchPinnedTab_ = this.appendMenuItem_('applaunchtypepinned'); 52 this.launchPinnedTab_ = this.appendMenuItem_('applaunchtypepinned');
53 if (loadTimeData.getBoolean('canHostedAppsOpenInWindows')) 53 if (loadTimeData.getBoolean('canHostedAppsOpenInWindows'))
54 this.launchNewWindow_ = this.appendMenuItem_('applaunchtypewindow'); 54 this.launchNewWindow_ = this.appendMenuItem_('applaunchtypewindow');
55 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen'); 55 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen');
56 56
57 var self = this; 57 var self = this;
58 this.forAllLaunchTypes_(function(launchTypeButton, id) { 58 this.forAllLaunchTypes_(function(launchTypeButton, id) {
(...skipping 29 matching lines...) Expand all
88 'activate', this.onCreateShortcut_.bind(this)); 88 'activate', this.onCreateShortcut_.bind(this));
89 } 89 }
90 90
91 document.body.appendChild(menu); 91 document.body.appendChild(menu);
92 }, 92 },
93 93
94 /** 94 /**
95 * Appends a menu item to |this.menu|. 95 * Appends a menu item to |this.menu|.
96 * @param {string=} opt_textId If defined, the ID for the localized string 96 * @param {string=} opt_textId If defined, the ID for the localized string
97 * that acts as the item's label. 97 * that acts as the item's label.
98 * @private
98 */ 99 */
99 appendMenuItem_: function(opt_textId) { 100 appendMenuItem_: function(opt_textId) {
100 var button = cr.doc.createElement('button'); 101 var button = cr.doc.createElement('button');
101 this.menu.appendChild(button); 102 this.menu.appendChild(button);
102 cr.ui.decorate(button, cr.ui.MenuItem); 103 cr.ui.decorate(button, cr.ui.MenuItem);
103 if (opt_textId) 104 if (opt_textId)
104 button.textContent = loadTimeData.getString(opt_textId); 105 button.textContent = loadTimeData.getString(opt_textId);
105 return button; 106 return button;
106 }, 107 },
107 108
108 /** 109 /**
109 * Iterates over all the launch type menu items. 110 * Iterates over all the launch type menu items.
110 * @param {function(cr.ui.MenuItem, number)} f The function to call for each 111 * @param {function(cr.ui.MenuItem, number)} f The function to call for each
111 * menu item. The parameters to the function include the menu item and 112 * menu item. The parameters to the function include the menu item and
112 * the associated launch ID. 113 * the associated launch ID.
114 * @private
113 */ 115 */
114 forAllLaunchTypes_: function(f) { 116 forAllLaunchTypes_: function(f) {
115 // Order matters: index matches launchType id. 117 // Order matters: index matches launchType id.
116 var launchTypes = [this.launchPinnedTab_, 118 var launchTypes = [this.launchPinnedTab_,
117 this.launchRegularTab_, 119 this.launchRegularTab_,
118 this.launchFullscreen_, 120 this.launchFullscreen_,
119 this.launchNewWindow_]; 121 this.launchNewWindow_];
120 122
121 for (var i = 0; i < launchTypes.length; ++i) { 123 for (var i = 0; i < launchTypes.length; ++i) {
122 if (!launchTypes[i]) 124 if (!launchTypes[i])
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 165
164 if (cr.isMac) { 166 if (cr.isMac) {
165 // On Windows and Linux, these should always be visible. On ChromeOS, 167 // On Windows and Linux, these should always be visible. On ChromeOS,
166 // they are never created. On Mac, shortcuts can only be created for 168 // they are never created. On Mac, shortcuts can only be created for
167 // new-style packaged apps, so hide the menu item. 169 // new-style packaged apps, so hide the menu item.
168 this.createShortcutSeparator_.hidden = this.createShortcut_.hidden = 170 this.createShortcutSeparator_.hidden = this.createShortcut_.hidden =
169 !app.appData.packagedApp; 171 !app.appData.packagedApp;
170 } 172 }
171 }, 173 },
172 174
175 /** @private */
176 onActivate_: function() {
177 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]);
178 },
179
173 /** 180 /**
174 * Handlers for menu item activation. 181 * @param {Event} e
175 * @param {Event} e The activation event.
176 * @private 182 * @private
177 */ 183 */
178 onLaunch_: function(e) {
179 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]);
180 },
181 onLaunchTypeChanged_: function(e) { 184 onLaunchTypeChanged_: function(e) {
182 var pressed = e.currentTarget; 185 var pressed = e.currentTarget;
183 var app = this.app_; 186 var app = this.app_;
184 var targetLaunchType = pressed; 187 var targetLaunchType = pressed;
185 // When bookmark apps are enabled, hosted apps can only toggle between 188 // When bookmark apps are enabled, hosted apps can only toggle between
186 // open as window and open as tab. 189 // open as window and open as tab.
187 if (loadTimeData.getBoolean('enableNewBookmarkApps')) { 190 if (loadTimeData.getBoolean('enableNewBookmarkApps')) {
188 targetLaunchType = this.launchNewWindow_.checked ? 191 targetLaunchType = this.launchNewWindow_.checked ?
189 this.launchRegularTab_ : this.launchNewWindow_; 192 this.launchRegularTab_ : this.launchNewWindow_;
190 } 193 }
191 this.forAllLaunchTypes_(function(launchTypeButton, id) { 194 this.forAllLaunchTypes_(function(launchTypeButton, id) {
192 if (launchTypeButton == targetLaunchType) { 195 if (launchTypeButton == targetLaunchType) {
193 chrome.send('setLaunchType', [app.appId, id]); 196 chrome.send('setLaunchType', [app.appId, id]);
194 // Manually update the launch type. We will only get 197 // Manually update the launch type. We will only get
195 // appsPrefChangeCallback calls after changes to other NTP instances. 198 // appsPrefChangeCallback calls after changes to other NTP instances.
196 app.appData.launch_type = id; 199 app.appData.launch_type = id;
197 } 200 }
198 }); 201 });
199 }, 202 },
200 onShowOptions_: function(e) { 203
204 /** @private */
205 onShowOptions_: function() {
201 window.location = this.app_.appData.optionsUrl; 206 window.location = this.app_.appData.optionsUrl;
202 }, 207 },
203 onShowDetails_: function(e) { 208
209 /** @private */
210 onShowDetails_: function() {
204 var url = this.app_.appData.detailsUrl; 211 var url = this.app_.appData.detailsUrl;
205 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher'); 212 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher');
206 window.location = url; 213 window.location = url;
207 }, 214 },
208 onUninstall_: function(e) { 215
216 /** @private */
217 onUninstall_: function() {
209 chrome.send('uninstallApp', [this.app_.appData.id]); 218 chrome.send('uninstallApp', [this.app_.appData.id]);
210 }, 219 },
211 onCreateShortcut_: function(e) { 220
221 /** @private */
222 onCreateShortcut_: function() {
212 chrome.send('createAppShortcut', [this.app_.appData.id]); 223 chrome.send('createAppShortcut', [this.app_.appData.id]);
213 }, 224 },
214 onShowAppInfo_: function(e) { 225
226 /** @private */
227 onShowAppInfo_: function() {
215 chrome.send('showAppInfo', [this.app_.appData.id]); 228 chrome.send('showAppInfo', [this.app_.appData.id]);
216 } 229 }
217 }; 230 };
218 231
219 /** 232 /**
220 * Creates a new App object. 233 * Creates a new App object.
221 * @param {Object} appData The data object that describes the app. 234 * @param {Object} appData The data object that describes the app.
222 * @constructor 235 * @constructor
223 * @extends {HTMLDivElement} 236 * @extends {HTMLDivElement}
224 */ 237 */
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 setBounds: function(size, x, y) { 354 setBounds: function(size, x, y) {
342 var imgSize = size * APP_IMG_SIZE_FRACTION; 355 var imgSize = size * APP_IMG_SIZE_FRACTION;
343 this.appImgContainer_.style.width = this.appImgContainer_.style.height = 356 this.appImgContainer_.style.width = this.appImgContainer_.style.height =
344 toCssPx(imgSize); 357 toCssPx(imgSize);
345 this.style.width = this.style.height = toCssPx(size); 358 this.style.width = this.style.height = toCssPx(size);
346 this.style.left = toCssPx(x); 359 this.style.left = toCssPx(x);
347 this.style.right = toCssPx(x); 360 this.style.right = toCssPx(x);
348 this.style.top = toCssPx(y); 361 this.style.top = toCssPx(y);
349 }, 362 },
350 363
351 onBlur_: function(e) { 364 /** @private */
365 onBlur_: function() {
352 this.classList.remove('click-focus'); 366 this.classList.remove('click-focus');
353 this.appContents_.classList.remove('suppress-active'); 367 this.appContents_.classList.remove('suppress-active');
354 }, 368 },
355 369
356 /** 370 /**
357 * Invoked when an app is clicked. 371 * Invoked when an app is clicked.
358 * @param {Event} e The click/auxclick event. 372 * @param {Event} e The click/auxclick event.
359 * @private 373 * @private
360 */ 374 */
361 onClick_: function(e) { 375 onClick_: function(e) {
(...skipping 23 matching lines...) Expand all
385 } 399 }
386 }, 400 },
387 401
388 /** 402 /**
389 * Adds a node to the list of targets that will launch the app. This list 403 * Adds a node to the list of targets that will launch the app. This list
390 * is also used in onMousedown to determine whether the app contents should 404 * is also used in onMousedown to determine whether the app contents should
391 * be shown as active (if we don't do this, then clicking anywhere in 405 * be shown as active (if we don't do this, then clicking anywhere in
392 * appContents, even a part that is outside the ideally clickable region, 406 * appContents, even a part that is outside the ideally clickable region,
393 * will cause the app icon to look active). 407 * will cause the app icon to look active).
394 * @param {HTMLElement} node The node that should be clickable. 408 * @param {HTMLElement} node The node that should be clickable.
409 * @private
395 */ 410 */
396 addLaunchClickTarget_: function(node) { 411 addLaunchClickTarget_: function(node) {
397 node.classList.add('launch-click-target'); 412 node.classList.add('launch-click-target');
398 node.addEventListener('click', this.onClick_.bind(this)); 413 node.addEventListener('click', this.onClick_.bind(this));
399 node.addEventListener('auxclick', this.onClick_.bind(this)); 414 node.addEventListener('auxclick', this.onClick_.bind(this));
400 }, 415 },
401 416
402 /** 417 /**
403 * Handler for mousedown on the App. Adds a class that allows us to 418 * Handler for mousedown on the App. Adds a class that allows us to
404 * not display as :active for right clicks (specifically, don't pulse on 419 * not display as :active for right clicks (specifically, don't pulse on
405 * these occasions). Also, we don't pulse for clicks that aren't within the 420 * these occasions). Also, we don't pulse for clicks that aren't within the
406 * clickable regions. 421 * clickable regions.
407 * @param {Event} e The mousedown event. 422 * @param {Event} e The mousedown event.
423 * @private
408 */ 424 */
409 onMousedown_: function(e) { 425 onMousedown_: function(e) {
410 // If the current platform uses middle click to autoscroll and this 426 // If the current platform uses middle click to autoscroll and this
411 // mousedown isn't handled, onClick_() will never fire. crbug.com/142939 427 // mousedown isn't handled, onClick_() will never fire. crbug.com/142939
412 if (e.button == 1) 428 if (e.button == 1)
413 e.preventDefault(); 429 e.preventDefault();
414 430
415 if (e.button == 2 || 431 if (e.button == 2 ||
416 !findAncestorByClass(/** @type {Element} */(e.target), 432 !findAncestorByClass(/** @type {Element} */(e.target),
417 'launch-click-target')) { 433 'launch-click-target')) {
(...skipping 17 matching lines...) Expand all
435 this.loadIcon(); 451 this.loadIcon();
436 }, 452 },
437 453
438 /** 454 /**
439 * The data and preferences for this app. 455 * The data and preferences for this app.
440 * @type {Object} 456 * @type {Object}
441 */ 457 */
442 set appData(data) { this.appData_ = data; }, 458 set appData(data) { this.appData_ = data; },
443 get appData() { return this.appData_; }, 459 get appData() { return this.appData_; },
444 460
461 /** @type {string} */
445 get appId() { return this.appData_.id; }, 462 get appId() { return this.appData_.id; },
446 463
447 /** 464 /**
448 * Returns a pointer to the context menu for this app. All apps share the 465 * Returns a pointer to the context menu for this app. All apps share the
449 * singleton AppContextMenu. This function is called by the 466 * singleton AppContextMenu. This function is called by the
450 * ContextMenuHandler in response to the 'contextmenu' event. 467 * ContextMenuHandler in response to the 'contextmenu' event.
451 * @type {cr.ui.Menu} 468 * @type {cr.ui.Menu}
452 */ 469 */
453 get contextMenu() { 470 get contextMenu() {
454 var menu = AppContextMenu.getInstance(); 471 var menu = AppContextMenu.getInstance();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 572 }
556 573
557 this.addTileAt(new App(appData), index, animate); 574 this.addTileAt(new App(appData), index, animate);
558 }, 575 },
559 576
560 /** 577 /**
561 * Handler for 'cardselected' event, fired when |this| is selected. The 578 * Handler for 'cardselected' event, fired when |this| is selected. The
562 * first time this is called, we load all the app icons. 579 * first time this is called, we load all the app icons.
563 * @private 580 * @private
564 */ 581 */
565 onCardSelected_: function(e) { 582 onCardSelected_: function() {
566 var apps = this.querySelectorAll('.app.icon-loading'); 583 var apps = this.querySelectorAll('.app.icon-loading');
567 for (var i = 0; i < apps.length; i++) { 584 for (var i = 0; i < apps.length; i++) {
568 apps[i].loadIcon(); 585 apps[i].loadIcon();
569 } 586 }
570 }, 587 },
571 588
572 /** 589 /**
573 * Handler for tile additions to this page. 590 * Handler for tile additions to this page.
574 * @param {Event} e The tilePage:tile_added event. 591 * @param {Event} e The tilePage:tile_added event.
592 * @private
575 */ 593 */
576 onTileAdded_: function(e) { 594 onTileAdded_: function(e) {
577 assert(e.currentTarget == this); 595 assert(e.currentTarget == this);
578 assert(e.addedTile.firstChild instanceof App); 596 assert(e.addedTile.firstChild instanceof App);
579 if (this.classList.contains('selected-card')) 597 if (this.classList.contains('selected-card'))
580 e.addedTile.firstChild.loadIcon(); 598 e.addedTile.firstChild.loadIcon();
581 }, 599 },
582 600
583 /** 601 /**
584 * A handler for when the apps page is scrolled (then we need to reposition 602 * A handler for when the apps page is scrolled (then we need to reposition
585 * the bubbles. 603 * the bubbles.
586 * @private 604 * @private
587 */ 605 */
588 onScroll_: function(e) { 606 onScroll_: function() {
589 if (!this.selected) 607 if (!this.selected)
590 return; 608 return;
591 for (var i = 0; i < this.tileElements_.length; i++) { 609 for (var i = 0; i < this.tileElements_.length; i++) {
592 var app = this.tileElements_[i].firstChild; 610 var app = this.tileElements_[i].firstChild;
593 assert(app instanceof App); 611 assert(app instanceof App);
594 } 612 }
595 }, 613 },
596 614
597 /** @override */ 615 /** @override */
598 doDragOver: function(e) { 616 doDragOver: function(e) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); 745 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]);
728 } 746 }
729 747
730 return { 748 return {
731 APP_LAUNCH: APP_LAUNCH, 749 APP_LAUNCH: APP_LAUNCH,
732 App: App, 750 App: App,
733 AppsPage: AppsPage, 751 AppsPage: AppsPage,
734 launchAppAfterEnable: launchAppAfterEnable, 752 launchAppAfterEnable: launchAppAfterEnable,
735 }; 753 };
736 }); 754 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698