Diff
Modified: branches/safari-604.1.5-branch/Source/WebKit2/ChangeLog (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/ChangeLog 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/ChangeLog 2017-02-09 02:06:00 UTC (rev 211921)
@@ -1,5 +1,67 @@
2017-02-08 Matthew Hanson <[email protected]>
+ Merge r211679. rdar://problem/30363014
+
+ 2017-02-04 Wenson Hsieh <[email protected]>
+
+ Data interaction on an image should make it stand out when presenting the action sheet
+ https://bugs.webkit.org/show_bug.cgi?id=167846
+ <rdar://problem/30363014>
+
+ Reviewed by Tim Horton.
+
+ Adds infrastructure to improve the behavior of data interaction for images. We make two changes to accomplish
+ this: first, add some plumbing to WebKit so the web process can tell the UI process when it is done handling a
+ request to start data interaction, so that the UI process is able to clean up UI-side state in the event that
+ the page prevented the default behavior.
+
+ Secondly, this patch tweaks the heuristic used to present action sheets as popovers. For image elements, if
+ there is sufficient space around the element, we will use the element rect as the target rect; otherwise, we
+ fall back to presenting the popover at the touch location.
+
+ * UIProcess/PageClient.h:
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ * UIProcess/ios/PageClientImplIOS.h:
+ * UIProcess/ios/PageClientImplIOS.mm:
+ (WebKit::PageClientImpl::didHandleStartDataInteractionRequest):
+ * UIProcess/ios/WKActionSheet.h:
+ * UIProcess/ios/WKActionSheet.mm:
+ (-[WKActionSheet presentSheet:]):
+
+ Added a presentation style parameter, used to specify whether or not WKActionSheet should present the popover
+ using the element rect as the target rect, or the touch location.
+
+ (-[WKActionSheet doneWithSheet]):
+ (-[WKActionSheet updateSheetPosition]):
+ (-[WKActionSheet presentSheet]): Deleted.
+ * UIProcess/ios/WKActionSheetAssistant.mm:
+ (-[WKActionSheetAssistant presentationRectForIndicatedElement]):
+
+ Returns the (inflated) bounds of the element that is currently being indicated.
+
+ (-[WKActionSheetAssistant showImageSheet]):
+ (-[WKActionSheetAssistant _presentationStyleForImageAtElementRect:]):
+ (-[WKActionSheetAssistant showLinkSheet]):
+ (-[WKActionSheetAssistant showDataDetectorsSheet]):
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WebPageProxyIOS.mm:
+ (WebKit::WebPageProxy::didHandleStartDataInteractionRequest):
+ * UIProcess/mac/PageClientImpl.h:
+ * UIProcess/mac/PageClientImpl.mm:
+
+ Remove unnecessary function declarations and implementations.
+
+ (WebKit::PageClientImpl::didPerformDataInteractionControllerOperation): Deleted.
+ (WebKit::PageClientImpl::startDataInteractionWithImage): Deleted.
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::requestStartDataInteraction):
+
+ Notify the UI process that the web process is done handling a data interaction request, specifying whether or
+ not the request was granted.
+
+2017-02-08 Matthew Hanson <[email protected]>
+
Merge r211643. rdar://problem/30334861
2017-02-03 Wenson Hsieh <[email protected]>
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/PageClient.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/PageClient.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/PageClient.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -383,6 +383,7 @@
#if ENABLE(DATA_INTERACTION)
virtual void didPerformDataInteractionControllerOperation() = 0;
+ virtual void didHandleStartDataInteractionRequest(bool started) = 0;
virtual void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, const WebCore::FloatPoint& anchorPoint, bool isLink) = 0;
#endif
};
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -547,6 +547,7 @@
void setIsScrollingOrZooming(bool);
#if ENABLE(DATA_INTERACTION)
void didPerformDataInteractionControllerOperation();
+ void didHandleStartDataInteractionRequest(bool started);
void requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
#endif
#endif
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2017-02-09 02:06:00 UTC (rev 211921)
@@ -318,6 +318,7 @@
#if ENABLE(DATA_INTERACTION)
DidPerformDataInteractionControllerOperation()
+ DidHandleStartDataInteractionRequest(bool started)
#endif
#if PLATFORM(COCOA)
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -203,6 +203,7 @@
#if ENABLE(DATA_INTERACTION)
void didPerformDataInteractionControllerOperation() override;
+ void didHandleStartDataInteractionRequest(bool started) override;
void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, const WebCore::FloatPoint& anchorPoint, bool isLink) override;
#endif
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -768,6 +768,11 @@
[m_contentView _didPerformDataInteractionControllerOperation];
}
+void PageClientImpl::didHandleStartDataInteractionRequest(bool started)
+{
+ [m_contentView _didHandleStartDataInteractionRequest:started];
+}
+
void PageClientImpl::startDataInteractionWithImage(const IntPoint& clientPosition, const ShareableBitmap::Handle& image, const FloatPoint& anchorPoint, bool isLink)
{
[m_contentView _startDataInteractionWithImage:ShareableBitmap::create(image)->makeCGImageCopy() atClientPosition:CGPointMake(clientPosition.x(), clientPosition.y()) anchorPoint:anchorPoint isLink:isLink];
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -28,6 +28,11 @@
#import <UIKit/UIAlertController.h>
#import <UIKit/UIPopoverController.h>
+typedef NS_ENUM(NSInteger, WKActionSheetPresentationStyle) {
+ WKActionSheetPresentAtTouchLocation,
+ WKActionSheetPresentAtElementRect
+};
+
@protocol WKActionSheetDelegate;
@class WKContentView;
@@ -36,7 +41,7 @@
@property (nonatomic, assign) id <WKActionSheetDelegate> sheetDelegate;
@property (nonatomic) UIPopoverArrowDirection arrowDirections;
- (void)doneWithSheet;
-- (BOOL)presentSheet;
+- (BOOL)presentSheet:(WKActionSheetPresentationStyle)style;
- (BOOL)presentSheetFromRect:(CGRect)presentationRect;
- (void)updateSheetPosition;
@end
@@ -45,6 +50,7 @@
@required
- (UIView *)hostViewForSheet;
- (CGRect)initialPresentationRectInHostViewForSheet;
+- (CGRect)presentationRectForIndicatedElement;
- (CGRect)presentationRectInHostViewForSheet;
- (void)updatePositionInformation;
@end
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheet.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -37,6 +37,7 @@
BOOL _isRotating;
BOOL _readyToPresentAfterRotation;
+ WKActionSheetPresentationStyle _currentPresentationStyle;
RetainPtr<UIViewController> _currentPresentingViewController;
RetainPtr<UIViewController> _presentedViewControllerWhileRotating;
RetainPtr<id <UIPopoverPresentationControllerDelegate>> _popoverPresentationControllerDelegateWhileRotating;
@@ -70,16 +71,17 @@
#pragma mark - Sheet presentation code
-- (BOOL)presentSheet
+- (BOOL)presentSheet:(WKActionSheetPresentationStyle)style
{
// Calculate the presentation rect just before showing.
CGRect presentationRect = CGRectZero;
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
- presentationRect = [_sheetDelegate initialPresentationRectInHostViewForSheet];
+ presentationRect = style == WKActionSheetPresentAtElementRect ? [_sheetDelegate presentationRectForIndicatedElement] : [_sheetDelegate initialPresentationRectInHostViewForSheet];
if (CGRectIsEmpty(presentationRect))
return NO;
}
+ _currentPresentationStyle = style;
return [self presentSheetFromRect:presentationRect];
}
@@ -114,6 +116,7 @@
_currentPresentingViewController = nil;
_presentedViewControllerWhileRotating = nil;
_popoverPresentationControllerDelegateWhileRotating = nil;
+ _currentPresentationStyle = WKActionSheetPresentAtTouchLocation;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_didRotateAndLayout) object:nil];
}
@@ -193,7 +196,7 @@
if (_isRotating || !_readyToPresentAfterRotation || isBeingPresented)
return;
- CGRect presentationRect = [_sheetDelegate initialPresentationRectInHostViewForSheet];
+ CGRect presentationRect = _currentPresentationStyle == WKActionSheetPresentAtElementRect ? [_sheetDelegate presentationRectForIndicatedElement] : [_sheetDelegate initialPresentationRectInHostViewForSheet];
BOOL wasPresentedViewControllerModal = [_presentedViewControllerWhileRotating isModalInPopover];
if (!CGRectIsEmpty(presentationRect) || wasPresentedViewControllerModal) {
@@ -204,7 +207,7 @@
if (!CGRectIsEmpty(intersection))
[self presentSheetFromRect:intersection];
else if (wasPresentedViewControllerModal)
- [self presentSheet];
+ [self presentSheet:_currentPresentationStyle];
_presentedViewControllerWhileRotating = nil;
_popoverPresentationControllerDelegateWhileRotating = nil;
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -152,6 +152,18 @@
return [self superviewForSheet];
}
+- (CGRect)presentationRectForIndicatedElement
+{
+ UIView *view = [self superviewForSheet];
+ auto delegate = _delegate.get();
+ if (!view || !delegate)
+ return CGRectZero;
+
+ static const CGFloat presentationElementRectPadding = 15;
+ auto elementBounds = [delegate positionInformationForActionSheetAssistant:self].bounds;
+ return CGRectInset([view convertRect:elementBounds fromView:_view], -presentationElementRectPadding, -presentationElementRectPadding);
+}
+
- (CGRect)initialPresentationRectInHostViewForSheet
{
UIView *view = [self superviewForSheet];
@@ -293,7 +305,8 @@
const auto& positionInformation = [delegate positionInformationForActionSheetAssistant:self];
NSURL *targetURL = [NSURL _web_URLWithWTFString:positionInformation.url];
- auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:positionInformation.request.point title:positionInformation.title ID:positionInformation.idAttribute rect:positionInformation.bounds image:positionInformation.image.get()]);
+ auto elementBounds = positionInformation.bounds;
+ auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:positionInformation.request.point title:positionInformation.title ID:positionInformation.idAttribute rect:elementBounds image:positionInformation.image.get()]);
if ([delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] && [delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()])
return;
auto defaultActions = [self defaultActionsForImageSheet:elementInfo.get()];
@@ -309,10 +322,30 @@
_elementInfo = WTFMove(elementInfo);
- if (![_interactionSheet presentSheet])
+ if (![_interactionSheet presentSheet:[self _presentationStyleForImageAtElementRect:elementBounds]])
[self cleanupSheet];
}
+- (WKActionSheetPresentationStyle)_presentationStyleForImageAtElementRect:(CGRect)elementRect
+{
+ auto apparentElementRect = [_view convertRect:elementRect toView:_view.window];
+ auto windowRect = _view.window.bounds;
+ apparentElementRect = CGRectIntersection(apparentElementRect, windowRect);
+
+ auto leftInset = CGRectGetMinX(apparentElementRect) - CGRectGetMinX(windowRect);
+ auto topInset = CGRectGetMinY(apparentElementRect) - CGRectGetMinY(windowRect);
+ auto rightInset = CGRectGetMaxX(windowRect) - CGRectGetMaxX(apparentElementRect);
+ auto bottomInset = CGRectGetMaxY(windowRect) - CGRectGetMaxY(apparentElementRect);
+
+ // If at least this much of the window is available for the popover to draw in, then target the element rect when presenting the action menu popover.
+ // Otherwise, there is not enough space to position the popover around the element, so revert to using the touch location instead.
+ static const CGFloat minimumAvailableWidthOrHeightRatio = 0.4;
+ if (std::max(leftInset, rightInset) > minimumAvailableWidthOrHeightRatio * CGRectGetWidth(windowRect) || std::max(topInset, bottomInset) > minimumAvailableWidthOrHeightRatio * CGRectGetHeight(windowRect))
+ return WKActionSheetPresentAtElementRect;
+
+ return WKActionSheetPresentAtTouchLocation;
+}
+
- (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
{
#if HAVE(APP_LINKS)
@@ -428,7 +461,7 @@
_elementInfo = WTFMove(elementInfo);
- if (![_interactionSheet presentSheet])
+ if (![_interactionSheet presentSheet:WKActionSheetPresentAtTouchLocation])
[self cleanupSheet];
}
@@ -494,7 +527,7 @@
if (elementActions.count <= 1)
_interactionSheet.get().arrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
- if (![_interactionSheet presentSheet])
+ if (![_interactionSheet presentSheet:WKActionSheetPresentAtTouchLocation])
[self cleanupSheet];
}
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -250,6 +250,7 @@
#if ENABLE(DATA_INTERACTION)
- (void)_didPerformDataInteractionControllerOperation;
+- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
- (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint isLink:(BOOL)isLink;
#endif
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -1088,6 +1088,11 @@
m_pageClient.didPerformDataInteractionControllerOperation();
}
+void WebPageProxy::didHandleStartDataInteractionRequest(bool started)
+{
+ m_pageClient.didHandleStartDataInteractionRequest(started);
+}
+
void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition)
{
if (isValid())
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h 2017-02-09 02:06:00 UTC (rev 211921)
@@ -232,11 +232,6 @@
_WKRemoteObjectRegistry *remoteObjectRegistry() override;
#endif
-#if ENABLE(DATA_INTERACTION)
- void didPerformDataInteractionControllerOperation() override;
- void startDataInteractionWithImage(const WebCore::IntPoint& clientPosition, const ShareableBitmap::Handle& image, const WebCore::FloatPoint& anchorPoint, bool isLink) override;
-#endif
-
NSView *m_view;
WKWebView *m_webView;
WebViewImpl* m_impl { nullptr };
Modified: branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -875,18 +875,6 @@
return m_impl->windowIsFrontWindowUnderMouse(event.nativeEvent());
}
-#if ENABLE(DATA_INTERACTION)
-void PageClientImpl::didPerformDataInteractionControllerOperation()
-{
- // FIXME: Implement me.
-}
-
-void PageClientImpl::startDataInteractionWithImage(const IntPoint&, const ShareableBitmap::Handle&, const FloatPoint&, bool)
-{
- // FIXME: Implement me.
-}
-#endif
-
WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
{
if (!m_view)
Modified: branches/safari-604.1.5-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (211920 => 211921)
--- branches/safari-604.1.5-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2017-02-09 02:05:54 UTC (rev 211920)
+++ branches/safari-604.1.5-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2017-02-09 02:06:00 UTC (rev 211921)
@@ -623,7 +623,8 @@
#if ENABLE(DATA_INTERACTION)
void WebPage::requestStartDataInteraction(const IntPoint& clientPosition, const IntPoint& globalPosition)
{
- m_page->mainFrame().eventHandler().tryToBeginDataInteractionAtPoint(clientPosition, globalPosition);
+ bool didStart = m_page->mainFrame().eventHandler().tryToBeginDataInteractionAtPoint(clientPosition, globalPosition);
+ send(Messages::WebPageProxy::DidHandleStartDataInteractionRequest(didStart));
}
#endif