PDFPlugin: Main-frame PDFPlugin Accessibility
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 May 2013 19:50:48 +0000 (19:50 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 May 2013 19:50:48 +0000 (19:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=116563
<rdar://problem/13458534>

Reviewed by Sam Weinig.

* WebProcess/Plugins/PDF/PDFLayerControllerDetails.h:
Forward-declare a variety of accessibility methods.

* WebProcess/Plugins/PDF/PDFPlugin.h:
Add convertFromPDFViewToScreen, boundsOnScreen, accessibilityObject, and
storage for our accessibility wrapper.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
Add WKPDFPluginAccessibilityObject.

(-[WKPDFPluginAccessibilityObject accessibilityIsIgnored]):
We want to be included in the accessibility tree.

(-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:]):
(-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:forParameter:]):
Grab values for accessibility attributes from the relevant sources
(mostly from PDFLayerController).

(-[WKPDFPluginAccessibilityObject readingModel]): Ditto.
(-[WKPDFPluginAccessibilityObject accessibilityAttributeNames]):
(-[WKPDFPluginAccessibilityObject accessibilityParameterizedAttributeNames]):
(-[WKPDFPluginAccessibilityObject accessibilityActionNames]):
Return the set of accessibility attributes, actions, and parameterized
attributes that we support.

(-[WKPDFPluginAccessibilityObject accessibilityIsAttributeSettable:]):
(-[WKPDFPluginAccessibilityObject accessibilitySetValue:forAttribute:]):
Forward some other accessibility methods to PDFLayerController.

(-[WKPDFPluginAccessibilityObject accessibilityFocusedUIElement]):
(-[WKPDFPluginAccessibilityObject accessibilityHitTest:]):
We have no children, so if a hit test makes it to us, it's ours.

(WebKit::PDFPlugin::PDFPlugin):
Make a WKPDFPluginAccessibilityObject and hook it up.
[FIXME: this could use some de-crapifying]

(WebKit::PDFPlugin::convertFromPluginToPDFView):
Transform a point from plugin space to PDFLayerController space.

(WebKit::PDFPlugin::convertFromPDFViewToRootView):
(WebKit::PDFPlugin::convertFromPDFViewToScreen): Added.
(WebKit::PDFPlugin::boundsOnScreen):
Return the PDFPlugin's frame in screen coordinates.

(WebKit::PDFPlugin::accessibilityObject):
Return our accessibility wrapper.

* WebProcess/Plugins/PDF/SimplePDFPlugin.h:
* WebProcess/Plugins/Plugin.h:
(WebKit::Plugin::accessibilityObject):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::accessibilityObject):
* WebProcess/Plugins/PluginView.h:
Add accessibilityObject(), to acquire accessibility wrappers from plugins.

* WebProcess/WebPage/WebPage.h:
(WebPage): Add accessibilityObjectForMainFramePlugin();
* WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm:
(-[WKAccessibilityWebPageObject accessibilityRootObjectWrapper]):
If the main frame has a PluginDocument that has an accessibilityObject,
use that one instead of the WebPage's.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::accessibilityObjectForMainFramePlugin):
Return the accessibilityObject from the main-frame PluginDocument, if
there is one.

* WebCore.exp.in: Export AffineTransform::mapRect.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150771 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h
Source/WebKit2/WebProcess/Plugins/Plugin.h
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/Plugins/PluginView.h
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index d358a63..1d892ca 100644 (file)
@@ -1,3 +1,13 @@
+2013-05-27  Tim Horton  <timothy_horton@apple.com>
+
+        PDFPlugin: Main-frame PDFPlugin Accessibility
+        https://bugs.webkit.org/show_bug.cgi?id=116563
+        <rdar://problem/13458534>
+
+        Reviewed by Sam Weinig.
+
+        * WebCore.exp.in: Export AffineTransform::mapRect.
+
 2013-05-27  Tiancheng Jiang  <tijiang@rim.com>
 
         Checkbox UX update.
index a514d43..1985cc3 100644 (file)
@@ -1429,6 +1429,7 @@ __ZNK7WebCore15AffineTransform12isInvertibleEv
 __ZNK7WebCore15AffineTransform6xScaleEv
 __ZNK7WebCore15AffineTransform6yScaleEv
 __ZNK7WebCore15AffineTransform7inverseEv
+__ZNK7WebCore15AffineTransform7mapRectERKNS_9FloatRectE
 __ZNK7WebCore15AffineTransform8mapPointERKNS_10FloatPointE
 __ZNK7WebCore15AffineTransform8mapPointERKNS_8IntPointE
 __ZNK7WebCore15FocusController18focusedOrMainFrameEv
index 4f79231..bcd26cd 100644 (file)
@@ -1,3 +1,78 @@
+2013-05-27  Tim Horton  <timothy_horton@apple.com>
+
+        PDFPlugin: Main-frame PDFPlugin Accessibility
+        https://bugs.webkit.org/show_bug.cgi?id=116563
+        <rdar://problem/13458534>
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/Plugins/PDF/PDFLayerControllerDetails.h:
+        Forward-declare a variety of accessibility methods.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        Add convertFromPDFViewToScreen, boundsOnScreen, accessibilityObject, and
+        storage for our accessibility wrapper.
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        Add WKPDFPluginAccessibilityObject.
+
+        (-[WKPDFPluginAccessibilityObject accessibilityIsIgnored]):
+        We want to be included in the accessibility tree.
+
+        (-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:]):
+        (-[WKPDFPluginAccessibilityObject accessibilityAttributeValue:forParameter:]):
+        Grab values for accessibility attributes from the relevant sources
+        (mostly from PDFLayerController).
+
+        (-[WKPDFPluginAccessibilityObject readingModel]): Ditto.
+        (-[WKPDFPluginAccessibilityObject accessibilityAttributeNames]):
+        (-[WKPDFPluginAccessibilityObject accessibilityParameterizedAttributeNames]):
+        (-[WKPDFPluginAccessibilityObject accessibilityActionNames]):
+        Return the set of accessibility attributes, actions, and parameterized
+        attributes that we support.
+
+        (-[WKPDFPluginAccessibilityObject accessibilityIsAttributeSettable:]):
+        (-[WKPDFPluginAccessibilityObject accessibilitySetValue:forAttribute:]):
+        Forward some other accessibility methods to PDFLayerController.
+
+        (-[WKPDFPluginAccessibilityObject accessibilityFocusedUIElement]):
+        (-[WKPDFPluginAccessibilityObject accessibilityHitTest:]):
+        We have no children, so if a hit test makes it to us, it's ours.
+
+        (WebKit::PDFPlugin::PDFPlugin):
+        Make a WKPDFPluginAccessibilityObject and hook it up.
+        [FIXME: this could use some de-crapifying]
+
+        (WebKit::PDFPlugin::convertFromPluginToPDFView):
+        Transform a point from plugin space to PDFLayerController space.
+
+        (WebKit::PDFPlugin::convertFromPDFViewToRootView):
+        (WebKit::PDFPlugin::convertFromPDFViewToScreen): Added.
+        (WebKit::PDFPlugin::boundsOnScreen):
+        Return the PDFPlugin's frame in screen coordinates.
+
+        (WebKit::PDFPlugin::accessibilityObject):
+        Return our accessibility wrapper.
+
+        * WebProcess/Plugins/PDF/SimplePDFPlugin.h:
+        * WebProcess/Plugins/Plugin.h:
+        (WebKit::Plugin::accessibilityObject):
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::accessibilityObject):
+        * WebProcess/Plugins/PluginView.h:
+        Add accessibilityObject(), to acquire accessibility wrappers from plugins.
+
+        * WebProcess/WebPage/WebPage.h:
+        (WebPage): Add accessibilityObjectForMainFramePlugin();
+        * WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm:
+        (-[WKAccessibilityWebPageObject accessibilityRootObjectWrapper]):
+        If the main frame has a PluginDocument that has an accessibilityObject,
+        use that one instead of the WebPage's.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::accessibilityObjectForMainFramePlugin):
+        Return the accessibilityObject from the main-frame PluginDocument, if
+        there is one.
+
 2013-05-27  Marcelo Lira  <marcelo.lira@openbossa.org>
 
         [WK2][CoordinatedGraphics] Misuse of DrawingAreaProxy::setVisibleContentsRect() in WebView::updateViewportSize()
index 48fe603..a1d4af7 100644 (file)
@@ -25,6 +25,8 @@
 
 #import <PDFKit/PDFKit.h>
 
+@class CPReadingModel;
+
 @protocol PDFLayerControllerDelegate <NSObject>
 
 - (void)updateScrollPosition:(CGPoint)newPosition;
 
 - (void)searchInDictionaryWithSelection:(PDFSelection *)selection;
 
+// Accessibility
+
+- (CPReadingModel *)readingModel;
+- (id)accessibilityFocusedUIElement;
+- (NSArray *)accessibilityAttributeNames;
+- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute;
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute;
+- (NSArray *)accessibilityParameterizedAttributeNames;
+- (NSString *)accessibilityRoleAttribute;
+- (NSString *)accessibilityRoleDescriptionAttribute;
+- (NSString *)accessibilityValueAttribute;
+- (BOOL)accessibilityIsValueAttributeSettable;
+- (NSString *)accessibilitySelectedTextAttribute;
+- (BOOL)accessibilityIsSelectedTextAttributeSettable;
+- (NSValue *)accessibilitySelectedTextRangeAttribute;
+- (NSNumber *)accessibilityNumberOfCharactersAttribute;
+- (BOOL)accessibilityIsNumberOfCharactersAttributeSettable;
+- (NSValue *)accessibilityVisibleCharacterRangeAttribute;
+- (BOOL)accessibilityIsVisibleCharacterRangeAttributeSettable;
+- (NSNumber *)accessibilityLineForIndexAttributeForParameter:(id)parameter;
+- (NSValue *)accessibilityRangeForLineAttributeForParameter:(id)parameter;
+- (NSString *)accessibilityStringForRangeAttributeForParameter:(id)parameter;
+- (NSValue *)accessibilityBoundsForRangeAttributeForParameter:(id)parameter;
+
 @end
index 1d55610..2791864 100644 (file)
@@ -44,6 +44,7 @@ OBJC_CLASS NSArray;
 OBJC_CLASS PDFAnnotation;
 OBJC_CLASS PDFLayerController;
 OBJC_CLASS PDFSelection;
+OBJC_CLASS WKPDFPluginAccessibilityObject;
 OBJC_CLASS WKPDFLayerControllerDelegate;
 
 namespace CoreIPC {
@@ -89,6 +90,11 @@ public:
 
     void attemptToUnlockPDF(const String& password);
 
+    WebCore::FloatRect convertFromPDFViewToScreen(const WebCore::FloatRect&) const;
+    WebCore::IntRect boundsOnScreen() const;
+    
+    bool showContextMenuAtPoint(const WebCore::IntPoint&);
+
 private:
     explicit PDFPlugin(WebFrame*);
 
@@ -132,6 +138,7 @@ private:
     NSEvent *nsEventForWebMouseEvent(const WebMouseEvent&);
     WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
     WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const;
+    WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
     
     bool supportsForms();
     bool isFullFramePlugin();
@@ -140,8 +147,6 @@ private:
 
     void createPasswordEntryForm();
 
-    WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
-
     virtual NSData *liveData() const OVERRIDE;
 
     enum UpdateCursorMode {
@@ -156,12 +161,15 @@ private:
 
     void updateCursor(const WebMouseEvent&, UpdateCursorMode = UpdateIfNeeded);
 
+    virtual NSObject *accessibilityObject() const OVERRIDE;
+
     RetainPtr<CALayer> m_containerLayer;
     RetainPtr<CALayer> m_contentLayer;
     RetainPtr<CALayer> m_horizontalScrollbarLayer;
     RetainPtr<CALayer> m_verticalScrollbarLayer;
     RetainPtr<CALayer> m_scrollCornerLayer;
     RetainPtr<PDFLayerController> m_pdfLayerController;
+    RetainPtr<WKPDFPluginAccessibilityObject> m_accessibilityObject;
     
     RefPtr<PDFPluginAnnotation> m_activeAnnotation;
     RefPtr<PDFPluginPasswordField> m_passwordField;
index a125520..8499d3b 100644 (file)
@@ -45,6 +45,7 @@
 #import "WebPage.h"
 #import "WebPageProxyMessages.h"
 #import "WebProcess.h"
+#import "WKAccessibilityWebPageObject.h"
 #import <PDFKit/PDFKit.h>
 #import <QuartzCore/QuartzCore.h>
 #import <WebCore/Cursor.h>
@@ -64,6 +65,7 @@
 #import <WebCore/ScrollbarTheme.h>
 #import <WebCore/UUID.h>
 #import <WebKitSystemInterface.h>
+#import <wtf/CurrentTime.h>
 
 using namespace WebCore;
 
@@ -100,18 +102,169 @@ static const char* annotationStyle =
 // will jump to the next or previous page, to match PDFKit behavior.
 static const int defaultScrollMagnitudeThresholdForPageFlip = 20;
 
-@interface WKPDFPluginScrollbarLayer : CALayer
+@interface WKPDFPluginAccessibilityObject : NSObject
+
+@property(assign) PDFLayerController *pdfLayerController;
+@property(assign) NSObject *parent;
+@property(assign) WebKit::PDFPlugin* pdfPlugin;
+
+- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin;
+
+@end
+
+@implementation WKPDFPluginAccessibilityObject
+
+@synthesize pdfLayerController = _pdfLayerController;
+@synthesize parent = _parent;
+@synthesize pdfPlugin = _pdfPlugin;
+
+- (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin
 {
-    WebKit::PDFPlugin* _pdfPlugin;
+    if (!(self = [super init]))
+        return nil;
+
+    _pdfPlugin = plugin;
+
+    return self;
+}
+
+- (BOOL)accessibilityIsIgnored
+{
+    return NO;
+}
+
+- (id)accessibilityAttributeValue:(NSString *)attribute
+{
+    if ([attribute isEqualToString:NSAccessibilityParentAttribute])
+        return _parent;
+    else if ([attribute isEqualToString:NSAccessibilityValueAttribute])
+        return [_pdfLayerController accessibilityValueAttribute];
+    else if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute])
+        return [_pdfLayerController accessibilitySelectedTextAttribute];
+    else if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute])
+        return [_pdfLayerController accessibilitySelectedTextRangeAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute])
+        return [_pdfLayerController accessibilityNumberOfCharactersAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
+        return [_pdfLayerController accessibilityVisibleCharacterRangeAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityTopLevelUIElementAttribute])
+        return [_parent accessibilityAttributeValue:NSAccessibilityTopLevelUIElementAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityRoleAttribute])
+        return [_pdfLayerController accessibilityRoleAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute])
+        return [_pdfLayerController accessibilityRoleDescriptionAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityWindowAttribute])
+        return [_parent accessibilityAttributeValue:NSAccessibilityWindowAttribute];
+    else if ([attribute isEqualToString:NSAccessibilitySizeAttribute])
+        return [NSValue valueWithSize:_pdfPlugin->boundsOnScreen().size()];
+    else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute])
+        return [_parent accessibilityAttributeValue:NSAccessibilityFocusedAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityEnabledAttribute])
+        return [_parent accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
+    else if ([attribute isEqualToString:NSAccessibilityPositionAttribute])
+        return [NSValue valueWithPoint:_pdfPlugin->boundsOnScreen().location()];
+
+    return 0;
+}
+
+- (id)accessibilityAttributeValue:(NSString *)attribute forParameter:(id)parameter
+{
+    if ([attribute isEqualToString:NSAccessibilityBoundsForRangeParameterizedAttribute]) {
+        NSRect boundsInPDFViewCoordinates = [[_pdfLayerController accessibilityBoundsForRangeAttributeForParameter:parameter] rectValue];
+        NSRect boundsInScreenCoordinates = _pdfPlugin->convertFromPDFViewToScreen(boundsInPDFViewCoordinates);
+        return [NSValue valueWithRect:boundsInScreenCoordinates];;
+    } else if ([attribute isEqualToString:NSAccessibilityLineForIndexParameterizedAttribute])
+        return [_pdfLayerController accessibilityLineForIndexAttributeForParameter:parameter];
+    else if ([attribute isEqualToString:NSAccessibilityRangeForLineParameterizedAttribute])
+        return [_pdfLayerController accessibilityRangeForLineAttributeForParameter:parameter];
+    else if ([attribute isEqualToString:NSAccessibilityStringForRangeParameterizedAttribute])
+        return [_pdfLayerController accessibilityStringForRangeAttributeForParameter:parameter];
+
+    return 0;
+}
+
+- (CPReadingModel *)readingModel
+{
+    return [_pdfLayerController readingModel];
+}
+
+- (NSArray *)accessibilityAttributeNames
+{
+    static NSArray *attributeNames = 0;
+
+    if (!attributeNames)
+        attributeNames = [[NSArray arrayWithObjects:NSAccessibilityValueAttribute,
+            NSAccessibilitySelectedTextAttribute,
+            NSAccessibilitySelectedTextRangeAttribute,
+            NSAccessibilityNumberOfCharactersAttribute,
+            NSAccessibilityVisibleCharacterRangeAttribute,
+            NSAccessibilityParentAttribute,
+            NSAccessibilityRoleAttribute,
+            NSAccessibilityWindowAttribute,
+            NSAccessibilityTopLevelUIElementAttribute,
+            NSAccessibilityRoleDescriptionAttribute,
+            NSAccessibilitySizeAttribute,
+            NSAccessibilityFocusedAttribute,
+            NSAccessibilityEnabledAttribute,
+            NSAccessibilityPositionAttribute,
+            nil] retain];
+
+    return attributeNames;
+}
+
+- (NSArray *)accessibilityActionNames
+{
+    static NSArray *actionNames = 0;
+    
+    if (!actionNames)
+        actionNames = [[NSArray arrayWithObject:NSAccessibilityShowMenuAction] retain];
+    
+    return actionNames;
+}
+
+- (void)accessibilityPerformAction:(NSString *)action
+{
+    if ([action isEqualToString:NSAccessibilityShowMenuAction])
+        _pdfPlugin->showContextMenuAtPoint(IntRect(IntPoint(), _pdfPlugin->size()).center());
+}
+
+- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute
+{
+    return [_pdfLayerController accessibilityIsAttributeSettable:attribute];
+}
+
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
+{
+    return [_pdfLayerController accessibilitySetValue:value forAttribute:attribute];
+}
+
+- (NSArray *)accessibilityParameterizedAttributeNames
+{
+    return [_pdfLayerController accessibilityParameterizedAttributeNames];
 }
 
+- (id)accessibilityFocusedUIElement
+{
+    return self;
+}
+
+- (id)accessibilityHitTest:(NSPoint)point
+{
+    return self;
+}
+
+@end
+
+
+@interface WKPDFPluginScrollbarLayer : CALayer
+
 @property(assign) WebKit::PDFPlugin* pdfPlugin;
 
 @end
 
 @implementation WKPDFPluginScrollbarLayer
 
-@synthesize pdfPlugin=_pdfPlugin;
+@synthesize pdfPlugin = _pdfPlugin;
 
 - (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin
 {
@@ -252,6 +405,10 @@ PDFPlugin::PDFPlugin(WebFrame* frame)
         document->body()->appendChild(m_annotationContainer.get());
     }
 
+    m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this]);
+    m_accessibilityObject.get().pdfLayerController = m_pdfLayerController.get();
+    m_accessibilityObject.get().parent = webFrame()->page()->accessibilityRemoteObject();
+
     [m_containerLayer.get() addSublayer:m_contentLayer.get()];
     [m_containerLayer.get() addSublayer:m_scrollCornerLayer.get()];
 }
@@ -456,14 +613,45 @@ PlatformLayer* PDFPlugin::pluginLayer()
     return m_containerLayer.get();
 }
 
+IntPoint PDFPlugin::convertFromPluginToPDFView(const IntPoint& point) const
+{
+    return IntPoint(point.x(), size().height() - point.y());
+}
+
 IntPoint PDFPlugin::convertFromRootViewToPlugin(const IntPoint& point) const
 {
     return m_rootViewToPluginTransform.mapPoint(point);
 }
 
-IntPoint PDFPlugin::convertFromPluginToPDFView(const IntPoint& point) const
+IntPoint PDFPlugin::convertFromPDFViewToRootView(const IntPoint& point) const
 {
-    return IntPoint(point.x(), size().height() - point.y());
+    IntPoint pointInPluginCoordinates(point.x(), size().height() - point.y());
+    return m_rootViewToPluginTransform.inverse().mapPoint(pointInPluginCoordinates);
+}
+
+FloatRect PDFPlugin::convertFromPDFViewToScreen(const FloatRect& rect) const
+{
+    FrameView* frameView = webFrame()->coreFrame()->view();
+
+    if (!frameView)
+        return FloatRect();
+
+    FloatPoint originInPluginCoordinates(rect.x(), size().height() - rect.y() - rect.height());
+    FloatRect rectInRootViewCoordinates = m_rootViewToPluginTransform.inverse().mapRect(FloatRect(originInPluginCoordinates, rect.size()));
+
+    return frameView->contentsToScreen(enclosingIntRect(rectInRootViewCoordinates));
+}
+
+IntRect PDFPlugin::boundsOnScreen() const
+{
+    FrameView* frameView = webFrame()->coreFrame()->view();
+
+    if (!frameView)
+        return IntRect();
+
+    FloatRect bounds = FloatRect(FloatPoint(), size());
+    FloatRect rectInRootViewCoordinates = m_rootViewToPluginTransform.inverse().mapRect(bounds);
+    return frameView->contentsToScreen(enclosingIntRect(rectInRootViewCoordinates));
 }
 
 void PDFPlugin::geometryDidChange(const IntSize& pluginSize, const IntRect&, const AffineTransform& pluginToRootViewTransform)
@@ -700,13 +888,20 @@ bool PDFPlugin::handleMouseLeaveEvent(const WebMouseEvent&)
     return false;
 }
     
-bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
+bool PDFPlugin::showContextMenuAtPoint(const IntPoint& point)
 {
-    NSMenu *nsMenu = [m_pdfLayerController.get() menuForEvent:nsEventForWebMouseEvent(event)];
+    FrameView* frameView = webFrame()->coreFrame()->view();
+    IntPoint contentsPoint = frameView->contentsToRootView(point);
+    WebMouseEvent event(WebEvent::MouseDown, WebMouseEvent::RightButton, contentsPoint, contentsPoint, 0, 0, 0, 1, static_cast<WebEvent::Modifiers>(0), monotonicallyIncreasingTime());
+    return handleContextMenuEvent(event);
+}
 
+bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
+{
     FrameView* frameView = webFrame()->coreFrame()->view();
     IntPoint point = frameView->contentsToScreen(IntRect(frameView->windowToContents(event.position()), IntSize())).location();
-    if (nsMenu) {
+    
+    if (NSMenu *nsMenu = [m_pdfLayerController.get() menuForEvent:nsEventForWebMouseEvent(event)]) {
         WKPopupContextMenu(nsMenu, point);
         return true;
     }
@@ -911,12 +1106,6 @@ void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
     }
 }
 
-IntPoint PDFPlugin::convertFromPDFViewToRootView(const IntPoint& point) const
-{
-    IntPoint pointInPluginCoordinates(point.x(), size().height() - point.y());
-    return m_rootViewToPluginTransform.inverse().mapPoint(pointInPluginCoordinates);
-}
-
 void PDFPlugin::showDefinitionForAttributedString(NSAttributedString *string, CGPoint point)
 {
     DictionaryPopupInfo dictionaryPopupInfo;
@@ -1106,6 +1295,11 @@ NSData *PDFPlugin::liveData() const
     return SimplePDFPlugin::liveData();
 }
 
+NSObject *PDFPlugin::accessibilityObject() const
+{
+    return m_accessibilityObject.get();
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(PDFKIT_PLUGIN)
index 7774f92..1d9e97c 100644 (file)
@@ -56,13 +56,14 @@ public:
     virtual bool isBeingAsynchronouslyInitialized() const { return false; }
 
     void didMutatePDFDocument() { m_pdfDocumentWasMutated = true; }
+    
+    WebCore::IntSize size() const { return m_size; }
 
 protected:
     explicit SimplePDFPlugin(WebFrame*);
 
     WebFrame* webFrame() const { return m_frame; }
 
-    WebCore::IntSize size() const { return m_size; }
     void setSize(WebCore::IntSize size) { m_size = size; }
 
     RetainPtr<PDFDocument> pdfDocument() const { return m_pdfDocument; }
index 80a435f..f8de5a7 100644 (file)
@@ -38,6 +38,7 @@
 #if PLATFORM(MAC)
 #include "LayerHostingContext.h"
 
+OBJC_CLASS NSObject;
 OBJC_CLASS PDFDocument;
 #endif
 
@@ -259,6 +260,7 @@ public:
 
 #if PLATFORM(MAC)
     virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
+    virtual NSObject *accessibilityObject() const { return 0; }
 #endif
 
     virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
index 1fdaf91..d4fe090 100644 (file)
@@ -519,7 +519,14 @@ void PluginView::setLayerHostingMode(LayerHostingMode layerHostingMode)
 
     m_plugin->setLayerHostingMode(layerHostingMode);
 }
-
+    
+NSObject *PluginView::accessibilityObject() const
+{
+    if (!m_isInitialized || !m_plugin)
+        return 0;
+    
+    return m_plugin->accessibilityObject();
+}
 #endif
 
 void PluginView::initializePlugin()
index c6cd588..d0a2a85 100644 (file)
@@ -76,6 +76,7 @@ public:
     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
     void setLayerHostingMode(LayerHostingMode);
     RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
+    NSObject *accessibilityObject() const;
 #endif
 
     WebCore::HTMLPlugInElement* pluginElement() const { return m_pluginElement.get(); }
index c290c01..1699cc3 100644 (file)
@@ -461,6 +461,7 @@ public:
 #if PLATFORM(MAC)
     void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
     WKAccessibilityWebPageObject* accessibilityRemoteObject();
+    NSObject *accessibilityObjectForMainFramePlugin();
     const WebCore::FloatPoint& accessibilityPosition() const { return m_accessibilityPosition; }
     
     void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
index 6721b41..659fd6e 100644 (file)
@@ -46,6 +46,10 @@ using namespace WebKit;
     if (!WebCore::AXObjectCache::accessibilityEnabled())
         WebCore::AXObjectCache::enableAccessibility();
 
+    NSObject* mainFramePluginAccessibilityObjectWrapper = m_page->accessibilityObjectForMainFramePlugin();
+    if (mainFramePluginAccessibilityObjectWrapper)
+        return mainFramePluginAccessibilityObjectWrapper;
+
     WebCore::Page* page = m_page->corePage();
     if (!page)
         return nil;
@@ -119,7 +123,7 @@ using namespace WebKit;
     id wrapper = [self accessibilityRootObjectWrapper];
     if (!wrapper)
         return [NSArray array];
-    
+
     return [NSArray arrayWithObject:wrapper];
 }
 
index df0e697..e54c881 100644 (file)
@@ -97,6 +97,18 @@ void WebPage::platformInitialize()
     m_mockAccessibilityElement = mockAccessibilityElement;
 }
 
+NSObject *WebPage::accessibilityObjectForMainFramePlugin()
+{
+    Frame* frame = m_page->mainFrame();
+    if (!frame)
+        return 0;
+
+    if (PluginView* pluginView = pluginViewForFrame(frame))
+        return pluginView->accessibilityObject();
+
+    return 0;
+}
+
 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
 {
     if (WebInspector* inspector = this->inspector())