Move Lookup Code for better cross platform usage
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 01:41:15 +0000 (01:41 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 01:41:15 +0000 (01:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191732

Reviewed by Alex Christensen.

Source/WebCore:

Not currenlty testable

DictionaryLookup uses Reveal now, which is slated to be cross-platform.
That patch gates the parts of DictionaryLookup that currently do not have
an available implementation on iOS. Once Reveal is ready, this code will be
replaced or expanded upon, as appropriate.

* editing/mac/DictionaryLookup.h:
* editing/mac/DictionaryLookup.mm:
(WebCore::showPopupOrCreateAnimationController):
(WebCore::DictionaryLookup::showPopup):
(WebCore::DictionaryLookup::hidePopup):
(WebCore::DictionaryLookup::animationControllerForPopup):

Source/WebCore/PAL:

* pal/spi/mac/LookupSPI.h:
* pal/spi/mac/RevealSPI.h:

Source/WebKit:

Lookup is being replaced by Reveal. This framework should work on all platforms.
The patch moves the code that we expect will be needed for all platforms to the more
general cocoa area. This patch changes no funcationality, and should not change
anything currently. This work will be build on later when Reveal is ready to support
multiple platforms.

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::performDictionaryLookupAtLocation):
(WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]):
(-[WKContentView cleanupInteraction]):
(-[WKContentView _removeDefaultGestureRecognizers]):
(-[WKContentView _addDefaultGestureRecognizers]):
(-[WKContentView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]):
(-[WKContentView _lookupGestureRecognized:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
(WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): Deleted.
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForSelection):
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
(WebKit::WebPage::performDictionaryLookupForRange):
(WebKit::WebPage::dictionaryPopupInfoForRange):
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
(WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
(WebKit::WebPage::performDictionaryLookupForRange): Deleted.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
(WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Deleted.
(WebKit::WebPage::dictionaryPopupInfoForRange): Deleted.
(WebKit::WebPage::performDictionaryLookupForRange): Deleted.

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h [moved from Source/WebCore/PAL/pal/spi/mac/RevealSPI.h with 76% similarity]
Source/WebCore/PAL/pal/spi/mac/LookupSPI.h
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/cocoa/DictionaryLookup.mm [moved from Source/WebCore/editing/mac/DictionaryLookup.mm with 90% similarity]
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/editing/mac/DictionaryLookup.h
Source/WebKit/ChangeLog
Source/WebKit/Platform/spi/ios/UIKitSPI.h
Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

index 3cce1d4..c5b7b63 100644 (file)
@@ -1,3 +1,24 @@
+2018-11-15  Megan Gardner  <megan_gardner@apple.com>
+
+        Move Lookup Code for better cross platform usage
+        https://bugs.webkit.org/show_bug.cgi?id=191732
+
+        Reviewed by Alex Christensen.
+
+        Not currenlty testable
+
+        DictionaryLookup uses Reveal now, which is slated to be cross-platform.
+        That patch gates the parts of DictionaryLookup that currently do not have
+        an available implementation on iOS. Once Reveal is ready, this code will be
+        replaced or expanded upon, as appropriate.
+
+        * editing/mac/DictionaryLookup.h:
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::showPopupOrCreateAnimationController):
+        (WebCore::DictionaryLookup::showPopup):
+        (WebCore::DictionaryLookup::hidePopup):
+        (WebCore::DictionaryLookup::animationControllerForPopup):
+
 2018-11-28  Christopher Reid  <chris.reid@sony.com>
 
         SQLiteDatabase::open is constantly printing "SQLite database failed to checkpoint: database table is locked" errors
index 3e0a444..397a41f 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-15  Megan Gardner  <megan_gardner@apple.com>
+
+        Move Lookup Code for better cross platform usage
+        https://bugs.webkit.org/show_bug.cgi?id=191732
+
+        Reviewed by Alex Christensen.
+
+        * pal/spi/mac/LookupSPI.h:
+        * pal/spi/mac/RevealSPI.h:
+
 2018-11-28  Alexey Proskuryakov  <ap@apple.com>
 
         Modernize version checks for same site cookie support
index 77f2467..b8cc358 100644 (file)
                                0C2DA1391F3BEB4900DBC317 /* PassKitSPI.h */,
                                0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */,
                                0C2DA13B1F3BEB4900DBC317 /* QuartzCoreSPI.h */,
+                               442956CC218A72DE0080DB54 /* RevealSPI.h */,
                                570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */,
                                0C2DA13C1F3BEB4900DBC317 /* ServersSPI.h */,
                                0C2DA12B1F3BEB4900DBC317 /* URLFormattingSPI.h */,
                                0C7785861F45130F00F4EBB6 /* QTKitSPI.h */,
                                A102658A1F56748C00B4C844 /* QuickDrawSPI.h */,
                                0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */,
-                               442956CC218A72DE0080DB54 /* RevealSPI.h */,
                                A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */,
                                0C7785881F45130F00F4EBB6 /* TUCallSPI.h */,
                        );
similarity index 76%
rename from Source/WebCore/PAL/pal/spi/mac/RevealSPI.h
rename to Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h
index d6b8da4..d3d55d1 100644 (file)
@@ -24,7 +24,9 @@
  */
 
 #import <objc/runtime.h>
+#if PLATFORM(MAC)
 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#endif // PLATFORM(MAC)
 #import <wtf/SoftLinking.h>
 
 SOFT_LINK_PRIVATE_FRAMEWORK(Reveal)
@@ -36,13 +38,17 @@ SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVSelection)
 
 #if USE(APPLE_INTERNAL_SDK)
 
+#if PLATFORM(MAC)
 #import <Reveal/RVPresenter.h>
 #import <Reveal/Reveal.h>
+#endif // PLATFORM(MAC)
 #import <RevealCore/RVSelection.h>
 #import <RevealCore/RevealCore.h>
 
+#else // USE(APPLE_INTERNAL_SDK)
 
-#else
+
+@protocol RVPresenterHighlightDelegate;
 
 @interface RVItem : NSObject <NSSecureCoding>
 - (instancetype)initWithText:(NSString *)text selectedRange:(NSRange)selectedRange NS_DESIGNATED_INITIALIZER;
@@ -52,8 +58,25 @@ SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVSelection)
 + (NSRange)revealRangeAtIndex:(NSUInteger)clickIndex selectedRanges:(NSArray <NSValue *> *)selectedRanges shouldUpdateSelection:(BOOL *)shouldUpdateSelection;
 @end
 
+@interface RVPresentingContext : NSObject
+- (instancetype)initWithPointerLocationInView:(NSPoint)pointerLocationInView inView:(NSView *)view highlightDelegate:(id<RVPresenterHighlightDelegate>)highlightDelegate;
+@end
+
+@protocol RVPresenterHighlightDelegate <NSObject>
+@required
+- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item;
+@optional
+- (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item;
+- (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item;
+@end
+
+@interface RVDocumentContext : NSObject < NSSecureCoding >
+@end
+
 @interface RVPresenter : NSObject
+#if PLATFORM(MAC)
 - (id<NSImmediateActionAnimationController>)animationControllerForItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
+#endif // PLATFORM(MAC)
 - (BOOL)revealItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
 @end
 
index eb7f951..e0a3375 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+
+#if PLATFORM(MAC)
+
 #import <objc/runtime.h>
 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
 #import <wtf/SoftLinking.h>
 
-#if PLATFORM(MAC)
-
 SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Lookup)
 SOFT_LINK_CLASS_OPTIONAL(Lookup, LULookupDefinitionModule)
 
index 063dfdc..062cdd7 100644 (file)
@@ -77,6 +77,7 @@ editing/SelectionRectGatherer.cpp
 editing/SmartReplaceCF.cpp
 
 editing/cocoa/DataDetection.mm
+editing/cocoa/DictionaryLookup.mm
 editing/cocoa/EditorCocoa.mm
 editing/cocoa/FontAttributeChangesCocoa.mm
 editing/cocoa/FontAttributesCocoa.mm
@@ -90,7 +91,6 @@ editing/ios/DictationCommandIOS.cpp
 editing/ios/EditorIOS.mm
 
 editing/mac/AlternativeTextUIController.mm
-editing/mac/DictionaryLookup.mm
 editing/mac/DictionaryLookupLegacy.mm
 editing/mac/EditorMac.mm
 editing/mac/FrameSelectionMac.mm
index b41a396..78765f3 100644 (file)
                        children = (
                                C5227DEF1C3C6DD700F5ED54 /* DataDetection.h */,
                                C5227DF01C3C6DD700F5ED54 /* DataDetection.mm */,
+                               937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
                                9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
                                F42CEB54214031EE002DCA72 /* FontAttributeChangesCocoa.mm */,
                                F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */,
                                CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
                                CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
                                937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
-                               937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
                                442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */,
                                ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
                                4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */,
@@ -26,7 +26,7 @@
 #import "config.h"
 #import "DictionaryLookup.h"
 
-#if PLATFORM(MAC) && ENABLE(REVEAL)
+#if PLATFORM(COCOA)
 
 #import "Document.h"
 #import "Editing.h"
@@ -35,6 +35,7 @@
 #import "FrameSelection.h"
 #import "HTMLConverter.h"
 #import "HitTestResult.h"
+#import "NotImplemented.h"
 #import "Page.h"
 #import "Range.h"
 #import "RenderObject.h"
 #import "VisibleSelection.h"
 #import "VisibleUnits.h"
 #import <PDFKit/PDFKit.h>
+#import <pal/spi/cocoa/RevealSPI.h>
 #import <pal/spi/mac/LookupSPI.h>
-#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
-#import <pal/spi/mac/RevealSPI.h>
 #import <wtf/BlockObjCExceptions.h>
 #import <wtf/RefPtr.h>
 
+#if ENABLE(REVEAL)
+
+#if PLATFORM(MAC)
+
 @interface WebRevealHighlight <RVPresenterHighlightDelegate> : NSObject {
 @private
     Function<void()> _clearTextIndicator;
 
 @end
 
+#endif // PLATFORM(MAC)
+
+#endif // ENABLE(REVEAL)
+
 namespace WebCore {
 
+#if ENABLE(REVEAL)
+
 std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -302,11 +312,13 @@ std::tuple<NSString *, NSDictionary *> DictionaryLookup::stringForPDFSelection(P
     return { @"", nil };
 }
 
-static id <NSImmediateActionAnimationController> showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+static WKRevealController showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     
-    if (!getRVItemClass())
+#if PLATFORM(MAC)
+    
+    if (!getRVItemClass() || !getRVPresenterClass())
         return nil;
 
     RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
@@ -357,9 +369,21 @@ static id <NSImmediateActionAnimationController> showPopupOrCreateAnimationContr
         return [presenter animationControllerForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
     [presenter revealItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
     return nil;
-
-    END_BLOCK_OBJC_EXCEPTIONS;
+    
+#else // PLATFORM(MAC)
+    
+    UNUSED_PARAM(createAnimationController);
+    UNUSED_PARAM(dictionaryPopupInfo);
+    UNUSED_PARAM(view);
+    UNUSED_PARAM(textIndicatorInstallationCallback);
+    UNUSED_PARAM(rootViewToViewConversionCallback);
+    UNUSED_PARAM(clearTextIndicator);
+    
     return nil;
+#endif // PLATFORM(MAC)
+    
+    END_BLOCK_OBJC_EXCEPTIONS;
+    
 }
 
 void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
@@ -369,20 +393,32 @@ void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo,
 
 void DictionaryLookup::hidePopup()
 {
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    notImplemented();
+}
 
-    if (!getLULookupDefinitionModuleClass())
-        return;
-    [getLULookupDefinitionModuleClass() hideDefinition];
+#if PLATFORM(MAC)
 
-    END_BLOCK_OBJC_EXCEPTIONS;
+WKRevealController DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+{
+    return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
+}
+
+#endif // PLATFORM(MAC)
+
+#elif PLATFORM(IOS_FAMILY) // ENABLE(REVEAL)
+
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection&)
+{
+    return { nullptr, nil };
 }
 
-id <NSImmediateActionAnimationController> DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult&)
 {
-    return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
+    return { nullptr, nil };
 }
 
+#endif // ENABLE(REVEAL)
+
 } // namespace WebCore
 
-#endif // PLATFORM(MAC)
+#endif // PLATFORM(COCOA)
index e4b90bd..85c4274 100644 (file)
@@ -34,6 +34,8 @@
 #import "Document.h"
 #import "DocumentFragment.h"
 #import "DocumentLoader.h"
+#import "Editor.h"
+#import "EditorClient.h"
 #import "File.h"
 #import "FileSystem.h"
 #import "Frame.h"
index cb6d53e..f8f761c 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if PLATFORM(MAC)
+#pragma once
+
+#if PLATFORM(COCOA)
 
 #include "DictionaryPopupInfo.h"
-#include <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#if PLATFORM(MAC)
+#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#endif // PLATFORM(MAC)
 #include <wtf/Function.h>
 
 OBJC_CLASS NSView;
 OBJC_CLASS PDFSelection;
 
+#if PLATFORM(MAC)
+typedef id <NSImmediateActionAnimationController> WKRevealController;
+#else
+typedef id WKRevealController;
+#endif // PLATFORM(MAC)
+
 namespace WebCore {
 
 class HitTestResult;
@@ -48,8 +58,11 @@ public:
 
     WEBCORE_EXPORT static void showPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
     WEBCORE_EXPORT static void hidePopup();
-
-    WEBCORE_EXPORT static id <NSImmediateActionAnimationController> animationControllerForPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
+    
+#if PLATFORM(MAC)
+    WEBCORE_EXPORT static WKRevealController animationControllerForPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
+#endif // PLATFORM(MAC)
+    
 };
 
 } // namespace WebCore
index f88b0d4..834716c 100644 (file)
@@ -1,3 +1,51 @@
+2018-11-15  Megan Gardner  <megan_gardner@apple.com>
+
+        Move Lookup Code for better cross platform usage
+        https://bugs.webkit.org/show_bug.cgi?id=191732
+
+        Reviewed by Alex Christensen.
+
+        Lookup is being replaced by Reveal. This framework should work on all platforms.
+        The patch moves the code that we expect will be needed for all platforms to the more
+        general cocoa area. This patch changes no funcationality, and should not change
+        anything currently. This work will be build on later when Reveal is ready to support
+        multiple platforms.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::performDictionaryLookupAtLocation):
+        (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView setupInteraction]):
+        (-[WKContentView cleanupInteraction]):
+        (-[WKContentView _removeDefaultGestureRecognizers]):
+        (-[WKContentView _addDefaultGestureRecognizers]):
+        (-[WKContentView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]):
+        (-[WKContentView _lookupGestureRecognized:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
+        (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): Deleted.
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation):
+        (WebKit::WebPage::performDictionaryLookupForSelection):
+        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
+        (WebKit::WebPage::performDictionaryLookupForRange):
+        (WebKit::WebPage::dictionaryPopupInfoForRange):
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
+        (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
+        (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
+        (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
+        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Deleted.
+        (WebKit::WebPage::dictionaryPopupInfoForRange): Deleted.
+        (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
+
 2018-11-28  Keith Rollin  <krollin@apple.com>
 
         Update generate-{derived,unified}-sources scripts to support generating .xcfilelist files
index 143f16c..2323796 100644 (file)
@@ -733,6 +733,9 @@ struct _UIWebTouchEvent {
     bool isPotentialTap;
 };
 
+@interface _UILookupGestureRecognizer : UIGestureRecognizer
+@end
+
 @class UIWebTouchEventsGestureRecognizer;
 
 @protocol UIWebTouchEventsGestureRecognizerDelegate <NSObject>
index f56875d..65aecd9 100644 (file)
@@ -33,6 +33,7 @@
 #import "PageClient.h"
 #import "SafeBrowsingSPI.h"
 #import "SafeBrowsingWarning.h"
+#import "WebPageMessages.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DragItem.h>
 #import <WebCore/NotImplemented.h>
@@ -189,5 +190,21 @@ void WebPageProxy::platformCloneAttachment(Ref<API::Attachment>&& fromAttachment
 }
 
 #endif // ENABLE(ATTACHMENT_ELEMENT)
+    
+void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
+{
+    if (!isValid())
+        return;
+    
+    process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
+}
 
+void WebPageProxy::performDictionaryLookupOfCurrentSelection()
+{
+    if (!isValid())
+        return;
+    
+    process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
 }
+
+} // namespace WebKit
index a807ccd..da26332 100644 (file)
@@ -87,6 +87,7 @@ class WebOpenPanelResultListenerProxy;
 class WebPageProxy;
 }
 
+@class _UILookupGestureRecognizer;
 @class _UIHighlightView;
 @class _UIWebHighlightLongPressGestureRecognizer;
 @class UIHoverGestureRecognizer;
@@ -215,6 +216,7 @@ struct WKAutoCorrectionData {
 
 #if PLATFORM(IOSMAC)
     RetainPtr<UIHoverGestureRecognizer> _hoverGestureRecognizer;
+    RetainPtr<_UILookupGestureRecognizer> _lookupGestureRecognizer;
 #endif
 
     RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
index 60cfb8f..abb04a4 100644 (file)
 #if PLATFORM(IOSMAC)
 #import "NativeWebMouseEvent.h"
 #import <UIKit/UIHoverGestureRecognizer.h>
+#import <UIKit/_UILookupGestureRecognizer.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
 #endif
 
@@ -649,6 +650,11 @@ static inline bool hasAssistedNode(WebKit::AssistedNodeInformation assistedNodeI
     _hoverGestureRecognizer = adoptNS([[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(_hoverGestureRecognizerChanged:)]);
     [_hoverGestureRecognizer setDelegate:self];
     [self addGestureRecognizer:_hoverGestureRecognizer.get()];
+    
+    _lookupGestureRecognizer = adoptNS([[_UILookupGestureRecognizer alloc] initWithTarget:self action:@selector(_lookupGestureRecognized:)]);
+    [_lookupGestureRecognizer setDelegate:self];
+    [self addGestureRecognizer:_lookupGestureRecognizer.get()];
+    
 #endif
 
     _singleTapGestureRecognizer = adoptNS([[WKSyntheticClickTapGestureRecognizer alloc] initWithTarget:self action:@selector(_singleTapCommited:)]);
@@ -759,6 +765,9 @@ static inline bool hasAssistedNode(WebKit::AssistedNodeInformation assistedNodeI
 #if PLATFORM(IOSMAC)
     [_hoverGestureRecognizer setDelegate:nil];
     [self removeGestureRecognizer:_hoverGestureRecognizer.get()];
+    
+    [_lookupGestureRecognizer setDelegate:nil];
+    [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
 #endif
 
     [_singleTapGestureRecognizer setDelegate:nil];
@@ -846,6 +855,7 @@ static inline bool hasAssistedNode(WebKit::AssistedNodeInformation assistedNodeI
     [self removeGestureRecognizer:_stylusSingleTapGestureRecognizer.get()];
 #if PLATFORM(IOSMAC)
     [self removeGestureRecognizer:_hoverGestureRecognizer.get()];
+    [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
 #endif
 }
 
@@ -861,6 +871,7 @@ static inline bool hasAssistedNode(WebKit::AssistedNodeInformation assistedNodeI
     [self addGestureRecognizer:_stylusSingleTapGestureRecognizer.get()];
 #if PLATFORM(IOSMAC)
     [self addGestureRecognizer:_hoverGestureRecognizer.get()];
+    [self addGestureRecognizer:_lookupGestureRecognizer.get()];
 #endif
 }
 
@@ -1467,6 +1478,10 @@ static inline bool isSamePair(UIGestureRecognizer *a, UIGestureRecognizer *b, UI
 
     if ([gestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]] || [otherGestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]])
         return YES;
+    
+    if (([gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) || ([otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]]))
+        return YES;
+
 #endif
     if (isSamePair(gestureRecognizer, otherGestureRecognizer, _highlightLongPressGestureRecognizer.get(), _textSelectionAssistant.get().forcePressGesture))
         return YES;
@@ -6057,6 +6072,12 @@ static NSArray<NSItemProvider *> *extractItemProvidersFromDropSession(id <UIDrop
 #endif // PLATFORM(WATCHOS)
 
 #if PLATFORM(IOSMAC)
+- (void)_lookupGestureRecognized:(UIGestureRecognizer *)gestureRecognizer
+{
+    NSPoint locationInViewCoordinates = [gestureRecognizer locationInView:self];
+    _page->performDictionaryLookupAtLocation(WebCore::FloatPoint(locationInViewCoordinates));
+}
+
 - (void)_hoverGestureRecognizerChanged:(UIGestureRecognizer *)gestureRecognizer
 {
     if (!_page->isValid())
index b473f08..2795f73 100644 (file)
@@ -121,11 +121,6 @@ bool WebPageProxy::readSelectionFromPasteboard(const String&)
     return false;
 }
 
-void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)
-{
-    notImplemented();
-}
-
 void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID)
 {
     auto callback = m_callbacks.take<GestureCallback>(callbackID);
index fffc5e0..e2ab29c 100644 (file)
@@ -323,22 +323,6 @@ void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const S
 
 #endif
 
-void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
-{
-    if (!isValid())
-        return;
-
-    process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
-}
-
-void WebPageProxy::performDictionaryLookupOfCurrentSelection()
-{
-    if (!isValid())
-        return;
-
-    process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
-}
-
 // Complex text input support for plug-ins.
 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput)
 {
index 3e79431..a38cd2b 100644 (file)
 #import "config.h"
 #import "WebPage.h"
 
+
 #import "LoadParameters.h"
+#import "PluginView.h"
 #import "WebPageProxyMessages.h"
+#import <WebCore/DictionaryLookup.h>
+#import <WebCore/Editor.h>
+#import <WebCore/EventHandler.h>
+#import <WebCore/FocusController.h>
+#import <WebCore/HTMLConverter.h>
+#import <WebCore/HitTestResult.h>
+#import <WebCore/NodeRenderStyle.h>
 #import <WebCore/PlatformMediaSessionManager.h>
+#import <WebCore/RenderElement.h>
+#import <WebCore/RenderObject.h>
 
 #if PLATFORM(COCOA)
 
@@ -59,6 +70,114 @@ void WebPage::requestActiveNowPlayingSessionInfo(CallbackID callbackID)
 
     send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier, callbackID));
 }
+    
+void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
+{
+    if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
+        if (pluginView->performDictionaryLookupAtLocation(floatPoint))
+            return;
+    }
+    
+    // Find the frame the point is over.
+    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
+    RefPtr<Range> range;
+    NSDictionary *options;
+    std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
+    if (!range)
+        return;
+    
+    auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
+    if (!frame)
+        return;
+    
+    performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
+}
+
+void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
+{
+    RefPtr<Range> selectedRange;
+    NSDictionary *options;
+    std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
+    if (selectedRange)
+        performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
+}
+
+void WebPage::performDictionaryLookupOfCurrentSelection()
+{
+    auto& frame = m_page->focusController().focusedOrMainFrame();
+    performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
+}
+    
+void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+{
+    send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
+}
+
+DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+{
+    Editor& editor = frame.editor();
+    editor.setIsGettingDictionaryPopupInfo(true);
+    
+    DictionaryPopupInfo dictionaryPopupInfo;
+    if (range.text().stripWhiteSpace().isEmpty()) {
+        editor.setIsGettingDictionaryPopupInfo(false);
+        return dictionaryPopupInfo;
+    }
+    
+    Vector<FloatQuad> quads;
+    range.absoluteTextQuads(quads);
+    if (quads.isEmpty()) {
+        editor.setIsGettingDictionaryPopupInfo(false);
+        return dictionaryPopupInfo;
+    }
+    
+    IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
+    
+    const RenderStyle* style = range.startContainer().renderStyle();
+    float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
+    dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
+    dictionaryPopupInfo.options = options;
+
+#if PLATFORM(MAC)
+
+    NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
+    
+    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()];
+        if (font)
+            [scaledAttributes setObject:font forKey:NSFontAttributeName];
+        
+        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
+    }];
+
+#endif // PLATFORM(MAC)
+    
+    TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
+    if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
+        indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
+    
+    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
+    if (!textIndicator) {
+        editor.setIsGettingDictionaryPopupInfo(false);
+        return dictionaryPopupInfo;
+    }
+    
+    dictionaryPopupInfo.textIndicator = textIndicator->data();
+#if PLATFORM(MAC)
+    dictionaryPopupInfo.attributedString = scaledNSAttributedString;
+#endif // PLATFORM(MAC)
+    
+    editor.setIsGettingDictionaryPopupInfo(false);
+    return dictionaryPopupInfo;
+}
 
 } // namespace WebKit
 
index eac4f4f..6e5a6d1 100644 (file)
@@ -417,21 +417,6 @@ void WebPage::sendComplexTextInputToPlugin(uint64_t, const String&)
     notImplemented();
 }
 
-void WebPage::performDictionaryLookupAtLocation(const FloatPoint&)
-{
-    notImplemented();
-}
-
-void WebPage::performDictionaryLookupForSelection(Frame&, const VisibleSelection&, TextIndicatorPresentationTransition)
-{
-    notImplemented();
-}
-
-void WebPage::performDictionaryLookupForRange(Frame&, Range&, NSDictionary *, TextIndicatorPresentationTransition)
-{
-    notImplemented();
-}
-
 bool WebPage::performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*)
 {
     notImplemented();
index 4733b1c..fa7a6aa 100644 (file)
@@ -389,102 +389,7 @@ void WebPage::fontAtSelection(CallbackID callbackID)
     send(Messages::WebPageProxy::FontAtSelectionCallback(fontName, fontSize, selectionHasMultipleFonts, callbackID));
 }
     
-void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
-{
-    if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
-        if (pluginView->performDictionaryLookupAtLocation(floatPoint))
-            return;
-    }
-
-    // Find the frame the point is over.
-    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
-    RefPtr<Range> range;
-    NSDictionary *options;
-    std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
-    if (!range)
-        return;
-
-    auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
-    if (!frame)
-        return;
-
-    performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
-}
-
-void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
-{
-    RefPtr<Range> selectedRange;
-    NSDictionary *options;
-    std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
-    if (selectedRange)
-        performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
-}
 
-void WebPage::performDictionaryLookupOfCurrentSelection()
-{
-    auto& frame = m_page->focusController().focusedOrMainFrame();
-    performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
-}
-
-DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
-{
-    Editor& editor = frame.editor();
-    editor.setIsGettingDictionaryPopupInfo(true);
-
-    DictionaryPopupInfo dictionaryPopupInfo;
-    if (range.text().stripWhiteSpace().isEmpty()) {
-        editor.setIsGettingDictionaryPopupInfo(false);
-        return dictionaryPopupInfo;
-    }
-
-    Vector<FloatQuad> quads;
-    range.absoluteTextQuads(quads);
-    if (quads.isEmpty()) {
-        editor.setIsGettingDictionaryPopupInfo(false);
-        return dictionaryPopupInfo;
-    }
-
-    IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
-
-    const RenderStyle* style = range.startContainer().renderStyle();
-    float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
-    dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
-    dictionaryPopupInfo.options = options;
-
-    NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
-
-    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()];
-        if (font)
-            [scaledAttributes setObject:font forKey:NSFontAttributeName];
-
-        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
-    }];
-
-    TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
-    if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
-        indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
-
-    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
-    if (!textIndicator) {
-        editor.setIsGettingDictionaryPopupInfo(false);
-        return dictionaryPopupInfo;
-    }
-
-    dictionaryPopupInfo.textIndicator = textIndicator->data();
-    dictionaryPopupInfo.attributedString = scaledNSAttributedString;
-
-    editor.setIsGettingDictionaryPopupInfo(false);
-    return dictionaryPopupInfo;
-}
 
 #if ENABLE(PDFKIT_PLUGIN)
 
@@ -539,11 +444,6 @@ DictionaryPopupInfo WebPage::dictionaryPopupInfoForSelectionInPDFPlugin(PDFSelec
 
 #endif
 
-void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
-{
-    send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
-}
-
 bool WebPage::performNonEditingBehaviorForSelector(const String& selector, KeyboardEvent* event)
 {
     // First give accessibility a chance to handle the event.