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

Changeset 176680 in webkit


Ignore:
Timestamp:
Dec 2, 2014, 11:38:05 AM (12 years ago)
Author:
timothy_horton@apple.com
Message:

Implement Lookup transition from selection for Legacy WebKit
https://bugs.webkit.org/show_bug.cgi?id=139180
<rdar://problem/19067172>

Reviewed by Beth Dakin.

  • WebView/DictionaryPopupInfo.h: Added.

Split DictionaryPopupInfo out into its own file.

  • WebView/WebActionMenuController.mm:

(-[WebActionMenuController _lookupText:]):
Hand the DictionaryPopupInfo to WebView, which will show the TextIndicator and invoke Lookup.

(performDictionaryLookupForSelection):
(performDictionaryLookupForRange):
Plumb the transition style through these helpers.
Create a TextIndicator from the selection range.

  • WebView/WebHTMLView.mm:

(-[WebHTMLView _lookUpInDictionaryFromMenu:]):
Make use of TextIndicator (and DictionaryPopupInfo, and the new
_showDictionaryLookupPopup on WebView) to add a transition from blue
when performing Lookup from the context menu.

(-[WebHTMLView quickLookWithEvent:]):
Remove our TextIndicator whenever a normal three-finger-tap event
comes through, as it will have its own indication.

  • WebView/WebView.mm:

(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView _dictionaryLookupPopoverWillClose:]):
Register for the LUNotificationPopoverWillClose notification and remove
our TextIndicator when it is called, just like in WebKit2.
Deregistration is already handled in _close.

(-[WebView _showDictionaryLookupPopup:]):
Just like WebKit2, show our TextIndicator and tell Lookup not to show its own,
if the relevant API is available.

  • WebView/WebViewInternal.h:
  • WebKit.xcodeproj/project.pbxproj:

Add mac/WebView/DictionaryPopupInfo.h.

Location:
trunk/Source/WebKit
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r176614 r176680  
     12014-12-02  Tim Horton  <timothy_horton@apple.com>
     2
     3        Implement Lookup transition from selection for Legacy WebKit
     4        https://bugs.webkit.org/show_bug.cgi?id=139180
     5        <rdar://problem/19067172>
     6
     7        Reviewed by Beth Dakin.
     8
     9        * WebKit.xcodeproj/project.pbxproj:
     10        Add mac/WebView/DictionaryPopupInfo.h.
     11
    1122014-12-01  Anders Carlsson  <andersca@apple.com>
    213
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r176551 r176680  
    8686                2DD632C219E5D1F0002E9C7B /* WebSelectionServiceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD632C019E5D1F0002E9C7B /* WebSelectionServiceController.h */; };
    8787                2DD632C319E5D1F0002E9C7B /* WebSelectionServiceController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD632C119E5D1F0002E9C7B /* WebSelectionServiceController.mm */; };
     88                2DF064A91A2DD53C00DBB354 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */; };
    8889                312E2FE514E48182007CCA18 /* WebNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 312E2FE314E48182007CCA18 /* WebNotification.h */; settings = {ATTRIBUTES = (Private, ); }; };
    8990                312E2FE614E48182007CCA18 /* WebNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 312E2FE414E48182007CCA18 /* WebNotification.mm */; };
     
    537538                2DD632C019E5D1F0002E9C7B /* WebSelectionServiceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSelectionServiceController.h; sourceTree = "<group>"; };
    538539                2DD632C119E5D1F0002E9C7B /* WebSelectionServiceController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSelectionServiceController.mm; sourceTree = "<group>"; };
     540                2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryPopupInfo.h; sourceTree = "<group>"; };
    539541                312E2FE314E48182007CCA18 /* WebNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotification.h; sourceTree = "<group>"; };
    540542                312E2FE414E48182007CCA18 /* WebNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotification.mm; sourceTree = "<group>"; };
     
    12871289                                51E94C0706C02CA300A9B09E /* PDF */,
    12881290                                A10C1D79182030190036883A /* ios */,
     1291                                2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */,
    12891292                                935D44E219F9AFF000FB5306 /* WebActionMenuController.h */,
    12901293                                935D44E319F9AFF000FB5306 /* WebActionMenuController.mm */,
     
    18021805                                9398106D0824BF01008DF038 /* WebKitErrorsPrivate.h in Headers */,
    18031806                                CD8BFCE815531224005AFB25 /* WebKitFullScreenListener.h in Headers */,
     1807                                2DF064A91A2DD53C00DBB354 /* DictionaryPopupInfo.h in Headers */,
    18041808                                9398101D0824BF01008DF038 /* WebKitLogging.h in Headers */,
    18051809                                9398101E0824BF01008DF038 /* WebKitNSStringExtras.h in Headers */,
  • trunk/Source/WebKit/mac/ChangeLog

    r176670 r176680  
     12014-12-02  Tim Horton  <timothy_horton@apple.com>
     2
     3        Implement Lookup transition from selection for Legacy WebKit
     4        https://bugs.webkit.org/show_bug.cgi?id=139180
     5        <rdar://problem/19067172>
     6
     7        Reviewed by Beth Dakin.
     8
     9        * WebView/DictionaryPopupInfo.h: Added.
     10        Split DictionaryPopupInfo out into its own file.
     11
     12        * WebView/WebActionMenuController.mm:
     13        (-[WebActionMenuController _lookupText:]):
     14        Hand the DictionaryPopupInfo to WebView, which will show the TextIndicator and invoke Lookup.
     15
     16        (performDictionaryLookupForSelection):
     17        (performDictionaryLookupForRange):
     18        Plumb the transition style through these helpers.
     19        Create a TextIndicator from the selection range.
     20
     21        * WebView/WebHTMLView.mm:
     22        (-[WebHTMLView _lookUpInDictionaryFromMenu:]):
     23        Make use of TextIndicator (and DictionaryPopupInfo, and the new
     24        _showDictionaryLookupPopup on WebView) to add a transition from blue
     25        when performing Lookup from the context menu.
     26
     27        (-[WebHTMLView quickLookWithEvent:]):
     28        Remove our TextIndicator whenever a normal three-finger-tap event
     29        comes through, as it will have its own indication.
     30
     31        * WebView/WebView.mm:
     32        (-[WebView _commonInitializationWithFrameName:groupName:]):
     33        (-[WebView _dictionaryLookupPopoverWillClose:]):
     34        Register for the LUNotificationPopoverWillClose notification and remove
     35        our TextIndicator when it is called, just like in WebKit2.
     36        Deregistration is already handled in _close.
     37
     38        (-[WebView _showDictionaryLookupPopup:]):
     39        Just like WebKit2, show our TextIndicator and tell Lookup not to show its own,
     40        if the relevant API is available.
     41
     42        * WebView/WebViewInternal.h:
     43
    1442014-12-02  Anders Carlsson  <andersca@apple.com>
    245
  • trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm

    r176608 r176680  
    3131#import "DOMNodeInternal.h"
    3232#import "DOMRangeInternal.h"
     33#import "DictionaryPopupInfo.h"
    3334#import "WebDocumentInternal.h"
    3435#import "WebElementDictionary.h"
     
    8788using namespace WebCore;
    8889
    89 struct DictionaryPopupInfo {
    90     NSPoint origin;
    91     RetainPtr<NSDictionary> options;
    92     RetainPtr<NSAttributedString> attributedString;
    93 };
    94 
    9590@implementation WebActionMenuController
    9691
     
    634629
    635630    DictionaryPopupInfo popupInfo = performDictionaryLookupForSelection(frame, frame->selection().selection());
    636     if (!popupInfo.attributedString)
    637         return;
    638 
    639     NSPoint textBaselineOrigin = popupInfo.origin;
    640 
    641     // Convert to screen coordinates.
    642     textBaselineOrigin = [_webView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
    643 
    644     [getLULookupDefinitionModuleClass() showDefinitionForTerm:popupInfo.attributedString.get() atLocation:textBaselineOrigin options:popupInfo.options.get()];
     631    [_webView _showDictionaryLookupPopup:popupInfo];
    645632}
    646633
     
    682669    RefPtr<Range> selectedRange = rangeForDictionaryLookupForSelection(selection, &options);
    683670    if (selectedRange)
    684         popupInfo = performDictionaryLookupForRange(frame, *selectedRange, options);
     671        popupInfo = performDictionaryLookupForRange(frame, *selectedRange, options, TextIndicatorPresentationTransition::BounceAndCrossfade);
    685672    return popupInfo;
    686673}
    687674
    688 static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range& range, NSDictionary *options)
     675static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
    689676{
    690677    DictionaryPopupInfo popupInfo;
     
    722709
    723710    popupInfo.attributedString = scaledNSAttributedString.get();
     711    popupInfo.textIndicator = TextIndicator::createWithRange(range, presentationTransition);
    724712    return popupInfo;
    725713}
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r176608 r176680  
    3535#import "DOMNodeInternal.h"
    3636#import "DOMRangeInternal.h"
     37#import "DictionaryPopupInfo.h"
    3738#import "WebActionMenuController.h"
    3839#import "WebArchive.h"
     
    116117#import <WebCore/Text.h>
    117118#import <WebCore/TextAlternativeWithRange.h>
     119#import <WebCore/TextIndicator.h>
    118120#import <WebCore/TextUndoInsertionMarkupMac.h>
    119121#import <WebCore/WebCoreObjCExtras.h>
     
    56355637    NSRect rect = coreFrame->selection().selectionBounds();
    56365638
    5637     NSDictionary *attributes = [attrString fontAttributesInRange:NSMakeRange(0,1)];
     5639    NSDictionary *attributes = [attrString fontAttributesInRange:NSMakeRange(0, 1)];
    56385640    NSFont *font = [attributes objectForKey:NSFontAttributeName];
    56395641    if (font)
    5640         rect.origin.y += [font ascender];
    5641 
    5642     [self showDefinitionForAttributedString:attrString atPoint:rect.origin];
     5642        rect.origin.y += [font descender];
     5643
     5644    DictionaryPopupInfo info;
     5645    info.attributedString = attrString;
     5646    info.origin = coreFrame->view()->contentsToWindow(enclosingIntRect(rect)).location();
     5647    info.textIndicator = TextIndicator::createWithSelectionInFrame(*coreFrame, TextIndicatorPresentationTransition::BounceAndCrossfade);
     5648    [[self _webView] _showDictionaryLookupPopup:info];
     5649}
     5650
     5651- (void)quickLookWithEvent:(NSEvent *)event
     5652{
     5653    [[self _webView] _setTextIndicator:nullptr fadeOut:NO animationCompletionHandler:[] { }];
     5654    [super quickLookWithEvent:event];
    56435655}
    56445656#endif // !PLATFORM(IOS)
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r176670 r176680  
    3636#import "DOMNodeInternal.h"
    3737#import "DOMRangeInternal.h"
     38#import "DictionaryPopupInfo.h"
    3839#import "WebAlternativeTextClient.h"
    3940#import "WebApplicationCache.h"
     
    213214#import "WebNSPrintOperationExtras.h"
    214215#import "WebPDFView.h"
     216#import <WebCore/LookupSPI.h>
    215217#import <WebCore/NSViewSPI.h>
     218#import <WebCore/SoftLinking.h>
    216219#import <WebCore/TextIndicator.h>
    217220#import <WebCore/TextIndicatorWindow.h>
     
    284287#if ENABLE(GAMEPAD)
    285288#import <WebCore/HIDGamepadProvider.h>
     289#endif
     290
     291#if PLATFORM(MAC)
     292SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
     293SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
    286294#endif
    287295
     
    10221030#if !PLATFORM(IOS)
    10231031    [self _registerDraggedTypes];
     1032
     1033    if (canLoadLUNotificationPopoverWillClose())
     1034        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
    10241035#endif
    10251036
     
    85518562}
    85528563
    8553 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     8564#if PLATFORM(MAC)
     8565#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    85548566- (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
    85558567{
     
    85758587    [_private->actionMenuController didCloseMenu:menu withEvent:event];
    85768588}
     8589
     8590- (WebActionMenuController *)_actionMenuController
     8591{
     8592    return _private->actionMenuController;
     8593}
     8594#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    85778595
    85788596- (void)_setTextIndicator:(TextIndicator *)textIndicator fadeOut:(BOOL)fadeOut animationCompletionHandler:(std::function<void ()>)completionHandler
     
    85948612}
    85958613
    8596 - (WebActionMenuController *)_actionMenuController
    8597 {
    8598     return _private->actionMenuController;
    8599 }
    8600 #endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     8614- (void)_showDictionaryLookupPopup:(const DictionaryPopupInfo&)dictionaryPopupInfo
     8615{
     8616    if (!dictionaryPopupInfo.attributedString)
     8617        return;
     8618
     8619    NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
     8620
     8621    // Convert to screen coordinates.
     8622    textBaselineOrigin = [self.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
     8623
     8624    if (canLoadLUTermOptionDisableSearchTermIndicator()) {
     8625        RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([dictionaryPopupInfo.options mutableCopy]);
     8626        if (!mutableOptions)
     8627            mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
     8628        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
     8629        [self _setTextIndicator:dictionaryPopupInfo.textIndicator.get() fadeOut:NO animationCompletionHandler:[dictionaryPopupInfo, textBaselineOrigin, mutableOptions] {
     8630            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
     8631        }];
     8632    } else
     8633        [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:dictionaryPopupInfo.options.get()];
     8634}
     8635
     8636- (void)_dictionaryLookupPopoverWillClose:(NSNotification *)notification
     8637{
     8638    [self _setTextIndicator:nullptr fadeOut:NO animationCompletionHandler:[] { }];
     8639}
     8640#endif // PLATFORM(MAC)
    86018641
    86028642@end
  • trunk/Source/WebKit/mac/WebView/WebViewInternal.h

    r176608 r176680  
    6060}
    6161
     62struct DictionaryPopupInfo;
    6263class WebSelectionServiceController;
    6364#endif
     
    260261- (void)_setTextIndicator:(WebCore::TextIndicator*)textIndicator fadeOut:(BOOL)fadeOut animationCompletionHandler:(std::function<void ()>)completionHandler;
    261262- (void)_clearTextIndicator;
     263- (void)_showDictionaryLookupPopup:(const DictionaryPopupInfo&)dictionaryPopupInfo;
    262264#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    263265- (WebActionMenuController *)_actionMenuController;
Note: See TracChangeset for help on using the changeset viewer.