haikuwebkit/LayoutTests/accessibility/ios-simulator/image-overlay-elements.html

81 lines
2.5 KiB
HTML
Raw Permalink Normal View History

Accessibility support for image text recognition. https://bugs.webkit.org/show_bug.cgi?id=224280 rdar://76348740 Reviewed by Chris Fleizach. Source/WebCore: Test: accessibility/ios-simulator/image-overlay-elements.html Exposes to accessibility clients the elements created by WebPage::requestTextRecognition for static images. This allows clients to present the recognized text in images to assistive technology users. - Added a new AXObject subclass, AXImage, to encapsulate this functionality. This class can be expanded to offload some of the image specific code contained in AccessibilityRenderObject, AccessibilityNodeObject, AccessibilityObject and others. - Since requestTextRecognition is an async call, added an AXNotification to notify clients when the image overlay elements are available for consumption. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * accessibility/AXImage.cpp: Added. (WebCore::AXImage::AXImage): (WebCore::AXImage::create): (WebCore::AXImage::roleValue const): (WebCore::AXImage::imageOverlayElements): * accessibility/AXImage.h: Added. * accessibility/AXLogger.cpp: (WebCore::operator<<): * accessibility/AXObjectCache.cpp: (WebCore::isSimpleImage): Determines whether a given element is a static image. (WebCore::createFromRenderer): Instantiate an AXImage object when appropriate. * accessibility/AXObjectCache.h: * accessibility/AccessibilityNodeObject.cpp: (WebCore::AccessibilityNodeObject::canHaveChildren const): Images can have children. * accessibility/AccessibilityObject.h: * accessibility/AccessibilityObjectInterface.h: * accessibility/ios/AXObjectCacheIOS.mm: (WebCore::AXObjectCache::notificationPlatformName): * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm: (-[WebAccessibilityObjectWrapper accessibilityElements]): (-[WebAccessibilityObjectWrapper accessibilityImageOverlayElements]): * accessibility/isolatedtree/AXIsolatedObject.cpp: (WebCore::AXIsolatedObject::isAXImageInstance const): * accessibility/isolatedtree/AXIsolatedObject.h: * accessibility/mac/AXObjectCacheMac.mm: (WebCore::AXObjectCache::postPlatformNotification): * accessibility/mac/WebAccessibilityObjectWrapperMac.mm: (-[WebAccessibilityObjectWrapper ALLOW_DEPRECATED_IMPLEMENTATIONS_END]): (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]): Tools: * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp: (WTR::AccessibilityUIElement::children const): * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h: * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl: * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm: (WTR::AccessibilityUIElement::children const): (WTR::AccessibilityUIElement::imageOverlayElements const): * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm: (WTR::AccessibilityUIElement::children const): (WTR::AccessibilityUIElement::imageOverlayElements const): LayoutTests: * accessibility/image-link-expected.txt: * accessibility/ios-simulator/image-overlay-elements-expected.txt: Added. * accessibility/ios-simulator/image-overlay-elements.html: Added. * accessibility/resources/green-400x400.png: Added. Canonical link: https://commits.webkit.org/239068@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279171 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-23 16:59:34 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/accessibility-helper.js"></script>
<style>
img {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<img id="image1" src="../resources/green-400x400.png"></img>
<script>
window.jsTestIsAsync = true;
addEventListener("load", () => {
image = document.querySelector("img");
internals.installImageOverlay(image, [
{
topLeft : new DOMPointReadOnly(0, 0),
topRight : new DOMPointReadOnly(1, 0),
bottomRight : new DOMPointReadOnly(1, 0.5),
bottomLeft : new DOMPointReadOnly(0, 0.5),
children: [
{
text : "hello",
topLeft : new DOMPointReadOnly(0, 0),
topRight : new DOMPointReadOnly(1, 0),
bottomRight : new DOMPointReadOnly(1, 0.5),
bottomLeft : new DOMPointReadOnly(0, 0.5),
}
],
},
{
topLeft : new DOMPointReadOnly(0, 0.5),
topRight : new DOMPointReadOnly(1, 0.5),
bottomRight : new DOMPointReadOnly(1, 1),
bottomLeft : new DOMPointReadOnly(0, 1),
children: [
{
text : "world",
topLeft : new DOMPointReadOnly(0, 0.5),
topRight : new DOMPointReadOnly(1, 0.5),
bottomRight : new DOMPointReadOnly(1, 1),
bottomLeft : new DOMPointReadOnly(0, 1),
}
],
}
]);
runTest();
});
function runTest() {
if (window.accessibilityController) {
setTimeout(async () => {
var axImage = accessibilityController.accessibleElementById("image1");
await waitFor(() => {
axImageOverlayElements = axImage.imageOverlayElements;
return axImageOverlayElements.length == 2;
});
shouldBe("axImageOverlayElements.length", "2");
for (let axElement of axImageOverlayElements) {
let textMarkerRange = axElement.textMarkerRangeForElement(axElement);
debug(axElement.stringForTextMarkerRange(textMarkerRange));
}
finishJSTest();
}, 0);
}
}
</script>
</body>
</html>