Chromium Code Reviews| 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 var MAX_APPS_PER_ROW = []; | 5 var MAX_APPS_PER_ROW = []; |
| 6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; | 6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; |
| 7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; | 7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; |
| 8 | 8 |
| 9 function getAppsCallback(data) { | 9 function getAppsCallback(data) { |
| 10 logEvent('received apps'); | 10 logEvent('received apps'); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 function appNotificationChanged(id, lastNotification) { | 152 function appNotificationChanged(id, lastNotification) { |
| 153 // TODO(asargent/finnur) use this when we hook up notifications into the NTP. | 153 // TODO(asargent/finnur) use this when we hook up notifications into the NTP. |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE histogram. | 156 // Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE histogram. |
| 157 // This should only be invoked from the AppLauncherHandler. | 157 // This should only be invoked from the AppLauncherHandler. |
| 158 function launchAppAfterEnable(appId) { | 158 function launchAppAfterEnable(appId) { |
| 159 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 159 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Shows the notification bubble for a given app (the one clicked on). | |
| 163 function showNotificationBubble(event) { | |
| 164 var item = findAncestorByClass(event.target, 'app-anchor'); | |
| 165 var title = item.getAttribute('notification-title'); | |
| 166 var message = item.getAttribute('notification-message'); | |
| 167 var link = item.getAttribute('notification-link'); | |
| 168 var link_message = item.getAttribute('notification-link-message'); | |
| 169 | |
| 170 if (!title || !message) | |
| 171 return; | |
| 172 | |
| 173 // Set the content to the right text. | |
| 174 $('notification-title').textContent = title; | |
| 175 $('notification-message').textContent = message; | |
| 176 $('notification-link').href = link; | |
| 177 $('notification-link').textContent = link_message; | |
| 178 | |
| 179 var target = event.target; | |
| 180 while (target.parentElement && target.tagName != "A") { | |
| 181 target = target.parentElement; | |
| 182 } | |
| 183 | |
| 184 // Move the bubble to the right location. | |
| 185 var bubble = $('notification-bubble'); | |
| 186 var x = target.parentElement.offsetLeft + | |
| 187 target.parentElement.offsetWidth - 20; | |
| 188 var y = target.parentElement.offsetTop + 20; | |
| 189 bubble.style.left = x + "px"; | |
| 190 bubble.style.top = y + "px"; | |
| 191 | |
| 192 // Move the arrow and shadow to the right location. | |
| 193 var arrow = $('arrow-contents'); | |
| 194 var border = $('arrow-border'); | |
| 195 var shadow = $('arrow-shadow'); | |
| 196 y += 26; | |
| 197 x -= arrow.style.width + 23; | |
| 198 arrow.style.left = x + "px"; | |
| 199 arrow.style.top = y + "px"; | |
| 200 x -= 1; | |
| 201 border.style.left = x + "px"; | |
| 202 border.style.top = y + "px"; | |
| 203 x -= 1; | |
| 204 shadow.style.left = x + "px"; | |
| 205 shadow.style.top = y + "px"; | |
| 206 | |
| 207 // Animate the bubble into view. | |
| 208 bubble.style.opacity = 1; | |
| 209 arrow.style.opacity = 1; | |
| 210 border.style.opacity = 1; | |
| 211 shadow.style.opacity = 1; | |
| 212 | |
| 213 bubble.focus(); | |
| 214 } | |
| 215 | |
| 216 // Hide the notification bubble. | |
| 217 function hideNotificationBubble(event) { | |
| 218 // This will fade the bubble out of existence. | |
| 219 $('notification-bubble').style.opacity = 0; | |
| 220 $('arrow-border').style.opacity = 0; | |
| 221 $('arrow-shadow').style.opacity = 0; | |
| 222 $('arrow-contents').style.opacity = 0; | |
| 223 } | |
| 224 | |
| 162 var apps = (function() { | 225 var apps = (function() { |
| 163 | 226 |
| 164 function createElement(app) { | 227 function createElement(app) { |
| 165 var div = document.createElement('div'); | 228 var div = document.createElement('div'); |
| 166 div.className = 'app'; | 229 div.className = 'app'; |
| 167 | 230 |
| 168 var a = div.appendChild(document.createElement('a')); | 231 var a = div.appendChild(document.createElement('a')); |
| 232 a.className = 'app-anchor'; | |
| 169 a.setAttribute('app-id', app['id']); | 233 a.setAttribute('app-id', app['id']); |
| 170 a.setAttribute('launch-type', app['launch_type']); | 234 a.setAttribute('launch-type', app['launch_type']); |
| 235 if (typeof(app['notification']) != "undefined") { | |
| 236 a.setAttribute('notification-title', app['notification']['title']); | |
| 237 a.setAttribute('notification-message', app['notification']['body']); | |
| 238 if (typeof(app['notification']['linkUrl']) != "undefined" && | |
| 239 typeof(app['notification']['linkText']) != "undefined") { | |
| 240 a.setAttribute('notification-link', app['notification']['linkUrl']); | |
| 241 a.setAttribute('notification-link-message', | |
| 242 app['notification']['linkText']); | |
| 243 } | |
| 244 } | |
| 171 a.draggable = false; | 245 a.draggable = false; |
| 172 a.xtitle = a.textContent = app['name']; | |
| 173 a.href = app['launch_url']; | 246 a.href = app['launch_url']; |
| 174 | 247 |
| 248 var span = a.appendChild(document.createElement('span')); | |
| 249 span.textContent = app['name']; | |
| 250 | |
| 251 span = a.appendChild(document.createElement('span')); | |
| 252 span.className = "app_notification"; | |
| 253 span.textContent = | |
| 254 typeof(app['notification']) != "undefined" && | |
| 255 typeof(app['notification']['title']) != "undefined" ? | |
| 256 app['notification']['title'] : ""; | |
| 257 span.onclick = handleClick; | |
| 258 | |
| 259 $("notification-close").onclick = hideNotificationBubble; | |
| 260 $("notification-bubble").setAttribute("tabIndex", 0); | |
| 261 $("notification-bubble").onblur = hideNotificationBubble; | |
| 262 | |
| 175 return div; | 263 return div; |
| 176 } | 264 } |
| 177 | 265 |
| 178 /** | 266 /** |
| 179 * Launches an application. | 267 * Launches an application. |
| 180 * @param {string} appId Application to launch. | 268 * @param {string} appId Application to launch. |
| 181 * @param {MouseEvent} opt_mouseEvent Mouse event from the click that | 269 * @param {MouseEvent} opt_mouseEvent Mouse event from the click that |
| 182 * triggered the launch, used to detect modifier keys that change | 270 * triggered the launch, used to detect modifier keys that change |
| 183 * the tab's disposition. | 271 * the tab's disposition. |
| 184 */ | 272 */ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 212 return APP_LAUNCH.NTP_APPS_COLLAPSED; | 300 return APP_LAUNCH.NTP_APPS_COLLAPSED; |
| 213 else | 301 else |
| 214 return APP_LAUNCH.NTP_APPS_MAXIMIZED; | 302 return APP_LAUNCH.NTP_APPS_MAXIMIZED; |
| 215 } | 303 } |
| 216 | 304 |
| 217 /** | 305 /** |
| 218 * @this {!HTMLAnchorElement} | 306 * @this {!HTMLAnchorElement} |
| 219 */ | 307 */ |
| 220 function handleClick(e) { | 308 function handleClick(e) { |
| 221 var appId = e.currentTarget.getAttribute('app-id'); | 309 var appId = e.currentTarget.getAttribute('app-id'); |
| 310 if (appId == null) { | |
| 311 showNotificationBubble(e); | |
| 312 e.stopPropagation(); | |
| 313 return false; | |
| 314 } | |
| 315 | |
| 222 if (!appDragAndDrop.isDragging()) | 316 if (!appDragAndDrop.isDragging()) |
| 223 launchApp(appId, e); | 317 launchApp(appId, e); |
| 224 return false; | 318 return false; |
| 225 } | 319 } |
| 226 | 320 |
| 227 // Keep in sync with LaunchType in extension_prefs.h | 321 // Keep in sync with LaunchType in extension_prefs.h |
| 228 var LaunchType = { | 322 var LaunchType = { |
| 229 LAUNCH_PINNED: 0, | 323 LAUNCH_PINNED: 0, |
| 230 LAUNCH_REGULAR: 1, | 324 LAUNCH_REGULAR: 1, |
| 231 LAUNCH_FULLSCREEN: 2, | 325 LAUNCH_FULLSCREEN: 2, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 408 |
| 315 document.addEventListener('canExecute', function(e) { | 409 document.addEventListener('canExecute', function(e) { |
| 316 switch (e.command.id) { | 410 switch (e.command.id) { |
| 317 case 'apps-options-command': | 411 case 'apps-options-command': |
| 318 e.canExecute = currentApp && currentApp['options_url']; | 412 e.canExecute = currentApp && currentApp['options_url']; |
| 319 break; | 413 break; |
| 320 case 'apps-launch-command': | 414 case 'apps-launch-command': |
| 321 e.canExecute = true; | 415 e.canExecute = true; |
| 322 break; | 416 break; |
| 323 case 'apps-uninstall-command': | 417 case 'apps-uninstall-command': |
| 324 e.canExecute = !currentApp['can_uninstall']; | 418 e.canExecute = currentApp && !currentApp['can_uninstall']; |
| 325 break; | 419 break; |
| 326 } | 420 } |
| 327 }); | 421 }); |
| 328 | 422 |
| 329 // Moves the element at position |from| in array |arr| to position |to|. | 423 // Moves the element at position |from| in array |arr| to position |to|. |
| 330 function arrayMove(arr, from, to) { | 424 function arrayMove(arr, from, to) { |
| 331 var element = arr.splice(from, 1); | 425 var element = arr.splice(from, 1); |
| 332 arr.splice(to, 0, element[0]); | 426 arr.splice(to, 0, element[0]); |
| 333 } | 427 } |
| 334 | 428 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 return; | 771 return; |
| 678 } | 772 } |
| 679 }, | 773 }, |
| 680 | 774 |
| 681 showImages: function() { | 775 showImages: function() { |
| 682 $('apps-content').classList.add('visible'); | 776 $('apps-content').classList.add('visible'); |
| 683 clearTimeout(this.imageTimer); | 777 clearTimeout(this.imageTimer); |
| 684 }, | 778 }, |
| 685 | 779 |
| 686 createElement: function(app) { | 780 createElement: function(app) { |
| 781 var container = document.createElement('div'); | |
| 687 var div = createElement(app); | 782 var div = createElement(app); |
| 783 container.appendChild(div); | |
| 688 var a = div.firstChild; | 784 var a = div.firstChild; |
| 689 | 785 |
| 690 a.onclick = handleClick; | 786 a.onclick = handleClick; |
| 691 a.ping = getAppPingUrl( | 787 a.ping = getAppPingUrl( |
| 692 'PING_BY_ID', this.showPromo, 'NTP_APPS_MAXIMIZED'); | 788 'PING_BY_ID', this.showPromo, 'NTP_APPS_MAXIMIZED'); |
| 693 a.style.backgroundImage = url(app['icon_big']); | 789 a.style.backgroundImage = url(app['icon_big']); |
| 694 if (app.isNew) { | 790 if (app.isNew) { |
| 695 div.setAttribute('new', 'new'); | 791 div.setAttribute('new', 'new'); |
| 696 // Delay changing the attribute a bit to let the page settle down a bit. | 792 // Delay changing the attribute a bit to let the page settle down a bit. |
| 697 setTimeout(function() { | 793 setTimeout(function() { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 712 img.src = app['icon_big']; | 808 img.src = app['icon_big']; |
| 713 | 809 |
| 714 // User cannot change launch options or uninstall component extension. | 810 // User cannot change launch options or uninstall component extension. |
| 715 if (!app['is_component']) { | 811 if (!app['is_component']) { |
| 716 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); | 812 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); |
| 717 settingsButton.className = 'app-settings'; | 813 settingsButton.className = 'app-settings'; |
| 718 settingsButton.title = localStrings.getString('appsettings'); | 814 settingsButton.title = localStrings.getString('appsettings'); |
| 719 addContextMenu(div, app); | 815 addContextMenu(div, app); |
| 720 } | 816 } |
| 721 | 817 |
| 722 return div; | 818 if (app.notifications && app.notifications.length > 0) { |
|
asargent_no_longer_on_chrome
2011/07/01 05:03:06
FYI, in the code I ended up checking in, I just pu
Finnur
2011/07/01 13:43:18
I know. This is already wired up in this changelis
| |
| 819 // Create the notification div below the app icon that is used to | |
| 820 // trigger the hidden notification bubble to appear. | |
| 821 var notification = document.createElement('div') | |
| 822 container.appendChild(notification); | |
| 823 var title = document.createElement('span'); | |
| 824 title.innerText = app.notifications[0].title; | |
| 825 notification.appendChild(title); | |
| 826 notification.appendChild(document.createElement('br')); | |
| 827 | |
| 828 var body = document.createElement('span'); | |
| 829 container.appendChild(body); | |
| 830 body.innerText = app.notifications[0].body; | |
| 831 notification.appendChild(body); | |
| 832 if (app.notifications[0].linkUrl) { | |
| 833 notification.appendChild(document.createElement('br')); | |
| 834 var link = document.createElement('a'); | |
| 835 link.href = app.notifications[0].linkUrl; | |
| 836 link.innerText = app.notifications[0].linkText ? | |
| 837 app.notifications[0].linkText : "link"; | |
| 838 notification.appendChild(link); | |
| 839 } | |
| 840 } | |
| 841 | |
| 842 return container; | |
| 723 }, | 843 }, |
| 724 | 844 |
| 725 createMiniviewElement: function(app) { | 845 createMiniviewElement: function(app) { |
| 726 var span = document.createElement('span'); | 846 var span = document.createElement('span'); |
| 727 var a = span.appendChild(document.createElement('a')); | 847 var a = span.appendChild(document.createElement('a')); |
| 728 | 848 |
| 729 a.setAttribute('app-id', app['id']); | 849 a.setAttribute('app-id', app['id']); |
| 730 a.textContent = app['name']; | 850 a.textContent = app['name']; |
| 731 a.href = app['launch_url']; | 851 a.href = app['launch_url']; |
| 732 a.onclick = handleClick; | 852 a.onclick = handleClick; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 a.href = localStrings.getString('web_store_url'); | 905 a.href = localStrings.getString('web_store_url'); |
| 786 a.style.backgroundImage = url('chrome://theme/IDR_WEBSTORE_ICON_16'); | 906 a.style.backgroundImage = url('chrome://theme/IDR_WEBSTORE_ICON_16'); |
| 787 a.className = 'item'; | 907 a.className = 'item'; |
| 788 return a; | 908 return a; |
| 789 } | 909 } |
| 790 }; | 910 }; |
| 791 })(); | 911 })(); |
| 792 | 912 |
| 793 // Enable drag and drop reordering of the app launcher. | 913 // Enable drag and drop reordering of the app launcher. |
| 794 var appDragAndDrop = new DragAndDropController(apps); | 914 var appDragAndDrop = new DragAndDropController(apps); |
| OLD | NEW |