Immediate action not functional for embedded PDFs
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Apr 2015 19:33:10 +0000 (19:33 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Apr 2015 19:33:10 +0000 (19:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143952
<rdar://problem/19842365>

Reviewed by Tim Horton.

Source/WebCore:

Add a dictionary lookup method to allow us to retrieve
relevant information for PDFs.

* editing/mac/DictionaryLookup.mm:
(WebCore::dictionaryLookupForPDFSelection): Updated to properly handle cases
where the Lookup engine selects a smaller range than the initial automatic
selection performed on clicking.

Source/WebKit2:

Add a new method to retrieve appropriate dictionary lookup content and update the
hit test result with relevant dictionary content and the bounding rect of the
selection.

* WebProcess/Plugins/Netscape/NetscapePlugin.h: Add stub.
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp: Initialize plugin type.
* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::rectInWindowSpaceForRectInLayoutSpace): New helper function to
convert PDF 'in page' units to the equivalent view units.
(WebKit::PDFPlugin::PDFPlugin): Initialize plugin type.
(WebKit::PDFPlugin::viewRectForSelection): Query a provided PDFSelection for
its bounding rect and return the result in view units.
* WebProcess/Plugins/Plugin.h:
* WebProcess/Plugins/PluginProxy.cpp: Initialize plugin type.
* WebProcess/Plugins/PluginProxy.h: Add stub.
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::viewRectForSelection): Added.
* WebProcess/Plugins/PluginView.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::dictionaryPopupInfoForPDFSelectionInPluginView): Added.
(WebKit::textIndicatorTransitionForActionMenu): Added helper function.
(WebKit::WebPage::performActionMenuHitTestAtLocation): Update the hit test information
with relevant dictionary lookup content, and mark the result as a text node (if
appropriate).

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/mac/DictionaryLookup.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit2/WebProcess/Plugins/Plugin.cpp
Source/WebKit2/WebProcess/Plugins/Plugin.h
Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp
Source/WebKit2/WebProcess/Plugins/PluginProxy.h
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/Plugins/PluginView.h
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index 6a784fb..80c3c6a 100644 (file)
@@ -1,3 +1,19 @@
+2015-04-24  Brent Fulgham  <bfulgham@apple.com>
+
+        Immediate action not functional for embedded PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=143952
+        <rdar://problem/19842365>        
+
+        Reviewed by Tim Horton.
+
+        Add a dictionary lookup method to allow us to retrieve
+        relevant information for PDFs.
+
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::dictionaryLookupForPDFSelection): Updated to properly handle cases
+        where the Lookup engine selects a smaller range than the initial automatic
+        selection performed on clicking.
+
 2015-04-24  Simon Fraser  <simon.fraser@apple.com>
 
         Make it possible to map a secondary quad through TransformState
index b7e85d0..ad0709b 100644 (file)
@@ -203,10 +203,8 @@ NSString *dictionaryLookupForPDFSelection(PDFSelection *selection, NSDictionary
     if (extractedRange.location == NSNotFound)
         return selection.string;
     
-    NSInteger lookupAddedBefore = (extractedRange.location < rangeToPass.location) ? rangeToPass.location - extractedRange.location : 0;
-    NSInteger lookupAddedAfter = 0;
-    if ((extractedRange.location + extractedRange.length) > (rangeToPass.location + originalLength))
-        lookupAddedAfter = (extractedRange.location + extractedRange.length) - (rangeToPass.location + originalLength);
+    NSInteger lookupAddedBefore = rangeToPass.location - extractedRange.location;
+    NSInteger lookupAddedAfter = (extractedRange.location + extractedRange.length) - (rangeToPass.location + originalLength);
     
     [selection extendSelectionAtStart:lookupAddedBefore];
     [selection extendSelectionAtEnd:lookupAddedAfter];
index 93615ca..e9dd64e 100644 (file)
@@ -1,3 +1,38 @@
+2015-04-24  Brent Fulgham  <bfulgham@apple.com>
+
+        Immediate action not functional for embedded PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=143952
+        <rdar://problem/19842365>        
+
+        Reviewed by Tim Horton.
+
+        Add a new method to retrieve appropriate dictionary lookup content and update the
+        hit test result with relevant dictionary content and the bounding rect of the
+        selection.
+
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h: Add stub.
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp: Initialize plugin type.
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::rectInWindowSpaceForRectInLayoutSpace): New helper function to
+        convert PDF 'in page' units to the equivalent view units.
+        (WebKit::PDFPlugin::PDFPlugin): Initialize plugin type.
+        (WebKit::PDFPlugin::viewRectForSelection): Query a provided PDFSelection for
+        its bounding rect and return the result in view units.
+        * WebProcess/Plugins/Plugin.h:
+        * WebProcess/Plugins/PluginProxy.cpp: Initialize plugin type.
+        * WebProcess/Plugins/PluginProxy.h: Add stub.
+        * WebProcess/Plugins/PluginView.cpp: 
+        (WebKit::PluginView::viewRectForSelection): Added.
+        * WebProcess/Plugins/PluginView.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::dictionaryPopupInfoForPDFSelectionInPluginView): Added.
+        (WebKit::textIndicatorTransitionForActionMenu): Added helper function.
+        (WebKit::WebPage::performActionMenuHitTestAtLocation): Update the hit test information
+        with relevant dictionary lookup content, and mark the result as a text node (if
+        appropriate).
+
 2015-04-24  Jer Noble  <jer.noble@apple.com>
 
         [WK2] Only issue a isPlayingAudioDidChange() notification if the audio playing state actually changed.
index be43f4c..9ec033c 100644 (file)
@@ -58,7 +58,8 @@ PassRefPtr<NetscapePlugin> NetscapePlugin::create(PassRefPtr<NetscapePluginModul
 }
     
 NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
-    : m_nextRequestID(0)
+    : Plugin(NetscapePluginType)
+    , m_nextRequestID(0)
     , m_pluginModule(pluginModule)
     , m_npWindow()
     , m_isStarted(false)
index 7b0164a..b3c83bd 100644 (file)
@@ -241,7 +241,6 @@ private:
     void setComplexTextInputEnabled(bool);
 
     void updatePluginLayer();
-    String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection** selection, NSDictionary**) const override { return String(); }
 #endif
 
     virtual void contentsScaleFactorChanged(float) override;
@@ -401,6 +400,8 @@ public: // Need to call it in the NPN_GetValue browser callback.
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(NetscapePlugin, NetscapePluginType)
+
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
 #endif // NetscapePlugin_h
index acceaee..d3c0560 100644 (file)
@@ -104,6 +104,9 @@ public:
     
     bool showContextMenuAtPoint(const WebCore::IntPoint&);
 
+    String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection **, NSDictionary **) const;
+    WebCore::FloatRect viewRectForSelection(PDFSelection *) const;
+
 private:
     explicit PDFPlugin(WebFrame*);
 
@@ -170,7 +173,6 @@ private:
     String getSelectionString() const override;
     String getSelectionForWordAtPoint(const WebCore::FloatPoint&) const override;
     bool existingSelectionContainsPoint(const WebCore::FloatPoint&) const override;
-    String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection **, NSDictionary **) const override;
 
     virtual bool shouldAllowScripting() override { return false; }
     virtual bool shouldAllowNavigationFromDrags() override { return true; }
@@ -308,6 +310,8 @@ private:
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(PDFPlugin, PDFPluginType)
+
 #endif // ENABLE(PDFKIT_PLUGIN)
 
 #endif // PDFPlugin_h
index 41350f5..42d1646 100644 (file)
@@ -395,6 +395,7 @@ static const int defaultScrollMagnitudeThresholdForPageFlip = 20;
 
 @interface PDFViewLayout
 - (NSPoint)convertPoint:(NSPoint)point toPage:(PDFPage *)page forScaleFactor:(CGFloat)scaleFactor;
+- (NSRect)convertRect:(NSRect)rect fromPage:(PDFPage *) page forScaleFactor:(CGFloat) scaleFactor;
 - (PDFPage *)pageNearestPoint:(NSPoint)point currentPage:(PDFPage *)currentPage;
 @end
 
@@ -504,7 +505,8 @@ PassRefPtr<PDFPlugin> PDFPlugin::create(WebFrame* frame)
 }
 
 PDFPlugin::PDFPlugin(WebFrame* frame)
-    : m_frame(frame)
+    : Plugin(PDFPluginType)
+    , m_frame(frame)
     , m_isPostScript(false)
     , m_pdfDocumentWasMutated(false)
     , m_containerLayer(adoptNS([[CALayer alloc] init]))
@@ -1933,6 +1935,38 @@ String PDFPlugin::lookupTextAtLocation(const WebCore::FloatPoint& locationInView
     return lookupText;
 }
 
+static NSRect rectInViewSpaceForRectInLayoutSpace(PDFLayerController* pdfLayerController, NSRect layoutSpaceRect)
+{
+    CGRect newRect = NSRectToCGRect(layoutSpaceRect);
+    CGFloat scaleFactor = pdfLayerController.contentScaleFactor;
+    CGPoint scrollOffset = pdfLayerController.scrollPosition;
+
+    scrollOffset.y = pdfLayerController.contentSizeRespectingZoom.height - NSRectToCGRect(pdfLayerController.frame).size.height - scrollOffset.y;
+
+    newRect.origin.x *= scaleFactor;
+    newRect.origin.y *= scaleFactor;
+    newRect.size.width *= scaleFactor;
+    newRect.size.height *= scaleFactor;
+
+    newRect.origin.x -= scrollOffset.x;
+    newRect.origin.y -= scrollOffset.y;
+
+    return NSRectFromCGRect(newRect);
+}
+
+WebCore::FloatRect PDFPlugin::viewRectForSelection(PDFSelection *selection) const
+{
+    PDFPage *currentPage = [m_pdfLayerController currentPage];
+    
+    NSRect rectInPageSpace = [selection boundsForPage:currentPage];
+    NSRect rectInLayoutSpace = [[m_pdfLayerController layout] convertRect:rectInPageSpace fromPage:currentPage forScaleFactor:1.0];
+    NSRect rectInView = rectInViewSpaceForRectInLayoutSpace(m_pdfLayerController.get(), rectInLayoutSpace);
+
+    rectInView.origin = convertFromPDFViewToRootView(IntPoint(rectInView.origin));
+
+    return WebCore::FloatRect(rectInView);
+}
+
 void PDFPlugin::performWebSearch(NSString *string)
 {
     webFrame()->page()->send(Messages::WebPageProxy::SearchTheWeb(string));
index bb2456d..f6d1c05 100644 (file)
@@ -76,8 +76,9 @@ bool Plugin::Parameters::decode(IPC::ArgumentDecoder& decoder, Parameters& param
     return true;
 }
 
-Plugin::Plugin()
-    : m_pluginController(0)
+Plugin::Plugin(PluginType type)
+    : m_type(type)
+    , m_pluginController(0)
 {
 }
 
index c89fcb9..a14e98a 100644 (file)
@@ -74,6 +74,12 @@ class WebWheelEvent;
     
 class PluginController;
 
+enum PluginType {
+    PluginProxyType,
+    NetscapePluginType,
+    PDFPluginType,
+};
+
 class Plugin : public ThreadSafeRefCounted<Plugin> {
 public:
     struct Parameters {
@@ -105,6 +111,8 @@ public:
 
     virtual ~Plugin();
 
+    PluginType type() const { return m_type; }
+
 private:
 
     // Initializes the plug-in. If the plug-in fails to initialize this should return false.
@@ -282,16 +290,15 @@ public:
     virtual String getSelectionString() const = 0;
     virtual String getSelectionForWordAtPoint(const WebCore::FloatPoint&) const = 0;
     virtual bool existingSelectionContainsPoint(const WebCore::FloatPoint&) const = 0;
-#if PLATFORM(COCOA)
-    virtual String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection**, NSDictionary**) const = 0;
-#endif
 
     virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const { return WebCore::AudioHardwareActivityType::Unknown; }
 
     virtual void mutedStateChanged(bool) { }
 
 protected:
-    Plugin();
+    Plugin(PluginType);
+
+    PluginType m_type;
 
 private:
     PluginController* m_pluginController;
@@ -299,4 +306,9 @@ private:
     
 } // namespace WebKit
 
+#define SPECIALIZE_TYPE_TRAITS_PLUGIN(ToValueTypeName, SpecificPluginType) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \
+static bool isType(const WebKit::Plugin& plugin) { return plugin.type() == WebKit::SpecificPluginType; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // Plugin_h
index 02c3ee4..b660b77 100644 (file)
@@ -62,7 +62,8 @@ PassRefPtr<PluginProxy> PluginProxy::create(uint64_t pluginProcessToken, bool is
 }
 
 PluginProxy::PluginProxy(uint64_t pluginProcessToken, bool isRestartedProcess)
-    : m_pluginProcessToken(pluginProcessToken)
+    : Plugin(PluginProxyType)
+    , m_pluginProcessToken(pluginProcessToken)
     , m_pluginInstanceID(generatePluginInstanceID())
     , m_pluginBackingStoreContainsValidData(false)
     , m_isStarted(false)
index 4d57a95..ac22394 100644 (file)
@@ -123,7 +123,6 @@ private:
     virtual uint64_t pluginComplexTextInputIdentifier() const override;
     virtual void sendComplexTextInput(const String& textInput) override;
     virtual void setLayerHostingMode(LayerHostingMode) override;
-    String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection**, NSDictionary**) const override { return String(); }
 #endif
 
     virtual void contentsScaleFactorChanged(float) override;
@@ -237,6 +236,8 @@ private:
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(PluginProxy, PluginProxyType)
+
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
 #endif // PluginProxy_h
index 8db8e9f..a6a520b 100644 (file)
@@ -1009,16 +1009,6 @@ bool PluginView::existingSelectionContainsPoint(const WebCore::FloatPoint& point
     return m_plugin->existingSelectionContainsPoint(point);
 }
 
-#if PLATFORM(COCOA)
-String PluginView::lookupTextAtLocation(const WebCore::FloatPoint& point, WebHitTestResult::Data& data, PDFSelection **selection, NSDictionary **options) const
-{
-    if (!m_isInitialized || !m_plugin)
-        return String();
-
-    return m_plugin->lookupTextAtLocation(point, data, selection, options);
-}
-#endif
-
 void PluginView::notifyWidget(WidgetNotification notification)
 {
     switch (notification) {
index 6d4348c..fceb738 100644 (file)
@@ -89,11 +89,11 @@ public:
     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
     RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
     NSObject *accessibilityObject() const;
-    String lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResult::Data&, PDFSelection**, NSDictionary**) const;
 #endif
 
     WebCore::HTMLPlugInElement* pluginElement() const { return m_pluginElement.get(); }
     const Plugin::Parameters& initialParameters() const { return m_parameters; }
+    Plugin* plugin() const { return m_plugin.get(); }
 
     // FIXME: Remove this; nobody should have to know about the plug-in view's renderer except the plug-in view itself.
     WebCore::RenderBoxModelObject* renderer() const;
index da81857..694090d 100644 (file)
@@ -146,6 +146,7 @@ namespace WebKit {
 class DrawingArea;
 class InjectedBundleBackForwardList;
 class NotificationPermissionRequestManager;
+class PDFPlugin;
 class PageBanner;
 class PluginView;
 class VisibleContentRectUpdateInfo;
@@ -1013,6 +1014,9 @@ private:
     void performDictionaryLookupOfCurrentSelection();
     void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
     DictionaryPopupInfo dictionaryPopupInfoForRange(WebCore::Frame* frame, WebCore::Range& range, NSDictionary **options, WebCore::TextIndicatorPresentationTransition presentationTransition);
+#if ENABLE(PDFKIT_PLUGIN)
+    DictionaryPopupInfo dictionaryPopupInfoForPDFSelectionInPluginView(PDFSelection *, PDFPlugin&, NSDictionary **options, WebCore::TextIndicatorPresentationTransition);
+#endif
 
     void windowAndViewFramesChanged(const WebCore::FloatRect& windowFrameInScreenCoordinates, const WebCore::FloatRect& windowFrameInUnflippedScreenCoordinates, const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates);
 
index 88e9077..01a70c3 100644 (file)
@@ -35,6 +35,7 @@
 #import "EditorState.h"
 #import "InjectedBundleHitTestResult.h"
 #import "PDFKitImports.h"
+#import "PDFPlugin.h"
 #import "PageBanner.h"
 #import "PluginView.h"
 #import "PrintInfo.h"
@@ -586,6 +587,49 @@ DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame* frame, Range& ra
     return dictionaryPopupInfo;
 }
 
+#if ENABLE(PDFKIT_PLUGIN)
+DictionaryPopupInfo WebPage::dictionaryPopupInfoForPDFSelectionInPluginView(PDFSelection *selection, PDFPlugin& pdfPlugin, NSDictionary **options, WebCore::TextIndicatorPresentationTransition presentationTransition)
+{
+    DictionaryPopupInfo dictionaryPopupInfo;
+    if (!selection.string.length)
+        return dictionaryPopupInfo;
+
+    NSRect rangeRect = pdfPlugin.viewRectForSelection(selection);
+
+    dictionaryPopupInfo.origin = rangeRect.origin;
+    dictionaryPopupInfo.options = (CFDictionaryRef)*options;
+    
+    NSAttributedString *nsAttributedString = selection.attributedString;
+    
+    RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
+    
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    
+    [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
+        RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
+        
+        NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
+        if (font) {
+            font = [fontManager convertFont:font toSize:[font pointSize] * pageScaleFactor()];
+            [scaledAttributes setObject:font forKey:NSFontAttributeName];
+        }
+        
+        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
+    }];
+
+    TextIndicatorData dataForSelection;
+    dataForSelection.selectionRectInRootViewCoordinates = rangeRect;
+    dataForSelection.textBoundingRectInRootViewCoordinates = rangeRect;
+    dataForSelection.contentImageScaleFactor = 1.0;
+    dataForSelection.presentationTransition = presentationTransition;
+    
+    dictionaryPopupInfo.textIndicator = dataForSelection;
+    dictionaryPopupInfo.attributedString.string = scaledNSAttributedString;
+    
+    return dictionaryPopupInfo;
+}
+#endif
+
 void WebPage::performDictionaryLookupForRange(Frame* frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
 {
     DictionaryPopupInfo dictionaryPopupInfo = dictionaryPopupInfoForRange(frame, range, &options, presentationTransition);
@@ -1013,6 +1057,15 @@ static TextIndicatorPresentationTransition textIndicatorTransitionForActionMenu(
     return forImmediateAction ? TextIndicatorPresentationTransition::FadeIn : TextIndicatorPresentationTransition::Bounce;
 }
 
+#if ENABLE(PDFKIT_PLUGIN)
+static TextIndicatorPresentationTransition textIndicatorTransitionForActionMenu(bool forImmediateAction, bool forDataDetectors)
+{
+    if (forDataDetectors && !forImmediateAction)
+        return forImmediateAction ? TextIndicatorPresentationTransition::Crossfade : TextIndicatorPresentationTransition::BounceAndCrossfade;
+    return forImmediateAction ? TextIndicatorPresentationTransition::FadeIn : TextIndicatorPresentationTransition::Bounce;
+}
+#endif
+
 void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInViewCoordinates, bool forImmediateAction)
 {
     layoutIfNeeded();
@@ -1106,11 +1159,14 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
     // See if we have a PDF
     if (element && is<HTMLPlugInImageElement>(*element)) {
         HTMLPlugInImageElement& pluginImageElement = downcast<HTMLPlugInImageElement>(*element);
-        if (PluginView* pluginView = reinterpret_cast<PluginView*>(pluginImageElement.pluginWidget())) {
+        PluginView* pluginView = reinterpret_cast<PluginView*>(pluginImageElement.pluginWidget());
+        Plugin* plugin = pluginView ? pluginView->plugin() : nullptr;
+        if (is<PDFPlugin>(plugin)) {
+            PDFPlugin* pdfPugin = downcast<PDFPlugin>(plugin);
             // FIXME: We don't have API to identify images inside PDFs based on position.
             NSDictionary *options = nil;
             PDFSelection *selection = nil;
-            String selectedText = pluginView->lookupTextAtLocation(locationInContentCoordinates, actionMenuResult, &selection, &options);
+            String selectedText = pdfPugin->lookupTextAtLocation(locationInContentCoordinates, actionMenuResult, &selection, &options);
             if (!selectedText.isEmpty()) {
                 if (element->document().isPluginDocument()) {
                     // FIXME(144030): Focus does not seem to get set to the PDF when invoking the menu.
@@ -1119,8 +1175,11 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
                 }
 
                 actionMenuResult.lookupText = selectedText;
+                actionMenuResult.isTextNode = true;
                 actionMenuResult.isSelected = true;
                 actionMenuResult.allowsCopy = true;
+
+                actionMenuResult.dictionaryPopupInfo = dictionaryPopupInfoForPDFSelectionInPluginView(selection, *pdfPugin, &options, textIndicatorTransitionForActionMenu(forImmediateAction, false));
             }
         }
     }