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, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return self.contextMenu; | 288 return self.contextMenu; |
289 }); | 289 }); |
290 | 290 |
291 if (!this.appData_.kioskMode) { | 291 if (!this.appData_.kioskMode) { |
292 this.appContents_.addEventListener('contextmenu', | 292 this.appContents_.addEventListener('contextmenu', |
293 cr.ui.contextMenuHandler); | 293 cr.ui.contextMenuHandler); |
294 } | 294 } |
295 | 295 |
296 this.addEventListener('mousedown', this.onMousedown_, true); | 296 this.addEventListener('mousedown', this.onMousedown_, true); |
297 this.addEventListener('keydown', this.onKeydown_); | 297 this.addEventListener('keydown', this.onKeydown_); |
298 this.addEventListener('keyup', this.onKeyup_); | 298 this.addEventListener('blur', this.onBlur_); |
299 }, | 299 }, |
300 | 300 |
301 /** | 301 /** |
302 * Sets the color of the favicon dominant color bar. | 302 * Sets the color of the favicon dominant color bar. |
303 * @param {string} color The css-parsable value for the color. | 303 * @param {string} color The css-parsable value for the color. |
304 */ | 304 */ |
305 set stripeColor(color) { | 305 set stripeColor(color) { |
306 this.querySelector('.color-stripe').style.backgroundColor = color; | 306 this.querySelector('.color-stripe').style.backgroundColor = color; |
307 }, | 307 }, |
308 | 308 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 this.imgDiv_.style.marginTop = this.imgDiv_.style.marginBottom = | 371 this.imgDiv_.style.marginTop = this.imgDiv_.style.marginBottom = |
372 toCssPx((imgSize - iconSize) / 2); | 372 toCssPx((imgSize - iconSize) / 2); |
373 } | 373 } |
374 | 374 |
375 this.style.width = this.style.height = toCssPx(size); | 375 this.style.width = this.style.height = toCssPx(size); |
376 this.style.left = toCssPx(x); | 376 this.style.left = toCssPx(x); |
377 this.style.right = toCssPx(x); | 377 this.style.right = toCssPx(x); |
378 this.style.top = toCssPx(y); | 378 this.style.top = toCssPx(y); |
379 }, | 379 }, |
380 | 380 |
| 381 onBlur_: function(e) { |
| 382 this.classList.remove('click-focus'); |
| 383 this.appContents_.classList.remove('suppress-active'); |
| 384 }, |
| 385 |
381 /** | 386 /** |
382 * Invoked when an app is clicked. | 387 * Invoked when an app is clicked. |
383 * @param {Event} e The click event. | 388 * @param {Event} e The click event. |
384 * @private | 389 * @private |
385 */ | 390 */ |
386 onClick_: function(e) { | 391 onClick_: function(e) { |
387 var url = !this.appData_.is_webstore ? '' : | 392 var url = !this.appData_.is_webstore ? '' : |
388 appendParam(this.appData_.url, | 393 appendParam(this.appData_.url, |
389 'utm_source', | 394 'utm_source', |
390 'chrome-ntp-icon'); | 395 'chrome-ntp-icon'); |
(...skipping 12 matching lines...) Expand all Loading... |
403 * @private | 408 * @private |
404 */ | 409 */ |
405 onKeydown_: function(e) { | 410 onKeydown_: function(e) { |
406 if (e.keyIdentifier == 'Enter') { | 411 if (e.keyIdentifier == 'Enter') { |
407 chrome.send('launchApp', | 412 chrome.send('launchApp', |
408 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '', | 413 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, '', |
409 0, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 414 0, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); |
410 e.preventDefault(); | 415 e.preventDefault(); |
411 e.stopPropagation(); | 416 e.stopPropagation(); |
412 } | 417 } |
413 this.onKeyboardUsed_(e.keyCode); | |
414 }, | |
415 | |
416 /** | |
417 * Invoked when the user releases a key while the app is focused. | |
418 * @param {Event} e The key event. | |
419 * @private | |
420 */ | |
421 onKeyup_: function(e) { | |
422 this.onKeyboardUsed_(e.keyCode); | |
423 }, | |
424 | |
425 /** | |
426 * Called when the keyboard has been used (key down or up). The .click-focus | |
427 * hack is removed if the user presses a key that can change focus. | |
428 * @param {number} keyCode The key code of the keyboard event. | |
429 * @private | |
430 */ | |
431 onKeyboardUsed_: function(keyCode) { | |
432 switch (keyCode) { | |
433 case 9: // Tab. | |
434 case 37: // Left arrow. | |
435 case 38: // Up arrow. | |
436 case 39: // Right arrow. | |
437 case 40: // Down arrow. | |
438 this.classList.remove('click-focus'); | |
439 } | |
440 }, | 418 }, |
441 | 419 |
442 /** | 420 /** |
443 * Adds a node to the list of targets that will launch the app. This list | 421 * Adds a node to the list of targets that will launch the app. This list |
444 * is also used in onMousedown to determine whether the app contents should | 422 * is also used in onMousedown to determine whether the app contents should |
445 * be shown as active (if we don't do this, then clicking anywhere in | 423 * be shown as active (if we don't do this, then clicking anywhere in |
446 * appContents, even a part that is outside the ideally clickable region, | 424 * appContents, even a part that is outside the ideally clickable region, |
447 * will cause the app icon to look active). | 425 * will cause the app icon to look active). |
448 * @param {HTMLElement} node The node that should be clickable. | 426 * @param {HTMLElement} node The node that should be clickable. |
449 */ | 427 */ |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 function launchAppAfterEnable(appId) { | 765 function launchAppAfterEnable(appId) { |
788 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 766 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
789 } | 767 } |
790 | 768 |
791 return { | 769 return { |
792 APP_LAUNCH: APP_LAUNCH, | 770 APP_LAUNCH: APP_LAUNCH, |
793 AppsPage: AppsPage, | 771 AppsPage: AppsPage, |
794 launchAppAfterEnable: launchAppAfterEnable, | 772 launchAppAfterEnable: launchAppAfterEnable, |
795 }; | 773 }; |
796 }); | 774 }); |
OLD | NEW |