Bug 1911505: Expose highlighted text to Mac a11y. r=morgan,eeejay

We do this via the undocumented AXHighlight attribute, as gleaned from the WebKit and Chromium source code.

Differential Revision: https://phabricator.services.mozilla.com/D218513
This commit is contained in:
James Teh 2024-08-26 02:02:46 +00:00
parent d0e79f1b8c
commit 69b36e34e7
3 changed files with 34 additions and 0 deletions

View File

@ -135,6 +135,12 @@ NSDictionary* StringAttributesFromAccAttributes(AccAttributes* aAttributes,
forKey:NSAccessibilityMarkedMisspelledTextAttribute];
}
}
} else if (iter.Name() == nsGkAtoms::mark) {
if (auto value = iter.Value<bool>()) {
if (*value) {
[attrDict setObject:@YES forKey:@"AXHighlight"];
}
}
} else {
nsAutoString valueStr;
iter.ValueAsString(valueStr);

View File

@ -13,6 +13,7 @@ support-files = [
"!/accessible/tests/mochitest/letters.gif",
"!/accessible/tests/mochitest/moz.png",
]
prefs = ["dom.text_fragments.enabled=true"]
["browser_app.js"]
https_first_disabled = true

View File

@ -163,3 +163,30 @@ addAccessibleTask(
is(text, `hello world${kEmbedChar}`, "Unattributed string is correct");
}
);
// Test text fragment.
addAccessibleTask(
`This is a test.`,
async (browser, accDoc) => {
const macDoc = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
const range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUnorderedTextMarkers",
[
macDoc.getAttributeValue("AXStartTextMarker"),
macDoc.getAttributeValue("AXEndTextMarker"),
]
);
const attributedText = macDoc.getParameterizedAttributeValue(
"AXAttributedStringForTextMarkerRange",
range
);
is(attributedText.length, 3);
ok(!attributedText[0].AXHighlight);
ok(attributedText[1].AXHighlight);
is(attributedText[1].string, "test");
ok(!attributedText[2].AXHighlight);
},
{ urlSuffix: "#:~:text=test" }
);