Use TextIndicator instead of the built in Lookup highlight
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Nov 2014 20:41:27 +0000 (20:41 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Nov 2014 20:41:27 +0000 (20:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138775
<rdar://problem/18953982>

Reviewed by Anders Carlsson.

In order to make the yellow highlight for Lookup more accurately match the
painted content of the web page (in light of e.g. Web fonts, and interesting
text features that only WebKit implements and cannot round-trip through
NSAttributedString), use a TextIndicator instead of the built-in Lookup
highlight where possible.

* Configurations/BaseTarget.xcconfig:
Make it possible to include headers from private frameworks. This matches WebCore.

* Shared/DictionaryPopupInfo.cpp:
(WebKit::DictionaryPopupInfo::encode):
(WebKit::DictionaryPopupInfo::decode):
* Shared/DictionaryPopupInfo.h:
Include the attributed string inside the DictionaryPopupInfo, instead of
as a secondary argument to DidPerformDictionaryLookup.
Add a TextIndicator to DictionaryPopupInfo, which can be used to highlight
the text in the UI process.

* UIProcess/API/mac/WKView.mm:
(-[WKView dealloc]):
(-[WKView viewDidMoveToWindow]):
(-[WKView _dictionaryLookupPopoverWillClose:]):
(-[WKView _setTextIndicator:fadeOut:animate:animationCompletionHandler:]):
(-[WKView _setTextIndicator:fadeOut:animate:]):
(-[WKView initWithFrame:context:configuration:webView:]):
(+[WKView hideWordDefinitionWindow]):
* UIProcess/API/mac/WKViewInternal.h:
Adopt the Lookup SPI header.
If we have the requisite API, register the notification that Lookup sends
when the popover closes, and hook that up to hide the text indicator.
Add a version of _setTextIndicator: that takes an animation completion handler.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didPerformDictionaryLookup):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::didPerformDictionaryLookup):
Adjust to the new didPerformDictionaryLookup signature.

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove a WKSI import.

* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDictionaryLookup):
If we have the requisite API, disable Lookup's built-in highlight and
present a TextIndicator instead.
We currently have to run the animations serially (first bounce the TextIndicator,
then animate in the Lookup popover) because the act of adding the Lookup popover
blocks us from getting any animation events for the TextIndicator, and breaks
the bounce. We could also fix this by using a threaded animation for the TextIndicator,
but it's not clear that it's safe to do so.

(WebKit::PageClientImpl::dismissDictionaryLookupPanel):
When explicitly dismissing the Lookup panel, also hide the text indicator.

* UIProcess/mac/TextIndicatorWindow.h:
* UIProcess/mac/TextIndicatorWindow.mm:
(WebKit::TextIndicatorWindow::setTextIndicator):
Store the completion handler.

(WebKit::TextIndicatorWindow::bounceAnimationDidEnd):
Call the completion handler when the animation completes.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _createActionMenuItemForTag:]):
Disable the Lookup item if lookup is not available.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::showDefinitionForAttributedString):
Adjust to the new didPerformDictionaryLookup signature.
Since PDFPlugin can't trivially repaint the required part of the PDF,
we don't build a TextIndicator. This will result in PDFPlugin continuing
to use Lookup's built-in highlight.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupForRange):
Build a TextIndicator from the Lookup range and pass it along with
the DictionaryPopupInfo.

* WebCore.exp.in:
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:
Remove a WKSI import/export that we don't need anymore.

* platform/spi/mac/LookupSPI.h: Added.
(WebCore::canDisableLookupIndicator):
Add Lookup SPI header.
Add a 'canDisableLookupIndicator', which must be called in any translation
unit that wants to use either of the soft-linked constants related to
that functionality, before calling the get* function.

* WebCore.xcodeproj/project.pbxproj:
* editing/mac/DictionaryLookup.mm:
(WebCore::rangeForDictionaryLookupForSelection):
(WebCore::rangeForDictionaryLookupAtHitTestResult):
Adopt the Lookup SPI header.

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove a WKSI import.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _lookupText:]):
(-[WebActionMenuController _createActionMenuItemForTag:]):
Make use of the new Lookup SPI header.
Disable the Lookup item if lookup is not available.

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

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/mac/DictionaryLookup.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebCore/platform/spi/mac/LookupSPI.h [new file with mode: 0644]
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Configurations/BaseTarget.xcconfig
Source/WebKit2/Shared/DictionaryPopupInfo.cpp
Source/WebKit2/Shared/DictionaryPopupInfo.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/mac/TextIndicatorWindow.h
Source/WebKit2/UIProcess/mac/TextIndicatorWindow.mm
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm
Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index d87ad8c64749458f9adf61ec261d04781d32c036..76515c961c1c4c8ee96f74af3275830264368cf9 100644 (file)
@@ -1,3 +1,29 @@
+2014-11-16  Tim Horton  <timothy_horton@apple.com>
+
+        Use TextIndicator instead of the built in Lookup highlight
+        https://bugs.webkit.org/show_bug.cgi?id=138775
+        <rdar://problem/18953982>
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.exp.in:
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+        Remove a WKSI import/export that we don't need anymore.
+        
+        * platform/spi/mac/LookupSPI.h: Added.
+        (WebCore::canDisableLookupIndicator):
+        Add Lookup SPI header.
+        Add a 'canDisableLookupIndicator', which must be called in any translation
+        unit that wants to use either of the soft-linked constants related to
+        that functionality, before calling the get* function.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::rangeForDictionaryLookupForSelection):
+        (WebCore::rangeForDictionaryLookupAtHitTestResult):
+        Adopt the Lookup SPI header.
+
 2014-11-16  Joanmarie Diggs  <jdiggs@igalia.com>
 
         AX: [ATK] REGRESSION(r166288): Accessible values are no longer accessible via AT-SPI2
index b137244a0b07802b405a33a8e80237fb53af607c..f3152036ad747ce0e9393138b5b82b551b859104 100644 (file)
@@ -2441,7 +2441,6 @@ _wkDrawFocusRingAtTime
 _wkDrawMediaSliderTrack
 _wkDrawMediaUIPart
 _wkExecutableWasLinkedOnOrBeforeSnowLeopard
-_wkExtractWordDefinitionTokenRangeFromContextualString
 _wkGetAXTextMarkerRangeTypeID
 _wkGetAXTextMarkerTypeID
 _wkGetBytesFromAXTextMarker
index f7ad63499d0239612dee6aac1c6326e18426d07e..07fb3d7235fe042b3733575052b49b8bcdbd5f51 100644 (file)
                2D3EF4491917915C00034184 /* WebActionDisablingCALayerDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D3EF4451917915C00034184 /* WebActionDisablingCALayerDelegate.mm */; };
                2D3EF44A1917915C00034184 /* WebCoreCALayerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3EF4461917915C00034184 /* WebCoreCALayerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2D3EF44B1917915C00034184 /* WebCoreCALayerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D3EF4471917915C00034184 /* WebCoreCALayerExtras.mm */; };
+               2D413F611A187A3F0041A521 /* LookupSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D413F601A187A3F0041A521 /* LookupSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2D46F04E17B96FBD005647F0 /* IntPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D46F04D17B96FBD005647F0 /* IntPoint.cpp */; };
                2D46F05017B96FD2005647F0 /* IntSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D46F04F17B96FD2005647F0 /* IntSize.cpp */; };
                2D481F00146B5C4C00AA7834 /* CrossfadeGeneratedImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */; };
                2D3EF4451917915C00034184 /* WebActionDisablingCALayerDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebActionDisablingCALayerDelegate.mm; sourceTree = "<group>"; };
                2D3EF4461917915C00034184 /* WebCoreCALayerExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreCALayerExtras.h; sourceTree = "<group>"; };
                2D3EF4471917915C00034184 /* WebCoreCALayerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreCALayerExtras.mm; sourceTree = "<group>"; };
+               2D413F601A187A3F0041A521 /* LookupSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LookupSPI.h; sourceTree = "<group>"; };
                2D46F04D17B96FBD005647F0 /* IntPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntPoint.cpp; sourceTree = "<group>"; };
                2D46F04F17B96FD2005647F0 /* IntSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntSize.cpp; sourceTree = "<group>"; };
                2D58D8531A15F65F00A5F726 /* DataDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetection.h; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */,
+                               2D413F601A187A3F0041A521 /* LookupSPI.h */,
                                1C6466271A12C3F90094603C /* NSFontSPI.h */,
                                2DCB837719F99BBA00A7FBE4 /* NSSharingServicePickerSPI.h */,
                                2DCB837819F99BBA00A7FBE4 /* NSSharingServiceSPI.h */,
                                A584FE351864D5AF00843B10 /* CommandLineAPIHost.h in Headers */,
                                A584FE2C1863870F00843B10 /* CommandLineAPIModule.h in Headers */,
                                A584FE2618637DAB00843B10 /* CommandLineAPIModuleSource.h in Headers */,
+                               2D413F611A187A3F0041A521 /* LookupSPI.h in Headers */,
                                6550B6A2099DF0270090D781 /* Comment.h in Headers */,
                                E1FE137518402A6700892F13 /* CommonCryptoUtilities.h in Headers */,
                                37C236111097EE7700EF9F72 /* ComplexTextController.h in Headers */,
index db642875befe2f839ac63fde445f805b64511244..2fb7c9f68604af713b9bf5edaa8eb33b64535f1f 100644 (file)
@@ -34,6 +34,7 @@
 #import "FrameSelection.h"
 #import "HTMLConverter.h"
 #import "HitTestResult.h"
+#import "LookupSPI.h"
 #import "Page.h"
 #import "Range.h"
 #import "RenderObject.h"
@@ -115,8 +116,9 @@ PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection& s
     String fullPlainTextString = plainText(makeRange(paragraphStart, paragraphEnd).get());
 
     // Since we already have the range we want, we just need to grab the returned options.
-    wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
-    
+    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
+        [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
+
     return selectedRange.release();
 }
 
@@ -155,7 +157,9 @@ PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult& h
 
     String fullPlainTextString = plainText(fullCharacterRange.get());
 
-    NSRange extractedRange = wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
+    NSRange extractedRange = NSMakeRange(rangeToPass.location, 0);
+    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
+        extractedRange = [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
 
     // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
     if (extractedRange.location == NSNotFound)
index b6b27f872c6331809a20f3cd5194c5ff740aa9bd..cff58d385523f821a9af7e738608743711f9bbde 100644 (file)
@@ -238,8 +238,6 @@ extern int (*wkRecommendedScrollerStyle)(void);
 
 extern bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
 
-extern NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
-
 extern CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
 
 extern NSCursor *(*wkCursor)(const char*);
index 81432b423c0d6448ab0e8cc4476433758179bdaf..89b4c9a293467dc502ffbd193adc63a7d6ea3ccd 100644 (file)
@@ -110,8 +110,6 @@ int (*wkRecommendedScrollerStyle)(void);
 
 bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
 
-NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
-
 CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
 
 NSCursor *(*wkCursor)(const char*);
diff --git a/Source/WebCore/platform/spi/mac/LookupSPI.h b/Source/WebCore/platform/spi/mac/LookupSPI.h
new file mode 100644 (file)
index 0000000..54ad710
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2014 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 "SoftLinking.h"
+#import <objc/runtime.h>
+
+#if PLATFORM(MAC)
+
+SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Lookup)
+SOFT_LINK_CLASS_OPTIONAL(Lookup, LULookupDefinitionModule)
+
+SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
+SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
+
+namespace WebCore {
+inline bool canDisableLookupIndicator()
+{
+    return canLoadLUTermOptionDisableSearchTermIndicator() && canLoadLUNotificationPopoverWillClose();
+}
+};
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <Lookup/Lookup.h>
+
+#else
+
+@interface LULookupDefinitionModule : NSObject
+
++ (NSRange)tokenRangeForString:(NSString *)string range:(NSRange)range options:(NSDictionary **)options;
++ (void)showDefinitionForTerm:(NSAttributedString *)term atLocation:(NSPoint)screenPoint options:(NSDictionary *)options;
++ (void)hideDefinition;
+
+@end
+
+#endif // !USE(APPLE_INTERNAL_SDK)
+
+#endif // PLATFORM(MAC)
index 2778060e5774fb90502788e09efddab7ab172dc8..b131a4ebd48e3f7db09cd37275caa7e8ba3b0a2d 100644 (file)
@@ -1,3 +1,21 @@
+2014-11-16  Tim Horton  <timothy_horton@apple.com>
+
+        Use TextIndicator instead of the built in Lookup highlight
+        https://bugs.webkit.org/show_bug.cgi?id=138775
+        <rdar://problem/18953982>
+
+        Reviewed by Anders Carlsson.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Remove a WKSI import.
+
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController _lookupText:]):
+        (-[WebActionMenuController _createActionMenuItemForTag:]):
+        Make use of the new Lookup SPI header.
+        Disable the Lookup item if lookup is not available.
+
 2014-11-15  Tim Horton  <timothy_horton@apple.com>
 
         Implement data detectors and mailto action menus for WebKit1
index d74d08237ee0109a301225de652efdd930530057..15ea4d294f0d1ab1f67dff3ee7a3e5b93813215b 100644 (file)
@@ -135,7 +135,6 @@ void InitWebCoreSystemInterface(void)
 #if !PLATFORM(IOS)
     INIT(RecommendedScrollerStyle);
     INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
-    INIT(ExtractWordDefinitionTokenRangeFromContextualString);
     INIT(CopyDefaultSearchProviderDisplayName);
     INIT(Cursor);
 #endif
index 94d00c66f18363b92f5a961397fa20f5c5570820..6514d0e9ef140fe62475904fab77459ff449fda3 100644 (file)
@@ -47,6 +47,7 @@
 #import <WebCore/Frame.h>
 #import <WebCore/FrameView.h>
 #import <WebCore/HTMLConverter.h>
+#import <WebCore/LookupSPI.h>
 #import <WebCore/NSSharingServicePickerSPI.h>
 #import <WebCore/NSSharingServiceSPI.h>
 #import <WebCore/NSViewSPI.h>
@@ -563,7 +564,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     // Convert to screen coordinates.
     textBaselineOrigin = [_webView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
 
-    WKShowWordDefinitionWindow(popupInfo.attributedString.get(), textBaselineOrigin, popupInfo.options.get());
+    [getLULookupDefinitionModuleClass() showDefinitionForTerm:popupInfo.attributedString.get() atLocation:textBaselineOrigin options:popupInfo.options.get()];
 }
 
 - (void)_paste:(id)sender
@@ -689,6 +690,7 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
     SEL selector = nullptr;
     NSString *title = nil;
     NSImage *image = nil;
+    bool enabled = true;
 
     switch (tag) {
     case WebActionMenuItemTagOpenLinkInDefaultBrowser:
@@ -719,6 +721,7 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
         selector = @selector(_lookupText:);
         title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
         image = [NSImage imageNamed:@"NSActionMenuLookup"];
+        enabled = getLULookupDefinitionModuleClass();
         break;
 
     case WebActionMenuItemTagPaste:
@@ -781,6 +784,7 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
     [item setImage:image];
     [item setTarget:self];
     [item setTag:tag];
+    [item setEnabled:enabled];
     return item;
 }
 
index e1c001959ca975fdbf5b8af12babdeeb3e3def06..d566801a01426ff325b97f00ef33015db8d4a7a7 100644 (file)
@@ -1,3 +1,94 @@
+2014-11-16  Tim Horton  <timothy_horton@apple.com>
+
+        Use TextIndicator instead of the built in Lookup highlight
+        https://bugs.webkit.org/show_bug.cgi?id=138775
+        <rdar://problem/18953982>
+
+        Reviewed by Anders Carlsson.
+
+        In order to make the yellow highlight for Lookup more accurately match the
+        painted content of the web page (in light of e.g. Web fonts, and interesting
+        text features that only WebKit implements and cannot round-trip through
+        NSAttributedString), use a TextIndicator instead of the built-in Lookup
+        highlight where possible.
+
+        * Configurations/BaseTarget.xcconfig:
+        Make it possible to include headers from private frameworks. This matches WebCore.
+
+        * Shared/DictionaryPopupInfo.cpp:
+        (WebKit::DictionaryPopupInfo::encode):
+        (WebKit::DictionaryPopupInfo::decode):
+        * Shared/DictionaryPopupInfo.h:
+        Include the attributed string inside the DictionaryPopupInfo, instead of
+        as a secondary argument to DidPerformDictionaryLookup.
+        Add a TextIndicator to DictionaryPopupInfo, which can be used to highlight
+        the text in the UI process.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView dealloc]):
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView _dictionaryLookupPopoverWillClose:]):
+        (-[WKView _setTextIndicator:fadeOut:animate:animationCompletionHandler:]):
+        (-[WKView _setTextIndicator:fadeOut:animate:]):
+        (-[WKView initWithFrame:context:configuration:webView:]):
+        (+[WKView hideWordDefinitionWindow]):
+        * UIProcess/API/mac/WKViewInternal.h:
+        Adopt the Lookup SPI header.
+        If we have the requisite API, register the notification that Lookup sends
+        when the popover closes, and hook that up to hide the text indicator.
+        Add a version of _setTextIndicator: that takes an animation completion handler.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didPerformDictionaryLookup):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::didPerformDictionaryLookup):
+        Adjust to the new didPerformDictionaryLookup signature.
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Remove a WKSI import.
+
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didPerformDictionaryLookup):
+        If we have the requisite API, disable Lookup's built-in highlight and
+        present a TextIndicator instead.
+        We currently have to run the animations serially (first bounce the TextIndicator,
+        then animate in the Lookup popover) because the act of adding the Lookup popover
+        blocks us from getting any animation events for the TextIndicator, and breaks
+        the bounce. We could also fix this by using a threaded animation for the TextIndicator,
+        but it's not clear that it's safe to do so.
+
+        (WebKit::PageClientImpl::dismissDictionaryLookupPanel):
+        When explicitly dismissing the Lookup panel, also hide the text indicator.
+
+        * UIProcess/mac/TextIndicatorWindow.h:
+        * UIProcess/mac/TextIndicatorWindow.mm:
+        (WebKit::TextIndicatorWindow::setTextIndicator):
+        Store the completion handler.
+
+        (WebKit::TextIndicatorWindow::bounceAnimationDidEnd):
+        Call the completion handler when the animation completes.
+
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _createActionMenuItemForTag:]):
+        Disable the Lookup item if lookup is not available.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::showDefinitionForAttributedString):
+        Adjust to the new didPerformDictionaryLookup signature.
+        Since PDFPlugin can't trivially repaint the required part of the PDF,
+        we don't build a TextIndicator. This will result in PDFPlugin continuing
+        to use Lookup's built-in highlight.
+        
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupForRange):
+        Build a TextIndicator from the Lookup range and pass it along with
+        the DictionaryPopupInfo.
+
 2014-11-15  David Kilzer  <ddkilzer@apple.com>
 
         REGRESSION (r176137): iOS build broke after moving DataDetectors scanning code to WebCore
index 30fd318071b5892724e33ef53c4cf01261397d9b..b0b1a408c3f08fe560c472f88de86df0048853ba 100644 (file)
@@ -29,7 +29,7 @@ GCC_PREFIX_HEADER = WebKit2Prefix.h;
 GCC_PREPROCESSOR_DEFINITIONS = $(DEBUG_DEFINES) $(FEATURE_DEFINES) FRAMEWORK_NAME=WebKit
 HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/usr/local/include $(WEBCORE_PRIVATE_HEADERS_DIR)/ForwardingHeaders $(WEBCORE_PRIVATE_HEADERS_DIR)/icu $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit2 $(HEADER_SEARCH_PATHS);
 
-OTHER_CFLAGS = $(inherited) -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Quartz.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/CoreServices.framework/Frameworks;
+OTHER_CFLAGS = $(inherited) -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Quartz.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/CoreServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks;
 OTHER_CPLUSPLUSFLAGS = $(OTHER_CFLAGS);
 
 NORMAL_WEBKIT_FRAMEWORKS_DIR = $(SYSTEM_LIBRARY_DIR)/Frameworks;
index 243680756799c6df929d499d8f924700badef799..df5a36d6f780b23c99a912c64529c29083d4d044 100644 (file)
@@ -37,12 +37,15 @@ namespace WebKit {
 void DictionaryPopupInfo::encode(IPC::ArgumentEncoder& encoder) const
 {
     encoder << origin;
+    encoder << textIndicator;
 
 #if PLATFORM(COCOA)
     bool hadOptions = options;
     encoder << hadOptions;
     if (hadOptions)
         IPC::encode(encoder, options.get());
+
+    encoder << attributedString;
 #endif
 }
 
@@ -50,6 +53,10 @@ bool DictionaryPopupInfo::decode(IPC::ArgumentDecoder& decoder, DictionaryPopupI
 {
     if (!decoder.decode(result.origin))
         return false;
+
+    if (!decoder.decode(result.textIndicator))
+        return false;
+
 #if PLATFORM(COCOA)
     bool hadOptions;
     if (!decoder.decode(hadOptions))
@@ -58,6 +65,9 @@ bool DictionaryPopupInfo::decode(IPC::ArgumentDecoder& decoder, DictionaryPopupI
         if (!IPC::decode(decoder, result.options))
             return false;
     }
+
+    if (!decoder.decode(result.attributedString))
+        return false;
 #endif
     return true;
 }
index f609276e94c4e362c068ea73b4c0abbb00de7f73..a54fc083444edf4de3add4dc3346ad7c20975f70 100644 (file)
 #ifndef DictionaryPopupInfo_h
 #define DictionaryPopupInfo_h
 
+#include "TextIndicator.h"
 #include <WebCore/FloatPoint.h>
 
 #if PLATFORM(COCOA)
+#include "AttributedString.h"
 #include <wtf/RetainPtr.h>
 #endif
 
 namespace IPC {
-    class ArgumentDecoder;
-    class ArgumentEncoder;
+class ArgumentDecoder;
+class ArgumentEncoder;
 }
 
 namespace WebKit {
@@ -44,8 +46,10 @@ struct DictionaryPopupInfo {
     static bool decode(IPC::ArgumentDecoder&, DictionaryPopupInfo&);
 
     WebCore::FloatPoint origin;
+    TextIndicator::Data textIndicator;
 #if PLATFORM(COCOA)
     RetainPtr<CFDictionaryRef> options;
+    AttributedString attributedString;
 #endif
 };
 
index b700706dfa58981ce433a44f30877e1f685e33d3..29b7d08941952c4e14b21a7e555c1d0533947157 100644 (file)
@@ -88,6 +88,7 @@
 #import <WebCore/FileSystem.h>
 #import <WebCore/KeyboardEvent.h>
 #import <WebCore/LocalizedStrings.h>
+#import <WebCore/LookupSPI.h>
 #import <WebCore/NSViewSPI.h>
 #import <WebCore/PlatformEventFactoryMac.h>
 #import <WebCore/PlatformScreen.h>
@@ -325,6 +326,9 @@ struct WKViewInterpretKeyEventsParameters {
 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp];
 
+    if (canDisableLookupIndicator())
+        [[NSNotificationCenter defaultCenter] removeObserver:self name:getLUNotificationPopoverWillClose() object:nil];
+
     WebContext::statistics().wkViewCount--;
 
     [super dealloc];
@@ -2553,7 +2557,8 @@ static void* keyValueObservingContext = &keyValueObservingContext;
         [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
         _data->_flagsChangedEventMonitor = nil;
 
-        WKHideWordDefinitionWindow();
+        if (getLULookupDefinitionModuleClass())
+            [getLULookupDefinitionModuleClass() hideDefinition];
         [self _dismissActionMenuPopovers];
     }
 
@@ -2689,6 +2694,11 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     _data->_page->process().context().applicationWillTerminate();
 }
 
+- (void)_dictionaryLookupPopoverWillClose:(NSNotification *)notification
+{
+    [self _setTextIndicator:nil fadeOut:NO animate:NO];
+}
+
 - (void)_accessibilityRegisterUIProcessTokens
 {
     // Initialize remote accessibility when the window connection has been established.
@@ -3057,7 +3067,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     }
 }
 
-- (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate
+- (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate animationCompletionHandler:(std::function<void ()>)completionHandler
 {
     if (!textIndicator) {
         _data->_textIndicatorWindow = nullptr;
@@ -3067,7 +3077,12 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     if (!_data->_textIndicatorWindow)
         _data->_textIndicatorWindow = std::make_unique<TextIndicatorWindow>(self);
 
-    _data->_textIndicatorWindow->setTextIndicator(textIndicator, fadeOut, animate);
+    _data->_textIndicatorWindow->setTextIndicator(textIndicator, fadeOut, animate, WTF::move(completionHandler));
+}
+
+- (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate
+{
+    [self _setTextIndicator:textIndicator fadeOut:fadeOut animate:animate animationCompletionHandler:[] {}];
 }
 
 - (CALayer *)_rootLayer
@@ -3559,6 +3574,9 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp];
 
+    if (canDisableLookupIndicator())
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     if ([self respondsToSelector:@selector(setActionMenu:)]) {
         RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]);
@@ -3806,7 +3824,9 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
 
 + (void)hideWordDefinitionWindow
 {
-    WKHideWordDefinitionWindow();
+    if (!getLULookupDefinitionModuleClass())
+        return;
+    [getLULookupDefinitionModuleClass() hideDefinition];
 }
 
 - (CGFloat)minimumLayoutWidth
index bb617935b8d6d6d4f2dc85a9f5ec7e37e77007fe..f062810be99f8d60924baee290b59e6385654e4c 100644 (file)
@@ -81,6 +81,7 @@ struct WebPageConfiguration;
 - (NSRect)_convertToDeviceSpace:(NSRect)rect;
 - (NSRect)_convertToUserSpace:(NSRect)rect;
 - (void)_setTextIndicator:(PassRefPtr<WebKit::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate;
+- (void)_setTextIndicator:(PassRefPtr<WebKit::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate animationCompletionHandler:(std::function<void ()>)completionHandler;
 
 - (void)_setAcceleratedCompositingModeRootLayer:(CALayer *)rootLayer;
 - (CALayer *)_acceleratedCompositingModeRootLayer;
index f7b0be5fd11cc06ca83f46296da1467a82d20a7c..2b2137e9386a268105f6f4bd95248486b1661b0e 100644 (file)
@@ -223,7 +223,7 @@ public:
 #if PLATFORM(MAC)
     virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0;
     virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0;
-    virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&) = 0;
+    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&) = 0;
     virtual void dismissDictionaryLookupPanel() = 0;
     virtual void dismissActionMenuPopovers() = 0;
     virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0;
index 3692219a08713c332d8e6e804a69cbeb62f94dce..329cdd28d74c1b1af6ac09d4857b05e1ee837f32 100644 (file)
@@ -1174,7 +1174,7 @@ private:
     void searchTheWeb(const String&);
 
     // Dictionary.
-    void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
+    void didPerformDictionaryLookup(const DictionaryPopupInfo&);
 #endif
 
     // Spelling and grammar.
index 438f0d300f5540bc5d2c8ddc144da770ebd8e1b7..eeb88ae119e482d29430f626643fdd5ba344b327 100644 (file)
@@ -297,7 +297,7 @@ messages -> WebPageProxy {
 
 #if PLATFORM(COCOA)
     # Dictionary support.
-    DidPerformDictionaryLookup(WebKit::AttributedString text, WebKit::DictionaryPopupInfo dictionaryPopupInfo)
+    DidPerformDictionaryLookup(WebKit::DictionaryPopupInfo dictionaryPopupInfo)
 
     # Keyboard input support messages
     ExecuteSavedCommandBySelector(String selector) -> (bool handled)
index 5936dafa713baaff9e4aab139d1e24941f582d2a..fc24eb353423f868bb068ef67a547a6219153e19 100644 (file)
@@ -769,7 +769,7 @@ void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultip
     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
 }
 
-void WebPageProxy::didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&)
+void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo&)
 {
     notImplemented();
 }
index d25839b810bc7a163189700705faed2e5478780f..b3a9a009ea0d67aec7108295e27f55036342327e 100644 (file)
@@ -136,7 +136,7 @@ private:
 
     virtual void makeFirstResponder();
     
-    virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
+    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&);
     virtual void dismissDictionaryLookupPanel();
     virtual void dismissActionMenuPopovers();
 
index b50f27ae7949bcab8113f034fbbdccad440fc3d9..62da8300db5440140310cfb584644dac3552428f 100644 (file)
@@ -58,6 +58,7 @@
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/Image.h>
 #import <WebCore/KeyboardEvent.h>
+#import <WebCore/LookupSPI.h>
 #import <WebCore/NotImplemented.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/TextUndoInsertionMarkupMac.h>
@@ -529,22 +530,39 @@ void PageClientImpl::setPluginComplexTextInputState(uint64_t pluginComplexTextIn
     [m_wkView _setPluginComplexTextInputState:pluginComplexTextInputState pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
 }
 
-void PageClientImpl::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
+void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
 {
-    RetainPtr<NSAttributedString> attributedString = text.string;
+    if (!getLULookupDefinitionModuleClass())
+        return;
+
     NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
 
     // Convert to screen coordinates.
     textBaselineOrigin = [m_wkView convertPoint:textBaselineOrigin toView:nil];
     textBaselineOrigin = [m_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
 
-    WKShowWordDefinitionWindow(attributedString.get(), textBaselineOrigin, (NSDictionary *)dictionaryPopupInfo.options.get());
+    RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
+
+    if (canDisableLookupIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
+        // Run the animations serially because attaching another subwindow breaks the bounce animation.
+        // We could consider making the bounce NSAnimationNonblockingThreaded instead, which seems
+        // to work, but need to consider all of the implications.
+        [m_wkView _setTextIndicator:TextIndicator::create(dictionaryPopupInfo.textIndicator) fadeOut:NO animate:YES animationCompletionHandler:[dictionaryPopupInfo, textBaselineOrigin, mutableOptions] {
+            [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
+            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
+        }];
+    } else
+        [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
 }
 
 void PageClientImpl::dismissDictionaryLookupPanel()
 {
+    if (!getLULookupDefinitionModuleClass())
+        return;
+
     // FIXME: We don't know which panel we are dismissing, it may not even be in the current page (see <rdar://problem/13875766>).
-    WKHideWordDefinitionWindow();
+    [getLULookupDefinitionModuleClass() hideDefinition];
+    setTextIndicator(nil, false, true);
 }
 
 void PageClientImpl::dismissActionMenuPopovers()
index 9ef164d4ce8977d3047371422b308a23aac5e8da..705940e18938a486c7261d01451275d827a7c8bb 100644 (file)
@@ -29,6 +29,7 @@
 #if PLATFORM(MAC)
 
 #import "WebKitSystemInterface.h"
+#import <functional>
 #import <wtf/Noncopyable.h>
 #import <wtf/RefPtr.h>
 #import <wtf/RetainPtr.h>
@@ -48,7 +49,7 @@ public:
     explicit TextIndicatorWindow(WKView *);
     ~TextIndicatorWindow();
 
-    void setTextIndicator(PassRefPtr<TextIndicator>, bool fadeOut, bool animate);
+    void setTextIndicator(PassRefPtr<TextIndicator>, bool fadeOut, bool animate, std::function<void ()> animationCompletionHandler);
 
 private:
     void closeWindow();
@@ -70,6 +71,8 @@ private:
 
     RunLoop::Timer<TextIndicatorWindow> m_startFadeOutTimer;
     RetainPtr<WKTextIndicatorWindowAnimation> m_fadeOutAnimation;
+
+    std::function<void ()> m_bounceAnimationCompletionHandler;
 };
 
 } // namespace WebKit
index 5d658d574cdf04027babf5ecc1aef9142c56d4c6..82a4ba00b161f4afa3116c426b2313d870ee8657 100644 (file)
@@ -120,7 +120,7 @@ TextIndicatorWindow::~TextIndicatorWindow()
     closeWindow();
 }
 
-void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicator, bool fadeOut, bool animate)
+void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicator, bool fadeOut, bool animate, std::function<void ()> animationCompletionHandler)
 {
     if (m_textIndicator == textIndicator)
         return;
@@ -154,6 +154,7 @@ void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicat
     [m_textIndicatorWindow setReleasedWhenClosed:NO];
 
     if (animate) {
+        m_bounceAnimationCompletionHandler = WTF::move(animationCompletionHandler);
         // Start the bounce animation.
         m_bounceAnimationContext = WKWindowBounceAnimationContextCreate(m_textIndicatorWindow.get());
         m_bounceAnimation = adoptNS([[WKTextIndicatorWindowAnimation alloc] _initWithTextIndicatorWindow:this animationDuration:bounceAnimationDuration
@@ -230,6 +231,7 @@ void TextIndicatorWindow::bounceAnimationDidEnd()
 
     WKWindowBounceAnimationContextDestroy(m_bounceAnimationContext);
     m_bounceAnimationContext = 0;
+    m_bounceAnimationCompletionHandler();
 }
 
 } // namespace WebKit
index 2fdc24f45fd5aa02599963198463358d12725387..27d8089f5f0ab72b68905d264721f9ee503fbc09 100644 (file)
@@ -45,6 +45,7 @@
 #import <WebCore/DataDetectorsSPI.h>
 #import <WebCore/GeometryUtilities.h>
 #import <WebCore/LocalizedStrings.h>
+#import <WebCore/LookupSPI.h>
 #import <WebCore/NSSharingServiceSPI.h>
 #import <WebCore/NSSharingServicePickerSPI.h>
 #import <WebCore/NSViewSPI.h>
@@ -756,6 +757,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     SEL selector = nullptr;
     NSString *title = nil;
     NSImage *image = nil;
+    bool enabled = true;
 
     switch (tag) {
     case kWKContextActionItemTagOpenLinkInDefaultBrowser:
@@ -811,6 +813,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
         selector = @selector(_lookupText:);
         title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
         image = [NSImage imageNamed:@"NSActionMenuLookup"];
+        enabled = getLULookupDefinitionModuleClass();
         break;
 
     case kWKContextActionItemTagPaste:
@@ -850,6 +853,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     [item setImage:image];
     [item setTarget:self];
     [item setTag:tag];
+    [item setEnabled:enabled];
     return item;
 }
 
index e29ee5681b2127df7fe626ff42e22b616377e149..d57ad68e572f6f46eed07d2260142c5832a54578 100644 (file)
@@ -450,9 +450,9 @@ void WebPageProxy::setSmartInsertDeleteEnabled(bool isSmartInsertDeleteEnabled)
     process().send(Messages::WebPage::SetSmartInsertDeleteEnabled(isSmartInsertDeleteEnabled), m_pageID);
 }
 
-void WebPageProxy::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
+void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
 {
-    m_pageClient.didPerformDictionaryLookup(text, dictionaryPopupInfo);
+    m_pageClient.didPerformDictionaryLookup(dictionaryPopupInfo);
 }
     
 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
index 77b71ca134e9f938cd89174ae67b5ac0a0190d81..2e3201032fbe3af8a4c654257d7bb7fe68d64eee 100644 (file)
@@ -1699,11 +1699,9 @@ void PDFPlugin::showDefinitionForAttributedString(NSAttributedString *string, CG
 {
     DictionaryPopupInfo dictionaryPopupInfo;
     dictionaryPopupInfo.origin = convertFromPDFViewToRootView(IntPoint(point));
+    dictionaryPopupInfo.attributedString.string = string;
 
-    AttributedString attributedString;
-    attributedString.string = string;
-
-    webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
+    webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
 }
 
 unsigned PDFPlugin::countFindMatches(const String& target, WebCore::FindOptions options, unsigned maxMatchCount)
index c7155fb8702701c9d38cab991eb9cc7daec3043b..dfbb71ad3831e7cb5034b518393249b2082d6bea 100644 (file)
@@ -126,7 +126,6 @@ void InitWebCoreSystemInterface(void)
 #if !PLATFORM(IOS)
         INIT(RecommendedScrollerStyle);
         INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
-        INIT(ExtractWordDefinitionTokenRangeFromContextualString);
         INIT(CopyDefaultSearchProviderDisplayName);
         INIT(Cursor);
         INIT(WindowSetScaledFrame);
index c8a01e25be9eead0ee4acb96e0949e45add28749..d364c1ceb9a56aa09d6b917ebe2606aa863edf30 100644 (file)
@@ -548,10 +548,14 @@ void WebPage::performDictionaryLookupForRange(Frame* frame, Range& range, NSDict
         [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
     }];
 
-    AttributedString attributedString;
-    attributedString.string = scaledNSAttributedString;
+    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range);
+    if (!textIndicator)
+        return;
+
+    dictionaryPopupInfo.textIndicator = textIndicator->data();
+    dictionaryPopupInfo.attributedString.string = scaledNSAttributedString;
 
-    send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
+    send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
 }
 
 bool WebPage::performNonEditingBehaviorForSelector(const String& selector, KeyboardEvent* event)