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

Side by Side Diff: chrome/browser/resources/local_ntp/local_ntp.js

Issue 14562006: Handle Esc key press event in Local NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated description and added a TODO to handle !full_text.empty case. Created 7 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 (function() { 5 (function() {
6 <include src="../../../../ui/webui/resources/js/assert.js"> 6 <include src="../../../../ui/webui/resources/js/assert.js">
7 7
8 /** 8 /**
9 * True if this a Google page and not some other search provider. Used to 9 * True if this a Google page and not some other search provider. Used to
10 * determine whether to show the logo and fakebox. 10 * determine whether to show the logo and fakebox.
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 var KEY_UP_ARROW = 38; 641 var KEY_UP_ARROW = 38;
642 642
643 /** 643 /**
644 * "Down" arrow keycode. 644 * "Down" arrow keycode.
645 * @type {number} 645 * @type {number}
646 * @const 646 * @const
647 */ 647 */
648 var KEY_DOWN_ARROW = 40; 648 var KEY_DOWN_ARROW = 40;
649 649
650 /** 650 /**
651 * "Esc" keycode.
652 * @type {number}
653 * @const
654 */
655 var KEY_ESC = 27;
656
657 /**
651 * Pixels of padding inside a suggestion div for displaying its icon. 658 * Pixels of padding inside a suggestion div for displaying its icon.
652 * @type {number} 659 * @type {number}
653 * @const 660 * @const
654 */ 661 */
655 var SUGGESTION_ICON_PADDING = 26; 662 var SUGGESTION_ICON_PADDING = 26;
656 663
657 /** 664 /**
658 * Pixels by which iframes should be moved down relative to their wrapping 665 * Pixels by which iframes should be moved down relative to their wrapping
659 * suggestion div. 666 * suggestion div.
660 */ 667 */
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 }, 1074 },
1068 1075
1069 /** 1076 /**
1070 * Selects the suggestion after the current selection. 1077 * Selects the suggestion after the current selection.
1071 */ 1078 */
1072 selectNext: function() { 1079 selectNext: function() {
1073 this.changeSelection_(this.selectedIndex_ + 1); 1080 this.changeSelection_(this.selectedIndex_ + 1);
1074 }, 1081 },
1075 1082
1076 /** 1083 /**
1084 * Clears the selected suggestion.
1085 */
1086 clearSelection: function() {
1087 this.selectedIndex_ = -1;
1088 var oldSelection = this.container_.querySelector('.' + CLASSES.SELECTED);
1089 if (oldSelection)
1090 oldSelection.classList.remove(CLASSES.SELECTED);
1091 },
1092
1093 /**
1077 * Changes the current selected suggestion index. 1094 * Changes the current selected suggestion index.
1078 * @param {number} index The new selection to suggest. 1095 * @param {number} index The new selection to suggest.
1079 * @private 1096 * @private
1080 */ 1097 */
1081 changeSelection_: function(index) { 1098 changeSelection_: function(index) {
1082 var numSuggestions = this.suggestions_.length; 1099 var numSuggestions = this.suggestions_.length;
1083 this.selectedIndex_ = Math.min(numSuggestions - 1, Math.max(-1, index)); 1100 this.selectedIndex_ = Math.min(numSuggestions - 1, Math.max(-1, index));
1084 1101
1085 this.redrawSelection_(); 1102 this.redrawSelection_();
1086 this.redrawHover_(); 1103 this.redrawHover_();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 }, 1162 },
1146 1163
1147 /** 1164 /**
1148 * Clears the current hover. 1165 * Clears the current hover.
1149 */ 1166 */
1150 clearHover: function() { 1167 clearHover: function() {
1151 this.hoveredIndex_ = -1; 1168 this.hoveredIndex_ = -1;
1152 this.redrawHover_(); 1169 this.redrawHover_();
1153 }, 1170 },
1154 1171
1155 /** 1172 /**
jeremycho 2013/05/04 23:07:06 nit: move this alongside the other selection funct
kmadhusu 2013/05/05 22:44:54 Done.
1173 * Returns the selected suggestion index.
1174 */
1175 selectedIndex: function() {
1176 return this.selectedIndex_;
1177 },
1178
1179 /**
1156 * Redraws the mouse hover background. 1180 * Redraws the mouse hover background.
1157 * @private 1181 * @private
1158 */ 1182 */
1159 redrawHover_: function() { 1183 redrawHover_: function() {
1160 var oldHover = this.container_.querySelector('.' + CLASSES.HOVERED); 1184 var oldHover = this.container_.querySelector('.' + CLASSES.HOVERED);
1161 if (oldHover) 1185 if (oldHover)
1162 oldHover.classList.remove(CLASSES.HOVERED); 1186 oldHover.classList.remove(CLASSES.HOVERED);
1163 if (this.hoveredIndex_ != -1 && this.hoveredIndex_ != this.selectedIndex_) 1187 if (this.hoveredIndex_ != -1 && this.hoveredIndex_ != this.selectedIndex_)
1164 this.suggestions_[this.hoveredIndex_].hover(true); 1188 this.suggestions_[this.hoveredIndex_].hover(true);
1165 }, 1189 },
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 1324
1301 if (activeBox) 1325 if (activeBox)
1302 activeBox.repositionSuggestions(); 1326 activeBox.repositionSuggestions();
1303 1327
1304 // This is bound only for initialization. Afterwards this style should only 1328 // This is bound only for initialization. Afterwards this style should only
1305 // change onmarginchange. 1329 // change onmarginchange.
1306 window.removeEventListener('resize', setSuggestionStyles); 1330 window.removeEventListener('resize', setSuggestionStyles);
1307 } 1331 }
1308 1332
1309 /** 1333 /**
1310 * Makes keys navigate through suggestions. 1334 * Makes keys navigate through suggestions.
jeremycho 2013/05/04 23:07:06 Update comment.
kmadhusu 2013/05/05 22:44:54 Done.
1311 * @param {Object} e The key being pressed. 1335 * @param {Object} e The key being pressed.
1312 */ 1336 */
1313 function handleKeyPress(e) { 1337 function handleKeyPress(e) {
1314 if (!activeBox) 1338 if (!activeBox)
1315 return; 1339 return;
1316 1340
1317 switch (e.keyCode) { 1341 switch (e.keyCode) {
1318 case KEY_UP_ARROW: 1342 case KEY_UP_ARROW:
1319 activeBox.selectPrevious(); 1343 activeBox.selectPrevious();
1320 break; 1344 break;
1321 case KEY_DOWN_ARROW: 1345 case KEY_DOWN_ARROW:
1322 activeBox.selectNext(); 1346 activeBox.selectNext();
1323 break; 1347 break;
1348 case KEY_ESC:
1349 if (activeBox.selectedIndex() != -1) {
jeremycho 2013/05/04 23:07:06 Make this check a function and use it elsewhere.
kmadhusu 2013/05/05 22:44:54 Done.
1350 activeBox.clearSelection();
1351 } else {
1352 hideActiveSuggestions();
1353 document.body.classList.remove(CLASSES.HIDE_NTP);
jeremycho 2013/05/04 23:07:06 Can you factor the show/hide logic into a helper f
kmadhusu 2013/05/05 22:44:54 Done. Added showNtp().
1354 onThemeChange();
1355 }
1356 break;
1324 } 1357 }
1325 } 1358 }
1326 1359
1327 /** 1360 /**
1328 * Handles postMessage calls from suggestion iframes. 1361 * Handles postMessage calls from suggestion iframes.
1329 * @param {Object} message A notification that all iframes are done loading or 1362 * @param {Object} message A notification that all iframes are done loading or
1330 * that an iframe was clicked. 1363 * that an iframe was clicked.
1331 */ 1364 */
1332 function handleMessage(message) { 1365 function handleMessage(message) {
1333 if (message.origin != SUGGESTION_ORIGIN) 1366 if (message.origin != SUGGESTION_ORIGIN)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 } 1559 }
1527 } 1560 }
1528 1561
1529 document.addEventListener('DOMContentLoaded', init); 1562 document.addEventListener('DOMContentLoaded', init);
1530 window.addEventListener('message', handleMessage, false); 1563 window.addEventListener('message', handleMessage, false);
1531 window.addEventListener('blur', function() { 1564 window.addEventListener('blur', function() {
1532 if (activeBox) 1565 if (activeBox)
1533 activeBox.clearHover(); 1566 activeBox.clearHover();
1534 }, false); 1567 }, false);
1535 })(); 1568 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698