diff options
author | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 21:44:08 +0000 |
---|---|---|
committer | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-21 21:44:08 +0000 |
commit | 690679e143ba9762ba4cbd2721a922e914189116 (patch) | |
tree | 6c46ce0e3c876be0f2f54ff800e982a2643f5527 /ui/webui | |
parent | aca40ac4bc4e982a4af75ff2a80ab835382f1af1 (diff) | |
download | chromium_src-690679e143ba9762ba4cbd2721a922e914189116.zip chromium_src-690679e143ba9762ba4cbd2721a922e914189116.tar.gz chromium_src-690679e143ba9762ba4cbd2721a922e914189116.tar.bz2 |
Fixed focus behaviour for radio buttons on chrome://help and chrome://settings.
If some elemenent should be focused on the page and it's a radio
button, checked one from the corresponding group is selected, instead
of the first one.
BUG=318896
TEST=manual tests on Pixel.
Review URL: https://codereview.chromium.org/79803002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/webui')
-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 |