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

Unified 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: Don't steal keyboard events that the menu doesn't handle, and detect focusin on unrelated elements … 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/cr/ui/menu.js
diff --git a/chrome/browser/resources/shared/js/cr/ui/menu.js b/chrome/browser/resources/shared/js/cr/ui/menu.js
index 3e1e3dc31fc1e0630287a9c9fb6c03d21ed4d8a7..2640d92a6a92eda5baa9f8bbe4b16a5d2c137078 100644
--- a/chrome/browser/resources/shared/js/cr/ui/menu.js
+++ b/chrome/browser/resources/shared/js/cr/ui/menu.js
@@ -34,6 +34,7 @@ cr.define('cr.ui', function() {
this.addEventListener('mouseout', this.handleMouseOut_);
this.classList.add('decorated');
+ this.setAttribute('role', 'menu');
this.hidden = true; // Hide the menu by default.
// Decorate the children as menu items.
@@ -124,6 +125,20 @@ cr.define('cr.ui', function() {
},
/**
+ * Focuses the selected item. If selectedIndex is invalid, set it to 0
+ * first.
+ */
+ focusSelectedItem: function() {
+ if (this.selectedIndex < 0 ||
+ this.selectedIndex > this.children.length) {
+ this.selectedIndex = 0;
+ }
+
+ if (this.selectedItem)
+ this.selectedItem.focus();
+ },
+
+ /**
* Menu length
*/
get length() {
@@ -180,7 +195,10 @@ cr.define('cr.ui', function() {
case 'Enter':
case 'U+0020': // Space
if (item) {
- if (cr.dispatchSimpleEvent(item, 'activate', true, true)) {
+ var activationEvent = cr.doc.createEvent('Event');
+ activationEvent.initEvent('activate', true, true);
+ activationEvent.originalEvent = e;
+ if (item.dispatchEvent(activationEvent)) {
if (item.command)
item.command.execute();
}
@@ -208,8 +226,10 @@ cr.define('cr.ui', function() {
if (oldSelectedItem)
oldSelectedItem.selected = false;
var item = this.selectedItem;
- if (item)
+ if (item) {
item.selected = true;
+ this.focusSelectedItem();
+ }
}
/**
« no previous file with comments | « chrome/browser/resources/ntp4/recently_closed.js ('k') | chrome/browser/resources/shared/js/cr/ui/menu_button.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698