Commit 5854aa99 authored by Mark Schillaci's avatar Mark Schillaci Committed by Commit Bot

Added a11y state description to Checkbox on Android

This CL updates the behavior of Checkbox on Android.

With this change, the mixed state of a Checkbox will now
be announced during swipe navigation or when a node is
initially selected. Until now the mixed state has been
synonymous with false.

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

This CL also updates associated unit test expectations.


AX-Relnotes: Checkboxes on Android will now announce "partially checked" when in a mixed state
Bug: 1121750
Change-Id: Iec434d20b41ec71b4708b1815c78d3cf7b2497fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432089
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarMark Schillaci <mschillaci@google.com>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812364}
parent 66306884
......@@ -265,6 +265,13 @@ bool BrowserAccessibilityAndroid::IsRangeType() const {
(GetRole() == ax::mojom::Role::kSplitter && IsFocusable()));
}
bool BrowserAccessibilityAndroid::IsReportingCheckable() const {
// To communicate kMixed state Checkboxes, we will rely on state description,
// so we will not report node as checkable to avoid duplicate utterances.
return IsCheckable() &&
GetData().GetCheckedState() != ax::mojom::CheckedState::kMixed;
}
bool BrowserAccessibilityAndroid::IsScrollable() const {
return GetBoolAttribute(ax::mojom::BoolAttribute::kScrollable);
}
......@@ -557,6 +564,11 @@ base::string16 BrowserAccessibilityAndroid::GetStateDescription() const {
if (GetRole() == ax::mojom::Role::kToggleButton)
return GetToggleButtonStateDescription();
// For Checkboxes, if we are in a kMixed state, we will communicate
// "partially checked" through the state description.
if (IsCheckable() && !IsReportingCheckable())
return GetCheckboxStateDescription();
// Otherwise we will not use state description
return base::string16();
}
......@@ -604,6 +616,13 @@ base::string16 BrowserAccessibilityAndroid::GetToggleButtonStateDescription()
return content_client->GetLocalizedString(IDS_AX_TOGGLE_BUTTON_OFF);
}
base::string16 BrowserAccessibilityAndroid::GetCheckboxStateDescription()
const {
content::ContentClient* content_client = content::GetContentClient();
return content_client->GetLocalizedString(IDS_AX_CHECKBOX_PARTIALLY_CHECKED);
}
std::string BrowserAccessibilityAndroid::GetRoleString() const {
return ui::ToString(GetRole());
}
......
......@@ -47,6 +47,7 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
bool IsMultiLine() const;
bool IsMultiselectable() const;
bool IsRangeType() const;
bool IsReportingCheckable() const;
bool IsScrollable() const;
bool IsSeekControl() const;
bool IsSelected() const;
......@@ -93,6 +94,7 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
base::string16 GetStateDescription() const;
base::string16 GetMultiselectableStateDescription() const;
base::string16 GetToggleButtonStateDescription() const;
base::string16 GetCheckboxStateDescription() const;
base::string16 GetRoleDescription() const;
......
......@@ -758,11 +758,11 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo(
env, obj, info, android_node->unique_id());
}
Java_WebContentsAccessibilityImpl_setAccessibilityNodeInfoBooleanAttributes(
env, obj, info, unique_id, node->IsCheckable(), node->IsChecked(),
node->IsClickable(), node->IsContentInvalid(), node->IsEnabled(),
node->IsFocusable(), node->IsFocused(), node->HasImage(),
node->IsPasswordField(), node->IsScrollable(), node->IsSelected(),
node->IsVisibleToUser());
env, obj, info, unique_id, node->IsReportingCheckable(),
node->IsChecked(), node->IsClickable(), node->IsContentInvalid(),
node->IsEnabled(), node->IsFocusable(), node->IsFocused(),
node->HasImage(), node->IsPasswordField(), node->IsScrollable(),
node->IsSelected(), node->IsVisibleToUser());
Java_WebContentsAccessibilityImpl_addAccessibilityNodeInfoActions(
env, obj, info, unique_id, node->CanScrollForward(),
node->CanScrollBackward(), node->CanScrollUp(), node->CanScrollDown(),
......
android.webkit.WebView focusable focused scrollable
++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='CheckBox1'
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='CheckBox2'
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='CheckBox3'
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='CheckBox3' state_description='Partially Checked'
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='CheckBox4'
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='Complex checkbox'
++++android.widget.TextView name='Complex '
......
android.webkit.WebView focusable focused scrollable
++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable
\ No newline at end of file
++android.widget.CheckBox role_description='checkbox' checkable clickable focusable state_description='Partially Checked'
\ No newline at end of file
......@@ -2,4 +2,4 @@ android.webkit.WebView focusable focused scrollable
++android.view.View role_description='menu'
++++android.view.MenuItem role_description='checkbox' checkable clickable name='Menu item 1'
++++android.view.MenuItem role_description='checkbox' checkable checked clickable name='Menu item 2' item_index=1 row_index=1
++++android.view.MenuItem role_description='checkbox' checkable clickable name='Menu item 3' item_index=2 row_index=2
++++android.view.MenuItem role_description='checkbox' checkable clickable name='Menu item 3' state_description='Partially Checked' item_index=2 row_index=2
\ No newline at end of file
......@@ -4,4 +4,4 @@ android.webkit.WebView focusable focused scrollable
++++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='Checkbox1'
++++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='Checkbox2'
++++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='Checkbox3'
++++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='Checkbox4'
\ No newline at end of file
++++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='Checkbox4' state_description='Partially Checked'
\ No newline at end of file
......@@ -4,4 +4,4 @@ android.webkit.WebView focusable focused scrollable
++++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='Checkbox2'
++android.view.View role_description='menu'
++++android.widget.CheckBox role_description='checkbox' checkable checked clickable focusable name='Checkbox3'
++++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='Checkbox4'
\ No newline at end of file
++++android.widget.CheckBox role_description='checkbox' checkable clickable focusable name='Checkbox4' state_description='Partially Checked'
\ No newline at end of file
......@@ -790,6 +790,9 @@ below:
<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>
<message name="IDS_AX_CHECKBOX_PARTIALLY_CHECKED" desc="Accessibility state description for a checkbox that is in the partially checked state">
Partially Checked
</message>
</if>
<!-- Automatic image annotations for accessibility -->
......
764812a9256d7be7e640e7906551872dc2e5cb7d
\ 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