Commit aa9f4c85 authored by Daniel Clark's avatar Daniel Clark Committed by Commit Bot

A11y: Fix <input type='tel'> LocalizedControlType

An <input type='tel'> should have LocalizedControlType of "telephone"
per https://w3c.github.io/html-aam/#el-input-tel

Currently its LocalizedControlType is "edit".  This change updates it
to "telephone" by adding an entry to
BrowserAccessibility::GetLocalizedStringForRoleDescription().

Bug: 988138
Change-Id: I880df88fe45208e2a0bb296a1541599228ff73cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721033Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Commit-Queue: Dan Clark <daniec@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#683376}
parent 2d656572
......@@ -466,6 +466,10 @@ below:
<message name="IDS_AX_ROLE_SWITCH" desc="Accessibility role description for switch">
switch
</message>
<!-- https://w3c.github.io/html-aam/#el-input-tel -->
<message name="IDS_AX_ROLE_TELEPHONE" desc="Accessibility role description for telephone number input">
telephone
</message>
<message name="IDS_AX_ROLE_WEB_AREA" desc="Accessibility role description for web area">
HTML content
</message>
......
......@@ -1848,6 +1848,16 @@ base::string16 BrowserAccessibility::GetLocalizedStringForRoleDescription()
case ax::mojom::Role::kSearchBox:
return content_client->GetLocalizedString(IDS_AX_ROLE_SEARCH_BOX);
case ax::mojom::Role::kTextField: {
std::string input_type;
if (data.GetStringAttribute(ax::mojom::StringAttribute::kInputType,
&input_type) &&
input_type == "tel") {
return content_client->GetLocalizedString(IDS_AX_ROLE_TELEPHONE);
}
return {};
}
default:
return {};
}
......
......@@ -699,6 +699,41 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
TestLocalizedLandmarkType(16, ax::mojom::Role::kSearch, "search");
}
IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
LocalizedRoleDescription) {
AccessibilityNotificationWaiter waiter(shell()->web_contents(),
ui::kAXModeComplete,
ax::mojom::Event::kLoadComplete);
GURL url(
"data:text/html,"
"<input>"
"<input type='tel'>");
NavigateToURL(shell(), url);
waiter.WaitForNotification();
BrowserAccessibility* root = GetManager()->GetRoot();
ASSERT_NE(nullptr, root);
ASSERT_EQ(1u, root->PlatformChildCount());
BrowserAccessibility* body = root->PlatformGetChild(0);
ASSERT_EQ(2u, body->PlatformChildCount());
auto TestLocalizedRoleDescription =
[body](int child_index,
const base::string16& expected_localized_role_description = {}) {
BrowserAccessibility* node = body->PlatformGetChild(child_index);
ASSERT_NE(nullptr, node);
EXPECT_EQ(expected_localized_role_description,
node->GetLocalizedStringForRoleDescription());
};
// For testing purposes, assume we get en-US localized strings.
TestLocalizedRoleDescription(0, base::ASCIIToUTF16(""));
TestLocalizedRoleDescription(1, base::ASCIIToUTF16("telephone"));
}
IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
GetStyleNameAttributeAsLocalizedString) {
AccessibilityNotificationWaiter waiter(shell()->web_contents(),
......
......@@ -1042,6 +1042,16 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
if (FindExactlyOneInnerImageInMaxDepthTwo(src, &inner_image))
AddImageAnnotations(inner_image, dst);
}
WebNode node = src.GetNode();
if (!node.IsNull() && node.IsElementNode()) {
WebElement element = node.To<WebElement>();
if (element.HasHTMLTagName("input") && element.HasAttribute("type")) {
TruncateAndAddStringAttribute(dst,
ax::mojom::StringAttribute::kInputType,
element.GetAttribute("type").Utf8());
}
}
}
// The majority of the rest of this code computes attributes needed for
......
rootWebArea
++genericContainer
++++textField value='123-456-7890'
++++textField inputType='tel' value='123-456-7890'
++++++genericContainer
++++++++staticText name='123-456-7890'
++++++++++inlineTextBox name='123-456-7890'
document
++group
++++textbox Value.Value='123-456-7890'
document LocalizedControlType='document'
++group LocalizedControlType='group'
++++textbox LocalizedControlType='telephone' Value.Value='123-456-7890'
\ No newline at end of file
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE ia2_hypertext='<obj0>' n_selections=0
++IA2_ROLE_SECTION ia2_hypertext='<obj0>' n_selections=0
++++ROLE_SYSTEM_TEXT value='123-456-7890' FOCUSABLE text-input-type:tel ia2_hypertext='123-456-7890' caret_offset=0 n_selections=0
++++ROLE_SYSTEM_TEXT value='123-456-7890' FOCUSABLE text-input-type:tel ia2_hypertext='123-456-7890' caret_offset=0 n_selections=0 localized_extended_role='telephone'
<!--
@BLINK-ALLOW:inputType=*
@UIA-WIN-ALLOW:LocalizedControlType=*
@WIN-ALLOW:caret_offset*
@WIN-ALLOW:ia2_hypertext=*
@WIN-ALLOW:localized_extended_role=*
@WIN-ALLOW:n_selections*
@WIN-ALLOW:selection_start*
@WIN-ALLOW:selection_end*
......
......@@ -1380,6 +1380,8 @@ const char* ToString(ax::mojom::StringAttribute string_attribute) {
return "imageDataUrl";
case ax::mojom::StringAttribute::kInnerHtml:
return "innerHtml";
case ax::mojom::StringAttribute::kInputType:
return "inputType";
case ax::mojom::StringAttribute::kKeyShortcuts:
return "keyShortcuts";
case ax::mojom::StringAttribute::kLanguage:
......@@ -1438,6 +1440,8 @@ ax::mojom::StringAttribute ParseStringAttribute(const char* string_attribute) {
return ax::mojom::StringAttribute::kImageDataUrl;
if (0 == strcmp(string_attribute, "innerHtml"))
return ax::mojom::StringAttribute::kInnerHtml;
if (0 == strcmp(string_attribute, "inputType"))
return ax::mojom::StringAttribute::kInputType;
if (0 == strcmp(string_attribute, "keyShortcuts"))
return ax::mojom::StringAttribute::kKeyShortcuts;
if (0 == strcmp(string_attribute, "language"))
......
......@@ -488,6 +488,7 @@ enum StringAttribute {
kImageAnnotation,
kImageDataUrl,
kInnerHtml,
kInputType,
kKeyShortcuts,
// Only present when different from parent.
kLanguage,
......
......@@ -1305,6 +1305,9 @@ std::string AXNodeData::ToString() const {
case ax::mojom::StringAttribute::kInnerHtml:
result += " inner_html=" + value;
break;
case ax::mojom::StringAttribute::kInputType:
result += " input_type=" + value;
break;
case ax::mojom::StringAttribute::kKeyShortcuts:
result += " key_shortcuts=" + value;
break;
......
......@@ -558,6 +558,16 @@ base::string16 TestAXNodeWrapper::GetLocalizedStringForRoleDescription() const {
case ax::mojom::Role::kSearchBox:
return base::ASCIIToUTF16("search box");
case ax::mojom::Role::kTextField: {
std::string input_type;
if (data.GetStringAttribute(ax::mojom::StringAttribute::kInputType,
&input_type) &&
input_type == "tel") {
return base::ASCIIToUTF16("telephone");
}
return {};
}
default:
return {};
}
......
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