Chromium Code Reviews| 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..7e36605b666059e12d6a4be162b791ca6d363935 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,14 @@ Polymer({ |
| return; |
| } |
| + if (!this.hasMousemoveListener_) { |
|
dpapad
2017/04/06 18:00:31
Does this need to be above the following check? Ca
scottchen
2017/04/06 21:40:23
Acknowledged. I moved it into the if(nextOption) s
|
| + this.hasMousemoveListener_ = true; |
| + listenOnce(this, 'mousemove', function(e) { |
| + this.onMouseover_(e); |
| + this.hasMousemoveListener_ = false; |
| + }.bind(this)); |
| + } |
| + |
| if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') |
| return; |
| @@ -84,6 +96,26 @@ Polymer({ |
| }, |
| /** |
| + * @param {!Event} e |
| + * @private |
| + */ |
| + onMouseover_: function(e) { |
| + // 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 |