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('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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 break; | 234 break; |
235 | 235 |
236 item = menuItems[i]; | 236 item = menuItems[i]; |
237 if (item && !item.isSeparator() && !item.hidden && !item.disabled) | 237 if (item && !item.isSeparator() && !item.hidden && !item.disabled) |
238 break; | 238 break; |
239 } | 239 } |
240 if (item && !item.disabled) | 240 if (item && !item.disabled) |
241 self.selectedIndex = i; | 241 self.selectedIndex = i; |
242 } | 242 } |
243 | 243 |
244 switch (e.keyIdentifier) { | 244 switch (e.key) { |
245 case 'Down': | 245 case 'ArrowDown': |
246 selectNextAvailable(1); | 246 selectNextAvailable(1); |
247 this.focusSelectedItem(); | 247 this.focusSelectedItem(); |
248 return true; | 248 return true; |
249 case 'Up': | 249 case 'ArrowUp': |
250 selectNextAvailable(-1); | 250 selectNextAvailable(-1); |
251 this.focusSelectedItem(); | 251 this.focusSelectedItem(); |
252 return true; | 252 return true; |
253 case 'Enter': | 253 case 'Enter': |
254 case 'U+0020': // Space | 254 case ' ': |
255 if (item) { | 255 if (item) { |
256 // Store |contextElement| since it'll be removed when handling the | 256 // Store |contextElement| since it'll be removed when handling the |
257 // 'activate' event. | 257 // 'activate' event. |
258 var contextElement = this.contextElement; | 258 var contextElement = this.contextElement; |
259 var activationEvent = cr.doc.createEvent('Event'); | 259 var activationEvent = cr.doc.createEvent('Event'); |
260 activationEvent.initEvent('activate', true, true); | 260 activationEvent.initEvent('activate', true, true); |
261 activationEvent.originalEvent = e; | 261 activationEvent.originalEvent = e; |
262 if (item.dispatchEvent(activationEvent)) { | 262 if (item.dispatchEvent(activationEvent)) { |
263 if (item.command) | 263 if (item.command) |
264 item.command.execute(contextElement); | 264 item.command.execute(contextElement); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 /** | 316 /** |
317 * Selector for children which are menu items. | 317 * Selector for children which are menu items. |
318 */ | 318 */ |
319 cr.defineProperty(Menu, 'menuItemSelector', cr.PropertyKind.ATTR); | 319 cr.defineProperty(Menu, 'menuItemSelector', cr.PropertyKind.ATTR); |
320 | 320 |
321 // Export | 321 // Export |
322 return { | 322 return { |
323 Menu: Menu | 323 Menu: Menu |
324 }; | 324 }; |
325 }); | 325 }); |
OLD | NEW |