Bug 1825718 - map SVG elements to a role if they have an aria-label attribute r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D174465
This commit is contained in:
Robert Longson
2023-04-04 07:07:22 +00:00
parent 23c7e1fe89
commit 830affe37f
2 changed files with 10 additions and 6 deletions

View File

@@ -271,7 +271,8 @@ bool nsAccessibilityService::ShouldCreateImgAccessible(
/**
* Return true if the SVG element should be accessible
*/
static bool MustSVGElementBeAccessible(nsIContent* aContent) {
static bool MustSVGElementBeAccessible(nsIContent* aContent,
DocAccessible* aDocument) {
// https://w3c.github.io/svg-aam/#include_elements
for (nsIContent* childElm = aContent->GetFirstChild(); childElm;
childElm = childElm->GetNextSibling()) {
@@ -279,7 +280,7 @@ static bool MustSVGElementBeAccessible(nsIContent* aContent) {
return true;
}
}
return false;
return MustBeAccessible(aContent, aDocument);
}
/**
@@ -1331,21 +1332,21 @@ LocalAccessible* nsAccessibilityService::CreateAccessible(
// Shape elements: rect, circle, ellipse, line, path, polygon,
// and polyline. 'use' and 'text' graphic elements require
// special support.
if (MustSVGElementBeAccessible(content)) {
if (MustSVGElementBeAccessible(content, document)) {
newAcc = new EnumRoleAccessible<roles::GRAPHIC>(content, document);
}
} else if (content->IsSVGElement(nsGkAtoms::text)) {
newAcc = new HyperTextAccessibleWrap(content->AsElement(), document);
} else if (content->IsSVGElement(nsGkAtoms::svg)) {
// An <svg> element could contain <foreignobject>, which contains HTML
// An <svg> element could contain <foreignObject>, which contains HTML
// but does not normally create its own Accessible. This means that the
// <svg> Accessible could have TextLeafAccessible children, so it must
// be a HyperTextAccessible.
newAcc =
new EnumRoleHyperTextAccessible<roles::DIAGRAM>(content, document);
} else if (content->IsSVGElement(nsGkAtoms::g) &&
MustSVGElementBeAccessible(content)) {
// <g> can also contain <foreignobject>.
MustSVGElementBeAccessible(content, document)) {
// <g> can also contain <foreignObject>.
newAcc =
new EnumRoleHyperTextAccessible<roles::GROUPING>(content, document);
}

View File

@@ -25,6 +25,7 @@
testRole("polyline", ROLE_GRAPHIC);
testRole("path", ROLE_GRAPHIC);
testRole("image", ROLE_GRAPHIC);
testRole("image2", ROLE_GRAPHIC);
SimpleTest.finish();
}
@@ -82,6 +83,8 @@
xlink:href="../moz.png">
<title>image</title>
</image>
<image x1="25" y1="110" width="50" height="20" id="image2"
xlink:href="../moz.png" aria-label="hello"/>
</svg>
</body>