Skip to content

Commit

Permalink
Bug 1625870 - Support figure and figcaption is OSX. r=morgan
Browse files Browse the repository at this point in the history
  • Loading branch information
eeejay committed Apr 28, 2020
1 parent 54fb8b0 commit b62ce6a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion accessible/base/RoleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ ROLE(ENTRY,
ROLE(CAPTION,
"caption",
ATK_ROLE_CAPTION,
NSAccessibilityStaticTextRole,
NSAccessibilityGroupRole,
USE_ROLE_STRING,
IA2_ROLE_CAPTION,
java::SessionAccessibility::CLASSNAME_VIEW,
Expand Down
1 change: 1 addition & 0 deletions accessible/html/HTMLFormControlAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ ENameValueFlag HTMLFigureAccessible::NativeName(nsString& aName) const {
if (captionContent)
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);

aName.CompressWhitespace();
return eNameOK;
}

Expand Down
17 changes: 12 additions & 5 deletions accessible/mac/mozAccessible.mm
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ - (NSString*)accessibilityActionDescription:(NSString*)action {
return NSAccessibilityActionDescription(action);
}

- (BOOL)providesLabelNotTitle {
// These accessible types are the exception to the rule of label vs. title:
// They may be named explicitly, but they still provide a label not a title.
return mRole == roles::GROUPING || mRole == roles::RADIO_GROUP || mRole == roles::FIGURE ||
mRole == roles::GRAPHIC;
}

- (NSString*)accessibilityLabel {
AccessibleWrap* accWrap = [self getGeckoAccessible];
ProxyAccessible* proxy = [self getProxyAccessible];
Expand All @@ -613,7 +620,7 @@ - (NSString*)accessibilityLabel {
/* If our accessible is:
* 1. Named by invisible text, or
* 2. Has more than one labeling relation, or
* 3. Is a grouping
* 3. Is a special role defined in providesLabelNotTitle
* ... return its name as a label (AXDescription).
*/
if (accWrap) {
Expand All @@ -622,7 +629,7 @@ - (NSString*)accessibilityLabel {
return nil;
}

if (mRole != roles::GROUPING && mRole != roles::RADIO_GROUP) {
if (![self providesLabelNotTitle]) {
Relation rel = accWrap->RelationByType(RelationType::LABELLED_BY);
if (rel.Next() && !rel.Next()) {
return nil;
Expand All @@ -634,7 +641,7 @@ - (NSString*)accessibilityLabel {
return nil;
}

if (mRole != roles::GROUPING && mRole != roles::RADIO_GROUP) {
if (![self providesLabelNotTitle]) {
nsTArray<ProxyAccessible*> rels = proxy->RelationByType(RelationType::LABELLED_BY);
if (rels.Length() == 1) {
return nil;
Expand Down Expand Up @@ -1128,8 +1135,8 @@ - (NSString*)roleDescription {
- (NSString*)title {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

// If this is a grouping we provide the name in the label (AXDescription).
if (mRole == roles::GROUPING || mRole == roles::RADIO_GROUP) {
// In some special cases we provide the name in the label (AXDescription).
if ([self providesLabelNotTitle]) {
return nil;
}

Expand Down
54 changes: 54 additions & 0 deletions accessible/tests/browser/mac/browser_roles_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,57 @@ addAccessibleTask(`<hr id="hr" />`, (browser, accDoc) => {
"Subrole for hr is AXContentSeparator"
);
});

addAccessibleTask(
`
<figure id="figure">
<img id="img" src="http://example.com/a11y/accessible/tests/mochitest/moz.png" alt="Logo">
<p>Non-image figure content</p>
<figcaption id="figcaption">Old Mozilla logo</figcaption>
</figure>`,
(browser, accDoc) => {
let figure = getNativeInterface(accDoc, "figure");
ok(!figure.getAttributeValue("AXTitle"), "Figure should not have a title");
is(
figure.getAttributeValue("AXDescription"),
"Old Mozilla logo",
"Correct figure label"
);
is(figure.getAttributeValue("AXRole"), "AXGroup", "Correct figure role");
is(
figure.getAttributeValue("AXRoleDescription"),
"figure",
"Correct figure role description"
);

let img = getNativeInterface(accDoc, "img");
ok(!img.getAttributeValue("AXTitle"), "img should not have a title");
is(img.getAttributeValue("AXDescription"), "Logo", "Correct img label");
is(img.getAttributeValue("AXRole"), "AXImage", "Correct img role");
is(
img.getAttributeValue("AXRoleDescription"),
"image",
"Correct img role description"
);

let figcaption = getNativeInterface(accDoc, "figcaption");
ok(
!figcaption.getAttributeValue("AXTitle"),
"figcaption should not have a title"
);
ok(
!figcaption.getAttributeValue("AXDescription"),
"figcaption should not have a label"
);
is(
figcaption.getAttributeValue("AXRole"),
"AXGroup",
"Correct figcaption role"
);
is(
figcaption.getAttributeValue("AXRoleDescription"),
"group",
"Correct figcaption role description"
);
}
);

0 comments on commit b62ce6a

Please sign in to comment.