Add infrastructure to support data interaction in WebKit2
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2017 04:22:05 +0000 (04:22 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2017 04:22:05 +0000 (04:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167443

Reviewed by Simon Fraser.

Source/WebCore:

Adds support in WebCore to determine whether there is interactive data at a given position. No new tests, since
there should be no behavior change yet.

* page/EventHandler.h:
* page/Page.cpp:
(WebCore::Page::hasDataInteractionAtPosition):
* page/Page.h:

Source/WebKit2:

Adds plumbing for two new XPC messages: WebPageProxy::DidPerformDataInteractionControllerOperation and
WebPage::RequestStartDataInteraction. Additionally, adds a new field to InteractionInformationAtPosition that
indicates whether or not there is data to interact with at a given location.

This patch only adds infrastructure, and does not change any behavior.

* Shared/ios/InteractionInformationAtPosition.h:
* Shared/ios/InteractionInformationAtPosition.mm:
(WebKit::InteractionInformationAtPosition::encode):
(WebKit::InteractionInformationAtPosition::decode):
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::didPerformDataInteractionControllerOperation):
(WebKit::PageClientImpl::startDataInteractionWithImage):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didPerformDataInteractionControllerOperation):
(WebKit::requestStartDataInteraction):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDataInteractionControllerOperation):
(WebKit::PageClientImpl::startDataInteractionWithImage):
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestStartDataInteraction):
(WebKit::WebPage::getPositionInformation):

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

19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ios/InteractionInformationAtPosition.h
Source/WebKit2/Shared/ios/InteractionInformationAtPosition.mm
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/ios/PageClientImplIOS.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index f40e666..b664ae2 100644 (file)
@@ -1,3 +1,18 @@
+2017-01-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Add infrastructure to support data interaction in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=167443
+
+        Reviewed by Simon Fraser.
+
+        Adds support in WebCore to determine whether there is interactive data at a given position. No new tests, since
+        there should be no behavior change yet.
+
+        * page/EventHandler.h:
+        * page/Page.cpp:
+        (WebCore::Page::hasDataInteractionAtPosition):
+        * page/Page.h:
+
 2017-01-25  Matt Rajca  <mrajca@apple.com>
 
         Notify clients when the user plays media otherwise prevented from autoplaying
index 9c75765..a82d7cd 100644 (file)
@@ -315,6 +315,10 @@ public:
 
     static Widget* widgetForEventTarget(Element* eventTarget);
 
+#if ENABLE(DATA_INTERACTION)
+    WEBCORE_EXPORT bool tryToBeginDataInteractionAtPoint(const IntPoint& clientPosition, const IntPoint& globalPosition);
+#endif
+
 private:
 #if ENABLE(DRAG_SUPPORT)
     static DragState& dragState();
index 77c7f3e..b316d66 100644 (file)
 #include "InProcessIDBServer.h"
 #endif
 
+#if ENABLE(DATA_INTERACTION)
+#include "SelectionRect.h"
+#endif
+
 namespace WebCore {
 
 static HashSet<Page*>* allPages;
@@ -2152,4 +2156,26 @@ void Page::accessibilitySettingsDidChange()
         LOG(Layout, "hasMediaQueriesAffectedByAccessibilitySettingsChange, enqueueing style recalc");
 }
 
+#if ENABLE(DATA_INTERACTION)
+
+bool Page::hasDataInteractionAtPosition(const FloatPoint& position) const
+{
+    auto currentSelection = m_mainFrame->selection().selection();
+    if (!currentSelection.isRange())
+        return false;
+
+    if (auto selectedRange = currentSelection.toNormalizedRange()) {
+        Vector<SelectionRect> selectionRects;
+        selectedRange->collectSelectionRects(selectionRects);
+        for (auto selectionRect : selectionRects) {
+            if (FloatRect(selectionRect.rect()).contains(position))
+                return true;
+        }
+    }
+
+    return false;
+}
+
+#endif
+
 } // namespace WebCore
index ad8351b..440d1ab 100644 (file)
@@ -566,6 +566,10 @@ public:
     bool isOnlyNonUtilityPage() const;
     bool isUtilityPage() const { return m_isUtilityPage; }
 
+#if ENABLE(DATA_INTERACTION)
+    WEBCORE_EXPORT bool hasDataInteractionAtPosition(const FloatPoint&) const;
+#endif
+
 private:
     WEBCORE_EXPORT void initGroup();
 
index fc247fe..0c27c3b 100644 (file)
@@ -1,3 +1,41 @@
+2017-01-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Add infrastructure to support data interaction in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=167443
+
+        Reviewed by Simon Fraser.
+
+        Adds plumbing for two new XPC messages: WebPageProxy::DidPerformDataInteractionControllerOperation and
+        WebPage::RequestStartDataInteraction. Additionally, adds a new field to InteractionInformationAtPosition that
+        indicates whether or not there is data to interact with at a given location.
+
+        This patch only adds infrastructure, and does not change any behavior.
+
+        * Shared/ios/InteractionInformationAtPosition.h:
+        * Shared/ios/InteractionInformationAtPosition.mm:
+        (WebKit::InteractionInformationAtPosition::encode):
+        (WebKit::InteractionInformationAtPosition::decode):
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::didPerformDataInteractionControllerOperation):
+        (WebKit::PageClientImpl::startDataInteractionWithImage):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didPerformDataInteractionControllerOperation):
+        (WebKit::requestStartDataInteraction):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didPerformDataInteractionControllerOperation):
+        (WebKit::PageClientImpl::startDataInteractionWithImage):
+        * WebProcess/WebPage/WebPage.cpp:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestStartDataInteraction):
+        (WebKit::WebPage::getPositionInformation):
+
 2017-01-25  Tim Horton  <timothy_horton@apple.com>
 
         Stop inheriting from UIWebScrollView, just use UIScrollView
index b9c2d8f..b41d64d 100644 (file)
@@ -41,6 +41,9 @@ struct InteractionInformationAtPosition {
     InteractionInformationRequest request;
 
     bool nodeAtPositionIsAssistedNode { false };
+#if ENABLE(DATA_INTERACTION)
+    bool hasDataInteractionAtPosition { false };
+#endif
     bool isSelectable { false };
     bool isNearMarkedText { false };
     bool touchCalloutEnabled { true };
index a64e79b..ba1a4c5 100644 (file)
@@ -43,6 +43,9 @@ void InteractionInformationAtPosition::encode(IPC::Encoder& encoder) const
     encoder << request;
 
     encoder << nodeAtPositionIsAssistedNode;
+#if ENABLE(DATA_INTERACTION)
+    encoder << hasDataInteractionAtPosition;
+#endif
     encoder << isSelectable;
     encoder << isNearMarkedText;
     encoder << touchCalloutEnabled;
@@ -87,6 +90,11 @@ bool InteractionInformationAtPosition::decode(IPC::Decoder& decoder, Interaction
     if (!decoder.decode(result.nodeAtPositionIsAssistedNode))
         return false;
 
+#if ENABLE(DATA_INTERACTION)
+    if (!decoder.decode(result.hasDataInteractionAtPosition))
+        return false;
+#endif
+
     if (!decoder.decode(result.isSelectable))
         return false;
 
index 06d9f3b..4257010 100644 (file)
@@ -380,6 +380,11 @@ public:
 #if USE(QUICK_LOOK)
     virtual void requestPasswordForQuickLookDocument(const String& fileName, std::function<void(const String&)>&&) = 0;
 #endif
+
+#if ENABLE(DATA_INTERACTION)
+    virtual void didPerformDataInteractionControllerOperation() = 0;
+    virtual void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, bool isLink) = 0;
+#endif
 };
 
 } // namespace WebKit
index 288f6d3..008c14c 100644 (file)
@@ -543,6 +543,10 @@ public:
     void handleTwoFingerTapAtPoint(const WebCore::IntPoint&, uint64_t requestID);
     void setForceAlwaysUserScalable(bool);
     void setIsScrollingOrZooming(bool);
+#if ENABLE(DATA_INTERACTION)
+    void didPerformDataInteractionControllerOperation();
+    void requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
+#endif
 #endif
 #if ENABLE(DATA_DETECTION)
     void setDataDetectionResult(const DataDetectionResult&);
index 67edab3..19fed04 100644 (file)
@@ -316,6 +316,10 @@ messages -> WebPageProxy {
     StartDrag(struct WebKit::WebSelectionData selection, uint64_t dragOperation, WebKit::ShareableBitmap::Handle dragImage)
 #endif
 
+#if ENABLE(DATA_INTERACTION)
+    DidPerformDataInteractionControllerOperation()
+#endif
+
 #if PLATFORM(COCOA)
     # Dictionary support.
     DidPerformDictionaryLookup(struct WebCore::DictionaryPopupInfo dictionaryPopupInfo)
index 1095803..c466024 100644 (file)
@@ -199,6 +199,11 @@ private:
 
     void requestPasswordForQuickLookDocument(const String& fileName, std::function<void(const String&)>&&) override;
 
+#if ENABLE(DATA_INTERACTION)
+    void didPerformDataInteractionControllerOperation() override;
+    void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, bool isLink) override;
+#endif
+
     WKContentView *m_contentView;
     WKWebView *m_webView;
     RetainPtr<WKEditorUndoTargetObjC> m_undoTarget;
index eabd934..8b7b665 100644 (file)
@@ -762,6 +762,16 @@ Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& messa
     return ValidationBubble::create(m_contentView, message);
 }
 
+#if ENABLE(DATA_INTERACTION)
+void PageClientImpl::didPerformDataInteractionControllerOperation()
+{
+}
+
+void PageClientImpl::startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, bool isLink)
+{
+}
+#endif
+
 void PageClientImpl::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime)
 {
     [m_webView _handleActiveNowPlayingSessionInfoResponse:hasActiveSession title:nsStringFromWebCoreString(title) duration:duration elapsedTime:elapsedTime];
index f8c9b5a..03f447f 100644 (file)
@@ -1081,6 +1081,21 @@ void WebPageProxy::setIsScrollingOrZooming(bool isScrollingOrZooming)
         m_validationBubble->show();
 }
 
+#if ENABLE(DATA_INTERACTION)
+
+void WebPageProxy::didPerformDataInteractionControllerOperation()
+{
+    m_pageClient.didPerformDataInteractionControllerOperation();
+}
+
+void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition)
+{
+    if (isValid())
+        m_process->send(Messages::WebPage::RequestStartDataInteraction(clientPosition, globalPosition), m_pageID);
+}
+
+#endif
+
 #if USE(QUICK_LOOK)
     
 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
index 0d2ddaa..cedb7b2 100644 (file)
@@ -232,6 +232,11 @@ private:
     _WKRemoteObjectRegistry *remoteObjectRegistry() override;
 #endif
 
+#if ENABLE(DATA_INTERACTION)
+    void didPerformDataInteractionControllerOperation() override;
+    void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, bool isLink) override;
+#endif
+
     NSView *m_view;
     WKWebView *m_webView;
     WebViewImpl* m_impl { nullptr };
index b0e4676..d3acc58 100644 (file)
@@ -875,6 +875,18 @@ bool PageClientImpl::windowIsFrontWindowUnderMouse(const NativeWebMouseEvent& ev
     return m_impl->windowIsFrontWindowUnderMouse(event.nativeEvent());
 }
 
+#if ENABLE(DATA_INTERACTION)
+void PageClientImpl::didPerformDataInteractionControllerOperation()
+{
+    // FIXME: Implement me.
+}
+
+void PageClientImpl::startDataInteractionWithImage(const IntPoint&, const ShareableBitmap::Handle&, bool)
+{
+    // FIXME: Implement me.
+}
+#endif
+
 WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
 {
     if (!m_view)
index df5d054..ae82800 100644 (file)
@@ -3527,6 +3527,9 @@ void WebPage::performDragControllerAction(uint64_t action, const WebCore::DragDa
         m_pendingDropSandboxExtension = nullptr;
 
         m_pendingDropExtensionsForFileUpload.clear();
+#if ENABLE(DATA_INTERACTION)
+        send(Messages::WebPageProxy::DidPerformDataInteractionControllerOperation());
+#endif
         break;
     }
 
index 2f7fbb1..ebccc33 100644 (file)
@@ -1014,6 +1014,9 @@ private:
     PassRefPtr<WebCore::Range> rangeForGranularityAtPoint(const WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithAssistedNode);
     bool shouldSwitchToBlockModeForHandle(const WebCore::IntPoint& handlePoint, SelectionHandlePosition);
     RefPtr<WebCore::Range> switchToBlockSelectionAtPoint(const WebCore::IntPoint&, SelectionHandlePosition);
+#if ENABLE(DATA_INTERACTION)
+    void requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
+#endif
 #endif
 
 #if !PLATFORM(COCOA)
index b9b4b78..8b72885 100644 (file)
@@ -246,6 +246,10 @@ messages -> WebPage LegacyReceiver {
     DragEnded(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t operation)
 #endif
 
+#if ENABLE(DATA_INTERACTION)
+    RequestStartDataInteraction(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition)
+#endif
+
     # Popup menu.
     DidChangeSelectedIndexForActivePopupMenu(int32_t newIndex)
     SetTextForActivePopupMenu(int32_t index)
index d1cf332..1e3d590 100644 (file)
@@ -620,6 +620,13 @@ void WebPage::handleTap(const IntPoint& point, uint64_t lastLayerTreeTransaction
         handleSyntheticClick(nodeRespondingToClick, adjustedPoint);
 }
 
+#if ENABLE(DATA_INTERACTION)
+void WebPage::requestStartDataInteraction(const IntPoint& clientPosition, const IntPoint& globalPosition)
+{
+    m_page->mainFrame().eventHandler().tryToBeginDataInteractionAtPoint(clientPosition, globalPosition);
+}
+#endif
+
 void WebPage::sendTapHighlightForNodeIfNecessary(uint64_t requestID, Node* node)
 {
 #if ENABLE(TOUCH_EVENTS)
@@ -2463,6 +2470,10 @@ void WebPage::getPositionInformation(const InteractionInformationRequest& reques
             }
         }
     }
+
+#if ENABLE(DATA_INTERACTION)
+    info.hasDataInteractionAtPosition = m_page->hasDataInteractionAtPosition(adjustedPoint);
+#endif
 }
 
 void WebPage::requestPositionInformation(const InteractionInformationRequest& request)