Commit 2dc3de6b authored by Mark Schillaci's avatar Mark Schillaci Committed by Commit Bot

Added a11y state description to ToggleButton on Android

This CL updates the behavior of ToggleButton on Android.

With this change, the state of a ToggleButton ("On"/"Off")
will now be read during swipe navigation when a node is
initially selected. Until now the state of the toggle button
has only been announced during a toggle action.

We append the state of the Toggle in the stateDescription
element of the node's corresponding AccessibilityNodeInfo
object.

This CL also updates associated unit test expectations.


AX-Relnotes: ToggleButtons on Android now explicitly announce their state.
Bug: 1121743
Change-Id: Iaa25379fa9c478c6c96c9a58d99495a8a8fe978f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432211Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarMark Schillaci <mschillaci@google.com>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Cr-Commit-Position: refs/heads/master@{#811759}
parent 3201d75d
...@@ -553,6 +553,10 @@ base::string16 BrowserAccessibilityAndroid::GetStateDescription() const { ...@@ -553,6 +553,10 @@ base::string16 BrowserAccessibilityAndroid::GetStateDescription() const {
if (IsMultiselectable()) if (IsMultiselectable())
return GetMultiselectableStateDescription(); return GetMultiselectableStateDescription();
// For Toggle buttons, we will append "on"/"off" in the state description.
if (GetRole() == ax::mojom::Role::kToggleButton)
return GetToggleButtonStateDescription();
// Otherwise we will not use state description // Otherwise we will not use state description
return base::string16(); return base::string16();
} }
...@@ -589,6 +593,17 @@ base::string16 BrowserAccessibilityAndroid::GetMultiselectableStateDescription() ...@@ -589,6 +593,17 @@ base::string16 BrowserAccessibilityAndroid::GetMultiselectableStateDescription()
values, nullptr); values, nullptr);
} }
base::string16 BrowserAccessibilityAndroid::GetToggleButtonStateDescription()
const {
content::ContentClient* content_client = content::GetContentClient();
// For checked Toggle buttons, we will return "on", otherwise "off".
if (IsChecked())
return content_client->GetLocalizedString(IDS_AX_TOGGLE_BUTTON_ON);
return content_client->GetLocalizedString(IDS_AX_TOGGLE_BUTTON_OFF);
}
std::string BrowserAccessibilityAndroid::GetRoleString() const { std::string BrowserAccessibilityAndroid::GetRoleString() const {
return ui::ToString(GetRole()); return ui::ToString(GetRole());
} }
......
...@@ -92,6 +92,7 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility { ...@@ -92,6 +92,7 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
base::string16 GetStateDescription() const; base::string16 GetStateDescription() const;
base::string16 GetMultiselectableStateDescription() const; base::string16 GetMultiselectableStateDescription() const;
base::string16 GetToggleButtonStateDescription() const;
base::string16 GetRoleDescription() const; base::string16 GetRoleDescription() const;
......
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.Button role_description='button' clickable focusable name='Button1' ++android.widget.Button role_description='button' clickable focusable name='Button1'
++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Button2' ++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Button2' state_description='On'
++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Button3' ++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Button3' state_description='Off'
++android.widget.Spinner role_description='pop up button' clickable focusable name='Button4' ++android.widget.Spinner role_description='pop up button' clickable focusable name='Button4'
++android.widget.Button role_description='button' clickable focusable name='Button5' ++android.widget.Button role_description='button' clickable focusable name='Button5'
++android.widget.Button role_description='button' clickable focusable name='Complex button ' ++android.widget.Button role_description='button' clickable focusable name='Complex button '
++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Complex toggle button ' ++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Complex toggle button ' state_description='On'
++++android.widget.TextView name='Complex toggle button ' ++++android.widget.TextView name='Complex toggle button '
++++android.widget.EditText clickable editable_text focusable input_type=1 ++++android.widget.EditText clickable editable_text focusable input_type=1
++android.widget.Spinner role_description='pop up button' clickable focusable name='Complex pop up button ' ++android.widget.Spinner role_description='pop up button' clickable focusable name='Complex pop up button '
......
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.Button role_description='button' clickable focusable name='Regular button' ++android.widget.Button role_description='button' clickable focusable name='Regular button'
++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button unpressed' ++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button unpressed' state_description='Off'
++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Toggle button pressed' ++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Toggle button pressed' state_description='On'
++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button mixed' ++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button mixed' state_description='Off'
\ No newline at end of file \ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.widget.Button role_description='button' clickable focusable name='Regular button' ++android.widget.Button role_description='button' clickable focusable name='Regular button'
++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button' ++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button' state_description='Off'
++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Toggle button' ++android.widget.ToggleButton role_description='toggle button' checkable checked clickable focusable name='Toggle button' state_description='On'
++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button' ++android.widget.ToggleButton role_description='toggle button' checkable clickable focusable name='Toggle button' state_description='Off'
\ No newline at end of file
...@@ -784,6 +784,12 @@ below: ...@@ -784,6 +784,12 @@ below:
<message name="IDS_AX_MULTISELECTABLE_STATE_DESCRIPTION_NONE" desc="Accessibility state description for a multiselectable node when no children are selected"> <message name="IDS_AX_MULTISELECTABLE_STATE_DESCRIPTION_NONE" desc="Accessibility state description for a multiselectable node when no children are selected">
multiselectable, none selected. multiselectable, none selected.
</message> </message>
<message name="IDS_AX_TOGGLE_BUTTON_ON" desc="Accessibility state description for a toggle button when it is in the on/checked state">
On
</message>
<message name="IDS_AX_TOGGLE_BUTTON_OFF" desc="Accessibility state description for a toggle button when it is in the off/unchecked state">
Off
</message>
</if> </if>
<!-- Automatic image annotations for accessibility --> <!-- Automatic image annotations for accessibility -->
......
c931549c9cd042e8d3f44a325df3fd9346b26452
\ No newline at end of file
3ac2df284011cb4f293a9c82e97ca32d631212c4
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment