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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/menu.js

Issue 10966027: Basic keyboard access for recently_closed menu on NTP. Allows using up and down arrows to navigate,… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Get rid of pointless experimental code" Created 8 years, 3 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
OLDNEW
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('cr.ui', function() { 5 cr.define('cr.ui', function() {
6 6
7 /** @const */ var MenuItem = cr.ui.MenuItem; 7 /** @const */ var MenuItem = cr.ui.MenuItem;
8 8
9 /** 9 /**
10 * Creates a new menu element. Menu dispatches all commands on the element it 10 * Creates a new menu element. Menu dispatches all commands on the element it
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 switch (e.keyIdentifier) { 173 switch (e.keyIdentifier) {
174 case 'Down': 174 case 'Down':
175 selectNextAvailable(1); 175 selectNextAvailable(1);
176 return true; 176 return true;
177 case 'Up': 177 case 'Up':
178 selectNextAvailable(-1); 178 selectNextAvailable(-1);
179 return true; 179 return true;
180 case 'Enter': 180 case 'Enter':
181 case 'U+0020': // Space 181 case 'U+0020': // Space
182 if (item) { 182 if (item) {
183 if (cr.dispatchSimpleEvent(item, 'activate', true, true)) { 183 var activationEvent = cr.doc.createEvent('Event');
184 activationEvent.initEvent('activate', true, true);
185 activationEvent.originalEvent = e;
186 if (item.dispatchEvent(activationEvent)) {
184 if (item.command) 187 if (item.command)
185 item.command.execute(); 188 item.command.execute();
186 } 189 }
187 } 190 }
188 return true; 191 return true;
189 } 192 }
190 193
191 return false; 194 return false;
192 }, 195 },
193 196
194 /** 197 /**
195 * Updates menu items command according to context. 198 * Updates menu items command according to context.
196 * @param {Node=} node Node for which to actuate commands state. 199 * @param {Node=} node Node for which to actuate commands state.
197 */ 200 */
198 updateCommands: function(node) { 201 updateCommands: function(node) {
199 var children = this.children; 202 var children = this.children;
200 203
201 for (var i = 0, child; child = children[i]; i++) 204 for (var i = 0, child; child = children[i]; i++)
202 child.updateCommand(node); 205 child.updateCommand(node);
203 } 206 }
204 }; 207 };
205 208
206 function selectedIndexChanged(selectedIndex, oldSelectedIndex) { 209 function selectedIndexChanged(selectedIndex, oldSelectedIndex) {
207 var oldSelectedItem = this.children[oldSelectedIndex]; 210 var oldSelectedItem = this.children[oldSelectedIndex];
208 if (oldSelectedItem) 211 if (oldSelectedItem)
209 oldSelectedItem.selected = false; 212 oldSelectedItem.selected = false;
210 var item = this.selectedItem; 213 var item = this.selectedItem;
211 if (item) 214 if (item) {
212 item.selected = true; 215 item.selected = true;
216 item.focus();
217 }
213 } 218 }
214 219
215 /** 220 /**
216 * The selected menu item. 221 * The selected menu item.
217 * @type {number} 222 * @type {number}
218 */ 223 */
219 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS, 224 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS,
220 selectedIndexChanged); 225 selectedIndexChanged);
221 226
222 // Export 227 // Export
223 return { 228 return {
224 Menu: Menu 229 Menu: Menu
225 }; 230 };
226 }); 231 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698