Changeset 245153 in webkit


Ignore:
Timestamp:
May 9, 2019 12:42:44 PM (5 years ago)
Author:
dino@apple.com
Message:

Guard long press link preview with a USE macro rather than complicated includes
https://bugs.webkit.org/show_bug.cgi?id=197728
<rdar://problem/50604700>

Reviewed by Wenson Hsieh.

It was getting complicated to manage the coordination between WebKitAdditions
and WebKit without having to split up the includes into multiple files
or have lots of duplication.

Instead, WebKitAdditions will now define a USE macro which can be used
in various places through WebKit.

  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView dragInteraction:itemsForBeginningSession:]):
(-[WKContentView _contentsOfUserInterfaceItem:]):
(previewIdentifierForElementAction):
(-[WKContentView shouldUsePreviewForLongPress]):
(-[WKContentView _registerPreview]):
(-[WKContentView _unregisterPreview]):
(shouldUsePreviewForLongPress): Deleted.
(-[WKContentView _registerPreviewLongPress]): Deleted.
(-[WKContentView _unregisterPreviewLongPress]): Deleted.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245151 r245153  
     12019-05-08  Dean Jackson  <dino@apple.com>
     2
     3        Guard long press link preview with a USE macro rather than complicated includes
     4        https://bugs.webkit.org/show_bug.cgi?id=197728
     5        <rdar://problem/50604700>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        It was getting complicated to manage the coordination between WebKitAdditions
     10        and WebKit without having to split up the includes into multiple files
     11        or have lots of duplication.
     12
     13        Instead, WebKitAdditions will now define a USE macro which can be used
     14        in various places through WebKit.
     15
     16        * UIProcess/ios/WKContentViewInteraction.h:
     17        * UIProcess/ios/WKContentViewInteraction.mm:
     18        (-[WKContentView dragInteraction:itemsForBeginningSession:]):
     19        (-[WKContentView _contentsOfUserInterfaceItem:]):
     20        (previewIdentifierForElementAction):
     21        (-[WKContentView shouldUsePreviewForLongPress]):
     22        (-[WKContentView _registerPreview]):
     23        (-[WKContentView _unregisterPreview]):
     24        (shouldUsePreviewForLongPress): Deleted.
     25        (-[WKContentView _registerPreviewLongPress]): Deleted.
     26        (-[WKContentView _unregisterPreviewLongPress]): Deleted.
     27
    1282019-05-09  Alex Christensen  <achristensen@webkit.org>
    229
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r245112 r245153  
    6262#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKInteractionPreviewAdditions.h>)
    6363#import <WebKitAdditions/WKInteractionPreviewAdditions.h>
    64 #else
    65 #ifndef ADDITIONAL_LINK_PREVIEW_MEMBERS
    66 #define ADDITIONAL_LINK_PREVIEW_MEMBERS
    67 #endif
    68 #ifndef ADDITIONAL_LINK_PREVIEW_PROTOCOLS
    69 #define ADDITIONAL_LINK_PREVIEW_PROTOCOLS
    70 #endif
    7164#endif
    7265
     
    256249    Vector<bool> _focusStateStack;
    257250#if HAVE(LINK_PREVIEW)
     251#if USE(LONG_PRESS_FOR_LINK_PREVIEW)
     252    LONG_PRESS_LINK_PREVIEW_MEMBERS
     253#else
    258254    RetainPtr<UIPreviewItemController> _previewItemController;
    259     ADDITIONAL_LINK_PREVIEW_MEMBERS
     255#endif
    260256#endif
    261257
     
    528524
    529525#if HAVE(LINK_PREVIEW)
    530 @interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate ADDITIONAL_LINK_PREVIEW_PROTOCOLS>
     526#if USE(LONG_PRESS_FOR_LINK_PREVIEW)
     527@interface WKContentView (WKInteractionPreview) <LONG_PRESS_LINK_PREVIEW_PROTOCOL>
     528#else
     529@interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
     530#endif
    531531
    532532@property (nonatomic, readonly) BOOL shouldUsePreviewForLongPress;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r245148 r245153  
    72167216#if HAVE(LINK_PREVIEW)
    72177217    if ([userInterfaceItem isEqualToString:@"linkPreviewPopoverContents"]) {
     7218#if USE(LONG_PRESS_FOR_LINK_PREVIEW)
     7219        return @{ userInterfaceItem: @{ @"pageURL": WTF::userVisibleString(_positionInformation.url) } };
     7220#else
    72187221        NSString *url = [_previewItemController previewData][UIPreviewDataLink];
    72197222        return @{ userInterfaceItem: @{ @"pageURL": url } };
     7223#endif
    72207224    }
    72217225#endif
     
    72347238#if HAVE(LINK_PREVIEW)
    72357239
    7236 @implementation WKContentView (WKInteractionPreview)
    7237 
    7238 #if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKInteractionPreviewAdditions.mm>)
     7240static NSString *previewIdentifierForElementAction(_WKElementAction *action)
     7241{
     7242    switch (action.type) {
     7243    case _WKElementActionTypeOpen:
     7244        return WKPreviewActionItemIdentifierOpen;
     7245    case _WKElementActionTypeCopy:
     7246        return WKPreviewActionItemIdentifierCopy;
     7247#if !defined(TARGET_OS_IOS) || TARGET_OS_IOS
     7248    case _WKElementActionTypeAddToReadingList:
     7249        return WKPreviewActionItemIdentifierAddToReadingList;
     7250#endif
     7251    case _WKElementActionTypeShare:
     7252        return WKPreviewActionItemIdentifierShare;
     7253    default:
     7254        return nil;
     7255    }
     7256    ASSERT_NOT_REACHED();
     7257    return nil;
     7258}
     7259
     7260#if USE(LONG_PRESS_FOR_LINK_PREVIEW)
    72397261#include <WebKitAdditions/WKInteractionPreviewAdditions.mm>
    72407262#else
    7241 static BOOL shouldUsePreviewForLongPress()
     7263
     7264@implementation WKContentView (WKInteractionPreview)
     7265
     7266- (BOOL)shouldUsePreviewForLongPress
    72427267{
    72437268    return NO;
    72447269}
    72457270
    7246 - (void)_registerPreviewLongPress
    7247 {
    7248 }
    7249 
    7250 - (void)_unregisterPreviewLongPress
    7251 {
    7252 }
    7253 #endif
    7254 
    7255 - (BOOL)shouldUsePreviewForLongPress
    7256 {
    7257     return shouldUsePreviewForLongPress();
    7258 }
    7259 
    72607271- (void)_registerPreview
    72617272{
     
    72637274        return;
    72647275
    7265     if (shouldUsePreviewForLongPress())
    7266         [self _registerPreviewLongPress];
    7267     else {
    7268         _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
    7269         [_previewItemController setDelegate:self];
    7270         _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;
    7271         if ([_previewItemController respondsToSelector:@selector(presentationSecondaryGestureRecognizer)])
    7272             _previewSecondaryGestureRecognizer = _previewItemController.get().presentationSecondaryGestureRecognizer;
    7273     }
     7276    _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
     7277    [_previewItemController setDelegate:self];
     7278    _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;
     7279    if ([_previewItemController respondsToSelector:@selector(presentationSecondaryGestureRecognizer)])
     7280        _previewSecondaryGestureRecognizer = _previewItemController.get().presentationSecondaryGestureRecognizer;
    72747281}
    72757282
    72767283- (void)_unregisterPreview
    72777284{
    7278     if (shouldUsePreviewForLongPress())
    7279         [self _unregisterPreviewLongPress];
    7280     else {
    7281         [_previewItemController setDelegate:nil];
    7282         _previewGestureRecognizer = nil;
    7283         _previewSecondaryGestureRecognizer = nil;
    7284         _previewItemController = nil;
    7285     }
     7285    [_previewItemController setDelegate:nil];
     7286    _previewGestureRecognizer = nil;
     7287    _previewSecondaryGestureRecognizer = nil;
     7288    _previewItemController = nil;
    72867289}
    72877290
     
    74177420}
    74187421
    7419 static NSString *previewIdentifierForElementAction(_WKElementAction *action)
    7420 {
    7421     switch (action.type) {
    7422     case _WKElementActionTypeOpen:
    7423         return WKPreviewActionItemIdentifierOpen;
    7424     case _WKElementActionTypeCopy:
    7425         return WKPreviewActionItemIdentifierCopy;
    7426 #if !defined(TARGET_OS_IOS) || TARGET_OS_IOS
    7427     case _WKElementActionTypeAddToReadingList:
    7428         return WKPreviewActionItemIdentifierAddToReadingList;
    7429 #endif
    7430     case _WKElementActionTypeShare:
    7431         return WKPreviewActionItemIdentifierShare;
    7432     default:
    7433         return nil;
    7434     }
    7435     ASSERT_NOT_REACHED();
    7436     return nil;
    7437 }
    7438 
    74397422- (UIViewController *)_presentedViewControllerForPreviewItemController:(UIPreviewItemController *)controller
    74407423{
     
    76077590@end
    76087591
     7592#endif // USE(LONG_PRESS_FOR_LINK_PREVIEW)
     7593
    76097594#endif // HAVE(LINK_PREVIEW)
    76107595
Note: See TracChangeset for help on using the changeset viewer.