haikuwebkit/Source/WebCore/accessibility/AXImage.h

52 lines
2.1 KiB
C
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
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "AccessibilityRenderObject.h"
#include "RenderImage.h"
namespace WebCore {
class AXImage : public AccessibilityRenderObject {
public:
static Ref<AXImage> create(RenderImage*);
virtual ~AXImage() = default;
private:
explicit AXImage(RenderImage*);
bool isAXImageInstance() const override { return true; }
AccessibilityRole roleValue() const override;
std::optional<AccessibilityChildrenVector> imageOverlayElements() override;
};
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_ACCESSIBILITY(AXImage, isAXImageInstance())