Title: [289818] trunk/Source
Revision
289818
Author
[email protected]
Date
2022-02-15 10:05:44 -0800 (Tue, 15 Feb 2022)

Log Message

Source/WebCore:
Implement additional Reveal methods.
https://bugs.webkit.org/show_bug.cgi?id=236627

Reviewed by Tim Horton.

Respond to protocol methods that instantiate a selection and request RVItems for a menu.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/EditingBehavior.h:
(WebCore::EditingBehavior::shouldSelectBasedOnDictionaryLookup const):
* editing/cocoa/DictionaryLookup.mm:
(WebCore::canCreateRevealItems):
(WebCore::showPopupOrCreateAnimationController):
* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestContextualWordFromHitTestResult):
(WebCore::EventHandler::selectClosestContextualWordOrLinkFromHitTestResult):
(WebCore::EventHandler::handleMousePressEventDoubleClick):
(WebCore::EventHandler::sendContextMenuEvent):
(WebCore::EventHandler::selectClosestWordFromMouseEvent): Deleted.
(WebCore::EventHandler::selectClosestContextualWordFromMouseEvent): Deleted.
(WebCore::EventHandler::selectClosestContextualWordOrLinkFromMouseEvent): Deleted.
* page/EventHandler.h:
* page/cocoa/EventHandlerCocoa.mm: Added.
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):

Source/WebKit:
Implement additional Reveeal methods.
https://bugs.webkit.org/show_bug.cgi?id=236627

Reviewed by Tim Horton.

Respond to protocol methods that instantiate a selection and request RVItems for a menu.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView prepareSelectionForContextMenuWithLocationInView:completionHandler:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::prepareSelectionForContextMenuWithLocationInView):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDictationContext):
(WebKit::WebPage::rvItemForCurrentSelection):
(WebKit::WebPage::requestRVItemInCurrentSelectedRange):
(WebKit::WebPage::prepareSelectionForContextMenuWithLocationInView):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289817 => 289818)


--- trunk/Source/WebCore/ChangeLog	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/ChangeLog	2022-02-15 18:05:44 UTC (rev 289818)
@@ -1,3 +1,31 @@
+2022-02-15  Megan Gardner  <[email protected]>
+
+        Implement additional Reveal methods.
+        https://bugs.webkit.org/show_bug.cgi?id=236627
+
+        Reviewed by Tim Horton.
+
+        Respond to protocol methods that instantiate a selection and request RVItems for a menu.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/EditingBehavior.h:
+        (WebCore::EditingBehavior::shouldSelectBasedOnDictionaryLookup const):
+        * editing/cocoa/DictionaryLookup.mm:
+        (WebCore::canCreateRevealItems):
+        (WebCore::showPopupOrCreateAnimationController):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::selectClosestContextualWordFromHitTestResult):
+        (WebCore::EventHandler::selectClosestContextualWordOrLinkFromHitTestResult):
+        (WebCore::EventHandler::handleMousePressEventDoubleClick):
+        (WebCore::EventHandler::sendContextMenuEvent):
+        (WebCore::EventHandler::selectClosestWordFromMouseEvent): Deleted.
+        (WebCore::EventHandler::selectClosestContextualWordFromMouseEvent): Deleted.
+        (WebCore::EventHandler::selectClosestContextualWordOrLinkFromMouseEvent): Deleted.
+        * page/EventHandler.h:
+        * page/cocoa/EventHandlerCocoa.mm: Added.
+        (WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
+
 2022-02-10  Sergio Villar Senin  <[email protected]>
 
         Do not update the fragmented flow state while internally mutating the render tree

Modified: trunk/Source/WebCore/SourcesCocoa.txt (289817 => 289818)


--- trunk/Source/WebCore/SourcesCocoa.txt	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2022-02-15 18:05:44 UTC (rev 289818)
@@ -193,6 +193,7 @@
 loader/mac/ResourceLoaderMac.mm
 page/CaptionUserPreferencesMediaAF.cpp
 page/cocoa/CaptionUserPreferencesMediaAFCocoa.mm
+page/cocoa/EventHandlerCocoa.mm
 page/cocoa/MemoryReleaseCocoa.mm
 page/cocoa/PerformanceLoggingCocoa.mm
 page/cocoa/ResourceUsageOverlayCocoa.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (289817 => 289818)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-15 18:05:44 UTC (rev 289818)
@@ -9132,6 +9132,7 @@
 		4437C4A724E2AE5F00095128 /* LazyLoadFrameObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LazyLoadFrameObserver.h; sourceTree = "<group>"; };
 		4437C4A924E2AE5F00095128 /* LazyLoadFrameObserver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LazyLoadFrameObserver.cpp; sourceTree = "<group>"; };
 		443877E3271681F600FD3E33 /* CaptionUserPreferencesMediaAFCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CaptionUserPreferencesMediaAFCocoa.mm; sourceTree = "<group>"; };
+		443BFDC627BB372C0001245F /* EventHandlerCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = EventHandlerCocoa.mm; sourceTree = "<group>"; };
 		443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkStateNotifierIOS.mm; sourceTree = "<group>"; };
 		444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponseIOS.mm; sourceTree = "<group>"; };
 		445210DD25D61EFF003A2ED8 /* AppHighlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppHighlight.h; sourceTree = "<group>"; };
@@ -23353,6 +23354,7 @@
 				443877E3271681F600FD3E33 /* CaptionUserPreferencesMediaAFCocoa.mm */,
 				F446EDDD265DAE3F0031DA8F /* DataDetectionResultsStorage.h */,
 				F446EDE7265DD8900031DA8F /* DataDetectorElementInfo.h */,
+				443BFDC627BB372C0001245F /* EventHandlerCocoa.mm */,
 				F446EDE0265DB1E50031DA8F /* ImageOverlayDataDetectionResultIdentifier.h */,
 				413E007B1DB0E707002341D2 /* MemoryReleaseCocoa.mm */,
 				AD5A0C221DECA37E00707054 /* PerformanceLoggingCocoa.mm */,
@@ -25914,10 +25916,10 @@
 				314877E01FAA8FE900C05759 /* OffscreenCanvas.cpp */,
 				314877E11FAA8FE900C05759 /* OffscreenCanvas.h */,
 				314877D91FAA870600C05759 /* OffscreenCanvas.idl */,
+				F55B3D951251F12D003EF269 /* PasswordInputType.cpp */,
+				F55B3D961251F12D003EF269 /* PasswordInputType.h */,
 				494EBD0827AA9C5300F4844F /* PDFDocument.cpp */,
 				494EBD0627AA9C5300F4844F /* PDFDocument.h */,
-				F55B3D951251F12D003EF269 /* PasswordInputType.cpp */,
-				F55B3D961251F12D003EF269 /* PasswordInputType.h */,
 				97205AB91239292700B17380 /* PluginDocument.cpp */,
 				97205ABA1239292700B17380 /* PluginDocument.h */,
 				CDEE393617974259001D7580 /* PublicURLManager.cpp */,

Modified: trunk/Source/WebCore/editing/EditingBehavior.h (289817 => 289818)


--- trunk/Source/WebCore/editing/EditingBehavior.h	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/editing/EditingBehavior.h	2022-02-15 18:05:44 UTC (rev 289818)
@@ -87,7 +87,7 @@
     // space when deleting password cause space been showed insecurely.
     bool shouldRebalanceWhiteSpacesInSecureField() const { return m_type != EditingBehaviorType::iOS; }
 
-    bool shouldSelectBasedOnDictionaryLookup() const { return m_type == EditingBehaviorType::Mac; }
+    bool shouldSelectBasedOnDictionaryLookup() const { return m_type == EditingBehaviorType::Mac || m_type == EditingBehaviorType::iOS; }
 
     // Linux and Windows always extend selections from the extent endpoint.
     bool shouldAlwaysExtendSelectionFromExtentEndpoint() const { return m_type != EditingBehaviorType::Mac && m_type != EditingBehaviorType::iOS; }

Modified: trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm (289817 => 289818)


--- trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -257,7 +257,7 @@
     static bool result;
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [&] {
-        result = PAL::isRevealFrameworkAvailable() && PAL::isRevealCoreFrameworkAvailable() && PAL::getRVItemClass();
+        result = PAL::isRevealCoreFrameworkAvailable() && PAL::getRVItemClass();
     });
     return result;
 }
@@ -427,7 +427,7 @@
     BEGIN_BLOCK_OBJC_EXCEPTIONS
     
 #if PLATFORM(MAC)
-    if (!canCreateRevealItems() || !PAL::getRVPresenterClass())
+    if (!PAL::isRevealFrameworkAvailable() || !canCreateRevealItems() || !PAL::getRVPresenterClass())
         return nil;
 
     auto mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);

Modified: trunk/Source/WebCore/page/EventHandler.cpp (289817 => 289818)


--- trunk/Source/WebCore/page/EventHandler.cpp	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2022-02-15 18:05:44 UTC (rev 289818)
@@ -534,13 +534,7 @@
     return (result.event().clickCount() == 2 && frame.editor().isSelectTrailingWhitespaceEnabled()) ? ShouldAppendTrailingWhitespace : DontAppendTrailingWhitespace;
 }
 
-void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
-{
-    if (mouseDownMayStartSelect())
-        selectClosestWordFromHitTestResult(result.hitTestResult(), shouldAppendTrailingWhitespace(result, m_frame));
-}
-
-#if !PLATFORM(MAC)
+#if !PLATFORM(COCOA)
 VisibleSelection EventHandler::selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult&)
 {
     return VisibleSelection();
@@ -547,12 +541,10 @@
 }
 #endif
     
-void EventHandler::selectClosestContextualWordFromMouseEvent(const MouseEventWithHitTestResults& mouseEvent)
+void EventHandler::selectClosestContextualWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
 {
-    RefPtr targetNode = mouseEvent.targetNode();
-    const HitTestResult& result = mouseEvent.hitTestResult();
+    RefPtr targetNode = result.targetNode();
     VisibleSelection newSelection;
-    bool appendTrailingWhitespace = shouldAppendTrailingWhitespace(mouseEvent, m_frame);
     
     if (targetNode && targetNode->renderer()) {
         newSelection = selectClosestWordFromHitTestResultBasedOnLookup(result);
@@ -571,16 +563,19 @@
     }
 }
     
-void EventHandler::selectClosestContextualWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& result)
+void EventHandler::selectClosestContextualWordOrLinkFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
 {
-    RefPtr urlElement = result.hitTestResult().URLElement();
+    RefPtr urlElement = result.URLElement();
     if (!urlElement || !isDraggableLink(*urlElement)) {
         if (RefPtr targetNode = result.targetNode()) {
-            if (isEditableNode(*targetNode))
-                return selectClosestWordFromMouseEvent(result);
+            if (isEditableNode(*targetNode)) {
+                if (mouseDownMayStartSelect())
+                    return selectClosestWordFromHitTestResult(result, appendTrailingWhitespace);
+                return;
+            }
         }
 
-        return selectClosestContextualWordFromMouseEvent(result);
+        return selectClosestContextualWordFromHitTestResult(result, appendTrailingWhitespace);
     }
 
     RefPtr targetNode = result.targetNode();
@@ -602,12 +597,12 @@
     if (m_frame.selection().isRange())
         // A double-click when range is already selected
         // should not change the selection.  So, do not call
-        // selectClosestWordFromMouseEvent, but do set
+        // selectClosestWordFromHitTestResult, but do set
         // m_beganSelectingText to prevent handleMouseReleaseEvent
         // from setting caret selection.
         m_selectionInitiationState = ExtendedSelection;
     else
-        selectClosestWordFromMouseEvent(event);
+        selectClosestWordFromHitTestResult(event.hitTestResult(), shouldAppendTrailingWhitespace(event, m_frame));
 
     return true;
 }
@@ -3280,7 +3275,7 @@
         // available for text selections.  But only if we're above text.
         && (m_frame.selection().selection().isContentEditable() || (mouseEvent.targetNode() && mouseEvent.targetNode()->isTextNode()))) {
         m_mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
-        selectClosestContextualWordOrLinkFromMouseEvent(mouseEvent);
+        selectClosestContextualWordOrLinkFromHitTestResult(mouseEvent.hitTestResult(), shouldAppendTrailingWhitespace(mouseEvent, m_frame));
     }
 
     swallowEvent = !dispatchMouseEvent(eventNames().contextmenuEvent, mouseEvent.targetNode(), 0, event, FireMouseOverOut::No);

Modified: trunk/Source/WebCore/page/EventHandler.h (289817 => 289818)


--- trunk/Source/WebCore/page/EventHandler.h	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/page/EventHandler.h	2022-02-15 18:05:44 UTC (rev 289818)
@@ -359,6 +359,8 @@
 #endif
 
     static bool scrollableAreaCanHandleEvent(const PlatformWheelEvent&, ScrollableArea&);
+    
+    WEBCORE_EXPORT void selectClosestContextualWordOrLinkFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
 
 private:
 #if ENABLE(DRAG_SUPPORT)
@@ -370,9 +372,8 @@
     bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity);
     void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
     VisibleSelection selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult&);
-    void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&);
-    void selectClosestContextualWordFromMouseEvent(const MouseEventWithHitTestResults&);
-    void selectClosestContextualWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults&);
+    void selectClosestContextualWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
+    
 
     bool handleMouseDoubleClickEvent(const PlatformMouseEvent&);
 

Added: trunk/Source/WebCore/page/cocoa/EventHandlerCocoa.mm (0 => 289818)


--- trunk/Source/WebCore/page/cocoa/EventHandlerCocoa.mm	                        (rev 0)
+++ trunk/Source/WebCore/page/cocoa/EventHandlerCocoa.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "EventHandler.h"
+
+#import "DictionaryLookup.h"
+#import "Editor.h"
+
+#if PLATFORM(COCOA)
+
+namespace WebCore {
+
+#if ENABLE(REVEAL)
+
+VisibleSelection EventHandler::selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult& result)
+{
+    if (!m_frame.editor().behavior().shouldSelectBasedOnDictionaryLookup())
+        return { };
+
+    auto range = DictionaryLookup::rangeAtHitTestResult(result);
+    if (!range)
+        return { };
+
+    return std::get<SimpleRange>(*range);
+}
+
+#else
+
+VisibleSelection EventHandler::selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult&)
+{
+    return VisibleSelection();
+}
+
+#endif
+    
+}
+
+#endif // PLATFORM(COCOA)

Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (289817 => 289818)


--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -991,18 +991,6 @@
         scrollAnimator->processWheelEventForScrollSnap(wheelEvent);
 }
 
-VisibleSelection EventHandler::selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult& result)
-{
-    if (!m_frame.editor().behavior().shouldSelectBasedOnDictionaryLookup())
-        return { };
-
-    auto range = DictionaryLookup::rangeAtHitTestResult(result);
-    if (!range)
-        return { };
-
-    return std::get<SimpleRange>(*range);
-}
-
 static IntSize autoscrollAdjustmentFactorForScreenBoundaries(const IntPoint& screenPoint, const FloatRect& screenRect)
 {
     // If the window is at the edge of the screen, and the mouse position is also at that edge of the screen,

Modified: trunk/Source/WebKit/ChangeLog (289817 => 289818)


--- trunk/Source/WebKit/ChangeLog	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/ChangeLog	2022-02-15 18:05:44 UTC (rev 289818)
@@ -1,3 +1,25 @@
+2022-02-15  Megan Gardner  <[email protected]>
+
+        Implement additional Reveeal methods.
+        https://bugs.webkit.org/show_bug.cgi?id=236627
+
+        Reviewed by Tim Horton.
+
+        Respond to protocol methods that instantiate a selection and request RVItems for a menu.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView prepareSelectionForContextMenuWithLocationInView:completionHandler:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::prepareSelectionForContextMenuWithLocationInView):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDictationContext):
+        (WebKit::WebPage::rvItemForCurrentSelection):
+        (WebKit::WebPage::requestRVItemInCurrentSelectedRange):
+        (WebKit::WebPage::prepareSelectionForContextMenuWithLocationInView):
+
 2022-02-15  J Pascoe  <[email protected]>
 
         Modify getAllLocalAuthenticatorCredentials according to internal requirements

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (289817 => 289818)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-15 18:05:44 UTC (rev 289818)
@@ -879,6 +879,7 @@
     void requestDictationContext(CompletionHandler<void(const String&, const String&, const String&)>&&);
 #if ENABLE(REVEAL)
     void requestRVItemInCurrentSelectedRange(CompletionHandler<void(const RevealItem&)>&&);
+    void prepareSelectionForContextMenuWithLocationInView(const WebCore::IntPoint, CompletionHandler<void(bool, const RevealItem&)>&&);
 #endif
     void replaceDictatedText(const String& oldText, const String& newText);
     void replaceSelectedText(const String& oldText, const String& newText);

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (289817 => 289818)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -7554,6 +7554,13 @@
         revealItemSelectionHandler(item.item());
     });
 }
+
+- (void)prepareSelectionForContextMenuWithLocationInView:(CGPoint)locationInView completionHandler:(void(^)(BOOL shouldPresentMenu, RVItem *item))completionHandler
+{
+    _page->prepareSelectionForContextMenuWithLocationInView(WebCore::roundedIntPoint(locationInView), [protectedCompletionHandler = makeBlockPtr(completionHandler)](bool shouldPresentMenu, const WebKit::RevealItem& item) {
+        protectedCompletionHandler(shouldPresentMenu, item.item());
+    });
+}
 #endif
 
 - (BOOL)hasHiddenContentEditable

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (289817 => 289818)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -534,6 +534,14 @@
 
     sendWithAsyncReply(Messages::WebPage::RequestRVItemInCurrentSelectedRange(), WTFMove(callbackFunction));
 }
+
+void WebPageProxy::prepareSelectionForContextMenuWithLocationInView(const WebCore::IntPoint point, CompletionHandler<void(bool, const RevealItem&)>&& callbackFunction)
+{
+    if (!hasRunningProcess())
+        return callbackFunction(false, RevealItem());
+
+    sendWithAsyncReply(Messages::WebPage::PrepareSelectionForContextMenuWithLocationInView(point), WTFMove(callbackFunction));
+}
 #endif
 
 void WebPageProxy::requestAutocorrectionContext()

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (289817 => 289818)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-15 18:05:44 UTC (rev 289818)
@@ -168,6 +168,7 @@
 OBJC_CLASS NSDictionary;
 OBJC_CLASS NSObject;
 OBJC_CLASS WKAccessibilityWebPageObject;
+OBJC_CLASS RVItem;
 #endif
 
 #define ENABLE_VIEWPORT_RESIZING PLATFORM(IOS_FAMILY)
@@ -798,7 +799,9 @@
 
     void requestDictationContext(CompletionHandler<void(const String&, const String&, const String&)>&&);
 #if ENABLE(REVEAL)
+    RetainPtr<RVItem> revealItemForCurrentSelection();
     void requestRVItemInCurrentSelectedRange(CompletionHandler<void(const WebKit::RevealItem&)>&&);
+    void prepareSelectionForContextMenuWithLocationInView(const WebCore::IntPoint, CompletionHandler<void(bool, const RevealItem&)>&&);
 #endif
     void replaceDictatedText(const String& oldText, const String& newText);
     void replaceSelectedText(const String& oldText, const String& newText);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (289817 => 289818)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-15 18:05:44 UTC (rev 289818)
@@ -83,6 +83,7 @@
     RequestDictationContext() -> (String selectedText, String textBefore, String textAfter) Async
 #if ENABLE(REVEAL)
     RequestRVItemInCurrentSelectedRange() -> (WebKit::RevealItem item) Async
+    PrepareSelectionForContextMenuWithLocationInView(WebCore::IntPoint point) -> (bool shouldShowMenu, WebKit::RevealItem item) Async
 #endif
     ReplaceDictatedText(String oldText, String newText)
     ReplaceSelectedText(String oldText, String newText)

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (289817 => 289818)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-02-15 17:03:54 UTC (rev 289817)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-02-15 18:05:44 UTC (rev 289818)
@@ -2343,9 +2343,8 @@
 
     completionHandler(selectedText, contextBefore, contextAfter);
 }
-
 #if ENABLE(REVEAL)
-void WebPage::requestRVItemInCurrentSelectedRange(CompletionHandler<void(const WebKit::RevealItem&)>&& completionHandler)
+RetainPtr<RVItem> WebPage::revealItemForCurrentSelection()
 {
     Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     auto selection = frame->selection().selection();
@@ -2368,8 +2367,23 @@
             }
         }
     }
+    return item;
+}
+
+void WebPage::requestRVItemInCurrentSelectedRange(CompletionHandler<void(const WebKit::RevealItem&)>&& completionHandler)
+{
+    completionHandler(RevealItem(revealItemForCurrentSelection()));
+}
+
+void WebPage::prepareSelectionForContextMenuWithLocationInView(const WebCore::IntPoint point, CompletionHandler<void(bool, const RevealItem&)>&& completionHandler)
+{
+    constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::AllowVisibleChildFrameContentOnly };
+    auto& eventHander = m_page->mainFrame().eventHandler();
+    HitTestResult result = eventHander.hitTestResultAtPoint(point, hitType);
     
-    completionHandler(RevealItem(WTFMove(item)));
+    eventHander.selectClosestContextualWordOrLinkFromHitTestResult(result, WebCore::DontAppendTrailingWhitespace);
+    
+    completionHandler(true, RevealItem(revealItemForCurrentSelection()));
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to