Title: [183277] trunk/Source
Revision
183277
Author
[email protected]
Date
2015-04-24 12:33:10 -0700 (Fri, 24 Apr 2015)

Log Message

Immediate action not functional for embedded PDFs
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).

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (183276 => 183277)


--- trunk/Source/WebCore/ChangeLog	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebCore/ChangeLog	2015-04-24 19:33:10 UTC (rev 183277)
@@ -1,3 +1,19 @@
+2015-04-24  Brent Fulgham  <[email protected]>
+
+        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  <[email protected]>
 
         Make it possible to map a secondary quad through TransformState

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (183276 => 183277)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-04-24 19:33:10 UTC (rev 183277)
@@ -203,10 +203,8 @@
     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];

Modified: trunk/Source/WebKit2/ChangeLog (183276 => 183277)


--- trunk/Source/WebKit2/ChangeLog	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/ChangeLog	2015-04-24 19:33:10 UTC (rev 183277)
@@ -1,3 +1,38 @@
+2015-04-24  Brent Fulgham  <[email protected]>
+
+        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  <[email protected]>
 
         [WK2] Only issue a isPlayingAudioDidChange() notification if the audio playing state actually changed.

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2015-04-24 19:33:10 UTC (rev 183277)
@@ -58,7 +58,8 @@
 }
     
 NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
-    : m_nextRequestID(0)
+    : Plugin(NetscapePluginType)
+    , m_nextRequestID(0)
     , m_pluginModule(pluginModule)
     , m_npWindow()
     , m_isStarted(false)

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -241,7 +241,6 @@
     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 @@
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(NetscapePlugin, NetscapePluginType)
+
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
 #endif // NetscapePlugin_h

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -104,6 +104,9 @@
     
     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 @@
     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 @@
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(PDFPlugin, PDFPluginType)
+
 #endif // ENABLE(PDFKIT_PLUGIN)
 
 #endif // PDFPlugin_h

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2015-04-24 19:33:10 UTC (rev 183277)
@@ -395,6 +395,7 @@
 
 @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 @@
 }
 
 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 @@
     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));

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Plugin.cpp (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/Plugin.cpp	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Plugin.cpp	2015-04-24 19:33:10 UTC (rev 183277)
@@ -76,8 +76,9 @@
     return true;
 }
 
-Plugin::Plugin()
-    : m_pluginController(0)
+Plugin::Plugin(PluginType type)
+    : m_type(type)
+    , m_pluginController(0)
 {
 }
 

Modified: trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -74,6 +74,12 @@
     
 class PluginController;
 
+enum PluginType {
+    PluginProxyType,
+    NetscapePluginType,
+    PDFPluginType,
+};
+
 class Plugin : public ThreadSafeRefCounted<Plugin> {
 public:
     struct Parameters {
@@ -105,6 +111,8 @@
 
     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,21 +290,25 @@
     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;
 };
     
 } // 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

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp	2015-04-24 19:33:10 UTC (rev 183277)
@@ -62,7 +62,8 @@
 }
 
 PluginProxy::PluginProxy(uint64_t pluginProcessToken, bool isRestartedProcess)
-    : m_pluginProcessToken(pluginProcessToken)
+    : Plugin(PluginProxyType)
+    , m_pluginProcessToken(pluginProcessToken)
     , m_pluginInstanceID(generatePluginInstanceID())
     , m_pluginBackingStoreContainsValidData(false)
     , m_isStarted(false)

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -123,7 +123,6 @@
     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 @@
 
 } // namespace WebKit
 
+SPECIALIZE_TYPE_TRAITS_PLUGIN(PluginProxy, PluginProxyType)
+
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 
 #endif // PluginProxy_h

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp	2015-04-24 19:33:10 UTC (rev 183277)
@@ -1009,16 +1009,6 @@
     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) {

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -89,11 +89,11 @@
     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;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-04-24 19:33:10 UTC (rev 183277)
@@ -146,6 +146,7 @@
 class DrawingArea;
 class InjectedBundleBackForwardList;
 class NotificationPermissionRequestManager;
+class PDFPlugin;
 class PageBanner;
 class PluginView;
 class VisibleContentRectUpdateInfo;
@@ -1013,6 +1014,9 @@
     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);
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (183276 => 183277)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-04-24 19:15:57 UTC (rev 183276)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-04-24 19:33:10 UTC (rev 183277)
@@ -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 @@
     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 @@
     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 @@
     // 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 @@
                 }
 
                 actionMenuResult.lookupText = selectedText;
+                actionMenuResult.isTextNode = true;
                 actionMenuResult.isSelected = true;
                 actionMenuResult.allowsCopy = true;
+
+                actionMenuResult.dictionaryPopupInfo = dictionaryPopupInfoForPDFSelectionInPluginView(selection, *pdfPugin, &options, textIndicatorTransitionForActionMenu(forImmediateAction, false));
             }
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to