Changeset 238678 in webkit


Ignore:
Timestamp:
Nov 29, 2018 10:54:19 AM (5 years ago)
Author:
Megan Gardner
Message:

Move Lookup Code for better cross platform usage
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.

Location:
trunk/Source
Files:
19 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r238677 r238678  
     12018-11-29  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Move Lookup Code for better cross platform usage
     4        https://bugs.webkit.org/show_bug.cgi?id=191732
     5
     6        Reviewed by Alex Christensen.
     7
     8        Not currenlty testable
     9
     10        DictionaryLookup uses Reveal now, which is slated to be cross-platform.
     11        That patch gates the parts of DictionaryLookup that currently do not have
     12        an available implementation on iOS. Once Reveal is ready, this code will be
     13        replaced or expanded upon, as appropriate.
     14
     15        * editing/mac/DictionaryLookup.h:
     16        * editing/mac/DictionaryLookup.mm:
     17        (WebCore::showPopupOrCreateAnimationController):
     18        (WebCore::DictionaryLookup::showPopup):
     19        (WebCore::DictionaryLookup::hidePopup):
     20        (WebCore::DictionaryLookup::animationControllerForPopup):
     21
    1222018-11-29  Sihui Liu  <sihui_liu@apple.com>
    223
  • trunk/Source/WebCore/PAL/ChangeLog

    r238657 r238678  
     12018-11-29  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Move Lookup Code for better cross platform usage
     4        https://bugs.webkit.org/show_bug.cgi?id=191732
     5
     6        Reviewed by Alex Christensen.
     7
     8        * pal/spi/mac/LookupSPI.h:
     9        * pal/spi/mac/RevealSPI.h:
     10
    1112018-11-28  Commit Queue  <commit-queue@webkit.org>
    212
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r238657 r238678  
    407407                                0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */,
    408408                                0C2DA13B1F3BEB4900DBC317 /* QuartzCoreSPI.h */,
     409                                442956CC218A72DE0080DB54 /* RevealSPI.h */,
    409410                                570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */,
    410411                                0C2DA13C1F3BEB4900DBC317 /* ServersSPI.h */,
     
    472473                                A102658A1F56748C00B4C844 /* QuickDrawSPI.h */,
    473474                                0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */,
    474                                 442956CC218A72DE0080DB54 /* RevealSPI.h */,
    475475                                A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */,
    476476                                0C7785881F45130F00F4EBB6 /* TUCallSPI.h */,
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h

    r238677 r238678  
    2525
    2626#import <objc/runtime.h>
     27#if PLATFORM(MAC)
    2728#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
     29#endif // PLATFORM(MAC)
    2830#import <wtf/SoftLinking.h>
    2931
     
    3739#if USE(APPLE_INTERNAL_SDK)
    3840
     41#if PLATFORM(MAC)
    3942#import <Reveal/RVPresenter.h>
    4043#import <Reveal/Reveal.h>
     44#endif // PLATFORM(MAC)
    4145#import <RevealCore/RVSelection.h>
    4246#import <RevealCore/RevealCore.h>
    4347
     48#else // USE(APPLE_INTERNAL_SDK)
    4449
    45 #else
     50
     51@protocol RVPresenterHighlightDelegate;
    4652
    4753@interface RVItem : NSObject <NSSecureCoding>
     
    5359@end
    5460
     61#if PLATFORM(MAC)
     62@interface RVPresentingContext : NSObject
     63- (instancetype)initWithPointerLocationInView:(NSPoint)pointerLocationInView inView:(NSView *)view highlightDelegate:(id<RVPresenterHighlightDelegate>)highlightDelegate;
     64@end
     65#endif
     66
     67@protocol RVPresenterHighlightDelegate <NSObject>
     68@required
     69- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item;
     70@optional
     71- (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item;
     72- (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item;
     73@end
     74
     75@interface RVDocumentContext : NSObject < NSSecureCoding >
     76@end
     77
    5578@interface RVPresenter : NSObject
     79#if PLATFORM(MAC)
    5680- (id<NSImmediateActionAnimationController>)animationControllerForItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
     81#endif // PLATFORM(MAC)
    5782- (BOOL)revealItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
    5883@end
  • trunk/Source/WebCore/PAL/pal/spi/mac/LookupSPI.h

    r238657 r238678  
    2424 */
    2525
     26
     27#if PLATFORM(MAC)
     28
    2629#import <objc/runtime.h>
    2730#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
    2831#import <wtf/SoftLinking.h>
    29 
    30 #if PLATFORM(MAC)
    3132
    3233SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Lookup)
  • trunk/Source/WebCore/SourcesCocoa.txt

    r238657 r238678  
    7878
    7979editing/cocoa/DataDetection.mm
     80editing/cocoa/DictionaryLookup.mm
    8081editing/cocoa/EditorCocoa.mm
    8182editing/cocoa/FontAttributeChangesCocoa.mm
     
    9192
    9293editing/mac/AlternativeTextUIController.mm
    93 editing/mac/DictionaryLookup.mm
    9494editing/mac/DictionaryLookupLegacy.mm
    9595editing/mac/EditorMac.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r238667 r238678  
    2052420524                                C5227DEF1C3C6DD700F5ED54 /* DataDetection.h */,
    2052520525                                C5227DF01C3C6DD700F5ED54 /* DataDetection.mm */,
     20526                                937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
    2052620527                                9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
    2052720528                                F42CEB54214031EE002DCA72 /* FontAttributeChangesCocoa.mm */,
     
    2623026231                                CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
    2623126232                                937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
    26232                                 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
    2623326233                                442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */,
    2623426234                                ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
  • trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm

    r238677 r238678  
    2727#import "DictionaryLookup.h"
    2828
    29 #if PLATFORM(MAC) && ENABLE(REVEAL)
     29#if PLATFORM(COCOA)
    3030
    3131#import "Document.h"
     
    3636#import "HTMLConverter.h"
    3737#import "HitTestResult.h"
     38#import "NotImplemented.h"
    3839#import "Page.h"
    3940#import "Range.h"
     
    4445#import "VisibleUnits.h"
    4546#import <PDFKit/PDFKit.h>
     47#import <pal/spi/cocoa/RevealSPI.h>
    4648#import <pal/spi/mac/LookupSPI.h>
    47 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
    48 #import <pal/spi/mac/RevealSPI.h>
    4949#import <wtf/BlockObjCExceptions.h>
    5050#import <wtf/RefPtr.h>
     51
     52#if ENABLE(REVEAL)
     53
     54#if PLATFORM(MAC)
    5155
    5256@interface WebRevealHighlight <RVPresenterHighlightDelegate> : NSObject {
     
    133137@end
    134138
     139#endif // PLATFORM(MAC)
     140
     141#endif // ENABLE(REVEAL)
     142
    135143namespace WebCore {
     144
     145#if ENABLE(REVEAL)
    136146
    137147std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
     
    303313}
    304314
    305 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)
     315static 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)
    306316{
    307317    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    308318   
    309     if (!getRVItemClass())
     319#if PLATFORM(MAC)
     320   
     321    if (!getRVItemClass() || !getRVPresenterClass())
    310322        return nil;
    311323
     
    358370    [presenter revealItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
    359371    return nil;
    360 
     372   
     373#else // PLATFORM(MAC)
     374   
     375    UNUSED_PARAM(createAnimationController);
     376    UNUSED_PARAM(dictionaryPopupInfo);
     377    UNUSED_PARAM(view);
     378    UNUSED_PARAM(textIndicatorInstallationCallback);
     379    UNUSED_PARAM(rootViewToViewConversionCallback);
     380    UNUSED_PARAM(clearTextIndicator);
     381   
     382    return nil;
     383#endif // PLATFORM(MAC)
     384   
    361385    END_BLOCK_OBJC_EXCEPTIONS;
    362     return nil;
     386   
    363387}
    364388
     
    370394void DictionaryLookup::hidePopup()
    371395{
    372     BEGIN_BLOCK_OBJC_EXCEPTIONS;
    373 
    374     if (!getLULookupDefinitionModuleClass())
    375         return;
    376     [getLULookupDefinitionModuleClass() hideDefinition];
    377 
    378     END_BLOCK_OBJC_EXCEPTIONS;
    379 }
    380 
    381 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)
     396    notImplemented();
     397}
     398
     399#if PLATFORM(MAC)
     400
     401WKRevealController DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
    382402{
    383403    return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
    384404}
    385405
     406#endif // PLATFORM(MAC)
     407
     408#elif PLATFORM(IOS_FAMILY) // ENABLE(REVEAL)
     409
     410std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection&)
     411{
     412    return { nullptr, nil };
     413}
     414
     415std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult&)
     416{
     417    return { nullptr, nil };
     418}
     419
     420#endif // ENABLE(REVEAL)
     421
    386422} // namespace WebCore
    387423
    388 #endif // PLATFORM(MAC)
     424#endif // PLATFORM(COCOA)
  • trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r238661 r238678  
    3535#import "DocumentFragment.h"
    3636#import "DocumentLoader.h"
     37#import "Editor.h"
     38#import "EditorClient.h"
    3739#import "File.h"
    3840#import "FileSystem.h"
  • trunk/Source/WebCore/editing/mac/DictionaryLookup.h

    r238657 r238678  
    2424 */
    2525
    26 #if PLATFORM(MAC)
     26#pragma once
     27
     28#if PLATFORM(COCOA)
    2729
    2830#include "DictionaryPopupInfo.h"
    29 #include <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
     31#if PLATFORM(MAC)
     32#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
     33#endif // PLATFORM(MAC)
    3034#include <wtf/Function.h>
    3135
    3236OBJC_CLASS NSView;
    3337OBJC_CLASS PDFSelection;
     38
     39#if PLATFORM(MAC)
     40typedef id <NSImmediateActionAnimationController> WKRevealController;
     41#else
     42typedef id WKRevealController;
     43#endif // PLATFORM(MAC)
    3444
    3545namespace WebCore {
     
    4959    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);
    5060    WEBCORE_EXPORT static void hidePopup();
    51 
    52     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);
     61   
     62#if PLATFORM(MAC)
     63    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);
     64#endif // PLATFORM(MAC)
     65   
    5366};
    5467
  • trunk/Source/WebKit/ChangeLog

    r238674 r238678  
     12018-11-29  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Move Lookup Code for better cross platform usage
     4        https://bugs.webkit.org/show_bug.cgi?id=191732
     5
     6        Reviewed by Alex Christensen.
     7
     8        Lookup is being replaced by Reveal. This framework should work on all platforms.
     9        The patch moves the code that we expect will be needed for all platforms to the more
     10        general cocoa area. This patch changes no funcationality, and should not change
     11        anything currently. This work will be build on later when Reveal is ready to support
     12        multiple platforms.
     13
     14        * Platform/spi/ios/UIKitSPI.h:
     15        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     16        (WebKit::WebPageProxy::performDictionaryLookupAtLocation):
     17        (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
     18        * UIProcess/ios/WKContentViewInteraction.h:
     19        * UIProcess/ios/WKContentViewInteraction.mm:
     20        (-[WKContentView setupInteraction]):
     21        (-[WKContentView cleanupInteraction]):
     22        (-[WKContentView _removeDefaultGestureRecognizers]):
     23        (-[WKContentView _addDefaultGestureRecognizers]):
     24        (-[WKContentView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]):
     25        (-[WKContentView _lookupGestureRecognized:]):
     26        * UIProcess/ios/WebPageProxyIOS.mm:
     27        (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
     28        * UIProcess/mac/WebPageProxyMac.mm:
     29        (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
     30        (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): Deleted.
     31        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
     32        (WebKit::WebPage::performDictionaryLookupAtLocation):
     33        (WebKit::WebPage::performDictionaryLookupForSelection):
     34        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
     35        (WebKit::WebPage::performDictionaryLookupForRange):
     36        (WebKit::WebPage::dictionaryPopupInfoForRange):
     37        * WebProcess/WebPage/WebPage.messages.in:
     38        * WebProcess/WebPage/ios/WebPageIOS.mm:
     39        (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
     40        (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
     41        (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
     42        * WebProcess/WebPage/mac/WebPageMac.mm:
     43        (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
     44        (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
     45        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Deleted.
     46        (WebKit::WebPage::dictionaryPopupInfoForRange): Deleted.
     47        (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
     48
    1492018-11-29  Conrad Shultz  <conrad_shultz@apple.com>
    250
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r238657 r238678  
    734734};
    735735
     736@interface _UILookupGestureRecognizer : UIGestureRecognizer
     737@end
     738
    736739@class UIWebTouchEventsGestureRecognizer;
    737740
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r238657 r238678  
    3434#import "SafeBrowsingSPI.h"
    3535#import "SafeBrowsingWarning.h"
     36#import "WebPageMessages.h"
    3637#import "WebProcessProxy.h"
    3738#import <WebCore/DragItem.h>
     
    190191
    191192#endif // ENABLE(ATTACHMENT_ELEMENT)
    192 
    193 }
     193   
     194void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
     195{
     196    if (!isValid())
     197        return;
     198   
     199    process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
     200}
     201
     202void WebPageProxy::performDictionaryLookupOfCurrentSelection()
     203{
     204    if (!isValid())
     205        return;
     206   
     207    process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
     208}
     209
     210} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r238657 r238678  
    8888}
    8989
     90@class _UILookupGestureRecognizer;
    9091@class _UIHighlightView;
    9192@class _UIWebHighlightLongPressGestureRecognizer;
     
    216217#if PLATFORM(IOSMAC)
    217218    RetainPtr<UIHoverGestureRecognizer> _hoverGestureRecognizer;
     219    RetainPtr<_UILookupGestureRecognizer> _lookupGestureRecognizer;
    218220#endif
    219221
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r238657 r238678  
    113113#import "NativeWebMouseEvent.h"
    114114#import <UIKit/UIHoverGestureRecognizer.h>
     115#import <UIKit/_UILookupGestureRecognizer.h>
    115116#import <pal/spi/ios/GraphicsServicesSPI.h>
    116117#endif
     
    650651    [_hoverGestureRecognizer setDelegate:self];
    651652    [self addGestureRecognizer:_hoverGestureRecognizer.get()];
     653   
     654    _lookupGestureRecognizer = adoptNS([[_UILookupGestureRecognizer alloc] initWithTarget:self action:@selector(_lookupGestureRecognized:)]);
     655    [_lookupGestureRecognizer setDelegate:self];
     656    [self addGestureRecognizer:_lookupGestureRecognizer.get()];
     657   
    652658#endif
    653659
     
    760766    [_hoverGestureRecognizer setDelegate:nil];
    761767    [self removeGestureRecognizer:_hoverGestureRecognizer.get()];
     768   
     769    [_lookupGestureRecognizer setDelegate:nil];
     770    [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
    762771#endif
    763772
     
    847856#if PLATFORM(IOSMAC)
    848857    [self removeGestureRecognizer:_hoverGestureRecognizer.get()];
     858    [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
    849859#endif
    850860}
     
    862872#if PLATFORM(IOSMAC)
    863873    [self addGestureRecognizer:_hoverGestureRecognizer.get()];
     874    [self addGestureRecognizer:_lookupGestureRecognizer.get()];
    864875#endif
    865876}
     
    14681479    if ([gestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]] || [otherGestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]])
    14691480        return YES;
     1481   
     1482    if (([gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) || ([otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]]))
     1483        return YES;
     1484
    14701485#endif
    14711486    if (isSamePair(gestureRecognizer, otherGestureRecognizer, _highlightLongPressGestureRecognizer.get(), _textSelectionAssistant.get().forcePressGesture))
     
    60586073
    60596074#if PLATFORM(IOSMAC)
     6075- (void)_lookupGestureRecognized:(UIGestureRecognizer *)gestureRecognizer
     6076{
     6077    NSPoint locationInViewCoordinates = [gestureRecognizer locationInView:self];
     6078    _page->performDictionaryLookupAtLocation(WebCore::FloatPoint(locationInViewCoordinates));
     6079}
     6080
    60606081- (void)_hoverGestureRecognizerChanged:(UIGestureRecognizer *)gestureRecognizer
    60616082{
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r238657 r238678  
    122122}
    123123
    124 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)
    125 {
    126     notImplemented();
    127 }
    128 
    129124void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID)
    130125{
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r238657 r238678  
    324324#endif
    325325
    326 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
    327 {
    328     if (!isValid())
    329         return;
    330 
    331     process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
    332 }
    333 
    334 void WebPageProxy::performDictionaryLookupOfCurrentSelection()
    335 {
    336     if (!isValid())
    337         return;
    338 
    339     process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
    340 }
    341 
    342326// Complex text input support for plug-ins.
    343327void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput)
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm

    r238657 r238678  
    2727#import "WebPage.h"
    2828
     29
    2930#import "LoadParameters.h"
     31#import "PluginView.h"
    3032#import "WebPageProxyMessages.h"
     33#import <WebCore/DictionaryLookup.h>
     34#import <WebCore/Editor.h>
     35#import <WebCore/EventHandler.h>
     36#import <WebCore/FocusController.h>
     37#import <WebCore/HTMLConverter.h>
     38#import <WebCore/HitTestResult.h>
     39#import <WebCore/NodeRenderStyle.h>
    3140#import <WebCore/PlatformMediaSessionManager.h>
     41#import <WebCore/RenderElement.h>
     42#import <WebCore/RenderObject.h>
    3243
    3344#if PLATFORM(COCOA)
     
    6071    send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier, callbackID));
    6172}
     73   
     74void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
     75{
     76    if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
     77        if (pluginView->performDictionaryLookupAtLocation(floatPoint))
     78            return;
     79    }
     80   
     81    // Find the frame the point is over.
     82    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
     83    RefPtr<Range> range;
     84    NSDictionary *options;
     85    std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
     86    if (!range)
     87        return;
     88   
     89    auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
     90    if (!frame)
     91        return;
     92   
     93    performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
     94}
     95
     96void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
     97{
     98    RefPtr<Range> selectedRange;
     99    NSDictionary *options;
     100    std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
     101    if (selectedRange)
     102        performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
     103}
     104
     105void WebPage::performDictionaryLookupOfCurrentSelection()
     106{
     107    auto& frame = m_page->focusController().focusedOrMainFrame();
     108    performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
     109}
     110   
     111void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
     112{
     113    send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
     114}
     115
     116DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
     117{
     118    Editor& editor = frame.editor();
     119    editor.setIsGettingDictionaryPopupInfo(true);
     120   
     121    DictionaryPopupInfo dictionaryPopupInfo;
     122    if (range.text().stripWhiteSpace().isEmpty()) {
     123        editor.setIsGettingDictionaryPopupInfo(false);
     124        return dictionaryPopupInfo;
     125    }
     126   
     127    Vector<FloatQuad> quads;
     128    range.absoluteTextQuads(quads);
     129    if (quads.isEmpty()) {
     130        editor.setIsGettingDictionaryPopupInfo(false);
     131        return dictionaryPopupInfo;
     132    }
     133   
     134    IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
     135   
     136    const RenderStyle* style = range.startContainer().renderStyle();
     137    float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
     138    dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
     139    dictionaryPopupInfo.options = options;
     140
     141#if PLATFORM(MAC)
     142
     143    NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
     144   
     145    RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
     146   
     147    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     148   
     149    [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
     150        RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
     151       
     152        NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
     153        if (font)
     154            font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()];
     155        if (font)
     156            [scaledAttributes setObject:font forKey:NSFontAttributeName];
     157       
     158        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
     159    }];
     160
     161#endif // PLATFORM(MAC)
     162   
     163    TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
     164    if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
     165        indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
     166   
     167    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
     168    if (!textIndicator) {
     169        editor.setIsGettingDictionaryPopupInfo(false);
     170        return dictionaryPopupInfo;
     171    }
     172   
     173    dictionaryPopupInfo.textIndicator = textIndicator->data();
     174#if PLATFORM(MAC)
     175    dictionaryPopupInfo.attributedString = scaledNSAttributedString;
     176#endif // PLATFORM(MAC)
     177   
     178    editor.setIsGettingDictionaryPopupInfo(false);
     179    return dictionaryPopupInfo;
     180}
    62181
    63182} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r238623 r238678  
    190190    ForceRepaint(WebKit::CallbackID callbackID)
    191191
    192 #if PLATFORM(COCOA)
    193     # Dictionary support.
    194     PerformDictionaryLookupAtLocation(WebCore::FloatPoint point)
    195 #endif
    196 
    197192#if ENABLE(DATA_DETECTION)
    198193    DetectDataInAllFrames(uint64_t types) -> (struct WebKit::DataDetectionResult result) Async
     
    200195#endif
    201196
    202 #if PLATFORM(MAC)
     197#if PLATFORM(COCOA)
     198    # Dictionary support.
     199    PerformDictionaryLookupAtLocation(WebCore::FloatPoint point)
    203200    PerformDictionaryLookupOfCurrentSelection()
    204201#endif
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r238657 r238678  
    418418}
    419419
    420 void WebPage::performDictionaryLookupAtLocation(const FloatPoint&)
    421 {
    422     notImplemented();
    423 }
    424 
    425 void WebPage::performDictionaryLookupForSelection(Frame&, const VisibleSelection&, TextIndicatorPresentationTransition)
    426 {
    427     notImplemented();
    428 }
    429 
    430 void WebPage::performDictionaryLookupForRange(Frame&, Range&, NSDictionary *, TextIndicatorPresentationTransition)
    431 {
    432     notImplemented();
    433 }
    434 
    435420bool WebPage::performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*)
    436421{
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r238657 r238678  
    390390}
    391391   
    392 void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
    393 {
    394     if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
    395         if (pluginView->performDictionaryLookupAtLocation(floatPoint))
    396             return;
    397     }
    398 
    399     // Find the frame the point is over.
    400     HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
    401     RefPtr<Range> range;
    402     NSDictionary *options;
    403     std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
    404     if (!range)
    405         return;
    406 
    407     auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
    408     if (!frame)
    409         return;
    410 
    411     performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
    412 }
    413 
    414 void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
    415 {
    416     RefPtr<Range> selectedRange;
    417     NSDictionary *options;
    418     std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
    419     if (selectedRange)
    420         performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
    421 }
    422 
    423 void WebPage::performDictionaryLookupOfCurrentSelection()
    424 {
    425     auto& frame = m_page->focusController().focusedOrMainFrame();
    426     performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
    427 }
    428 
    429 DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
    430 {
    431     Editor& editor = frame.editor();
    432     editor.setIsGettingDictionaryPopupInfo(true);
    433 
    434     DictionaryPopupInfo dictionaryPopupInfo;
    435     if (range.text().stripWhiteSpace().isEmpty()) {
    436         editor.setIsGettingDictionaryPopupInfo(false);
    437         return dictionaryPopupInfo;
    438     }
    439 
    440     Vector<FloatQuad> quads;
    441     range.absoluteTextQuads(quads);
    442     if (quads.isEmpty()) {
    443         editor.setIsGettingDictionaryPopupInfo(false);
    444         return dictionaryPopupInfo;
    445     }
    446 
    447     IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
    448 
    449     const RenderStyle* style = range.startContainer().renderStyle();
    450     float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
    451     dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
    452     dictionaryPopupInfo.options = options;
    453 
    454     NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
    455 
    456     RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
    457 
    458     NSFontManager *fontManager = [NSFontManager sharedFontManager];
    459 
    460     [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
    461         RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
    462 
    463         NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
    464         if (font)
    465             font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()];
    466         if (font)
    467             [scaledAttributes setObject:font forKey:NSFontAttributeName];
    468 
    469         [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
    470     }];
    471 
    472     TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
    473     if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
    474         indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
    475 
    476     RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
    477     if (!textIndicator) {
    478         editor.setIsGettingDictionaryPopupInfo(false);
    479         return dictionaryPopupInfo;
    480     }
    481 
    482     dictionaryPopupInfo.textIndicator = textIndicator->data();
    483     dictionaryPopupInfo.attributedString = scaledNSAttributedString;
    484 
    485     editor.setIsGettingDictionaryPopupInfo(false);
    486     return dictionaryPopupInfo;
    487 }
     392
    488393
    489394#if ENABLE(PDFKIT_PLUGIN)
     
    539444
    540445#endif
    541 
    542 void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
    543 {
    544     send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
    545 }
    546446
    547447bool WebPage::performNonEditingBehaviorForSelector(const String& selector, KeyboardEvent* event)
Note: See TracChangeset for help on using the changeset viewer.