diff options
Diffstat (limited to 'ui/webui/resources/js/cr/ui/focus_manager.js')
-rw-r--r-- | ui/webui/resources/js/cr/ui/focus_manager.js | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/ui/webui/resources/js/cr/ui/focus_manager.js b/ui/webui/resources/js/cr/ui/focus_manager.js index caa0454..4291d7c 100644 --- a/ui/webui/resources/js/cr/ui/focus_manager.js +++ b/ui/webui/resources/js/cr/ui/focus_manager.js @@ -112,14 +112,7 @@ cr.define('cr.ui', function() { * @private */ setFocus_: function() { - // If |this.focusDirBackwards_| is true, the user has pressed "Shift+Tab" - // and has caused the focus to be transferred backward, outside of the - // current dialog. In this case, loop around and try to focus the last - // element of the dialog; otherwise, try to focus the first element of the - // dialog. - var focusableElements = this.getFocusableElements_(); - var element = this.focusDirBackwards_ ? focusableElements.pop() : - focusableElements.shift(); + var element = this.selectFocusableElement_(); if (element) { element.focus(); this.dispatchFocusEvent_(element); @@ -134,6 +127,40 @@ cr.define('cr.ui', function() { }, /** + * Selects first appropriate focusable element according to the + * current focus direction and element type. If it is a radio button, + * checked one is selected from the group. + * @private + */ + selectFocusableElement_: function() { + // If |this.focusDirBackwards_| is true, the user has pressed "Shift+Tab" + // and has caused the focus to be transferred backward, outside of the + // current dialog. In this case, loop around and try to focus the last + // element of the dialog; otherwise, try to focus the first element of the + // dialog. + var focusableElements = this.getFocusableElements_(); + var element = this.focusDirBackwards_ ? focusableElements.pop() : + focusableElements.shift(); + if (!element) + return null; + if (element.tagName != 'INPUT' || element.type != 'radio' || + element.name == '') { + return element; + } + if (!element.checked) { + for (var i = 0; i < focusableElements.length; i++) { + var e = focusableElements[i]; + if (e && e.tagName == 'INPUT' && e.type == 'radio' && + e.name == element.name && e.checked) { + element = e; + break; + } + } + } + return element; + }, + + /** * Handler for focus events on the page. * @param {Event} event The focus event. * @private |