Title: [176092] branches/safari-600.3-branch/Source/WebKit2

Diff

Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog	2014-11-13 22:14:10 UTC (rev 176092)
@@ -1,3 +1,51 @@
+2014-11-13  Tim Horton  <[email protected]>
+
+        Adjust the WKBundlePageOverlay Data Detectors SPI
+        https://bugs.webkit.org/show_bug.cgi?id=138685
+        <rdar://problem/18947156>
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _defaultMenuItemsForDataDetectedText]):
+        Forward DDActionContext callbacks to the Web process.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp:
+        * WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h:
+        * WebProcess/WebPage/WebPageOverlay.cpp:
+        * WebProcess/WebPage/WebPageOverlay.h:
+        Add four DataDetectors-related WebKit2-only page overlay callbacks:
+
+        (WebKit::WebPageOverlay::actionContextForResultAtPoint):
+        Called during the action menu hit test; clients can reply with a DDActionContext
+        and a DOM range, and WebKit will treat that result and range as if it had
+        detected it itself, building the action menu and showing the yellow highlight as usual.
+
+        (WebKit::WebPageOverlay::dataDetectorsPresentedUI):
+        (WebKit::WebPageOverlay::dataDetectorsChangedUI):
+        (WebKit::WebPageOverlay::dataDetectorsHidUI):
+        These correspond to the DDActionContext callbacks, and can be used by clients
+        to show/hide corresponding UI while DataDetectors in the UI process is presenting UI.
+
+        (WebKit::WebPageOverlay::prepareForActionMenu): Deleted.
+        Get rid of prepareForActionMenu, as nobody ever used it.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        Add WebPageOverlay.h so that we can build, because the destructor lives here.
+
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        Give all of the WebPageOverlays the first shot at data detection; if none of them
+        reply with a valid DDActionContext/DOM range, we'll go ahead and do our normal detection.
+
+        (WebKit::WebPage::dataDetectorsPresentedUI):
+        (WebKit::WebPage::dataDetectorsChangedUI):
+        (WebKit::WebPage::dataDetectorsHidUI):
+        Forward these along to the active WebPageOverlay.
+
 2014-11-12  Matthew Hanson  <[email protected]>
 
         Merge r175966. <rdar://problem/18866308>

Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-11-13 22:14:10 UTC (rev 176092)
@@ -585,11 +585,16 @@
         return @[ ];
 
     if (hasDataDetectorsCompletionAPI()) {
+        // Ref our WebPageProxy for use in the blocks below.
+        RefPtr<WebPageProxy> page = _page;
         _currentActionContext = [actionContext contextForView:_wkView altMode:YES interactionStartedHandler:^() {
+            page->send(Messages::WebPage::DataDetectorsDidPresentUI());
         } interactionChangedHandler:^() {
             [self _showTextIndicator];
+            page->send(Messages::WebPage::DataDetectorsDidChangeUI());
         } interactionStoppedHandler:^() {
             [self _hideTextIndicator];
+            page->send(Messages::WebPage::DataDetectorsDidHideUI());
         }];
     } else {
         _currentActionContext = actionContext;

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp	2014-11-13 22:14:10 UTC (rev 176092)
@@ -27,6 +27,7 @@
 #include "WKBundlePageOverlay.h"
 
 #include "APIClient.h"
+#include "InjectedBundleRangeHandle.h"
 #include "WKAPICast.h"
 #include "WKArray.h"
 #include "WKBundleAPICast.h"
@@ -132,20 +133,46 @@
         }
     }
 
-    virtual bool prepareForActionMenu(WebPageOverlay& pageOverlay, RefPtr<API::Object>& userData) override
+#if PLATFORM(MAC)
+    virtual DDActionContext *actionContextForResultAtPoint(WebPageOverlay& pageOverlay, WebCore::FloatPoint location, RefPtr<WebCore::Range>& rangeHandle)
     {
-        if (!m_client.prepareForActionMenu)
-            return false;
+        if (!m_client.actionContextForResultAtPoint)
+            return nil;
 
-        WKTypeRef userDataToPass = nullptr;
-        if (m_client.prepareForActionMenu(toAPI(&pageOverlay), &userDataToPass, m_client.base.clientInfo)) {
-            userData = adoptRef(toImpl(userDataToPass));
-            return true;
-        }
+        WKBundleRangeHandleRef apiRange;
+        DDActionContext *actionContext = (DDActionContext *)m_client.actionContextForResultAtPoint(toAPI(&pageOverlay), WKPointMake(location.x(), location.y()), &apiRange, m_client.base.clientInfo);
 
-        return false;
+        if (apiRange)
+            rangeHandle = toImpl(apiRange)->coreRange();
+
+        return actionContext;
     }
-    
+
+    virtual void dataDetectorsDidPresentUI(WebPageOverlay& pageOverlay)
+    {
+        if (!m_client.dataDetectorsDidPresentUI)
+            return;
+
+        m_client.dataDetectorsDidPresentUI(toAPI(&pageOverlay), m_client.base.clientInfo);
+    }
+
+    virtual void dataDetectorsDidChangeUI(WebPageOverlay& pageOverlay)
+    {
+        if (!m_client.dataDetectorsDidChangeUI)
+            return;
+
+        m_client.dataDetectorsDidChangeUI(toAPI(&pageOverlay), m_client.base.clientInfo);
+    }
+
+    virtual void dataDetectorsDidHideUI(WebPageOverlay& pageOverlay)
+    {
+        if (!m_client.dataDetectorsDidHideUI)
+            return;
+
+        m_client.dataDetectorsDidHideUI(toAPI(&pageOverlay), m_client.base.clientInfo);
+    }
+#endif // PLATFORM(MAC)
+
     virtual bool copyAccessibilityAttributeStringValueForPoint(WebPageOverlay& pageOverlay, String attribute, WebCore::FloatPoint parameter, String& value) override
     {
         if (!m_accessibilityClient.client().copyAccessibilityAttributeValue)

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h	2014-11-13 22:14:10 UTC (rev 176092)
@@ -48,8 +48,12 @@
 typedef bool (*WKBundlePageOverlayMouseUpCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKEventMouseButton mouseButton, const void* clientInfo);
 typedef bool (*WKBundlePageOverlayMouseMovedCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, const void* clientInfo);
 typedef bool (*WKBundlePageOverlayMouseDraggedCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKEventMouseButton mouseButton, const void* clientInfo);
-typedef bool (*WKBundlePageOverlayPrepareForActionMenuCallback)(WKBundlePageOverlayRef pageOverlay, WKTypeRef* userData, const void* clientInfo);
 
+typedef void* (*WKBundlePageOverlayActionContextForResultAtPointCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKBundleRangeHandleRef* rangeHandle, const void* clientInfo);
+typedef void (*WKBundlePageOverlayDatadetectorsDidPresentUI)(WKBundlePageOverlayRef pageOverlay, const void* clientInfo);
+typedef void (*WKBundlePageOverlayDatadetectorsDidChangeUI)(WKBundlePageOverlayRef pageOverlay, const void* clientInfo);
+typedef void (*WKBundlePageOverlayDatadetectorsDidHideUI)(WKBundlePageOverlayRef pageOverlay, const void* clientInfo);
+
 typedef struct WKBundlePageOverlayClientBase {
     int                                                                 version;
     const void *                                                        clientInfo;
@@ -78,7 +82,10 @@
     WKBundlePageOverlayMouseMovedCallback                               mouseMoved;
     WKBundlePageOverlayMouseDraggedCallback                             mouseDragged;
 
-    WKBundlePageOverlayPrepareForActionMenuCallback                     prepareForActionMenu;
+    WKBundlePageOverlayActionContextForResultAtPointCallback            actionContextForResultAtPoint;
+    WKBundlePageOverlayDatadetectorsDidPresentUI                         dataDetectorsDidPresentUI;
+    WKBundlePageOverlayDatadetectorsDidChangeUI                           dataDetectorsDidChangeUI;
+    WKBundlePageOverlayDatadetectorsDidHideUI                               dataDetectorsDidHideUI;
 } WKBundlePageOverlayClientV1;
 
 enum { kWKBundlePageOverlayClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 0 };

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-11-13 22:14:10 UTC (rev 176092)
@@ -84,6 +84,7 @@
 #include "WebPageCreationParameters.h"
 #include "WebPageGroupProxy.h"
 #include "WebPageMessages.h"
+#include "WebPageOverlay.h"
 #include "WebPageProxyMessages.h"
 #include "WebPlugInClient.h"
 #include "WebPopupMenu.h"

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-11-13 22:14:10 UTC (rev 176092)
@@ -158,6 +158,7 @@
 class WebNotificationClient;
 class WebOpenPanelResultListener;
 class WebPageGroupProxy;
+class WebPageOverlay;
 class WebPopupMenu;
 class WebUndoStep;
 class WebUserContentController;
@@ -1041,6 +1042,10 @@
     void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
     PassRefPtr<WebCore::Range> lookupTextAtLocation(WebCore::FloatPoint);
     void selectLastActionMenuRange();
+
+    void dataDetectorsDidPresentUI();
+    void dataDetectorsDidChangeUI();
+    void dataDetectorsDidHideUI();
 #endif
 
     uint64_t m_pageID;
@@ -1267,6 +1272,7 @@
 
 #if PLATFORM(MAC)
     RefPtr<WebCore::Range> m_lastActionMenuRangeForSelection;
+    RefPtr<WebPageOverlay> m_lastActionMenuHitPageOverlay;
 #endif
 };
 

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-11-13 22:14:10 UTC (rev 176092)
@@ -390,5 +390,8 @@
 #if PLATFORM(MAC)
     PerformActionMenuHitTestAtLocation(WebCore::FloatPoint location)
     SelectLastActionMenuRange()
+    DataDetectorsDidPresentUI()
+    DataDetectorsDidChangeUI()
+    DataDetectorsDidHideUI()
 #endif
 }

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.cpp (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.cpp	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.cpp	2014-11-13 22:14:10 UTC (rev 176092)
@@ -118,11 +118,28 @@
     m_client.didScrollFrame(*this, WebFrame::fromCoreFrame(frame));
 }
 
-bool WebPageOverlay::prepareForActionMenu(RefPtr<API::Object>& userData)
+#if PLATFORM(MAC)
+DDActionContext *WebPageOverlay::actionContextForResultAtPoint(FloatPoint location, RefPtr<WebCore::Range>& rangeHandle)
 {
-    return m_client.prepareForActionMenu(*this, userData);
+    return m_client.actionContextForResultAtPoint(*this, location, rangeHandle);
 }
 
+void WebPageOverlay::dataDetectorsDidPresentUI()
+{
+    m_client.dataDetectorsDidPresentUI(*this);
+}
+
+void WebPageOverlay::dataDetectorsDidChangeUI()
+{
+    m_client.dataDetectorsDidChangeUI(*this);
+}
+
+void WebPageOverlay::dataDetectorsDidHideUI()
+{
+    m_client.dataDetectorsDidHideUI(*this);
+}
+#endif // PLATFORM(MAC)
+
 bool WebPageOverlay::copyAccessibilityAttributeStringValueForPoint(PageOverlay&, String attribute, FloatPoint parameter, String& value)
 {
     return m_client.copyAccessibilityAttributeStringValueForPoint(*this, attribute, parameter, value);

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.h (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.h	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebPageOverlay.h	2014-11-13 22:14:10 UTC (rev 176092)
@@ -30,8 +30,12 @@
 #include <WebCore/FloatPoint.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/PageOverlay.h>
+#include <WebCore/Range.h>
 #include <wtf/PassRefPtr.h>
+#include <wtf/RetainPtr.h>
 
+OBJC_CLASS DDActionContext;
+
 namespace WebKit {
 
 class WebFrame;
@@ -50,8 +54,14 @@
         virtual void drawRect(WebPageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) = 0;
         virtual bool mouseEvent(WebPageOverlay&, const WebCore::PlatformMouseEvent&) = 0;
         virtual void didScrollFrame(WebPageOverlay&, WebFrame*) { }
-        virtual bool prepareForActionMenu(WebPageOverlay&, RefPtr<API::Object>& userData) { return false; }
 
+#if PLATFORM(MAC)
+        virtual DDActionContext *actionContextForResultAtPoint(WebPageOverlay&, WebCore::FloatPoint location, RefPtr<WebCore::Range>& rangeHandle) { return nullptr; }
+        virtual void dataDetectorsDidPresentUI(WebPageOverlay&) { }
+        virtual void dataDetectorsDidChangeUI(WebPageOverlay&) { }
+        virtual void dataDetectorsDidHideUI(WebPageOverlay&) { }
+#endif
+
         virtual bool copyAccessibilityAttributeStringValueForPoint(WebPageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, String& value) { return false; }
         virtual bool copyAccessibilityAttributeBoolValueForPoint(WebPageOverlay&, String /* attribute */, WebCore::FloatPoint /* parameter */, bool& value) { return false; }
         virtual Vector<String> copyAccessibilityAttributeNames(WebPageOverlay&, bool /* parameterizedNames */) { return Vector<String>(); }
@@ -69,7 +79,12 @@
     WebCore::PageOverlay* coreOverlay() const { return m_overlay.get(); }
     Client& client() const { return m_client; }
 
-    bool prepareForActionMenu(RefPtr<API::Object>& userData);
+#if PLATFORM(MAC)
+    DDActionContext *actionContextForResultAtPoint(WebCore::FloatPoint, RefPtr<WebCore::Range>&);
+    void dataDetectorsDidPresentUI();
+    void dataDetectorsDidChangeUI();
+    void dataDetectorsDidHideUI();
+#endif
 
 private:
     WebPageOverlay(Client&, WebCore::PageOverlay::OverlayType);

Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (176091 => 176092)


--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-11-13 22:11:41 UTC (rev 176091)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-11-13 22:14:10 UTC (rev 176092)
@@ -1044,6 +1044,8 @@
 
 void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInViewCooordinates)
 {
+    m_lastActionMenuHitPageOverlay = nullptr;
+
     layoutIfNeeded();
 
     MainFrame& mainFrame = corePage()->mainFrame();
@@ -1083,8 +1085,37 @@
             actionMenuResult.image->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
     }
 
+    bool pageOverlayDidOverrideDataDetectors = false;
+    for (const auto& overlay : mainFrame.pageOverlayController().pageOverlays()) {
+        WebPageOverlay* webOverlay = WebPageOverlay::fromCoreOverlay(*overlay);
+        if (!webOverlay)
+            continue;
+
+        RefPtr<Range> mainResultRange;
+        DDActionContext *actionContext = webOverlay->actionContextForResultAtPoint(locationInContentCoordinates, mainResultRange);
+        if (!actionContext || !mainResultRange)
+            continue;
+
+        pageOverlayDidOverrideDataDetectors = true;
+        actionMenuResult.actionContext = actionContext;
+
+        Vector<FloatQuad> quads;
+        mainResultRange->textQuads(quads);
+        FloatRect detectedDataBoundingBox;
+        FrameView* frameView = mainResultRange->ownerDocument().view();
+        for (const auto& quad : quads)
+            detectedDataBoundingBox.unite(frameView->contentsToWindow(quad.enclosingBoundingBox()));
+
+        actionMenuResult.detectedDataBoundingBox = detectedDataBoundingBox;
+        actionMenuResult.detectedDataTextIndicator = textIndicatorForRange(mainResultRange.get());
+        m_lastActionMenuRangeForSelection = mainResultRange;
+        m_lastActionMenuHitPageOverlay = webOverlay;
+
+        break;
+    }
+
     // FIXME: Avoid scanning if we will just throw away the result (e.g. we're over a link).
-    if (hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode()) {
+    if (!pageOverlayDidOverrideDataDetectors && hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode()) {
         FloatRect detectedDataBoundingBox;
         RefPtr<Range> detectedDataRange;
         actionMenuResult.actionContext = scanForDataDetectedItems(hitTestResult, detectedDataBoundingBox, detectedDataRange);
@@ -1096,23 +1127,9 @@
     }
 
     RefPtr<API::Object> userData;
+    RefPtr<InjectedBundleHitTestResult> injectedBundleHitTestResult = InjectedBundleHitTestResult::create(hitTestResult);
+    injectedBundleContextMenuClient().prepareForActionMenu(this, injectedBundleHitTestResult.get(), userData);
 
-    bool handled = false;
-    for (const auto& overlay : mainFrame.pageOverlayController().pageOverlays()) {
-        WebPageOverlay* webOverlay = WebPageOverlay::fromCoreOverlay(*overlay);
-        if (!webOverlay)
-            continue;
-        if (webOverlay->prepareForActionMenu(userData)) {
-            handled = true;
-            break;
-        }
-    }
-
-    if (!handled) {
-        RefPtr<InjectedBundleHitTestResult> injectedBundleHitTestResult = InjectedBundleHitTestResult::create(hitTestResult);
-        injectedBundleContextMenuClient().prepareForActionMenu(this, injectedBundleHitTestResult.get(), userData);
-    }
-
     send(Messages::WebPageProxy::DidPerformActionMenuHitTest(actionMenuResult, InjectedBundleUserMessageEncoder(userData.get())));
 }
 
@@ -1134,6 +1151,25 @@
         corePage()->mainFrame().selection().setSelectedRange(m_lastActionMenuRangeForSelection.get(), DOWNSTREAM, true);
 }
 
+void WebPage::dataDetectorsDidPresentUI()
+{
+    if (m_lastActionMenuHitPageOverlay)
+        m_lastActionMenuHitPageOverlay->dataDetectorsDidPresentUI();
+}
+
+void WebPage::dataDetectorsDidChangeUI()
+{
+    if (m_lastActionMenuHitPageOverlay)
+        m_lastActionMenuHitPageOverlay->dataDetectorsDidChangeUI();
+}
+
+void WebPage::dataDetectorsDidHideUI()
+{
+    if (m_lastActionMenuHitPageOverlay)
+        m_lastActionMenuHitPageOverlay->dataDetectorsDidHideUI();
+    m_lastActionMenuHitPageOverlay = nil;
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to