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

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

Issue 8208014: Update the notification bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Comments addressed Created 9 years, 2 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 */ 289 */
290 loadIcon: function() { 290 loadIcon: function() {
291 if (this.appImgSrc_) { 291 if (this.appImgSrc_) {
292 this.appImg_.src = this.appImgSrc_; 292 this.appImg_.src = this.appImgSrc_;
293 this.appImg_.classList.remove('invisible'); 293 this.appImg_.classList.remove('invisible');
294 this.appImgSrc_ = null; 294 this.appImgSrc_ = null;
295 } 295 }
296 this.classList.remove('icon-loading'); 296 this.classList.remove('icon-loading');
297 }, 297 },
298 298
299 // Shows a notification text below the app icon and stuffs the attributes 299 /**
300 // necessary to show the bubble when the user clicks on the notification 300 * Creates a bubble node.
301 // text. 301 * @param {Object} notification The notification to show in the bubble.
302 setupNotification_: function(notification) { 302 * @param {boolean} full Whether we want the headline or just the content.
303 // Remove the old notification from this node (if any). 303 * @private
304 if (this.appNotification_) 304 */
305 this.appNotification_.parentNode.removeChild(this.appNotification_); 305 createBubbleNode_: function(notification, full) {
306 if (!full) {
307 var titleItem = this.ownerDocument.createElement('span');
308 titleItem.textContent = notification['title'];
309 return titleItem;
310 } else {
311 var container = this.ownerDocument.createElement('div');
306 312
307 if (notification) { 313 var messageItem = this.ownerDocument.createElement('div');
308 // Add a new notification to this node. 314 messageItem.textContent = notification['body'];
309 var appNotification = this.ownerDocument.createElement('span'); 315 container.appendChild(messageItem);
310 appNotification.className = 'app-notification'; 316
311 appNotification.textContent = notification['title']; 317 if (notification['linkUrl'] && notification['linkText']) {
312 appNotification.addEventListener('click', 318 var anchor = this.ownerDocument.createElement('a');
313 this.onNotificationClick_.bind(this)); 319 anchor.href = notification['linkUrl'];
314 appNotification.notificationTitle = notification['title']; 320 anchor.textContent = notification['linkText'];
315 appNotification.notificationMessage = notification['body']; 321 container.appendChild(anchor);
316 if (typeof notification['linkUrl'] != 'undefined' &&
317 typeof notification['linkText'] != 'undefined') {
318 appNotification.notificationLink = notification['linkUrl'];
319 appNotification.notificationLinkText = notification['linkText'];
320 } 322 }
321 this.appNotification_ = appNotification; 323
322 this.appendChild(appNotification); 324 return container;
323 } 325 }
324 }, 326 },
325 327
328 /**
329 * Sets up a notification for the app icon.
330 * @param {Object} notification The notification to show in the bubble.
331 * @private
332 */
333 setupNotification_: function(notification) {
334 if (notification) {
335 var infoBubble;
336 if (!this.currentBubbleShowing_) {
337 // Create a new bubble.
338 infoBubble = new cr.ui.ExpandableBubble;
339 infoBubble.anchorNode = this;
340 } else {
341 // Reuse the old bubble instead of popping up a new bubble over
342 // the old one.
343 infoBubble = this.currentBubbleShowing_;
344 infoBubble.collapseBubble_();
345 }
346 infoBubble.contentTitle = this.createBubbleNode_(notification, false);
347 infoBubble.content = this.createBubbleNode_(notification, true);
348 infoBubble.show();
349
350 this.currentBubbleShowing_ = infoBubble;
351 }
352 },
353
326 /** 354 /**
327 * Creates the apps-promo section of the app (should only be called for the 355 * Creates the apps-promo section of the app (should only be called for the
328 * webstore app). 356 * webstore app).
329 * @private 357 * @private
330 */ 358 */
331 createAppsPromoExtras_: function() { 359 createAppsPromoExtras_: function() {
332 this.classList.add('webstore'); 360 this.classList.add('webstore');
333 361
334 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); 362 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true);
335 this.appsPromoExtras_.id = ''; 363 this.appsPromoExtras_.id = '';
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 onClick_: function(e) { 432 onClick_: function(e) {
405 chrome.send('launchApp', 433 chrome.send('launchApp',
406 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, 434 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED,
407 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, e.button]); 435 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, e.button]);
408 436
409 // Don't allow the click to trigger a link or anything 437 // Don't allow the click to trigger a link or anything
410 e.preventDefault(); 438 e.preventDefault();
411 }, 439 },
412 440
413 /** 441 /**
442 <<<<<<< .mine
arv (Not doing code reviews) 2011/10/18 16:50:30 Please resolve
443 =======
414 * Invoked when the user presses a key while the app is focused. 444 * Invoked when the user presses a key while the app is focused.
415 * @param {Event} e The key event. 445 * @param {Event} e The key event.
416 * @private 446 * @private
417 */ 447 */
418 onKeydown_: function(e) { 448 onKeydown_: function(e) {
419 if (e.keyIdentifier == 'Enter') { 449 if (e.keyIdentifier == 'Enter') {
420 chrome.send('launchApp', 450 chrome.send('launchApp',
421 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, 451 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED,
422 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, 0]); 452 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, 0]);
423 e.preventDefault(); 453 e.preventDefault();
(...skipping 30 matching lines...) Expand all
454 container.appendChild(anchor); 484 container.appendChild(anchor);
455 } 485 }
456 486
457 var infoBubble = new cr.ui.Bubble; 487 var infoBubble = new cr.ui.Bubble;
458 infoBubble.anchorNode = e.target; 488 infoBubble.anchorNode = e.target;
459 infoBubble.content = container; 489 infoBubble.content = container;
460 infoBubble.show(); 490 infoBubble.show();
461 }, 491 },
462 492
463 /** 493 /**
494 >>>>>>> .r105287
464 * Adds a node to the list of targets that will launch the app. This list 495 * Adds a node to the list of targets that will launch the app. This list
465 * is also used in onMousedown to determine whether the app contents should 496 * is also used in onMousedown to determine whether the app contents should
466 * be shown as active (if we don't do this, then clicking anywhere in 497 * be shown as active (if we don't do this, then clicking anywhere in
467 * appContents, even a part that is outside the ideally clickable region, 498 * appContents, even a part that is outside the ideally clickable region,
468 * will cause the app icon to look active). 499 * will cause the app icon to look active).
469 * @param {HTMLElement} node The node that should be clickable. 500 * @param {HTMLElement} node The node that should be clickable.
470 */ 501 */
471 addLaunchClickTarget_: function(node) { 502 addLaunchClickTarget_: function(node) {
472 node.classList.add('launch-click-target'); 503 node.classList.add('launch-click-target');
473 node.addEventListener('click', this.onClick_.bind(this)); 504 node.addEventListener('click', this.onClick_.bind(this));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 }, 579 },
549 580
550 /** 581 /**
551 * Uninstalls the app after it's been dropped on the trash. 582 * Uninstalls the app after it's been dropped on the trash.
552 */ 583 */
553 removeFromChrome: function() { 584 removeFromChrome: function() {
554 chrome.send('uninstallApp', [this.appData_.id, true]); 585 chrome.send('uninstallApp', [this.appData_.id, true]);
555 586
556 this.tile.tilePage.cleanupDrag(); 587 this.tile.tilePage.cleanupDrag();
557 this.tile.parentNode.removeChild(this.tile); 588 this.tile.parentNode.removeChild(this.tile);
589
590 if (this.currentBubbleShowing_)
591 currentBubbleShowing_.hide();
558 }, 592 },
559 593
560 /** 594 /**
561 * Called when a drag is starting on the tile. Updates dataTransfer with 595 * Called when a drag is starting on the tile. Updates dataTransfer with
562 * data for this tile. 596 * data for this tile.
563 */ 597 */
564 setDragData: function(dataTransfer) { 598 setDragData: function(dataTransfer) {
565 dataTransfer.setData('Text', this.appData_.title); 599 dataTransfer.setData('Text', this.appData_.title);
566 dataTransfer.setData('URL', this.appData_.url); 600 dataTransfer.setData('URL', this.appData_.url);
567 }, 601 },
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 appNotificationChanged: appNotificationChanged, 827 appNotificationChanged: appNotificationChanged,
794 AppsPage: AppsPage, 828 AppsPage: AppsPage,
795 launchAppAfterEnable: launchAppAfterEnable, 829 launchAppAfterEnable: launchAppAfterEnable,
796 }; 830 };
797 }); 831 });
798 832
799 // TODO(estade): update the content handlers to use ntp namespace instead of 833 // TODO(estade): update the content handlers to use ntp namespace instead of
800 // making these global. 834 // making these global.
801 var appNotificationChanged = ntp4.appNotificationChanged; 835 var appNotificationChanged = ntp4.appNotificationChanged;
802 var launchAppAfterEnable = ntp4.launchAppAfterEnable; 836 var launchAppAfterEnable = ntp4.launchAppAfterEnable;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698