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

Changeset 187314 in webkit


Ignore:
Timestamp:
Jul 24, 2015, 12:54:18 AM (11 years ago)
Author:
matthew_hanson@apple.com
Message:

Merge r187193. rdar://problem/21945775

Location:
branches/safari-601.1-branch/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-601.1-branch/Source/WebKit2/ChangeLog

    r187312 r187314  
     12015-07-24  Matthew Hanson  <matthew_hanson@apple.com>
     2
     3        Merge r187193. rdar://problem/21945775
     4
     5    2015-07-22  Tim Horton  <timothy_horton@apple.com>
     6
     7            [iOS] Adjust the preview architecture
     8            https://bugs.webkit.org/show_bug.cgi?id=147203
     9            <rdar://problem/21945775>
     10
     11            Reviewed by Beth Dakin.
     12
     13            * Platform/spi/ios/UIKitSPI.h:
     14            * UIProcess/API/Cocoa/WKWebView.mm:
     15            (-[WKWebView _setAllowsLinkPreview:]): Deleted.
     16            * UIProcess/ios/WKContentView.mm:
     17            (-[WKContentView willMoveToWindow:]): Deleted.
     18            * UIProcess/ios/WKContentViewInteraction.h:
     19            * UIProcess/ios/WKContentViewInteraction.mm:
     20            (-[WKContentView setupInteraction]):
     21            (-[WKContentView cleanupInteraction]):
     22            (-[WKContentView _registerPreview]):
     23            (-[WKContentView _unregisterPreview]):
     24            (-[WKContentView _interactionShouldBeginFromPreviewItemController:forPosition:]):
     25            (-[WKContentView _dataForPreviewItemController:atPosition:type:]):
     26            (-[WKContentView _presentationRectForPreviewItemController:]):
     27            (-[WKContentView _presentedViewControllerForPreviewItemController:]):
     28            (-[WKContentView _previewItemController:commitPreview:]):
     29            (-[WKContentView _previewItemController:willPresentPreview:forPosition:inSourceView:]):
     30            (-[WKContentView _previewItemController:didDismissPreview:committing:]):
     31            (-[WKContentView _presentationSnapshotForPreviewItemController:]):
     32            (-[WKContentView _presentationRectsForPreviewItemController:]):
     33            (-[WKContentView gestureRecognizerShouldBegin:]): Deleted.
     34            (-[WKContentView _registerPreviewInWindow:]): Deleted.
     35            (-[WKContentView _unregisterPreviewInWindow:]): Deleted.
     36            (-[WKContentView previewViewControllerForPosition:inSourceView:]): Deleted.
     37            (-[WKContentView commitPreviewViewController:]): Deleted.
     38            (-[WKContentView willPresentPreviewViewController:forPosition:inSourceView:]): Deleted.
     39            (-[WKContentView didDismissPreviewViewController:committing:]): Deleted.
     40            Register and unregister in setup/cleanupInteraction instead of when moving between windows.
     41            Implement 'shouldBegin' instead of interacting directly with the recognizer.
     42            Make use of system enums instead of our own.
     43            Let UIPreviewItemController handle shrink-wrapping and the indicator view.
     44
    1452015-07-24  Matthew Hanson  <matthew_hanson@apple.com>
    246
  • branches/safari-601.1-branch/Source/WebKit2/Platform/spi/ios/UIKitSPI.h

    r186648 r187314  
    4949#import <UIKit/UIPickerView_Private.h>
    5050#import <UIKit/UIPresentationController_Private.h>
     51#import <UIKit/UIPreviewItemController.h>
    5152#import <UIKit/UIResponder_Private.h>
    5253#import <UIKit/UIScrollView_Private.h>
  • branches/safari-601.1-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r187306 r187314  
    30043004
    30053005    _allowsLinkPreview = allowsLinkPreview;
    3006 #if HAVE(LINK_PREVIEW)
    3007     if (_allowsLinkPreview)
    3008         [_contentView _registerPreviewInWindow:[_contentView window]];
    3009     else
    3010         [_contentView _unregisterPreviewInWindow:[_contentView window]];
    3011 #endif
    30123006}
    30133007
  • branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WKContentView.mm

    r186757 r187314  
    269269    if (window) {
    270270        [defaultCenter removeObserver:self name:UIWindowDidMoveToScreenNotification object:window];
    271 #if HAVE(LINK_PREVIEW)
    272         if (_webView._allowsLinkPreview)
    273             [self _unregisterPreviewInWindow:window];
    274 #endif
    275271
    276272        if (!newWindow) {
     
    282278    if (newWindow) {
    283279        [defaultCenter addObserver:self selector:@selector(_windowDidMoveToScreenNotification:) name:UIWindowDidMoveToScreenNotification object:newWindow];
    284 #if HAVE(LINK_PREVIEW)
    285         if (_webView._allowsLinkPreview)
    286             [self _registerPreviewInWindow:newWindow];
    287 #endif
    288280
    289281        [self _updateForScreen:newWindow.screen];
  • branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

    r187062 r187314  
    9595};
    9696
    97 enum class PreviewElementType {
    98     None = 0,
    99     Link,
    100     Image
    101 };
    102 
    10397}
    10498
     
    128122    RetainPtr<WKFileUploadPanel> _fileUploadPanel;
    129123    RetainPtr<UIGestureRecognizer> _previewGestureRecognizer;
    130     WebKit::PreviewElementType _previewType;
     124    RetainPtr<UIPreviewItemController> _previewItemController;
    131125
    132126    std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
     
    153147
    154148    WebKit::WKSelectionDrawingInfo _lastSelectionDrawingInfo;
    155 #if HAVE(LINK_PREVIEW)
    156     id <UIViewControllerPreviewing> _previewing;
    157 #endif
    158 
    159     RetainPtr<UIImageView> _previewIndicatorView;
    160149
    161150    BOOL _isEditable;
     
    219208
    220209#if HAVE(LINK_PREVIEW)
    221 @interface WKContentView (WKInteractionPreview) <UIViewControllerPreviewingDelegate>
    222 
    223 - (void)_registerPreviewInWindow:(UIWindow *)window;
    224 - (void)_unregisterPreviewInWindow:(UIWindow *)window;
     210@interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
     211
     212- (void)_registerPreview;
     213- (void)_unregisterPreview;
    225214@end
    226215#endif
  • branches/safari-601.1-branch/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r187311 r187314  
    342342    [self addGestureRecognizer:_longPressGestureRecognizer.get()];
    343343
     344    [self _registerPreview];
     345
    344346    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_resetShowingTextStyle:) name:UIMenuControllerDidHideMenuNotification object:nil];
    345347    _showingTextStyleOptions = NO;
     
    397399    }
    398400
     401    [self _unregisterPreview];
    399402    if (_fileUploadPanel) {
    400403        [_fileUploadPanel setDelegate:nil];
     
    964967            return [self _actionForLongPress] != nil;
    965968        }
    966     }
    967 
    968     if (gestureRecognizer == _previewGestureRecognizer) {
    969         [self ensurePositionInformationIsUpToDate:point];
    970         if (_positionInformation.clickableElementName != "A" && _positionInformation.clickableElementName != "IMG")
    971             return NO;
    972 
    973         String absoluteLinkURL = _positionInformation.url;
    974         if (_positionInformation.clickableElementName == "A" && (absoluteLinkURL.isEmpty() || !WebCore::protocolIsInHTTPFamily(absoluteLinkURL)))
    975             return NO;
    976969    }
    977970
     
    31943187@implementation WKContentView (WKInteractionPreview)
    31953188
    3196 - (void)_registerPreviewInWindow:(UIWindow *)window
    3197 {
    3198     _previewing = [[window.rootViewController registerForPreviewingWithSourceView:self] retain];
    3199     _previewing.delegate = self;
    3200     _previewGestureRecognizer = _previewing.presentationGestureRecognizer;
    3201     [_previewGestureRecognizer setDelegate:self];
    3202 }
    3203 
    3204 - (void)_unregisterPreviewInWindow:(UIWindow *)window
    3205 {
    3206     [window.rootViewController unregisterPreviewing:_previewing];
    3207     _previewing.delegate = nil;
    3208     [_previewGestureRecognizer setDelegate:nil];
     3189- (void)_registerPreview
     3190{
     3191    _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
     3192    [_previewItemController setDelegate:self];
     3193    _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;
     3194}
     3195
     3196- (void)_unregisterPreview
     3197{
     3198    [_previewItemController setDelegate:nil];
    32093199    _previewGestureRecognizer = nil;
    3210     [_previewing release];
    3211     _previewing = nil;
    3212 }
    3213 
    3214 - (UIViewController *)previewViewControllerForPosition:(CGPoint)position inSourceView:(UIView *)sourceView
    3215 {
    3216     ASSERT(self == sourceView);
    3217 
    3218     _previewType = PreviewElementType::None;
    3219 
    3220     BOOL canShowImagePreview = _positionInformation.clickableElementName == "IMG";
     3200    _previewItemController = nil;
     3201}
     3202
     3203- (BOOL)_interactionShouldBeginFromPreviewItemController:(UIPreviewItemController *)controller forPosition:(CGPoint)position
     3204{
     3205    [self ensurePositionInformationIsUpToDate:position];
     3206    if (_positionInformation.clickableElementName != "A" && _positionInformation.clickableElementName != "IMG")
     3207        return NO;
     3208   
     3209    String absoluteLinkURL = _positionInformation.url;
     3210    if (_positionInformation.clickableElementName == "A") {
     3211        if (absoluteLinkURL.isEmpty())
     3212            return NO;
     3213        if (WebCore::protocolIsInHTTPFamily(absoluteLinkURL))
     3214            return YES;
     3215        NSURL *targetURL = [NSURL _web_URLWithWTFString:_positionInformation.url];
     3216        if ([[getDDDetectionControllerClass() tapAndHoldSchemes] containsObject:[targetURL scheme]])
     3217            return YES;
     3218        return NO;
     3219    }
     3220    return YES;
     3221}
     3222
     3223- (NSDictionary *)_dataForPreviewItemController:(UIPreviewItemController *)controller atPosition:(CGPoint)position type:(UIPreviewItemType *)type
     3224{
     3225    *type = UIPreviewItemTypeNone;
     3226
     3227    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
     3228    BOOL supportsImagePreview = [uiDelegate respondsToSelector:@selector(_webView:commitPreviewedImageWithURL:)];
     3229    BOOL canShowImagePreview = _positionInformation.clickableElementName == "IMG" && supportsImagePreview;
    32213230    BOOL canShowLinkPreview = _positionInformation.clickableElementName == "A" || canShowImagePreview;
     3231    BOOL useImageURLForLink = NO;
     3232
     3233    if (canShowImagePreview && _positionInformation.isAnimatedImage) {
     3234        canShowImagePreview = NO;
     3235        canShowLinkPreview = YES;
     3236        useImageURLForLink = YES;
     3237    }
    32223238
    32233239    if (!canShowLinkPreview && !canShowImagePreview)
     
    32253241
    32263242    String absoluteLinkURL = _positionInformation.url;
    3227     if (absoluteLinkURL.isEmpty() || !WebCore::protocolIsInHTTPFamily(absoluteLinkURL)) {
     3243    if (!useImageURLForLink && (absoluteLinkURL.isEmpty() || !WebCore::protocolIsInHTTPFamily(absoluteLinkURL))) {
    32283244        if (canShowLinkPreview && !canShowImagePreview)
    32293245            return nil;
     
    32313247    }
    32323248
     3249    NSMutableDictionary *dataForPreview = [[[NSMutableDictionary alloc] init] autorelease];
     3250    if (canShowLinkPreview) {
     3251        *type = UIPreviewItemTypeLink;
     3252        if (useImageURLForLink)
     3253            dataForPreview[UIPreviewDataLink] = [NSURL _web_URLWithWTFString:_positionInformation.imageURL];
     3254        else
     3255            dataForPreview[UIPreviewDataLink] = [NSURL _web_URLWithWTFString:_positionInformation.url];
     3256    }
     3257    if (canShowImagePreview) {
     3258        *type = UIPreviewItemTypeImage;
     3259        dataForPreview[UIPreviewDataLink] = [NSURL _web_URLWithWTFString:_positionInformation.imageURL];
     3260    }
     3261   
     3262    return dataForPreview;
     3263}
     3264
     3265- (CGRect)_presentationRectForPreviewItemController:(UIPreviewItemController *)controller
     3266{
     3267    return _positionInformation.bounds;
     3268}
     3269
     3270- (UIViewController *)_presentedViewControllerForPreviewItemController:(UIPreviewItemController *)controller
     3271{
    32333272    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
    32343273
    3235     if (canShowLinkPreview) {
    3236         _previewType = PreviewElementType::Link;
    3237         NSURL *targetURL = [NSURL _web_URLWithWTFString:_positionInformation.url];
     3274    NSURL *targetURL = controller.previewData[UIPreviewDataLink];
     3275    URL coreTargetURL = targetURL;
     3276    bool isValidURLForImagePreview = !coreTargetURL.isEmpty() && (WebCore::protocolIsInHTTPFamily(coreTargetURL) || WebCore::protocolIs(coreTargetURL, "data"));
     3277
     3278    if ([_previewItemController type] == UIPreviewItemTypeLink) {
     3279        // Treat animated images like a link preview
     3280        if (isValidURLForImagePreview && _positionInformation.isAnimatedImage) {
     3281            RetainPtr<_WKActivatedElementInfo> animatedImageElementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
     3282
     3283            if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForAnimatedImageAtURL:defaultActions:elementInfo:imageSize:)]) {
     3284                RetainPtr<NSArray> actions = [_actionSheetAssistant defaultActionsForImageSheet:animatedImageElementInfo.get()];
     3285                _highlightLongPressCanClick = NO;
     3286                return [uiDelegate _webView:_webView previewViewControllerForAnimatedImageAtURL:targetURL defaultActions:actions.get() elementInfo:animatedImageElementInfo.get() imageSize:_positionInformation.image->size()];
     3287            }
     3288        }
     3289
    32383290        RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
     3291
    32393292        RetainPtr<NSArray> actions = [_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()];
    32403293        if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:defaultActions:elementInfo:)]) {
     
    32483301            return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL];
    32493302        }
    3250 #if HAVE(SAFARI_SERVICES_FRAMEWORK)
    3251         SFSafariViewController *previewViewController = [allocSFSafariViewControllerInstance() initWithURL:targetURL];
    3252         previewViewController._showingLinkPreview = YES;
    3253         previewViewController._activatedElementInfo = elementInfo.get();
    3254         previewViewController._previewActions = actions.get();
    3255         _highlightLongPressCanClick = NO;
    3256         _page->startInteractionWithElementAtPosition(_positionInformation.point);
    3257         return [previewViewController autorelease];
    3258 #else
    32593303        return nil;
    3260 #endif
    3261     }
    3262 
    3263     if (canShowImagePreview) {
    3264         if (![uiDelegate respondsToSelector:@selector(_webView:commitPreviewedImageWithURL:)])
     3304    }
     3305
     3306    if ([_previewItemController type] == UIPreviewItemTypeImage) {
     3307        if (!isValidURLForImagePreview)
    32653308            return nil;
    32663309
    3267         String absoluteImageURL = _positionInformation.imageURL;
    3268         if (absoluteImageURL.isEmpty() || !(WebCore::protocolIsInHTTPFamily(absoluteImageURL) || WebCore::protocolIs(absoluteImageURL, "data")))
    3269             return nil;
    3270 
    3271         NSURL *targetURL = [NSURL _web_URLWithWTFString:_positionInformation.imageURL];
    32723310        RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
    32733311        _page->startInteractionWithElementAtPosition(_positionInformation.point);
    32743312
    3275         // Treat animated images like a link preview
    3276         if (_positionInformation.isAnimatedImage) {
    3277             if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForAnimatedImageAtURL:defaultActions:elementInfo:imageSize:)]) {
    3278                 _previewType = PreviewElementType::Link;
    3279                 RetainPtr<NSArray> actions = [_actionSheetAssistant defaultActionsForImageSheet:elementInfo.get()];
    3280                 _highlightLongPressCanClick = NO;
    3281                 return [uiDelegate _webView:_webView previewViewControllerForAnimatedImageAtURL:targetURL defaultActions:actions.get() elementInfo:elementInfo.get() imageSize:_positionInformation.image->size()];
    3282             }
    3283         }
    3284 
    3285         _previewType = PreviewElementType::Image;
    32863313        if ([uiDelegate respondsToSelector:@selector(_webView:willPreviewImageWithURL:)])
    32873314            [uiDelegate _webView:_webView willPreviewImageWithURL:targetURL];
     
    32923319}
    32933320
    3294 - (void)commitPreviewViewController:(UIViewController *)viewController
     3321- (void)_previewItemController:(UIPreviewItemController *)controller commitPreview:(UIViewController *)viewController
    32953322{
    32963323    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
    3297     if (_previewType == PreviewElementType::Image) {
     3324    if ([_previewItemController type] == UIPreviewItemTypeImage) {
    32983325        if ([uiDelegate respondsToSelector:@selector(_webView:commitPreviewedImageWithURL:)]) {
    32993326            String absoluteImageURL = _positionInformation.imageURL;
     
    33113338    }
    33123339
    3313 #if HAVE(SAFARI_SERVICES_FRAMEWORK)
    3314     if (![viewController isKindOfClass:getSFSafariViewControllerClass()])
    3315         return;
    3316 
    3317     SFSafariViewController *safariViewController = (SFSafariViewController *)viewController;
    3318     safariViewController._showingLinkPreview = NO;
    3319 
    3320     viewController.transitioningDelegate = nil;
    3321     viewController.modalPresentationStyle = UIModalPresentationFullScreen;
    3322 
    3323     UIViewController *presentingViewController = viewController.presentingViewController ?: self.window.rootViewController;
    3324     [presentingViewController presentViewController:viewController animated:NO completion:nil];
    3325 #endif
    3326 }
    3327 
    3328 - (void)willPresentPreviewViewController:(UIViewController *)viewController forPosition:(CGPoint)position inSourceView:(UIView *)sourceView
     3340}
     3341
     3342- (void)_previewItemController:(UIPreviewItemController *)controller willPresentPreview:(UIViewController *)viewController forPosition:(CGPoint)position inSourceView:(UIView *)sourceView
    33293343{
    33303344    [self _removeDefaultGestureRecognizers];
    33313345
    33323346    [self _cancelInteraction];
    3333 
    3334     [_previewIndicatorView removeFromSuperview];
    3335 
    3336     float deviceScaleFactor = _page->deviceScaleFactor();
    3337 
    3338     RefPtr<Image> image = _positionInformation.linkIndicator.contentImage;
    3339     if (!image) {
    3340         IntRect sourceRect = _positionInformation.bounds;
    3341         const float marginInPoints = 4;
    3342         sourceRect.inflate(marginInPoints * deviceScaleFactor);
    3343         [[viewController presentationController] setSourceRect:sourceRect];
    3344         [[viewController presentationController] setSourceView:self];
    3345         return;
    3346     }
    3347 
    3348     RetainPtr<UIImage> indicatorImage = adoptNS([[UIImage alloc] initWithCGImage:image->getCGImageRef()]);
    3349     _previewIndicatorView = adoptNS([[UIImageView alloc] initWithImage:indicatorImage.get()]);
    3350 
    3351     const float cornerRadiusInPoints = 5;
    3352     Path path = PathUtilities::pathWithShrinkWrappedRects(_positionInformation.linkIndicator.textRectsInBoundingRectCoordinates, cornerRadiusInPoints * deviceScaleFactor);
    3353     RetainPtr<CAShapeLayer> maskLayer = adoptNS([[CAShapeLayer alloc] init]);
    3354     [maskLayer setPath:path.ensurePlatformPath()];
    3355 
    3356     [_previewIndicatorView layer].mask = maskLayer.get();
    3357     [_previewIndicatorView setFrame:_positionInformation.linkIndicator.textBoundingRectInRootViewCoordinates];
    3358     [self addSubview:_previewIndicatorView.get()];
    3359 
    3360     [[viewController presentationController] setSourceRect:[_previewIndicatorView bounds]];
    3361     [[viewController presentationController] setSourceView:_previewIndicatorView.get()];
    3362 }
    3363 
    3364 - (void)didDismissPreviewViewController:(UIViewController *)viewController committing:(BOOL)committing
     3347}
     3348
     3349- (void)_previewItemController:(UIPreviewItemController *)controller didDismissPreview:(UIViewController *)viewController committing:(BOOL)committing
    33653350{
    33663351    [self _addDefaultGestureRecognizers];
     
    33703355    if ([uiDelegate respondsToSelector:@selector(_webView:didDismissPreviewViewController:)])
    33713356        [uiDelegate _webView:_webView didDismissPreviewViewController:viewController];
    3372 
    3373     [_previewIndicatorView removeFromSuperview];
    3374     _previewIndicatorView = nil;
     3357}
     3358
     3359- (UIImage *)_presentationSnapshotForPreviewItemController:(UIPreviewItemController *)controller
     3360{
     3361    if (!_positionInformation.linkIndicator.contentImage)
     3362        return nullptr;
     3363    return [[[UIImage alloc] initWithCGImage:_positionInformation.linkIndicator.contentImage->getCGImageRef()] autorelease];
     3364}
     3365
     3366- (NSArray *)_presentationRectsForPreviewItemController:(UIPreviewItemController *)controller
     3367{
     3368    RetainPtr<NSMutableArray> rectArray = adoptNS([[NSMutableArray alloc] init]);
     3369
     3370    if (_positionInformation.linkIndicator.contentImage) {
     3371        FloatPoint origin = _positionInformation.linkIndicator.textBoundingRectInRootViewCoordinates.location();
     3372        for (FloatRect& rect : _positionInformation.linkIndicator.textRectsInBoundingRectCoordinates) {
     3373            CGRect cgRect = rect;
     3374            cgRect.origin.x += origin.x();
     3375            cgRect.origin.y += origin.y();
     3376            [rectArray addObject:[NSValue valueWithCGRect:cgRect]];
     3377        }
     3378    } else {
     3379        const float marginInPx = 4 * _page->deviceScaleFactor();
     3380        CGRect cgRect = CGRectInset(_positionInformation.bounds, -marginInPx, -marginInPx);
     3381        [rectArray addObject:[NSValue valueWithCGRect:cgRect]];
     3382    }
     3383
     3384    return rectArray.autorelease();
    33753385}
    33763386
Note: See TracChangeset for help on using the changeset viewer.