| Index: chrome/browser/resources/local_ntp/local_ntp.js
|
| diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js
|
| index 43b0f717ac4c5173b699fbb2499c33b1a5fba58a..1b9aea29e0e4b91a7c33ae92ee2ed92e7944560a 100644
|
| --- a/chrome/browser/resources/local_ntp/local_ntp.js
|
| +++ b/chrome/browser/resources/local_ntp/local_ntp.js
|
| @@ -507,6 +507,16 @@ function hideNtp() {
|
| }
|
|
|
| /**
|
| + * Shows the NTP (destroys the activeBox if exists and reloads the custom
|
| + * theme).
|
| + */
|
| +function showNtp() {
|
| + hideActiveSuggestions();
|
| + document.body.classList.remove(CLASSES.HIDE_NTP);
|
| + onThemeChange();
|
| +}
|
| +
|
| +/**
|
| * Clears the custom theme (if any).
|
| */
|
| function clearCustomTheme() {
|
| @@ -648,6 +658,13 @@ var KEY_UP_ARROW = 38;
|
| var KEY_DOWN_ARROW = 40;
|
|
|
| /**
|
| + * "Esc" keycode.
|
| + * @type {number}
|
| + * @const
|
| + */
|
| +var KEY_ESC = 27;
|
| +
|
| +/**
|
| * Pixels of padding inside a suggestion div for displaying its icon.
|
| * @type {number}
|
| * @const
|
| @@ -1074,6 +1091,24 @@ SuggestionsBox.prototype = {
|
| },
|
|
|
| /**
|
| + * @return {boolean} True if a suggestion is selected by default or because
|
| + * the user arrowed down to it.
|
| + */
|
| + hasSelectedSuggestion: function() {
|
| + return this.selectedIndex_ != -1;
|
| + },
|
| +
|
| + /**
|
| + * Clears the selected suggestion.
|
| + */
|
| + clearSelection: function() {
|
| + this.selectedIndex_ = -1;
|
| + var oldSelection = this.container_.querySelector('.' + CLASSES.SELECTED);
|
| + if (oldSelection)
|
| + oldSelection.classList.remove(CLASSES.SELECTED);
|
| + },
|
| +
|
| + /**
|
| * Changes the current selected suggestion index.
|
| * @param {number} index The new selection to suggest.
|
| * @private
|
| @@ -1094,7 +1129,7 @@ SuggestionsBox.prototype = {
|
| var oldSelection = this.container_.querySelector('.' + CLASSES.SELECTED);
|
| if (oldSelection)
|
| oldSelection.classList.remove(CLASSES.SELECTED);
|
| - if (this.selectedIndex_ == -1) {
|
| + if (!this.hasSelectedSuggestion()) {
|
| searchboxApiHandle.setValue(this.inputValue_);
|
| } else {
|
| this.suggestions_[this.selectedIndex_].select(true);
|
| @@ -1307,19 +1342,24 @@ function setSuggestionStyles() {
|
| }
|
|
|
| /**
|
| - * Makes keys navigate through suggestions.
|
| + * Handles key press events.
|
| * @param {Object} e The key being pressed.
|
| */
|
| function handleKeyPress(e) {
|
| - if (!activeBox)
|
| - return;
|
| -
|
| switch (e.keyCode) {
|
| case KEY_UP_ARROW:
|
| - activeBox.selectPrevious();
|
| + if (activeBox)
|
| + activeBox.selectPrevious();
|
| break;
|
| case KEY_DOWN_ARROW:
|
| - activeBox.selectNext();
|
| + if (activeBox)
|
| + activeBox.selectNext();
|
| + break;
|
| + case KEY_ESC:
|
| + if (activeBox && activeBox.hasSelectedSuggestion())
|
| + activeBox.clearSelection();
|
| + else
|
| + showNtp();
|
| break;
|
| }
|
| }
|
|
|