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

Changeset 246622 in webkit


Ignore:
Timestamp:
Jun 19, 2019, 5:50:30 PM (7 years ago)
Author:
aestes@apple.com
Message:

[iOS] Fall back to taking a UIView snapshohot for UITargetedPreviews if InteractionInformationAtPosition does not have an image
https://bugs.webkit.org/show_bug.cgi?id=199038
<rdar://problem/50555810>

Reviewed by Tim Horton.

In -contextMenuInteraction:previewForHighlightingMenuWithConfiguration: and friend, we
should always return a non-nil UITargetedPreview. When we do return nil, UIKit uses the web
view itself as the snapshot view, creating an unsightly animation.

For cases where we fail to create a UITargetedPreview from the information in
InteractionInformationAtPosition, this patch falls back to creating a UITargetedPreview with
a snapshot view obtained from
-[UIView resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:].

Also renamed -targetedPreview to -_ensureTargetedPreview and cached the UITargetedPreview
for reuse in -contextMenuInteraction:previewForDismissingMenuWithConfiguration:.

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

(createFallbackTargetedPreview):
(-[WKContentView _ensureTargetedPreview]):
(-[WKContentView contextMenuInteraction:previewForHighlightingMenuWithConfiguration:]):
(-[WKContentView contextMenuInteraction:previewForDismissingMenuWithConfiguration:]):
(-[WKContentView contextMenuInteractionDidEnd:]):
(-[WKContentView _targetedPreview]): Renamed to _ensureTargetedPreview.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246616 r246622  
     12019-06-19  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Fall back to taking a UIView snapshohot for UITargetedPreviews if InteractionInformationAtPosition does not have an image
     4        https://bugs.webkit.org/show_bug.cgi?id=199038
     5        <rdar://problem/50555810>
     6
     7        Reviewed by Tim Horton.
     8
     9        In -contextMenuInteraction:previewForHighlightingMenuWithConfiguration: and friend, we
     10        should always return a non-nil UITargetedPreview. When we do return nil, UIKit uses the web
     11        view itself as the snapshot view, creating an unsightly animation.
     12
     13        For cases where we fail to create a UITargetedPreview from the information in
     14        InteractionInformationAtPosition, this patch falls back to creating a UITargetedPreview with
     15        a snapshot view obtained from
     16        -[UIView resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:].
     17
     18        Also renamed -targetedPreview to -_ensureTargetedPreview and cached the UITargetedPreview
     19        for reuse in -contextMenuInteraction:previewForDismissingMenuWithConfiguration:.
     20
     21        * UIProcess/ios/WKContentViewInteraction.h:
     22        * UIProcess/ios/WKContentViewInteraction.mm:
     23        (createFallbackTargetedPreview):
     24        (-[WKContentView _ensureTargetedPreview]):
     25        (-[WKContentView contextMenuInteraction:previewForHighlightingMenuWithConfiguration:]):
     26        (-[WKContentView contextMenuInteraction:previewForDismissingMenuWithConfiguration:]):
     27        (-[WKContentView contextMenuInteractionDidEnd:]):
     28        (-[WKContentView _targetedPreview]): Renamed to _ensureTargetedPreview.
     29
    1302019-06-19  Devin Rousso  <drousso@apple.com>
    231
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r246583 r246622  
    9696@class _UIWebHighlightLongPressGestureRecognizer;
    9797@class UIHoverGestureRecognizer;
     98@class UITargetedPreview;
    9899@class WebEvent;
    99100@class WKActionSheetAssistant;
     
    250251    RetainPtr<UIMenu> _contextMenuLegacyMenu;
    251252    BOOL _contextMenuHasRequestedLegacyData;
     253    RetainPtr<UITargetedPreview> _contextMenuInteractionTargetedPreview;
    252254#else
    253255    RetainPtr<UIPreviewItemController> _previewItemController;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r246583 r246622  
    78607860}
    78617861
    7862 - (UITargetedPreview *)_targetedPreview
    7863 {
     7862static RetainPtr<UITargetedPreview> createFallbackTargetedPreview(UIView *rootView, UIView *containerView, const WebCore::FloatRect& frameInRootViewCoordinates)
     7863{
     7864    auto parameters = adoptNS([[UIPreviewParameters alloc] init]);
     7865    UIView *snapshotView = [rootView resizableSnapshotViewFromRect:frameInRootViewCoordinates afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero];
     7866
     7867    CGRect frameInContainerViewCoordinates = [rootView convertRect:frameInRootViewCoordinates toView:containerView];
     7868    snapshotView.frame = frameInContainerViewCoordinates;
     7869
     7870    CGPoint centerInContainerViewCoordinates = CGPointMake(CGRectGetMidX(frameInContainerViewCoordinates), CGRectGetMidY(frameInContainerViewCoordinates));
     7871    auto target = adoptNS([[UIPreviewTarget alloc] initWithContainer:containerView center:centerInContainerViewCoordinates]);
     7872
     7873    return adoptNS([[UITargetedPreview alloc] initWithView:snapshotView parameters:parameters.get() target:target.get()]);
     7874}
     7875
     7876- (UITargetedPreview *)_ensureTargetedPreview
     7877{
     7878    if (_contextMenuInteractionTargetedPreview)
     7879        return _contextMenuInteractionTargetedPreview.get();
     7880
     7881    RetainPtr<UITargetedPreview> targetedPreview;
     7882
    78647883    if (_positionInformation.isLink && _positionInformation.linkIndicator.contentImage) {
    7865         [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
    7866 
    78677884        auto indicator = _positionInformation.linkIndicator;
    78687885        auto textIndicatorImage = uiImageForImage(indicator.contentImage.get());
    7869 
    7870         return createTargetedPreview(textIndicatorImage.get(), self, self.unscaledView, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)]).autorelease();
    7871     }
    7872 
    7873     if ((_positionInformation.isAttachment || _positionInformation.isImage) && _positionInformation.image) {
    7874         [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
    7875 
    7876         RetainPtr<CGImageRef> cgImage = _positionInformation.image->makeCGImageCopy();
     7886        targetedPreview = createTargetedPreview(textIndicatorImage.get(), self, self.unscaledView, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)]);
     7887    } else if ((_positionInformation.isAttachment || _positionInformation.isImage) && _positionInformation.image) {
     7888        auto cgImage = _positionInformation.image->makeCGImageCopy();
    78777889        auto image = adoptNS([[UIImage alloc] initWithCGImage:cgImage.get()]);
    7878 
    7879         return createTargetedPreview(image.get(), self, self.unscaledView, _positionInformation.bounds, { }, nil).autorelease();
    7880     }
    7881 
    7882     return nil;
     7890        targetedPreview = createTargetedPreview(image.get(), self, self.unscaledView, _positionInformation.bounds, { }, nil);
     7891    }
     7892
     7893    if (!targetedPreview)
     7894        targetedPreview = createFallbackTargetedPreview(self, self.unscaledView, _positionInformation.bounds);
     7895
     7896    _contextMenuInteractionTargetedPreview = WTFMove(targetedPreview);
     7897    return _contextMenuInteractionTargetedPreview.get();
    78837898}
    78847899
    78857900- (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction previewForHighlightingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration
    78867901{
    7887     return [self _targetedPreview];
     7902    [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
     7903    return [self _ensureTargetedPreview];
    78887904}
    78897905
     
    79067922- (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction previewForDismissingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration
    79077923{
    7908     return [self _targetedPreview];
     7924    return [self _ensureTargetedPreview];
    79097925}
    79107926
     
    79868002    _contextMenuHasRequestedLegacyData = NO;
    79878003    _contextMenuElementInfo = nullptr;
     8004    _contextMenuInteractionTargetedPreview = nil;
    79888005}
    79898006
Note: See TracChangeset for help on using the changeset viewer.