| OLD | NEW |
| 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, |
| 11 NTP_APPS_COLLAPSED: 1, | 11 NTP_APPS_COLLAPSED: 1, |
| 12 NTP_APPS_MENU: 2, | 12 NTP_APPS_MENU: 2, |
| 13 NTP_MOST_VISITED: 3, | 13 NTP_MOST_VISITED: 3, |
| 14 NTP_APP_RE_ENABLE: 16, | 14 NTP_APP_RE_ENABLE: 16, |
| 15 NTP_WEBSTORE_FOOTER: 18, | 15 NTP_WEBSTORE_FOOTER: 18, |
| 16 NTP_WEBSTORE_PLUS_ICON: 19, | 16 NTP_WEBSTORE_PLUS_ICON: 19, |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 // Histogram buckets for UMA tracking of where a DnD drop came from. | 19 // Histogram buckets for UMA tracking of where a DnD drop came from. |
| 20 var DRAG_SOURCE = { | 20 var DRAG_SOURCE = { |
| 21 SAME_APPS_PANE: 0, | 21 SAME_APPS_PANE: 0, |
| 22 OTHER_APPS_PANE: 1, | 22 OTHER_APPS_PANE: 1, |
| 23 MOST_VISITED_PANE: 2, // Deprecated. | 23 MOST_VISITED_PANE: 2, // Deprecated. |
| 24 BOOKMARKS_PANE: 3, // Deprecated. | 24 BOOKMARKS_PANE: 3, // Deprecated. |
| 25 OUTSIDE_NTP: 4 | 25 OUTSIDE_NTP: 4 |
| 26 }; | 26 }; |
| 27 var DRAG_SOURCE_LIMIT = DRAG_SOURCE.OUTSIDE_NTP + 1; | 27 var DRAG_SOURCE_LIMIT = DRAG_SOURCE.OUTSIDE_NTP + 1; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * App context menu. The class is designed to be used as a singleton with | 30 * App context menu. The class is designed to be used as a singleton with |
| 31 * the app that is currently showing a context menu stored in this.app_. | 31 * the app that is currently showing a context menu stored in this.app_. |
| 32 * @constructor | 32 * @constructor |
| 33 */ | 33 */ |
| 34 function AppContextMenu() { | 34 function AppContextMenu() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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) { |
| 59 launchTypeButton.addEventListener('activate', | 59 launchTypeButton.addEventListener( |
| 60 self.onLaunchTypeChanged_.bind(self)); | 60 'activate', self.onLaunchTypeChanged_.bind(self)); |
| 61 }); | 61 }); |
| 62 | 62 |
| 63 this.launchTypeMenuSeparator_ = cr.ui.MenuItem.createSeparator(); | 63 this.launchTypeMenuSeparator_ = cr.ui.MenuItem.createSeparator(); |
| 64 menu.appendChild(this.launchTypeMenuSeparator_); | 64 menu.appendChild(this.launchTypeMenuSeparator_); |
| 65 this.options_ = this.appendMenuItem_('appoptions'); | 65 this.options_ = this.appendMenuItem_('appoptions'); |
| 66 this.uninstall_ = this.appendMenuItem_('appuninstall'); | 66 this.uninstall_ = this.appendMenuItem_('appuninstall'); |
| 67 | 67 |
| 68 if (loadTimeData.getBoolean('canShowAppInfoDialog')) { | 68 if (loadTimeData.getBoolean('canShowAppInfoDialog')) { |
| 69 this.appinfo_ = this.appendMenuItem_('appinfodialog'); | 69 this.appinfo_ = this.appendMenuItem_('appinfodialog'); |
| 70 this.appinfo_.addEventListener('activate', | 70 this.appinfo_.addEventListener( |
| 71 this.onShowAppInfo_.bind(this)); | 71 'activate', this.onShowAppInfo_.bind(this)); |
| 72 } else { | 72 } else { |
| 73 this.details_ = this.appendMenuItem_('appdetails'); | 73 this.details_ = this.appendMenuItem_('appdetails'); |
| 74 this.details_.addEventListener('activate', | 74 this.details_.addEventListener( |
| 75 this.onShowDetails_.bind(this)); | 75 'activate', this.onShowDetails_.bind(this)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 this.options_.addEventListener('activate', | 78 this.options_.addEventListener( |
| 79 this.onShowOptions_.bind(this)); | 79 'activate', this.onShowOptions_.bind(this)); |
| 80 this.uninstall_.addEventListener('activate', | 80 this.uninstall_.addEventListener( |
| 81 this.onUninstall_.bind(this)); | 81 'activate', this.onUninstall_.bind(this)); |
| 82 | 82 |
| 83 if (!cr.isChromeOS) { | 83 if (!cr.isChromeOS) { |
| 84 this.createShortcutSeparator_ = | 84 this.createShortcutSeparator_ = |
| 85 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 85 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
| 86 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); | 86 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); |
| 87 this.createShortcut_.addEventListener( | 87 this.createShortcut_.addEventListener( |
| 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); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Iterates over all the launch type menu items. | 110 * Iterates over all the launch type menu items. |
| 111 * @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 |
| 112 * 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 |
| 113 * the associated launch ID. | 113 * the associated launch ID. |
| 114 * @private | 114 * @private |
| 115 */ | 115 */ |
| 116 forAllLaunchTypes_: function(f) { | 116 forAllLaunchTypes_: function(f) { |
| 117 // Order matters: index matches launchType id. | 117 // Order matters: index matches launchType id. |
| 118 var launchTypes = [this.launchPinnedTab_, | 118 var launchTypes = [ |
| 119 this.launchRegularTab_, | 119 this.launchPinnedTab_, this.launchRegularTab_, this.launchFullscreen_, |
| 120 this.launchFullscreen_, | 120 this.launchNewWindow_ |
| 121 this.launchNewWindow_]; | 121 ]; |
| 122 | 122 |
| 123 for (var i = 0; i < launchTypes.length; ++i) { | 123 for (var i = 0; i < launchTypes.length; ++i) { |
| 124 if (!launchTypes[i]) | 124 if (!launchTypes[i]) |
| 125 continue; | 125 continue; |
| 126 | 126 |
| 127 f(launchTypes[i], i); | 127 f(launchTypes[i], i); |
| 128 } | 128 } |
| 129 }, | 129 }, |
| 130 | 130 |
| 131 /** | 131 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 145 // There are three cases when a launch type is hidden: | 145 // There are three cases when a launch type is hidden: |
| 146 // 1. packaged apps hide all launch types | 146 // 1. packaged apps hide all launch types |
| 147 // 2. canHostedAppsOpenInWindows is false and type is launchTypeWindow | 147 // 2. canHostedAppsOpenInWindows is false and type is launchTypeWindow |
| 148 // 3. enableNewBookmarkApps is true and type is anything except | 148 // 3. enableNewBookmarkApps is true and type is anything except |
| 149 // launchTypeWindow | 149 // launchTypeWindow |
| 150 launchTypeButton.hidden = app.appData.packagedApp || | 150 launchTypeButton.hidden = app.appData.packagedApp || |
| 151 (!loadTimeData.getBoolean('canHostedAppsOpenInWindows') && | 151 (!loadTimeData.getBoolean('canHostedAppsOpenInWindows') && |
| 152 launchTypeButton == launchTypeWindow) || | 152 launchTypeButton == launchTypeWindow) || |
| 153 (loadTimeData.getBoolean('enableNewBookmarkApps') && | 153 (loadTimeData.getBoolean('enableNewBookmarkApps') && |
| 154 launchTypeButton != launchTypeWindow); | 154 launchTypeButton != launchTypeWindow); |
| 155 if (!launchTypeButton.hidden) hasLaunchType = true; | 155 if (!launchTypeButton.hidden) |
| 156 hasLaunchType = true; |
| 156 }); | 157 }); |
| 157 | 158 |
| 158 this.launchTypeMenuSeparator_.hidden = | 159 this.launchTypeMenuSeparator_.hidden = |
| 159 app.appData.packagedApp || !hasLaunchType; | 160 app.appData.packagedApp || !hasLaunchType; |
| 160 | 161 |
| 161 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; | 162 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; |
| 162 if (this.details_) | 163 if (this.details_) |
| 163 this.details_.disabled = !app.appData.detailsUrl; | 164 this.details_.disabled = !app.appData.detailsUrl; |
| 164 this.uninstall_.disabled = !app.appData.mayDisable; | 165 this.uninstall_.disabled = !app.appData.mayDisable; |
| 165 | 166 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 182 * @private | 183 * @private |
| 183 */ | 184 */ |
| 184 onLaunchTypeChanged_: function(e) { | 185 onLaunchTypeChanged_: function(e) { |
| 185 var pressed = e.currentTarget; | 186 var pressed = e.currentTarget; |
| 186 var app = this.app_; | 187 var app = this.app_; |
| 187 var targetLaunchType = pressed; | 188 var targetLaunchType = pressed; |
| 188 // When bookmark apps are enabled, hosted apps can only toggle between | 189 // When bookmark apps are enabled, hosted apps can only toggle between |
| 189 // open as window and open as tab. | 190 // open as window and open as tab. |
| 190 if (loadTimeData.getBoolean('enableNewBookmarkApps')) { | 191 if (loadTimeData.getBoolean('enableNewBookmarkApps')) { |
| 191 targetLaunchType = this.launchNewWindow_.checked ? | 192 targetLaunchType = this.launchNewWindow_.checked ? |
| 192 this.launchRegularTab_ : this.launchNewWindow_; | 193 this.launchRegularTab_ : |
| 194 this.launchNewWindow_; |
| 193 } | 195 } |
| 194 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 196 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
| 195 if (launchTypeButton == targetLaunchType) { | 197 if (launchTypeButton == targetLaunchType) { |
| 196 chrome.send('setLaunchType', [app.appId, id]); | 198 chrome.send('setLaunchType', [app.appId, id]); |
| 197 // Manually update the launch type. We will only get | 199 // Manually update the launch type. We will only get |
| 198 // appsPrefChangeCallback calls after changes to other NTP instances. | 200 // appsPrefChangeCallback calls after changes to other NTP instances. |
| 199 app.appData.launch_type = id; | 201 app.appData.launch_type = id; |
| 200 } | 202 } |
| 201 }); | 203 }); |
| 202 }, | 204 }, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 assert(this.appData_.id, 'Got an app without an ID'); | 257 assert(this.appData_.id, 'Got an app without an ID'); |
| 256 this.id = this.appData_.id; | 258 this.id = this.appData_.id; |
| 257 this.setAttribute('role', 'menuitem'); | 259 this.setAttribute('role', 'menuitem'); |
| 258 | 260 |
| 259 this.className = 'app focusable'; | 261 this.className = 'app focusable'; |
| 260 | 262 |
| 261 this.appContents_ = $('app-icon-template').cloneNode(true); | 263 this.appContents_ = $('app-icon-template').cloneNode(true); |
| 262 this.appContents_.id = ''; | 264 this.appContents_.id = ''; |
| 263 this.appendChild(this.appContents_); | 265 this.appendChild(this.appContents_); |
| 264 | 266 |
| 265 this.appImgContainer_ = /** @type {HTMLElement} */( | 267 this.appImgContainer_ = |
| 266 this.querySelector('.app-img-container')); | 268 /** @type {HTMLElement} */ (this.querySelector('.app-img-container')); |
| 267 this.appImg_ = this.appImgContainer_.querySelector('img'); | 269 this.appImg_ = this.appImgContainer_.querySelector('img'); |
| 268 this.setIcon(); | 270 this.setIcon(); |
| 269 | 271 |
| 270 this.addLaunchClickTarget_(this.appImgContainer_); | 272 this.addLaunchClickTarget_(this.appImgContainer_); |
| 271 this.appImgContainer_.title = this.appData_.full_name; | 273 this.appImgContainer_.title = this.appData_.full_name; |
| 272 | 274 |
| 273 // The app's full name is shown in the tooltip, whereas the short name | 275 // The app's full name is shown in the tooltip, whereas the short name |
| 274 // is used for the label. | 276 // is used for the label. |
| 275 var appSpan = /** @type {HTMLElement} */( | 277 var appSpan = /** @type {HTMLElement} */ ( |
| 276 this.appContents_.querySelector('.title')); | 278 this.appContents_.querySelector('.title')); |
| 277 appSpan.textContent = this.appData_.title; | 279 appSpan.textContent = this.appData_.title; |
| 278 appSpan.title = this.appData_.full_name; | 280 appSpan.title = this.appData_.full_name; |
| 279 this.addLaunchClickTarget_(appSpan); | 281 this.addLaunchClickTarget_(appSpan); |
| 280 | 282 |
| 281 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 283 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 282 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 284 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 283 | 285 |
| 284 // This hack is here so that appContents.contextMenu will be the same as | 286 // This hack is here so that appContents.contextMenu will be the same as |
| 285 // this.contextMenu. | 287 // this.contextMenu. |
| 286 var self = this; | 288 var self = this; |
| 287 this.appContents_.__defineGetter__('contextMenu', function() { | 289 this.appContents_.__defineGetter__('contextMenu', function() { |
| 288 return self.contextMenu; | 290 return self.contextMenu; |
| 289 }); | 291 }); |
| 290 | 292 |
| 291 if (!this.appData_.kioskMode) { | 293 if (!this.appData_.kioskMode) { |
| 292 this.appContents_.addEventListener('contextmenu', | 294 this.appContents_.addEventListener( |
| 293 cr.ui.contextMenuHandler); | 295 'contextmenu', cr.ui.contextMenuHandler); |
| 294 } | 296 } |
| 295 | 297 |
| 296 this.addEventListener('mousedown', this.onMousedown_, true); | 298 this.addEventListener('mousedown', this.onMousedown_, true); |
| 297 this.addEventListener('keydown', this.onKeydown_); | 299 this.addEventListener('keydown', this.onKeydown_); |
| 298 this.addEventListener('blur', this.onBlur_); | 300 this.addEventListener('blur', this.onBlur_); |
| 299 }, | 301 }, |
| 300 | 302 |
| 301 /** | 303 /** |
| 302 * Removes the app tile from the page. Should be called after the app has | 304 * Removes the app tile from the page. Should be called after the app has |
| 303 * been uninstalled. | 305 * been uninstalled. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 this.classList.remove('click-focus'); | 368 this.classList.remove('click-focus'); |
| 367 this.appContents_.classList.remove('suppress-active'); | 369 this.appContents_.classList.remove('suppress-active'); |
| 368 }, | 370 }, |
| 369 | 371 |
| 370 /** | 372 /** |
| 371 * Invoked when an app is clicked. | 373 * Invoked when an app is clicked. |
| 372 * @param {Event} e The click/auxclick event. | 374 * @param {Event} e The click/auxclick event. |
| 373 * @private | 375 * @private |
| 374 */ | 376 */ |
| 375 onClick_: function(e) { | 377 onClick_: function(e) { |
| 376 if (/** @type {MouseEvent} */(e).button > 1) | 378 if (/** @type {MouseEvent} */ (e).button > 1) |
| 377 return; | 379 return; |
| 378 | 380 |
| 379 chrome.send('launchApp', | 381 chrome.send('launchApp', [ |
| 380 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, 'chrome-ntp-icon', | 382 this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, 'chrome-ntp-icon', e.button, |
| 381 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 383 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey |
| 384 ]); |
| 382 | 385 |
| 383 // Don't allow the click to trigger a link or anything | 386 // Don't allow the click to trigger a link or anything |
| 384 e.preventDefault(); | 387 e.preventDefault(); |
| 385 }, | 388 }, |
| 386 | 389 |
| 387 /** | 390 /** |
| 388 * Invoked when the user presses a key while the app is focused. | 391 * Invoked when the user presses a key while the app is focused. |
| 389 * @param {Event} e The key event. | 392 * @param {Event} e The key event. |
| 390 * @private | 393 * @private |
| 391 */ | 394 */ |
| 392 onKeydown_: function(e) { | 395 onKeydown_: function(e) { |
| 393 if (e.key == 'Enter') { | 396 if (e.key == 'Enter') { |
| 394 chrome.send('launchApp', | 397 chrome.send('launchApp', [ |
| 395 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '', | 398 this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '', 0, e.altKey, e.ctrlKey, |
| 396 0, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 399 e.metaKey, e.shiftKey |
| 400 ]); |
| 397 e.preventDefault(); | 401 e.preventDefault(); |
| 398 e.stopPropagation(); | 402 e.stopPropagation(); |
| 399 } | 403 } |
| 400 }, | 404 }, |
| 401 | 405 |
| 402 /** | 406 /** |
| 403 * Adds a node to the list of targets that will launch the app. This list | 407 * Adds a node to the list of targets that will launch the app. This list |
| 404 * is also used in onMousedown to determine whether the app contents should | 408 * is also used in onMousedown to determine whether the app contents should |
| 405 * be shown as active (if we don't do this, then clicking anywhere in | 409 * be shown as active (if we don't do this, then clicking anywhere in |
| 406 * appContents, even a part that is outside the ideally clickable region, | 410 * appContents, even a part that is outside the ideally clickable region, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 422 * @param {Event} e The mousedown event. | 426 * @param {Event} e The mousedown event. |
| 423 * @private | 427 * @private |
| 424 */ | 428 */ |
| 425 onMousedown_: function(e) { | 429 onMousedown_: function(e) { |
| 426 // If the current platform uses middle click to autoscroll and this | 430 // If the current platform uses middle click to autoscroll and this |
| 427 // mousedown isn't handled, onClick_() will never fire. crbug.com/142939 | 431 // mousedown isn't handled, onClick_() will never fire. crbug.com/142939 |
| 428 if (e.button == 1) | 432 if (e.button == 1) |
| 429 e.preventDefault(); | 433 e.preventDefault(); |
| 430 | 434 |
| 431 if (e.button == 2 || | 435 if (e.button == 2 || |
| 432 !findAncestorByClass(/** @type {Element} */(e.target), | 436 !findAncestorByClass( |
| 433 'launch-click-target')) { | 437 /** @type {Element} */ (e.target), 'launch-click-target')) { |
| 434 this.appContents_.classList.add('suppress-active'); | 438 this.appContents_.classList.add('suppress-active'); |
| 435 } else { | 439 } else { |
| 436 this.appContents_.classList.remove('suppress-active'); | 440 this.appContents_.classList.remove('suppress-active'); |
| 437 } | 441 } |
| 438 | 442 |
| 439 // This class is here so we don't show the focus state for apps that | 443 // This class is here so we don't show the focus state for apps that |
| 440 // gain keyboard focus via mouse clicking. | 444 // gain keyboard focus via mouse clicking. |
| 441 this.classList.add('click-focus'); | 445 this.classList.add('click-focus'); |
| 442 }, | 446 }, |
| 443 | 447 |
| 444 /** | 448 /** |
| 445 * Change the appData and update the appearance of the app. | 449 * Change the appData and update the appearance of the app. |
| 446 * @param {AppInfo} appData The new data object that describes the app. | 450 * @param {AppInfo} appData The new data object that describes the app. |
| 447 */ | 451 */ |
| 448 replaceAppData: function(appData) { | 452 replaceAppData: function(appData) { |
| 449 this.appData_ = appData; | 453 this.appData_ = appData; |
| 450 this.setIcon(); | 454 this.setIcon(); |
| 451 this.loadIcon(); | 455 this.loadIcon(); |
| 452 }, | 456 }, |
| 453 | 457 |
| 454 /** | 458 /** |
| 455 * The data and preferences for this app. | 459 * The data and preferences for this app. |
| 456 * @type {Object} | 460 * @type {Object} |
| 457 */ | 461 */ |
| 458 set appData(data) { this.appData_ = data; }, | 462 set appData(data) { |
| 459 get appData() { return this.appData_; }, | 463 this.appData_ = data; |
| 464 }, |
| 465 get appData() { |
| 466 return this.appData_; |
| 467 }, |
| 460 | 468 |
| 461 /** @type {string} */ | 469 /** @type {string} */ |
| 462 get appId() { return this.appData_.id; }, | 470 get appId() { |
| 471 return this.appData_.id; |
| 472 }, |
| 463 | 473 |
| 464 /** | 474 /** |
| 465 * Returns a pointer to the context menu for this app. All apps share the | 475 * Returns a pointer to the context menu for this app. All apps share the |
| 466 * singleton AppContextMenu. This function is called by the | 476 * singleton AppContextMenu. This function is called by the |
| 467 * ContextMenuHandler in response to the 'contextmenu' event. | 477 * ContextMenuHandler in response to the 'contextmenu' event. |
| 468 * @type {cr.ui.Menu} | 478 * @type {cr.ui.Menu} |
| 469 */ | 479 */ |
| 470 get contextMenu() { | 480 get contextMenu() { |
| 471 var menu = AppContextMenu.getInstance(); | 481 var menu = AppContextMenu.getInstance(); |
| 472 menu.setupForApp(this); | 482 menu.setupForApp(this); |
| 473 return menu.menu; | 483 return menu.menu; |
| 474 }, | 484 }, |
| 475 | 485 |
| 476 /** | 486 /** |
| 477 * Returns whether this element can be 'removed' from chrome (i.e. whether | 487 * Returns whether this element can be 'removed' from chrome (i.e. whether |
| 478 * the user can drag it onto the trash and expect something to happen). | 488 * the user can drag it onto the trash and expect something to happen). |
| 479 * @return {boolean} True if the app can be uninstalled. | 489 * @return {boolean} True if the app can be uninstalled. |
| 480 */ | 490 */ |
| 481 canBeRemoved: function() { return this.appData_.mayDisable; }, | 491 canBeRemoved: function() { |
| 492 return this.appData_.mayDisable; |
| 493 }, |
| 482 | 494 |
| 483 /** | 495 /** |
| 484 * Uninstalls the app after it's been dropped on the trash. | 496 * Uninstalls the app after it's been dropped on the trash. |
| 485 */ | 497 */ |
| 486 removeFromChrome: function() { | 498 removeFromChrome: function() { |
| 487 chrome.send('uninstallApp', [this.appData_.id, true]); | 499 chrome.send('uninstallApp', [this.appData_.id, true]); |
| 488 this.tile.tilePage.removeTile(this.tile, true); | 500 this.tile.tilePage.removeTile(this.tile, true); |
| 489 }, | 501 }, |
| 490 | 502 |
| 491 /** | 503 /** |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 this.setDropEffect(e.dataTransfer); | 635 this.setDropEffect(e.dataTransfer); |
| 624 } | 636 } |
| 625 }, | 637 }, |
| 626 | 638 |
| 627 /** @override */ | 639 /** @override */ |
| 628 shouldAcceptDrag: function(e) { | 640 shouldAcceptDrag: function(e) { |
| 629 if (ntp.getCurrentlyDraggingTile()) | 641 if (ntp.getCurrentlyDraggingTile()) |
| 630 return true; | 642 return true; |
| 631 if (!e.dataTransfer || !e.dataTransfer.types) | 643 if (!e.dataTransfer || !e.dataTransfer.types) |
| 632 return false; | 644 return false; |
| 633 return Array.prototype.indexOf.call(e.dataTransfer.types, | 645 return Array.prototype.indexOf.call( |
| 634 'text/uri-list') != -1; | 646 e.dataTransfer.types, 'text/uri-list') != -1; |
| 635 }, | 647 }, |
| 636 | 648 |
| 637 /** @override */ | 649 /** @override */ |
| 638 addDragData: function(dataTransfer, index) { | 650 addDragData: function(dataTransfer, index) { |
| 639 var sourceId = -1; | 651 var sourceId = -1; |
| 640 var currentlyDraggingTile = ntp.getCurrentlyDraggingTile(); | 652 var currentlyDraggingTile = ntp.getCurrentlyDraggingTile(); |
| 641 if (currentlyDraggingTile) { | 653 if (currentlyDraggingTile) { |
| 642 var tileContents = currentlyDraggingTile.firstChild; | 654 var tileContents = currentlyDraggingTile.firstChild; |
| 643 if (tileContents.classList.contains('app')) { | 655 if (tileContents.classList.contains('app')) { |
| 644 var originalPage = currentlyDraggingTile.tilePage; | 656 var originalPage = currentlyDraggingTile.tilePage; |
| 645 var samePageDrag = originalPage == this; | 657 var samePageDrag = originalPage == this; |
| 646 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE : | 658 sourceId = samePageDrag ? DRAG_SOURCE.SAME_APPS_PANE : |
| 647 DRAG_SOURCE.OTHER_APPS_PANE; | 659 DRAG_SOURCE.OTHER_APPS_PANE; |
| 648 this.tileGrid_.insertBefore(currentlyDraggingTile, | 660 this.tileGrid_.insertBefore( |
| 649 this.tileElements_[index]); | 661 currentlyDraggingTile, this.tileElements_[index]); |
| 650 this.tileMoved(currentlyDraggingTile); | 662 this.tileMoved(currentlyDraggingTile); |
| 651 if (!samePageDrag) { | 663 if (!samePageDrag) { |
| 652 originalPage.fireRemovedEvent(currentlyDraggingTile, index, true); | 664 originalPage.fireRemovedEvent(currentlyDraggingTile, index, true); |
| 653 this.fireAddedEvent(currentlyDraggingTile, index, true); | 665 this.fireAddedEvent(currentlyDraggingTile, index, true); |
| 654 } | 666 } |
| 655 } | 667 } |
| 656 } else { | 668 } else { |
| 657 this.addOutsideData_(dataTransfer); | 669 this.addOutsideData_(dataTransfer); |
| 658 sourceId = DRAG_SOURCE.OUTSIDE_NTP; | 670 sourceId = DRAG_SOURCE.OUTSIDE_NTP; |
| 659 } | 671 } |
| 660 | 672 |
| 661 assert(sourceId != -1); | 673 assert(sourceId != -1); |
| 662 chrome.send('metricsHandler:recordInHistogram', | 674 chrome.send( |
| 675 'metricsHandler:recordInHistogram', |
| 663 ['NewTabPage.AppsPageDragSource', sourceId, DRAG_SOURCE_LIMIT]); | 676 ['NewTabPage.AppsPageDragSource', sourceId, DRAG_SOURCE_LIMIT]); |
| 664 }, | 677 }, |
| 665 | 678 |
| 666 /** | 679 /** |
| 667 * Adds drag data that has been dropped from a source that is not a tile. | 680 * Adds drag data that has been dropped from a source that is not a tile. |
| 668 * @param {Object} dataTransfer The data transfer object that holds drop | 681 * @param {Object} dataTransfer The data transfer object that holds drop |
| 669 * data. | 682 * data. |
| 670 * @private | 683 * @private |
| 671 */ | 684 */ |
| 672 addOutsideData_: function(dataTransfer) { | 685 addOutsideData_: function(dataTransfer) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 758 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
| 746 } | 759 } |
| 747 | 760 |
| 748 return { | 761 return { |
| 749 APP_LAUNCH: APP_LAUNCH, | 762 APP_LAUNCH: APP_LAUNCH, |
| 750 App: App, | 763 App: App, |
| 751 AppsPage: AppsPage, | 764 AppsPage: AppsPage, |
| 752 launchAppAfterEnable: launchAppAfterEnable, | 765 launchAppAfterEnable: launchAppAfterEnable, |
| 753 }; | 766 }; |
| 754 }); | 767 }); |
| OLD | NEW |