Modified: trunk/Source/WebKit/ChangeLog (246621 => 246622)
--- trunk/Source/WebKit/ChangeLog 2019-06-20 00:40:27 UTC (rev 246621)
+++ trunk/Source/WebKit/ChangeLog 2019-06-20 00:50:30 UTC (rev 246622)
@@ -1,3 +1,32 @@
+2019-06-19 Andy Estes <[email protected]>
+
+ [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.
+
2019-06-19 Devin Rousso <[email protected]>
Web Inspector: Network: replace CFNetwork SPI with new API where able
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (246621 => 246622)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-06-20 00:40:27 UTC (rev 246621)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-06-20 00:50:30 UTC (rev 246622)
@@ -95,6 +95,7 @@
@class _UIHighlightView;
@class _UIWebHighlightLongPressGestureRecognizer;
@class UIHoverGestureRecognizer;
+@class UITargetedPreview;
@class WebEvent;
@class WKActionSheetAssistant;
@class WKContextMenuElementInfo;
@@ -249,6 +250,7 @@
RetainPtr<UIViewController> _contextMenuLegacyPreviewController;
RetainPtr<UIMenu> _contextMenuLegacyMenu;
BOOL _contextMenuHasRequestedLegacyData;
+ RetainPtr<UITargetedPreview> _contextMenuInteractionTargetedPreview;
#else
RetainPtr<UIPreviewItemController> _previewItemController;
#endif
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (246621 => 246622)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-06-20 00:40:27 UTC (rev 246621)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-06-20 00:50:30 UTC (rev 246622)
@@ -7859,32 +7859,48 @@
return adoptNS([[UITargetedPreview alloc] initWithView:imageView.get() parameters:parameters.get() target:target.get()]);
}
-- (UITargetedPreview *)_targetedPreview
+static RetainPtr<UITargetedPreview> createFallbackTargetedPreview(UIView *rootView, UIView *containerView, const WebCore::FloatRect& frameInRootViewCoordinates)
{
- if (_positionInformation.isLink && _positionInformation.linkIndicator.contentImage) {
- [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
+ auto parameters = adoptNS([[UIPreviewParameters alloc] init]);
+ UIView *snapshotView = [rootView resizableSnapshotViewFromRect:frameInRootViewCoordinates afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero];
- auto indicator = _positionInformation.linkIndicator;
- auto textIndicatorImage = uiImageForImage(indicator.contentImage.get());
+ CGRect frameInContainerViewCoordinates = [rootView convertRect:frameInRootViewCoordinates toView:containerView];
+ snapshotView.frame = frameInContainerViewCoordinates;
- return createTargetedPreview(textIndicatorImage.get(), self, self.unscaledView, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)]).autorelease();
- }
+ CGPoint centerInContainerViewCoordinates = CGPointMake(CGRectGetMidX(frameInContainerViewCoordinates), CGRectGetMidY(frameInContainerViewCoordinates));
+ auto target = adoptNS([[UIPreviewTarget alloc] initWithContainer:containerView center:centerInContainerViewCoordinates]);
- if ((_positionInformation.isAttachment || _positionInformation.isImage) && _positionInformation.image) {
- [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
+ return adoptNS([[UITargetedPreview alloc] initWithView:snapshotView parameters:parameters.get() target:target.get()]);
+}
- RetainPtr<CGImageRef> cgImage = _positionInformation.image->makeCGImageCopy();
+- (UITargetedPreview *)_ensureTargetedPreview
+{
+ if (_contextMenuInteractionTargetedPreview)
+ return _contextMenuInteractionTargetedPreview.get();
+
+ RetainPtr<UITargetedPreview> targetedPreview;
+
+ if (_positionInformation.isLink && _positionInformation.linkIndicator.contentImage) {
+ auto indicator = _positionInformation.linkIndicator;
+ auto textIndicatorImage = uiImageForImage(indicator.contentImage.get());
+ targetedPreview = createTargetedPreview(textIndicatorImage.get(), self, self.unscaledView, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)]);
+ } else if ((_positionInformation.isAttachment || _positionInformation.isImage) && _positionInformation.image) {
+ auto cgImage = _positionInformation.image->makeCGImageCopy();
auto image = adoptNS([[UIImage alloc] initWithCGImage:cgImage.get()]);
-
- return createTargetedPreview(image.get(), self, self.unscaledView, _positionInformation.bounds, { }, nil).autorelease();
+ targetedPreview = createTargetedPreview(image.get(), self, self.unscaledView, _positionInformation.bounds, { }, nil);
}
- return nil;
+ if (!targetedPreview)
+ targetedPreview = createFallbackTargetedPreview(self, self.unscaledView, _positionInformation.bounds);
+
+ _contextMenuInteractionTargetedPreview = WTFMove(targetedPreview);
+ return _contextMenuInteractionTargetedPreview.get();
}
- (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction previewForHighlightingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration
{
- return [self _targetedPreview];
+ [self _startSuppressingSelectionAssistantForReason:WebKit::InteractionIsHappening];
+ return [self _ensureTargetedPreview];
}
- (void)contextMenuInteractionWillPresent:(UIContextMenuInteraction *)interaction
@@ -7905,7 +7921,7 @@
- (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction previewForDismissingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration
{
- return [self _targetedPreview];
+ return [self _ensureTargetedPreview];
}
- (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willCommitWithAnimator:(id<UIContextMenuInteractionCommitAnimating>)animator
@@ -7985,6 +8001,7 @@
_contextMenuLegacyMenu = nullptr;
_contextMenuHasRequestedLegacyData = NO;
_contextMenuElementInfo = nullptr;
+ _contextMenuInteractionTargetedPreview = nil;
}
@end