Skip to content

Commit

Permalink
Update figure and figcaption HTML-AAM mapping and accName calculation
Browse files Browse the repository at this point in the history
Fixed: 1298054
Change-Id: I835bde6b6d65676fb798afca1c2f7c0193327ea0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3496582
Reviewed-by: Nektarios Paisios <[email protected]>
Reviewed-by: Eric Seckler <[email protected]>
Commit-Queue: Valerie Young <[email protected]>
Cr-Commit-Position: refs/heads/main@{#981803}
NOKEYCHECK=True
GitOrigin-RevId: f681e9502d7ee22dae19f02b2c9f281e40602a9f
  • Loading branch information
spectranaut authored and copybara-github committed Mar 16, 2022
1 parent 467ba96 commit 97a74d5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 131 deletions.
1 change: 0 additions & 1 deletion blink/renderer/modules/accessibility/ax_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ enum AccessibilityOptionalBool {
// https://w3c.github.io/html-aam/#accessible-name-and-description-computation
enum AXTextSource {
kAXTextFromNativeSourceUninitialized = -1,
kAXTextFromNativeHTMLFigcaption,
kAXTextFromNativeHTMLLabel,
kAXTextFromNativeHTMLLabelFor,
kAXTextFromNativeHTMLLabelWrapped,
Expand Down
69 changes: 16 additions & 53 deletions blink/renderer/modules/accessibility/ax_node_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,22 @@ AccessibilityOrientation AXNodeObject::Orientation() const {
}
}

// According to the standard, the figcaption should only be the first or
// last child: https://html.spec.whatwg.org/#the-figcaption-element
AXObject* AXNodeObject::GetChildFigcaption() const {
AXObject* child = FirstChildIncludingIgnored();
if (!child)
return nullptr;
if (child->RoleValue() == ax::mojom::blink::Role::kFigcaption)
return child;

child = LastChildIncludingIgnored();
if (child->RoleValue() == ax::mojom::blink::Role::kFigcaption)
return child;

return nullptr;
}

AXObject::AXObjectVector AXNodeObject::RadioButtonsInGroup() const {
AXObjectVector radio_buttons;
if (!node_ || RoleValue() != ax::mojom::blink::Role::kRadioButton)
Expand Down Expand Up @@ -4742,22 +4758,6 @@ AXObject* AXNodeObject::ErrorMessage() const {
return AXObjectCache().ValidationMessageObjectIfInvalid(true);
}

// According to the standard, the figcaption should only be the first or
// last child: https://html.spec.whatwg.org/#the-figcaption-element
static Element* GetChildFigcaption(const Node& node) {
Element* element = ElementTraversal::FirstChild(node);
if (!element)
return nullptr;
if (element->HasTagName(html_names::kFigcaptionTag))
return element;

element = ElementTraversal::LastChild(node);
if (element->HasTagName(html_names::kFigcaptionTag))
return element;

return nullptr;
}

// Based on
// http://rawgit.com/w3c/aria/master/html-aam/html-aam.html#accessible-name-and-description-calculation
String AXNodeObject::NativeTextAlternative(
Expand Down Expand Up @@ -5024,43 +5024,6 @@ String AXNodeObject::NativeTextAlternative(
return text_alternative;
}

// 5.7 figure and figcaption Elements
if (GetNode()->HasTagName(html_names::kFigureTag)) {
// figcaption
name_from = ax::mojom::blink::NameFrom::kRelatedElement;
if (name_sources) {
name_sources->push_back(NameSource(*found_text_alternative));
name_sources->back().type = name_from;
name_sources->back().native_source = kAXTextFromNativeHTMLFigcaption;
}
Element* figcaption = GetChildFigcaption(*(GetNode()));
if (figcaption) {
AXObject* figcaption_ax_object = AXObjectCache().GetOrCreate(figcaption);
if (figcaption_ax_object) {
text_alternative =
RecursiveTextAlternative(*figcaption_ax_object, nullptr, visited);

if (related_objects) {
local_related_objects.push_back(
MakeGarbageCollected<NameSourceRelatedObject>(
figcaption_ax_object, text_alternative));
*related_objects = local_related_objects;
local_related_objects.clear();
}

if (name_sources) {
NameSource& source = name_sources->back();
source.related_objects = *related_objects;
source.text = text_alternative;
*found_text_alternative = true;
} else {
return text_alternative;
}
}
}
return text_alternative;
}

// 5.8 img or area Element
if (IsA<HTMLImageElement>(GetNode()) || IsA<HTMLAreaElement>(GetNode()) ||
(GetLayoutObject() && GetLayoutObject()->IsSVGImage())) {
Expand Down
2 changes: 2 additions & 0 deletions blink/renderer/modules/accessibility/ax_node_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class MODULES_EXPORT AXNodeObject : public AXObject {
AXObject* InPageLinkTarget() const override;
AccessibilityOrientation Orientation() const override;

AXObject* GetChildFigcaption() const override;

// Used to compute kRadioGroupIds, which is only used on Mac.
// TODO(accessibility) Consider computing on browser side and removing here.
AXObjectVector RadioButtonsInGroup() const override;
Expand Down
12 changes: 12 additions & 0 deletions blink/renderer/modules/accessibility/ax_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,16 @@ void AXObject::SerializeOtherScreenReaderAttributes(
DCHECK_NE(node_data->role, ax::mojom::blink::Role::kUnknown);
DCHECK_NE(node_data->role, ax::mojom::blink::Role::kNone);

if (node_data->role == ax::mojom::blink::Role::kFigure) {
AXObject* fig_caption = GetChildFigcaption();
if (fig_caption) {
std::vector<int32_t> ids;
ids.push_back(GetChildFigcaption()->AXObjectID());
node_data->AddIntListAttribute(
ax::mojom::blink::IntListAttribute::kDetailsIds, ids);
}
}

if (ui::IsPlatformDocument(node_data->role) && !IsLoaded())
node_data->AddBoolAttribute(ax::mojom::blink::BoolAttribute::kBusy, true);

Expand Down Expand Up @@ -3862,6 +3872,8 @@ AccessibilityOrientation AXObject::Orientation() const {
return kAccessibilityOrientationUndefined;
}

AXObject* AXObject::GetChildFigcaption() const { return nullptr; }

void AXObject::LoadInlineTextBoxes() {}

void AXObject::ForceAddInlineTextBoxChildren() {}
Expand Down
2 changes: 2 additions & 0 deletions blink/renderer/modules/accessibility/ax_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
*text_underline_style = ax::mojom::blink::TextDecorationStyle::kNone;
}

virtual AXObject* GetChildFigcaption() const;

virtual AXObjectVector RadioButtonsInGroup() const {
return AXObjectVector();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ String NativeSourceType(AXTextSource native_source) {
switch (native_source) {
case kAXTextFromNativeSVGDescElement:
return SourceType::Description;
case kAXTextFromNativeHTMLFigcaption:
return SourceType::Figcaption;
case kAXTextFromNativeHTMLLabel:
return SourceType::Label;
case kAXTextFromNativeHTMLLabelFor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ element
AXRole: AXCell "Cell2"
AXRole: AXStaticText "Cell2"
AXRole: AXInlineTextBox "Cell2"
AXRole: AXFigure "Fig1. - Blue Box"
AXRole: AXFigure
AXRole: AXImage "blue"
AXRole: AXFigcaption
AXRole: AXStaticText "Fig1. - Blue Box"
Expand Down
8 changes: 4 additions & 4 deletions blink/web_tests/accessibility/name-calc-figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</script>

<div class="container">
<figure id="figure3" title="figure3-title">
<figure id="figure3">
<figcaption>figcaption3</figcaption>
<img src="resources/cake.png" alt="cake">
</figure>
Expand All @@ -39,9 +39,9 @@
<script>
test(function(t) {
var axFigure3 = accessibilityController.accessibleElementById("figure3");
assert_equals(axFigure3.name, "figcaption3");
assert_equals(axFigure3.nameFrom, "relatedElement");
}, "Figure element with figcaption and title");
assert_equals(axFigure3.name, "");
assert_equals(axFigure3.nameFrom, "");
}, "Figure element with figcaption and no title");
</script>

<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ Tests name sources in images and figures.
type : attribute
}
[2] : {
nativeSource : figcaption
type : relatedElement
}
[3] : {
attribute : title
type : attribute
}
Expand Down Expand Up @@ -49,10 +45,6 @@ Tests name sources in images and figures.
type : attribute
}
[2] : {
nativeSource : figcaption
type : relatedElement
}
[3] : {
attribute : title
type : attribute
value : {
Expand All @@ -75,10 +67,6 @@ Tests name sources in images and figures.
}
{
childIds : <object>
description : {
type : computedString
value : figure3-title
}
domNode : figure#figure3
ignored : false
name : {
Expand All @@ -92,25 +80,7 @@ Tests name sources in images and figures.
type : attribute
}
[2] : {
nativeSource : figcaption
nativeSourceValue : {
relatedNodes : [
[0] : {
backendDOMNodeId : <number>
text : figcaption3
}
]
type : nodeList
}
type : relatedElement
value : {
type : computedString
value : figcaption3
}
}
[3] : {
attribute : title
superseded : true
type : attribute
value : {
type : computedString
Expand All @@ -119,21 +89,21 @@ Tests name sources in images and figures.
}
]
type : computedString
value : figcaption3
value : figure3-title
}
nodeId : <string>
parentId : <string>
properties : [
[0] : {
name : labelledby
name : details
value : {
relatedNodes : [
[0] : {
nodeResult : figcaption
text : figcaption3
}
]
type : nodeList
type : idrefList
value :
}
}
]
Expand Down Expand Up @@ -169,24 +139,6 @@ Tests name sources in images and figures.
}
}
[2] : {
nativeSource : figcaption
nativeSourceValue : {
relatedNodes : [
[0] : {
backendDOMNodeId : <number>
text : figcaption4
}
]
type : nodeList
}
superseded : true
type : relatedElement
value : {
type : computedString
value : figcaption4
}
}
[3] : {
attribute : title
superseded : true
type : attribute
Expand All @@ -202,6 +154,18 @@ Tests name sources in images and figures.
nodeId : <string>
parentId : <string>
properties : [
[0] : {
name : details
value : {
relatedNodes : [
[0] : {
nodeResult : figcaption
}
]
type : idrefList
value :
}
}
]
role : {
type : role
Expand Down Expand Up @@ -251,24 +215,6 @@ Tests name sources in images and figures.
}
}
[2] : {
nativeSource : figcaption
nativeSourceValue : {
relatedNodes : [
[0] : {
backendDOMNodeId : <number>
text : figcaption5
}
]
type : nodeList
}
superseded : true
type : relatedElement
value : {
type : computedString
value : figcaption5
}
}
[3] : {
attribute : title
superseded : true
type : attribute
Expand All @@ -285,6 +231,18 @@ Tests name sources in images and figures.
parentId : <string>
properties : [
[0] : {
name : details
value : {
relatedNodes : [
[0] : {
nodeResult : figcaption
}
]
type : idrefList
value :
}
}
[1] : {
name : labelledby
value : {
relatedNodes : [
Expand Down

0 comments on commit 97a74d5

Please sign in to comment.