Changeset 282358 in webkit


Ignore:
Timestamp:
Sep 13, 2021 2:20:16 PM (10 months ago)
Author:
commit-queue@webkit.org
Message:

AX: Make PDFs loaded via <embed> accessible
https://bugs.webkit.org/show_bug.cgi?id=229556

Patch by Tyler Wilcock <Tyler Wilcock> on 2021-09-13
Reviewed by Chris Fleizach and Andres Gonzalez.

Source/WebCore:

This patch makes PDFs loaded in <embed> elements accessible to
clients by exposing the underlying WKPDFPluginAccessibilityObject
created by PDF plugins.

Full-frame PDF accessibility support (e.g. file:///path/to/example.pdf) was
implemented in https://bugs.webkit.org/show_bug.cgi?id=170589, but this
wasn't sufficient for PDFs loaded in <embed>s.

This patch only implements <embed> PDF support for Mac - iOS support will
need to follow in a separate patch.

Test: accessibility/mac/basic-embed-pdf-accessibility.html

  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::getOrCreate):
Change comment that suggests PluginViewBase Widgets are not supported,
because they are now.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::isAttachment const):
Don't consider plugins to be attachments since they need to be handled
differently.
(WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored const):
Don't ignore widgets with underlying accessibilty objects (such as PDF
plugins).

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper renderWidgetChildren]):
Extract underlying accessibility object from widgets that have one.
(-[WebAccessibilityObjectWrapper accessibilityHitTest:]):
Forward hit test to underlying plugin accessibility object if one
exists.
(isMatchingPlugin): Added.
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
Match renderWidgetChildren for searches with SearchKey::AnyType
criteria.

  • platform/Widget.h:

(WebCore::Widget::accessibilityHitTest const): Added this virtual
method.
(WebCore::Widget::accessibilityObject const): Added this virtual
method.

Source/WebKit:

This patch makes PDFs loaded in <embed> elements accessible to
clients by exposing the underlying WKPDFPluginAccessibilityObject
created by PDF plugins.

Full-frame PDF accessibility support (e.g. file:///path/to/example.pdf) was
implemented in https://bugs.webkit.org/show_bug.cgi?id=170589, but this
wasn't sufficient for PDFs loaded in <embed>s.

This patch only implements <embed> PDF support for Mac - iOS support will
need to follow in a separate patch.

  • WebProcess/Plugins/PDF/PDFPlugin.h:
  • WebProcess/Plugins/PDF/PDFPlugin.mm:

(-[WKPDFPluginAccessibilityObject initWithPDFPlugin:andElement:]):
Change this method to also accept the HTMLPlugInElement that the plugin
originates from.
(-[WKPDFPluginAccessibilityObject parent]):
Added. Returns the cached parent if present, otherwises tries to cache
the parent in the form of the HTMLPlugInElement that the plugin
originates from.
(-[WKPDFPluginAccessibilityObject setParent:]): Added.
(-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:]):
Query against newly added parent getter when fulfilling attribute
value requests.
(-[WKPDFPluginAccessibilityObject ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
(-[WKPDFPluginAccessibilityObject accessibilityHitTestIntPoint:]): Added.
(-[WKPDFPluginAccessibilityObject accessibilityHitTest:]):
Changed to convert NSPoint to WebCore::IntPoint and call
accessibilityHitTestIntPoint.
(WebKit::PDFPlugin::create):
Add parameter to accept the HTMLPlugInElement that the plugin
originates from.
(WebKit::PDFPlugin::PDFPlugin):
Add parameter to accept the HTMLPlugInElement that the plugin
originates from.
(WebKit::PDFPlugin::accessibilityHitTest const): Added.
(-[WKPDFPluginAccessibilityObject initWithPDFPlugin:]): Deleted.

  • WebProcess/Plugins/Plugin.h:

(WebKit::Plugin::accessibilityHitTest const): Added.
(WebKit::Plugin::accessibilityObject const): Change the return type to
id as that is more common practice.

  • WebProcess/Plugins/PluginView.h:

Add id accessibilityHitTest and change accessibilityObject()
to return id.

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::accessibilityObject const): Change return type to
id.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::createPlugin):
Pass the originating pluginElement to PDFPlugin::create.

Tools:

  • WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:

(WTR::attributeValue):
Some PDFKit elements don't respond to accessibilityAttributeValue,
so before calling that selector first check to see if the given element responds
to an attribute-specific selector (like accessibilityRole).

LayoutTests:

Add a test ensuring the PDF accessibility tree of PDFs loaded via
<embed> elements is accessible.

  • accessibility/mac/basic-embed-pdf-accessibility-expected.txt: Added.
  • accessibility/mac/basic-embed-pdf-accessibility.html: Added.
  • accessibility/resources/simple-webkit-pages.pdf: Added.
Location:
trunk
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r282357 r282358  
     12021-09-13  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Make PDFs loaded via <embed> accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=229556
     5
     6        Reviewed by Chris Fleizach and Andres Gonzalez.
     7
     8        Add a test ensuring the PDF accessibility tree of PDFs loaded via
     9        `<embed>` elements is accessible.
     10
     11        * accessibility/mac/basic-embed-pdf-accessibility-expected.txt: Added.
     12        * accessibility/mac/basic-embed-pdf-accessibility.html: Added.
     13        * accessibility/resources/simple-webkit-pages.pdf: Added.
     14
    1152021-09-13  Sam Sneddon  <gsnedders@apple.com>
    216
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r282346 r282358  
    576576accessibility/parent-delete.html [ Failure ]
    577577
     578# Skip because the embedded plugin never resolves in WK1, resulting in a timeout.
     579accessibility/mac/basic-embed-pdf-accessibility.html [ Skip ]
     580
    578581# rdar://problem/26478296
    579582svg/hixie/text/003.html [ Failure ]
  • trunk/Source/WebCore/ChangeLog

    r282357 r282358  
     12021-09-13  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Make PDFs loaded via <embed> accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=229556
     5
     6        Reviewed by Chris Fleizach and Andres Gonzalez.
     7
     8        This patch makes PDFs loaded in `<embed>` elements accessible to
     9        clients by exposing the underlying `WKPDFPluginAccessibilityObject`
     10        created by PDF plugins.
     11
     12        Full-frame PDF accessibility support (e.g. file:///path/to/example.pdf) was
     13        implemented in https://bugs.webkit.org/show_bug.cgi?id=170589, but this
     14        wasn't sufficient for PDFs loaded in `<embed>`s.
     15
     16        This patch only implements `<embed>` PDF support for Mac - iOS support will
     17        need to follow in a separate patch.
     18
     19        Test: accessibility/mac/basic-embed-pdf-accessibility.html
     20
     21        * accessibility/AXObjectCache.cpp:
     22        (WebCore::AXObjectCache::getOrCreate):
     23        Change comment that suggests PluginViewBase Widgets are not supported,
     24        because they are now.
     25
     26        * accessibility/AccessibilityRenderObject.cpp:
     27        (WebCore::AccessibilityRenderObject::isAttachment const):
     28        Don't consider plugins to be attachments since they need to be handled
     29        differently.
     30        (WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored const):
     31        Don't ignore widgets with underlying accessibilty objects (such as PDF
     32        plugins).
     33
     34        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     35        (-[WebAccessibilityObjectWrapper renderWidgetChildren]):
     36        Extract underlying accessibility object from widgets that have one.
     37        (-[WebAccessibilityObjectWrapper accessibilityHitTest:]):
     38        Forward hit test to underlying plugin accessibility object if one
     39        exists.
     40        (isMatchingPlugin): Added.
     41        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
     42        Match `renderWidgetChildren` for searches with `SearchKey::AnyType`
     43        criteria.
     44
     45        * platform/Widget.h:
     46        (WebCore::Widget::accessibilityHitTest const): Added this virtual
     47        method.
     48        (WebCore::Widget::accessibilityObject const): Added this virtual
     49        method.
     50
    1512021-09-13  Sam Sneddon  <gsnedders@apple.com>
    252
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r282022 r282358  
    672672    ASSERT(!get(widget));
    673673
    674     // Catch the case if an (unsupported) widget type is used. Only FrameView and ScrollBar are supported now.
     674    // Ensure we weren't given an unsupported widget type.
    675675    ASSERT(newObj);
    676676    if (!newObj)
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r281920 r282358  
    7777#include "Page.h"
    7878#include "PathUtilities.h"
     79#include "PluginViewBase.h"
    7980#include "ProgressTracker.h"
    8081#include "Range.h"
     
    532533    if (!renderer)
    533534        return false;
     535
     536    // Although plugins are also a type of widget, we need to treat them differently than attachments.
     537    if (is<PluginViewBase>(widget()))
     538        return false;
     539
    534540    // Widgets are the replaced elements that we represent to AX as attachments
    535541    bool isWidget = renderer->isWidget();
     
    13451351    if (isAttachment())
    13461352        return accessibilityIgnoreAttachment();
     1353
     1354#if PLATFORM(COCOA)
     1355    // If this widget has an underlying AX object, don't ignore it.
     1356    if (widget() && widget()->accessibilityObject())
     1357        return false;
     1358#endif
    13471359   
    13481360    // ignore popup menu items because AppKit does
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r281691 r282358  
    16581658        return nil;
    16591659
     1660    auto* widget = backingObject->widget();
     1661    if (widget && widget->accessibilityObject())
     1662        return @[widget->accessibilityObject()];
     1663
    16601664    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    16611665    return [backingObject->platformWidget() accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
     
    29452949        if (axObject->isAttachment() && [axObject->wrapper() attachmentView])
    29462950            return [axObject->wrapper() attachmentView];
     2951        auto* widget = axObject->widget();
     2952        if (is<PluginViewBase>(widget))
     2953            return NSAccessibilityUnignoredAncestor(widget->accessibilityHitTest(IntPoint(point)));
    29472954        return NSAccessibilityUnignoredAncestor(axObject->wrapper());
    29482955    }
     
    36953702}
    36963703
     3704static BOOL isMatchingPlugin(AXCoreObject* axObject, const AccessibilitySearchCriteria& criteria)
     3705{
     3706    auto* widget = axObject->widget();
     3707    if (!is<PluginViewBase>(widget))
     3708        return false;
     3709
     3710    return criteria.searchKeys.contains(AccessibilitySearchKey::AnyType)
     3711        && (!criteria.visibleOnly || downcast<PluginViewBase>(widget)->isVisible());
     3712}
     3713
    36973714ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
    36983715- (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)parameter
     
    37983815    if ([attribute isEqualToString:NSAccessibilityUIElementCountForSearchPredicateParameterizedAttribute]) {
    37993816        AccessibilitySearchCriteria criteria = accessibilitySearchCriteriaForSearchPredicateParameterizedAttribute(dictionary);
     3817        NSUInteger widgetChildrenSize = 0;
     3818        if (isMatchingPlugin(backingObject, criteria)) {
     3819            // FIXME: We should also be searching the tree(s) resulting from `renderWidgetChildren` for matches.
     3820            // This is tracked by https://bugs.webkit.org/show_bug.cgi?id=230167.
     3821            if (auto* widgetChildren = [self renderWidgetChildren]) {
     3822                widgetChildrenSize = [widgetChildren count];
     3823                if (widgetChildrenSize >= criteria.resultsLimit)
     3824                    return @(std::min(widgetChildrenSize, NSUInteger(criteria.resultsLimit)));
     3825                criteria.resultsLimit -= widgetChildrenSize;
     3826            }
     3827        }
     3828
    38003829        AccessibilityObject::AccessibilityChildrenVector results;
    38013830        backingObject->findMatchingObjects(&criteria, results);
    3802         return @(results.size());
     3831        return @(results.size() + widgetChildrenSize);
    38033832    }
    38043833
    38053834    if ([attribute isEqualToString:NSAccessibilityUIElementsForSearchPredicateParameterizedAttribute]) {
    38063835        AccessibilitySearchCriteria criteria = accessibilitySearchCriteriaForSearchPredicateParameterizedAttribute(dictionary);
     3836        NSArray *widgetChildren = nil;
     3837        if (isMatchingPlugin(backingObject, criteria)) {
     3838            // FIXME: We should also be searching the tree(s) resulting from `renderWidgetChildren` for matches.
     3839            // This is tracked by https://bugs.webkit.org/show_bug.cgi?id=230167.
     3840            if (auto* children = [self renderWidgetChildren]) {
     3841                NSUInteger includedChildrenCount = std::min([children count], NSUInteger(criteria.resultsLimit));
     3842                widgetChildren = [children subarrayWithRange:NSMakeRange(0, includedChildrenCount)];
     3843                if ([widgetChildren count] >= criteria.resultsLimit)
     3844                    return widgetChildren;
     3845                criteria.resultsLimit -= [widgetChildren count];
     3846            }
     3847        }
     3848
    38073849        AccessibilityObject::AccessibilityChildrenVector results;
    38083850        backingObject->findMatchingObjects(&criteria, results);
     3851        if (widgetChildren)
     3852            return [widgetChildren arrayByAddingObjectsFromArray:convertToNSArray(results)];
    38093853        return convertToNSArray(results);
    38103854    }
  • trunk/Source/WebCore/platform/Widget.h

    r259761 r282358  
    177177
    178178#if PLATFORM(COCOA)
     179    virtual id accessibilityHitTest(const IntPoint&) const { return nil; }
     180    virtual id accessibilityObject() const { return nil; }
    179181    NSView* getOuterView() const;
    180182
  • trunk/Source/WebKit/ChangeLog

    r282349 r282358  
     12021-09-13  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Make PDFs loaded via <embed> accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=229556
     5
     6        Reviewed by Chris Fleizach and Andres Gonzalez.
     7
     8        This patch makes PDFs loaded in `<embed>` elements accessible to
     9        clients by exposing the underlying `WKPDFPluginAccessibilityObject`
     10        created by PDF plugins.
     11
     12        Full-frame PDF accessibility support (e.g. file:///path/to/example.pdf) was
     13        implemented in https://bugs.webkit.org/show_bug.cgi?id=170589, but this
     14        wasn't sufficient for PDFs loaded in `<embed>`s.
     15
     16        This patch only implements `<embed>` PDF support for Mac - iOS support will
     17        need to follow in a separate patch.
     18
     19        * WebProcess/Plugins/PDF/PDFPlugin.h:
     20        * WebProcess/Plugins/PDF/PDFPlugin.mm:
     21        (-[WKPDFPluginAccessibilityObject initWithPDFPlugin:andElement:]):
     22        Change this method to also accept the `HTMLPlugInElement` that the plugin
     23        originates from.
     24        (-[WKPDFPluginAccessibilityObject parent]):
     25        Added. Returns the cached parent if present, otherwises tries to cache
     26        the parent in the form of the `HTMLPlugInElement` that the plugin
     27        originates from.
     28        (-[WKPDFPluginAccessibilityObject setParent:]): Added.
     29        (-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:]):
     30        Query against newly added `parent` getter when fulfilling attribute
     31        value requests.
     32        (-[WKPDFPluginAccessibilityObject ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
     33        (-[WKPDFPluginAccessibilityObject accessibilityHitTestIntPoint:]): Added.
     34        (-[WKPDFPluginAccessibilityObject accessibilityHitTest:]):
     35        Changed to convert `NSPoint` to `WebCore::IntPoint` and call
     36        `accessibilityHitTestIntPoint`.
     37        (WebKit::PDFPlugin::create):
     38        Add parameter to accept the `HTMLPlugInElement` that the plugin
     39        originates from.
     40        (WebKit::PDFPlugin::PDFPlugin):
     41        Add parameter to accept the `HTMLPlugInElement` that the plugin
     42        originates from.
     43        (WebKit::PDFPlugin::accessibilityHitTest const): Added.
     44        (-[WKPDFPluginAccessibilityObject initWithPDFPlugin:]): Deleted.
     45
     46        * WebProcess/Plugins/Plugin.h:
     47        (WebKit::Plugin::accessibilityHitTest const): Added.
     48        (WebKit::Plugin::accessibilityObject const): Change the return type to
     49        `id` as that is more common practice.
     50
     51        * WebProcess/Plugins/PluginView.h:
     52        Add `id accessibilityHitTest` and change `accessibilityObject()`
     53        to return `id`.
     54
     55        * WebProcess/Plugins/PluginView.cpp:
     56        (WebKit::PluginView::accessibilityObject const): Change return type to
     57        `id`.
     58
     59        * WebProcess/WebPage/WebPage.cpp:
     60        (WebKit::WebPage::createPlugin):
     61        Pass the originating `pluginElement` to `PDFPlugin::create`.
     62
    1632021-09-13  Wenson Hsieh  <wenson_hsieh@apple.com>
    264
  • trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h

    r278516 r282358  
    8383{
    8484public:
    85     static Ref<PDFPlugin> create(WebFrame&);
     85    static Ref<PDFPlugin> create(WebFrame&, WebCore::HTMLPlugInElement*);
    8686    ~PDFPlugin();
    8787
     
    157157
    158158private:
    159     explicit PDFPlugin(WebFrame&);
     159    explicit PDFPlugin(WebFrame&, WebCore::HTMLPlugInElement*);
    160160
    161161    // Plugin functions.
     
    214214    RetainPtr<PDFDocument> pdfDocumentForPrinting() const final { return m_pdfDocument; }
    215215    WebCore::FloatSize pdfDocumentSizeForPrinting() const final;
    216     NSObject *accessibilityObject() const final;
     216    id accessibilityHitTest(const WebCore::IntPoint&) const final;
     217    id accessibilityObject() const final;
    217218    id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const final;
    218219
  • trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm

    r281470 r282358  
    102102#import <wtf/UUID.h>
    103103#import <wtf/WTFSemaphore.h>
     104#import <wtf/WeakObjCPtr.h>
    104105#import <wtf/WorkQueue.h>
    105106#import <wtf/cocoa/VectorCocoa.h>
     
    156157@interface WKPDFPluginAccessibilityObject : NSObject {
    157158    PDFLayerController *_pdfLayerController;
    158     __unsafe_unretained NSObject *_parent;
     159    WeakObjCPtr<NSObject> _parent;
    159160    WebKit::PDFPlugin* _pdfPlugin;
     161    WeakPtr<WebCore::HTMLPlugInElement> _pluginElement;
    160162}
    161163
    162164@property (assign) PDFLayerController *pdfLayerController;
    163 @property (assign) NSObject *parent;
    164165@property (assign) WebKit::PDFPlugin* pdfPlugin;
    165 
    166 - (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin;
     166@property (assign) WeakPtr<WebCore::HTMLPlugInElement> pluginElement;
     167
     168- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin andElement:(WebCore::HTMLPlugInElement *)element;
    167169
    168170@end
     
    170172@implementation WKPDFPluginAccessibilityObject
    171173
    172 @synthesize parent = _parent;
    173174@synthesize pdfPlugin = _pdfPlugin;
    174 
    175 - (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin
     175@synthesize pluginElement = _pluginElement;
     176
     177- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin andElement:(WebCore::HTMLPlugInElement *)element
    176178{
    177179    if (!(self = [super init]))
     
    179181
    180182    _pdfPlugin = plugin;
     183    _pluginElement = makeWeakPtr(element);
    181184
    182185    return self;
     186}
     187
     188- (NSObject *)parent
     189{
     190    if (!_parent) {
     191        if (auto* axObjectCache = _pdfPlugin->axObjectCache()) {
     192            if (auto* pluginAxObject = axObjectCache->getOrCreate(_pluginElement.get()))
     193                _parent = pluginAxObject->wrapper();
     194        }
     195    }
     196    return _parent.get().get();
     197}
     198
     199- (void)setParent:(NSObject *)parent
     200{
     201    _parent = parent;
    183202}
    184203
     
    212231{
    213232    if ([attribute isEqualToString:NSAccessibilityParentAttribute])
    214         return _parent;
     233        return [self parent];
    215234    if ([attribute isEqualToString:NSAccessibilityTopLevelUIElementAttribute])
    216         return [_parent accessibilityAttributeValue:NSAccessibilityTopLevelUIElementAttribute];
     235        return [[self parent] accessibilityAttributeValue:NSAccessibilityTopLevelUIElementAttribute];
    217236    if ([attribute isEqualToString:NSAccessibilityWindowAttribute])
    218         return [_parent accessibilityAttributeValue:NSAccessibilityWindowAttribute];
     237        return [[self parent] accessibilityAttributeValue:NSAccessibilityWindowAttribute];
    219238    if ([attribute isEqualToString:NSAccessibilitySizeAttribute])
    220239        return [NSValue valueWithSize:_pdfPlugin->boundsOnScreen().size()];
    221240    if ([attribute isEqualToString:NSAccessibilityEnabledAttribute])
    222         return [_parent accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
     241        return [[self parent] accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
    223242    if ([attribute isEqualToString:NSAccessibilityPositionAttribute])
    224243        return [NSValue valueWithPoint:_pdfPlugin->boundsOnScreen().location()];
     
    229248        return NSAccessibilityGroupRole;
    230249    if ([attribute isEqualToString:NSAccessibilityPrimaryScreenHeightAttribute])
    231         return [_parent accessibilityAttributeValue:NSAccessibilityPrimaryScreenHeightAttribute];
     250        return [[self parent] accessibilityAttributeValue:NSAccessibilityPrimaryScreenHeightAttribute];
     251    if ([attribute isEqualToString:NSAccessibilitySubroleAttribute])
     252        return @"AXPDFPluginSubrole";
    232253
    233254    return 0;
     
    274295        // PDFLayerController has its own accessibilityChildren.
    275296        NSAccessibilityChildrenAttribute,
    276         NSAccessibilityPrimaryScreenHeightAttribute
     297        NSAccessibilityPrimaryScreenHeightAttribute,
     298        NSAccessibilitySubroleAttribute
    277299    ];
    278300
     
    347369}
    348370
     371- (id)accessibilityHitTestIntPoint:(const WebCore::IntPoint&)point
     372{
     373    auto convertedPoint = _pdfPlugin->convertFromRootViewToPDFView(point);
     374    return [_pdfLayerController accessibilityHitTest:convertedPoint];
     375}
     376
    349377- (id)accessibilityHitTest:(NSPoint)point
    350378{
    351     point = _pdfPlugin->convertFromRootViewToPDFView(WebCore::IntPoint(point));
    352     return [_pdfLayerController accessibilityHitTest:point];
     379    return [self accessibilityHitTestIntPoint:WebCore::IntPoint(point)];
    353380}
    354381
     
    362389@property (assign) WebKit::PDFPlugin* pdfPlugin;
    363390
     391- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin;
     392
    364393@end
    365394
     
    395424
    396425@property (assign) WebKit::PDFPlugin* pdfPlugin;
     426
     427- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin;
    397428
    398429@end
     
    596627}
    597628
    598 Ref<PDFPlugin> PDFPlugin::create(WebFrame& frame)
    599 {
    600     return adoptRef(*new PDFPlugin(frame));
    601 }
    602 
    603 inline PDFPlugin::PDFPlugin(WebFrame& frame)
     629Ref<PDFPlugin> PDFPlugin::create(WebFrame& frame, HTMLPlugInElement* pluginElement)
     630{
     631    return adoptRef(*new PDFPlugin(frame, pluginElement));
     632}
     633
     634inline PDFPlugin::PDFPlugin(WebFrame& frame, HTMLPlugInElement* pluginElement)
    604635    : Plugin(PDFPluginType)
    605636    , m_frame(makeWeakPtr(frame))
     
    621652    m_pdfLayerController.get().parentLayer = m_contentLayer.get();
    622653
    623     if (isFullFramePlugin()) {
     654    bool isFullFrame = isFullFramePlugin();
     655    if (isFullFrame) {
    624656        auto* document = frame.coreFrame()->document();
    625657
     
    640672    }
    641673
    642     m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this]);
     674    m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this andElement:pluginElement]);
    643675    [m_accessibilityObject setPdfLayerController:m_pdfLayerController.get()];
    644     [m_accessibilityObject setParent:frame.page()->accessibilityRemoteObject()];
     676    if (isFullFrame)
     677        [m_accessibilityObject setParent:frame.page()->accessibilityRemoteObject()];
     678    // If the plugin is not full-frame, we'll need to set the parent later after the AXObjectCache for the document has been initialized.
    645679
    646680    [m_containerLayer addSublayer:m_contentLayer.get()];
     
    30273061}
    30283062
    3029 NSObject *PDFPlugin::accessibilityObject() const
     3063id PDFPlugin::accessibilityHitTest(const WebCore::IntPoint& point) const
     3064{
     3065    return [m_accessibilityObject accessibilityHitTestIntPoint:point];
     3066}
     3067
     3068id PDFPlugin::accessibilityObject() const
    30303069{
    30313070    return m_accessibilityObject.get();
  • trunk/Source/WebKit/WebProcess/Plugins/Plugin.h

    r278516 r282358  
    278278    virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
    279279    virtual WebCore::FloatSize pdfDocumentSizeForPrinting() const;
    280     virtual NSObject *accessibilityObject() const { return 0; }
     280    virtual id accessibilityHitTest(const WebCore::IntPoint&) const { return nil; }
     281    virtual id accessibilityObject() const { return nil; }
    281282    virtual id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const { return nullptr; }
    282283#endif
  • trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp

    r282191 r282358  
    546546}
    547547   
    548 NSObject *PluginView::accessibilityObject() const
     548id PluginView::accessibilityObject() const
    549549{
    550550    if (!m_isInitialized || !m_plugin)
  • trunk/Source/WebKit/WebProcess/Plugins/PluginView.h

    r278516 r282358  
    8888    bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
    8989    RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
    90     NSObject *accessibilityObject() const;
     90    id accessibilityHitTest(const WebCore::IntPoint& point) const override { return m_plugin->accessibilityHitTest(point); }
     91    id accessibilityObject() const override;
    9192    id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const override;
    9293#endif
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r282314 r282358  
    11681168#if ENABLE(PDFKIT_PLUGIN)
    11691169        if (shouldUsePDFPlugin(parameters.mimeType, parameters.url.path()))
    1170             return PDFPlugin::create(*frame);
     1170            return PDFPlugin::create(*frame, pluginElement);
    11711171#endif
    11721172    }
  • trunk/Tools/ChangeLog

    r282347 r282358  
     12021-09-13  Tyler Wilcock  <tyler_w@apple.com>
     2
     3        AX: Make PDFs loaded via <embed> accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=229556
     5
     6        Reviewed by Chris Fleizach and Andres Gonzalez.
     7
     8        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
     9        (WTR::attributeValue):
     10        Some PDFKit elements don't respond to `accessibilityAttributeValue`,
     11        so before calling that selector first check to see if the given `element` responds
     12        to an attribute-specific selector (like `accessibilityRole`).
     13
    1142021-09-13  Jonathan Bedard  <jbedard@apple.com>
    215
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

    r281274 r282358  
    146146    BEGIN_AX_OBJC_EXCEPTIONS
    147147    AccessibilityUIElement::s_controller->executeOnAXThreadAndWait([&element, &attribute, &value] {
    148         value = [element accessibilityAttributeValue:attribute];
     148        // The given `element` may not respond to `accessibilityAttributeValue`, so first check to see if it responds to the attribute-specific selector.
     149        if ([attribute isEqual:NSAccessibilityChildrenAttribute] && [element respondsToSelector:@selector(accessibilityChildren)])
     150            value = [element accessibilityChildren];
     151        else if ([attribute isEqual:NSAccessibilityDescriptionAttribute] && [element respondsToSelector:@selector(accessibilityLabel)])
     152            value = [element accessibilityLabel];
     153        else if ([attribute isEqual:NSAccessibilityParentAttribute] && [element respondsToSelector:@selector(accessibilityParent)])
     154            value = [element accessibilityParent];
     155        else if ([attribute isEqual:NSAccessibilityRoleAttribute] && [element respondsToSelector:@selector(accessibilityRole)])
     156            value = [element accessibilityRole];
     157        else if ([attribute isEqual:NSAccessibilityValueAttribute] && [element respondsToSelector:@selector(accessibilityValue)])
     158            value = [element accessibilityValue];
     159        else
     160            value = [element accessibilityAttributeValue:attribute];
    149161    });
    150162    END_AX_OBJC_EXCEPTIONS
Note: See TracChangeset for help on using the changeset viewer.