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

Unified Diff: ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js

Issue 2801453002: MD Settings: mouse movements should focus cr-action-menu items (Closed)
Patch Set: added flag to avoid multiple mousemove listeners Created 3 years, 8 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
« no previous file with comments | « ui/webui/resources/cr_elements/cr_action_menu/compiled_resources2.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
diff --git a/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js b/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
index 9f58dc4f6cd9079f59c2ee05364b0f1f5aef5e46..96aab0547acdc08d49a471d2450289c165ffe2fc 100644
--- a/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
+++ b/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
@@ -26,12 +26,16 @@ Polymer({
*/
boundClose_: null,
+ /** @private {boolean} */
+ hasMousemoveListener_: false,
+
hostAttributes: {
tabindex: 0,
},
listeners: {
'keydown': 'onKeyDown_',
+ 'mouseover': 'onMouseover_',
'tap': 'onTap_',
},
@@ -73,6 +77,11 @@ Polymer({
return;
}
+ if (!this.hasMousemoveListener_) {
+ this.hasMousemoveListener_ = true;
+ listenOnce(this, 'mousemove', this.onMouseover_.bind(this));
Dan Beam 2017/04/06 03:03:03 this is fairly similar and easier to comprehend, I
scottchen 2017/04/06 17:41:36 Not intentional, updated.
+ }
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp')
return;
@@ -84,6 +93,27 @@ Polymer({
},
/**
+ * @param {!Event} e
+ * @private
+ */
+ onMouseover_: function(e) {
+ this.hasMousemoveListener_ = false;
+ // TODO(scottchen): Using "focus" to determine selected item might mess
+ // with screen readers in some edge cases.
+ var i = 0;
+ do {
+ var target = e.path[i++];
+ if (target.classList && target.classList.contains('dropdown-item')) {
+ target.focus();
+ return;
+ }
+ } while (this != target);
+
+ // The user moved the mouse off the options. Reset focus to the dialog.
+ this.focus();
+ },
+
+ /**
* @param {number} step -1 for getting previous option (up), 1 for getting
* next option (down).
* @return {?Element} The next focusable option, taking into account
« no previous file with comments | « ui/webui/resources/cr_elements/cr_action_menu/compiled_resources2.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698