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..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 |