⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 176164 in webkit


Ignore:
Timestamp:
Nov 16, 2014, 12:41:27 PM (12 years ago)
Author:
timothy_horton@apple.com
Message:

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.

  • 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.

Location:
trunk/Source
Files:
1 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176163 r176164  
     12014-11-16  Tim Horton  <timothy_horton@apple.com>
     2
     3        Use TextIndicator instead of the built in Lookup highlight
     4        https://bugs.webkit.org/show_bug.cgi?id=138775
     5        <rdar://problem/18953982>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * WebCore.exp.in:
     10        * platform/mac/WebCoreSystemInterface.h:
     11        * platform/mac/WebCoreSystemInterface.mm:
     12        Remove a WKSI import/export that we don't need anymore.
     13       
     14        * platform/spi/mac/LookupSPI.h: Added.
     15        (WebCore::canDisableLookupIndicator):
     16        Add Lookup SPI header.
     17        Add a 'canDisableLookupIndicator', which must be called in any translation
     18        unit that wants to use either of the soft-linked constants related to
     19        that functionality, before calling the get* function.
     20
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * editing/mac/DictionaryLookup.mm:
     23        (WebCore::rangeForDictionaryLookupForSelection):
     24        (WebCore::rangeForDictionaryLookupAtHitTestResult):
     25        Adopt the Lookup SPI header.
     26
    1272014-11-16  Joanmarie Diggs  <jdiggs@igalia.com>
    228
  • trunk/Source/WebCore/WebCore.exp.in

    r176156 r176164  
    24422442_wkDrawMediaUIPart
    24432443_wkExecutableWasLinkedOnOrBeforeSnowLeopard
    2444 _wkExtractWordDefinitionTokenRangeFromContextualString
    24452444_wkGetAXTextMarkerRangeTypeID
    24462445_wkGetAXTextMarkerTypeID
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r176157 r176164  
    10971097                2D3EF44A1917915C00034184 /* WebCoreCALayerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3EF4461917915C00034184 /* WebCoreCALayerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10981098                2D3EF44B1917915C00034184 /* WebCoreCALayerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D3EF4471917915C00034184 /* WebCoreCALayerExtras.mm */; };
     1099                2D413F611A187A3F0041A521 /* LookupSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D413F601A187A3F0041A521 /* LookupSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10991100                2D46F04E17B96FBD005647F0 /* IntPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D46F04D17B96FBD005647F0 /* IntPoint.cpp */; };
    11001101                2D46F05017B96FD2005647F0 /* IntSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D46F04F17B96FD2005647F0 /* IntSize.cpp */; };
     
    81078108                2D3EF4461917915C00034184 /* WebCoreCALayerExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreCALayerExtras.h; sourceTree = "<group>"; };
    81088109                2D3EF4471917915C00034184 /* WebCoreCALayerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreCALayerExtras.mm; sourceTree = "<group>"; };
     8110                2D413F601A187A3F0041A521 /* LookupSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LookupSPI.h; sourceTree = "<group>"; };
    81098111                2D46F04D17B96FBD005647F0 /* IntPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntPoint.cpp; sourceTree = "<group>"; };
    81108112                2D46F04F17B96FD2005647F0 /* IntSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntSize.cpp; sourceTree = "<group>"; };
     
    1754517547                        children = (
    1754617548                                2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */,
     17549                                2D413F601A187A3F0041A521 /* LookupSPI.h */,
    1754717550                                1C6466271A12C3F90094603C /* NSFontSPI.h */,
    1754817551                                2DCB837719F99BBA00A7FBE4 /* NSSharingServicePickerSPI.h */,
     
    2356223565                                A584FE2C1863870F00843B10 /* CommandLineAPIModule.h in Headers */,
    2356323566                                A584FE2618637DAB00843B10 /* CommandLineAPIModuleSource.h in Headers */,
     23567                                2D413F611A187A3F0041A521 /* LookupSPI.h in Headers */,
    2356423568                                6550B6A2099DF0270090D781 /* Comment.h in Headers */,
    2356523569                                E1FE137518402A6700892F13 /* CommonCryptoUtilities.h in Headers */,
  • trunk/Source/WebCore/editing/mac/DictionaryLookup.mm

    r176137 r176164  
    3535#import "HTMLConverter.h"
    3636#import "HitTestResult.h"
     37#import "LookupSPI.h"
    3738#import "Page.h"
    3839#import "Range.h"
     
    116117
    117118    // Since we already have the range we want, we just need to grab the returned options.
    118     wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
    119    
     119    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
     120        [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
     121
    120122    return selectedRange.release();
    121123}
     
    156158    String fullPlainTextString = plainText(fullCharacterRange.get());
    157159
    158     NSRange extractedRange = wkExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
     160    NSRange extractedRange = NSMakeRange(rangeToPass.location, 0);
     161    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
     162        extractedRange = [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
    159163
    160164    // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h

    r176112 r176164  
    239239extern bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
    240240
    241 extern NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
    242 
    243241extern CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
    244242
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm

    r176112 r176164  
    111111bool (*wkExecutableWasLinkedOnOrBeforeSnowLeopard)(void);
    112112
    113 NSRange (*wkExtractWordDefinitionTokenRangeFromContextualString)(NSString *contextString, NSRange range, NSDictionary **options);
    114 
    115113CFStringRef (*wkCopyDefaultSearchProviderDisplayName)(void);
    116114
  • trunk/Source/WebKit/mac/ChangeLog

    r176153 r176164  
     12014-11-16  Tim Horton  <timothy_horton@apple.com>
     2
     3        Use TextIndicator instead of the built in Lookup highlight
     4        https://bugs.webkit.org/show_bug.cgi?id=138775
     5        <rdar://problem/18953982>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * WebCoreSupport/WebSystemInterface.mm:
     10        (InitWebCoreSystemInterface):
     11        Remove a WKSI import.
     12
     13        * WebView/WebActionMenuController.mm:
     14        (-[WebActionMenuController _lookupText:]):
     15        (-[WebActionMenuController _createActionMenuItemForTag:]):
     16        Make use of the new Lookup SPI header.
     17        Disable the Lookup item if lookup is not available.
     18
    1192014-11-15  Tim Horton  <timothy_horton@apple.com>
    220
  • trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm

    r176112 r176164  
    136136    INIT(RecommendedScrollerStyle);
    137137    INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
    138     INIT(ExtractWordDefinitionTokenRangeFromContextualString);
    139138    INIT(CopyDefaultSearchProviderDisplayName);
    140139    INIT(Cursor);
  • trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm

    r176153 r176164  
    4848#import <WebCore/FrameView.h>
    4949#import <WebCore/HTMLConverter.h>
     50#import <WebCore/LookupSPI.h>
    5051#import <WebCore/NSSharingServicePickerSPI.h>
    5152#import <WebCore/NSSharingServiceSPI.h>
     
    564565    textBaselineOrigin = [_webView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
    565566
    566     WKShowWordDefinitionWindow(popupInfo.attributedString.get(), textBaselineOrigin, popupInfo.options.get());
     567    [getLULookupDefinitionModuleClass() showDefinitionForTerm:popupInfo.attributedString.get() atLocation:textBaselineOrigin options:popupInfo.options.get()];
    567568}
    568569
     
    690691    NSString *title = nil;
    691692    NSImage *image = nil;
     693    bool enabled = true;
    692694
    693695    switch (tag) {
     
    720722        title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
    721723        image = [NSImage imageNamed:@"NSActionMenuLookup"];
     724        enabled = getLULookupDefinitionModuleClass();
    722725        break;
    723726
     
    782785    [item setTarget:self];
    783786    [item setTag:tag];
     787    [item setEnabled:enabled];
    784788    return item;
    785789}
  • trunk/Source/WebKit2/ChangeLog

    r176156 r176164  
     12014-11-16  Tim Horton  <timothy_horton@apple.com>
     2
     3        Use TextIndicator instead of the built in Lookup highlight
     4        https://bugs.webkit.org/show_bug.cgi?id=138775
     5        <rdar://problem/18953982>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        In order to make the yellow highlight for Lookup more accurately match the
     10        painted content of the web page (in light of e.g. Web fonts, and interesting
     11        text features that only WebKit implements and cannot round-trip through
     12        NSAttributedString), use a TextIndicator instead of the built-in Lookup
     13        highlight where possible.
     14
     15        * Configurations/BaseTarget.xcconfig:
     16        Make it possible to include headers from private frameworks. This matches WebCore.
     17
     18        * Shared/DictionaryPopupInfo.cpp:
     19        (WebKit::DictionaryPopupInfo::encode):
     20        (WebKit::DictionaryPopupInfo::decode):
     21        * Shared/DictionaryPopupInfo.h:
     22        Include the attributed string inside the DictionaryPopupInfo, instead of
     23        as a secondary argument to DidPerformDictionaryLookup.
     24        Add a TextIndicator to DictionaryPopupInfo, which can be used to highlight
     25        the text in the UI process.
     26
     27        * UIProcess/API/mac/WKView.mm:
     28        (-[WKView dealloc]):
     29        (-[WKView viewDidMoveToWindow]):
     30        (-[WKView _dictionaryLookupPopoverWillClose:]):
     31        (-[WKView _setTextIndicator:fadeOut:animate:animationCompletionHandler:]):
     32        (-[WKView _setTextIndicator:fadeOut:animate:]):
     33        (-[WKView initWithFrame:context:configuration:webView:]):
     34        (+[WKView hideWordDefinitionWindow]):
     35        * UIProcess/API/mac/WKViewInternal.h:
     36        Adopt the Lookup SPI header.
     37        If we have the requisite API, register the notification that Lookup sends
     38        when the popover closes, and hook that up to hide the text indicator.
     39        Add a version of _setTextIndicator: that takes an animation completion handler.
     40
     41        * UIProcess/PageClient.h:
     42        * UIProcess/WebPageProxy.h:
     43        * UIProcess/WebPageProxy.messages.in:
     44        * UIProcess/ios/WebPageProxyIOS.mm:
     45        (WebKit::WebPageProxy::didPerformDictionaryLookup):
     46        * UIProcess/mac/WebPageProxyMac.mm:
     47        (WebKit::WebPageProxy::didPerformDictionaryLookup):
     48        Adjust to the new didPerformDictionaryLookup signature.
     49
     50        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
     51        (InitWebCoreSystemInterface):
     52        Remove a WKSI import.
     53
     54        * UIProcess/mac/PageClientImpl.h:
     55        * UIProcess/mac/PageClientImpl.mm:
     56        (WebKit::PageClientImpl::didPerformDictionaryLookup):
     57        If we have the requisite API, disable Lookup's built-in highlight and
     58        present a TextIndicator instead.
     59        We currently have to run the animations serially (first bounce the TextIndicator,
     60        then animate in the Lookup popover) because the act of adding the Lookup popover
     61        blocks us from getting any animation events for the TextIndicator, and breaks
     62        the bounce. We could also fix this by using a threaded animation for the TextIndicator,
     63        but it's not clear that it's safe to do so.
     64
     65        (WebKit::PageClientImpl::dismissDictionaryLookupPanel):
     66        When explicitly dismissing the Lookup panel, also hide the text indicator.
     67
     68        * UIProcess/mac/TextIndicatorWindow.h:
     69        * UIProcess/mac/TextIndicatorWindow.mm:
     70        (WebKit::TextIndicatorWindow::setTextIndicator):
     71        Store the completion handler.
     72
     73        (WebKit::TextIndicatorWindow::bounceAnimationDidEnd):
     74        Call the completion handler when the animation completes.
     75
     76        * UIProcess/mac/WKActionMenuController.mm:
     77        (-[WKActionMenuController _createActionMenuItemForTag:]):
     78        Disable the Lookup item if lookup is not available.
     79
     80        * WebProcess/Plugins/PDF/PDFPlugin.mm:
     81        (WebKit::PDFPlugin::showDefinitionForAttributedString):
     82        Adjust to the new didPerformDictionaryLookup signature.
     83        Since PDFPlugin can't trivially repaint the required part of the PDF,
     84        we don't build a TextIndicator. This will result in PDFPlugin continuing
     85        to use Lookup's built-in highlight.
     86       
     87        * WebProcess/WebPage/mac/WebPageMac.mm:
     88        (WebKit::WebPage::performDictionaryLookupForRange):
     89        Build a TextIndicator from the Lookup range and pass it along with
     90        the DictionaryPopupInfo.
     91
    1922014-11-15  David Kilzer  <ddkilzer@apple.com>
    293
  • trunk/Source/WebKit2/Configurations/BaseTarget.xcconfig

    r168550 r176164  
    3030HEADER_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);
    3131
    32 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;
     32OTHER_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;
    3333OTHER_CPLUSPLUSFLAGS = $(OTHER_CFLAGS);
    3434
  • trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp

    r163886 r176164  
    3838{
    3939    encoder << origin;
     40    encoder << textIndicator;
    4041
    4142#if PLATFORM(COCOA)
     
    4445    if (hadOptions)
    4546        IPC::encode(encoder, options.get());
     47
     48    encoder << attributedString;
    4649#endif
    4750}
     
    5154    if (!decoder.decode(result.origin))
    5255        return false;
     56
     57    if (!decoder.decode(result.textIndicator))
     58        return false;
     59
    5360#if PLATFORM(COCOA)
    5461    bool hadOptions;
     
    5966            return false;
    6067    }
     68
     69    if (!decoder.decode(result.attributedString))
     70        return false;
    6171#endif
    6272    return true;
  • trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h

    r163886 r176164  
    2727#define DictionaryPopupInfo_h
    2828
     29#include "TextIndicator.h"
    2930#include <WebCore/FloatPoint.h>
    3031
    3132#if PLATFORM(COCOA)
     33#include "AttributedString.h"
    3234#include <wtf/RetainPtr.h>
    3335#endif
    3436
    3537namespace IPC {
    36     class ArgumentDecoder;
    37     class ArgumentEncoder;
     38class ArgumentDecoder;
     39class ArgumentEncoder;
    3840}
    3941
     
    4547
    4648    WebCore::FloatPoint origin;
     49    TextIndicator::Data textIndicator;
    4750#if PLATFORM(COCOA)
    4851    RetainPtr<CFDictionaryRef> options;
     52    AttributedString attributedString;
    4953#endif
    5054};
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r175985 r176164  
    8989#import <WebCore/KeyboardEvent.h>
    9090#import <WebCore/LocalizedStrings.h>
     91#import <WebCore/LookupSPI.h>
    9192#import <WebCore/NSViewSPI.h>
    9293#import <WebCore/PlatformEventFactoryMac.h>
     
    325326
    326327    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp];
     328
     329    if (canDisableLookupIndicator())
     330        [[NSNotificationCenter defaultCenter] removeObserver:self name:getLUNotificationPopoverWillClose() object:nil];
    327331
    328332    WebContext::statistics().wkViewCount--;
     
    25542558        _data->_flagsChangedEventMonitor = nil;
    25552559
    2556         WKHideWordDefinitionWindow();
     2560        if (getLULookupDefinitionModuleClass())
     2561            [getLULookupDefinitionModuleClass() hideDefinition];
    25572562        [self _dismissActionMenuPopovers];
    25582563    }
     
    26882693{
    26892694    _data->_page->process().context().applicationWillTerminate();
     2695}
     2696
     2697- (void)_dictionaryLookupPopoverWillClose:(NSNotification *)notification
     2698{
     2699    [self _setTextIndicator:nil fadeOut:NO animate:NO];
    26902700}
    26912701
     
    30583068}
    30593069
    3060 - (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate
     3070- (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate animationCompletionHandler:(std::function<void ()>)completionHandler
    30613071{
    30623072    if (!textIndicator) {
     
    30683078        _data->_textIndicatorWindow = std::make_unique<TextIndicatorWindow>(self);
    30693079
    3070     _data->_textIndicatorWindow->setTextIndicator(textIndicator, fadeOut, animate);
     3080    _data->_textIndicatorWindow->setTextIndicator(textIndicator, fadeOut, animate, WTF::move(completionHandler));
     3081}
     3082
     3083- (void)_setTextIndicator:(PassRefPtr<TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate
     3084{
     3085    [self _setTextIndicator:textIndicator fadeOut:fadeOut animate:animate animationCompletionHandler:[] {}];
    30713086}
    30723087
     
    35603575    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp];
    35613576
     3577    if (canDisableLookupIndicator())
     3578        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
     3579
    35623580#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    35633581    if ([self respondsToSelector:@selector(setActionMenu:)]) {
     
    38073825+ (void)hideWordDefinitionWindow
    38083826{
    3809     WKHideWordDefinitionWindow();
     3827    if (!getLULookupDefinitionModuleClass())
     3828        return;
     3829    [getLULookupDefinitionModuleClass() hideDefinition];
    38103830}
    38113831
  • trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h

    r175973 r176164  
    8282- (NSRect)_convertToUserSpace:(NSRect)rect;
    8383- (void)_setTextIndicator:(PassRefPtr<WebKit::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate;
     84- (void)_setTextIndicator:(PassRefPtr<WebKit::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut animate:(BOOL)animate animationCompletionHandler:(std::function<void ()>)completionHandler;
    8485
    8586- (void)_setAcceleratedCompositingModeRootLayer:(CALayer *)rootLayer;
  • trunk/Source/WebKit2/UIProcess/PageClient.h

    r175966 r176164  
    224224    virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0;
    225225    virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0;
    226     virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&) = 0;
     226    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&) = 0;
    227227    virtual void dismissDictionaryLookupPanel() = 0;
    228228    virtual void dismissActionMenuPopovers() = 0;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r176136 r176164  
    11751175
    11761176    // Dictionary.
    1177     void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
     1177    void didPerformDictionaryLookup(const DictionaryPopupInfo&);
    11781178#endif
    11791179
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r176136 r176164  
    298298#if PLATFORM(COCOA)
    299299    # Dictionary support.
    300     DidPerformDictionaryLookup(WebKit::AttributedString text, WebKit::DictionaryPopupInfo dictionaryPopupInfo)
     300    DidPerformDictionaryLookup(WebKit::DictionaryPopupInfo dictionaryPopupInfo)
    301301
    302302    # Keyboard input support messages
  • trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

    r176097 r176164  
    770770}
    771771
    772 void WebPageProxy::didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&)
     772void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo&)
    773773{
    774774    notImplemented();
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h

    r175966 r176164  
    137137    virtual void makeFirstResponder();
    138138   
    139     virtual void didPerformDictionaryLookup(const AttributedString&, const DictionaryPopupInfo&);
     139    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&);
    140140    virtual void dismissDictionaryLookupPanel();
    141141    virtual void dismissActionMenuPopovers();
  • trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm

    r175973 r176164  
    5959#import <WebCore/Image.h>
    6060#import <WebCore/KeyboardEvent.h>
     61#import <WebCore/LookupSPI.h>
    6162#import <WebCore/NotImplemented.h>
    6263#import <WebCore/SharedBuffer.h>
     
    530531}
    531532
    532 void PageClientImpl::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
    533 {
    534     RetainPtr<NSAttributedString> attributedString = text.string;
     533void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
     534{
     535    if (!getLULookupDefinitionModuleClass())
     536        return;
     537
    535538    NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
    536539
     
    539542    textBaselineOrigin = [m_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
    540543
    541     WKShowWordDefinitionWindow(attributedString.get(), textBaselineOrigin, (NSDictionary *)dictionaryPopupInfo.options.get());
     544    RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
     545
     546    if (canDisableLookupIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
     547        // Run the animations serially because attaching another subwindow breaks the bounce animation.
     548        // We could consider making the bounce NSAnimationNonblockingThreaded instead, which seems
     549        // to work, but need to consider all of the implications.
     550        [m_wkView _setTextIndicator:TextIndicator::create(dictionaryPopupInfo.textIndicator) fadeOut:NO animate:YES animationCompletionHandler:[dictionaryPopupInfo, textBaselineOrigin, mutableOptions] {
     551            [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
     552            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
     553        }];
     554    } else
     555        [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
    542556}
    543557
    544558void PageClientImpl::dismissDictionaryLookupPanel()
    545559{
     560    if (!getLULookupDefinitionModuleClass())
     561        return;
     562
    546563    // FIXME: We don't know which panel we are dismissing, it may not even be in the current page (see <rdar://problem/13875766>).
    547     WKHideWordDefinitionWindow();
     564    [getLULookupDefinitionModuleClass() hideDefinition];
     565    setTextIndicator(nil, false, true);
    548566}
    549567
  • trunk/Source/WebKit2/UIProcess/mac/TextIndicatorWindow.h

    r175476 r176164  
    3030
    3131#import "WebKitSystemInterface.h"
     32#import <functional>
    3233#import <wtf/Noncopyable.h>
    3334#import <wtf/RefPtr.h>
     
    4950    ~TextIndicatorWindow();
    5051
    51     void setTextIndicator(PassRefPtr<TextIndicator>, bool fadeOut, bool animate);
     52    void setTextIndicator(PassRefPtr<TextIndicator>, bool fadeOut, bool animate, std::function<void ()> animationCompletionHandler);
    5253
    5354private:
     
    7172    RunLoop::Timer<TextIndicatorWindow> m_startFadeOutTimer;
    7273    RetainPtr<WKTextIndicatorWindowAnimation> m_fadeOutAnimation;
     74
     75    std::function<void ()> m_bounceAnimationCompletionHandler;
    7376};
    7477
  • trunk/Source/WebKit2/UIProcess/mac/TextIndicatorWindow.mm

    r175476 r176164  
    121121}
    122122
    123 void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicator, bool fadeOut, bool animate)
     123void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicator, bool fadeOut, bool animate, std::function<void ()> animationCompletionHandler)
    124124{
    125125    if (m_textIndicator == textIndicator)
     
    155155
    156156    if (animate) {
     157        m_bounceAnimationCompletionHandler = WTF::move(animationCompletionHandler);
    157158        // Start the bounce animation.
    158159        m_bounceAnimationContext = WKWindowBounceAnimationContextCreate(m_textIndicatorWindow.get());
     
    231232    WKWindowBounceAnimationContextDestroy(m_bounceAnimationContext);
    232233    m_bounceAnimationContext = 0;
     234    m_bounceAnimationCompletionHandler();
    233235}
    234236
  • trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm

    r176153 r176164  
    4646#import <WebCore/GeometryUtilities.h>
    4747#import <WebCore/LocalizedStrings.h>
     48#import <WebCore/LookupSPI.h>
    4849#import <WebCore/NSSharingServiceSPI.h>
    4950#import <WebCore/NSSharingServicePickerSPI.h>
     
    757758    NSString *title = nil;
    758759    NSImage *image = nil;
     760    bool enabled = true;
    759761
    760762    switch (tag) {
     
    812814        title = WEB_UI_STRING_KEY("Look Up", "Look Up (action menu item)", "action menu item");
    813815        image = [NSImage imageNamed:@"NSActionMenuLookup"];
     816        enabled = getLULookupDefinitionModuleClass();
    814817        break;
    815818
     
    851854    [item setTarget:self];
    852855    [item setTag:tag];
     856    [item setEnabled:enabled];
    853857    return item;
    854858}
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r175966 r176164  
    451451}
    452452
    453 void WebPageProxy::didPerformDictionaryLookup(const AttributedString& text, const DictionaryPopupInfo& dictionaryPopupInfo)
    454 {
    455     m_pageClient.didPerformDictionaryLookup(text, dictionaryPopupInfo);
     453void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
     454{
     455    m_pageClient.didPerformDictionaryLookup(dictionaryPopupInfo);
    456456}
    457457   
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm

    r173272 r176164  
    17001700    DictionaryPopupInfo dictionaryPopupInfo;
    17011701    dictionaryPopupInfo.origin = convertFromPDFViewToRootView(IntPoint(point));
    1702 
    1703     AttributedString attributedString;
    1704     attributedString.string = string;
    1705 
    1706     webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
     1702    dictionaryPopupInfo.attributedString.string = string;
     1703
     1704    webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
    17071705}
    17081706
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

    r176112 r176164  
    127127        INIT(RecommendedScrollerStyle);
    128128        INIT(ExecutableWasLinkedOnOrBeforeSnowLeopard);
    129         INIT(ExtractWordDefinitionTokenRangeFromContextualString);
    130129        INIT(CopyDefaultSearchProviderDisplayName);
    131130        INIT(Cursor);
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r176137 r176164  
    549549    }];
    550550
    551     AttributedString attributedString;
    552     attributedString.string = scaledNSAttributedString;
    553 
    554     send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
     551    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range);
     552    if (!textIndicator)
     553        return;
     554
     555    dictionaryPopupInfo.textIndicator = textIndicator->data();
     556    dictionaryPopupInfo.attributedString.string = scaledNSAttributedString;
     557
     558    send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
    555559}
    556560
Note: See TracChangeset for help on using the changeset viewer.