- Revision
- 242801
- Author
- [email protected]
- Date
- 2019-03-12 10:41:59 -0700 (Tue, 12 Mar 2019)
Log Message
Check whether to launch a default action instead of action sheet
https://bugs.webkit.org/show_bug.cgi?id=195225
<rdar://problem/47715544>
Patch by Jennifer Moore <[email protected]> on 2019-03-12
Source/WebCore/PAL:
Reviewed by Daniel Bates.
Add new SPI declarations.
* pal/spi/ios/DataDetectorsUISPI.h:
Source/WebKit:
Reviewed by Daniel Bates and Tim Horton.
Notify DataDetectors at the start of a touch on a link, and check whether to immediately
launch the default action instead of an action sheet.
* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant interactionDidStart]):
(-[WKActionSheetAssistant _createSheetWithElementActions:defaultTitle:showLinkTitle:]):
(-[WKActionSheetAssistant showImageSheet]):
(-[WKActionSheetAssistant showLinkSheet]):
(-[WKActionSheetAssistant showDataDetectorsSheet]):
(-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Deleted.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _webTouchEventsRecognized:]):
Modified Paths
Diff
Modified: trunk/Source/WebCore/PAL/ChangeLog (242800 => 242801)
--- trunk/Source/WebCore/PAL/ChangeLog 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebCore/PAL/ChangeLog 2019-03-12 17:41:59 UTC (rev 242801)
@@ -1,3 +1,15 @@
+2019-03-12 Jennifer Moore <[email protected]>
+
+ Check whether to launch a default action instead of action sheet
+ https://bugs.webkit.org/show_bug.cgi?id=195225
+ <rdar://problem/47715544>
+
+ Reviewed by Daniel Bates.
+
+ Add new SPI declarations.
+
+ * pal/spi/ios/DataDetectorsUISPI.h:
+
2019-03-11 Ross Kirsling <[email protected]>
Add Optional to Forward.h.
Modified: trunk/Source/WebCore/PAL/pal/spi/ios/DataDetectorsUISPI.h (242800 => 242801)
--- trunk/Source/WebCore/PAL/pal/spi/ios/DataDetectorsUISPI.h 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/DataDetectorsUISPI.h 2019-03-12 17:41:59 UTC (rev 242801)
@@ -62,6 +62,13 @@
#endif
+@interface DDDetectionController (Staging_48014858)
+- (NSString *)titleForURL:(NSURL *)url results:(NSArray *)results context:(NSDictionary *)context;
+- (DDAction *)defaultActionForURL:(NSURL *)url results:(NSArray *)results context:(NSDictionary *)context;
+- (void)interactionDidStartForURL:(NSURL *)url;
+- (BOOL)shouldImmediatelyLaunchDefaultActionForURL:(NSURL *)url;
+@end
+
SOFT_LINK_PRIVATE_FRAMEWORK(DataDetectorsUI)
SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController)
SOFT_LINK_CONSTANT(DataDetectorsUI, kDataDetectorsLeadingText, const NSString *)
Modified: trunk/Source/WebKit/ChangeLog (242800 => 242801)
--- trunk/Source/WebKit/ChangeLog 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebKit/ChangeLog 2019-03-12 17:41:59 UTC (rev 242801)
@@ -1,3 +1,25 @@
+2019-03-12 Jennifer Moore <[email protected]>
+
+ Check whether to launch a default action instead of action sheet
+ https://bugs.webkit.org/show_bug.cgi?id=195225
+ <rdar://problem/47715544>
+
+ Reviewed by Daniel Bates and Tim Horton.
+
+ Notify DataDetectors at the start of a touch on a link, and check whether to immediately
+ launch the default action instead of an action sheet.
+
+ * UIProcess/ios/WKActionSheetAssistant.h:
+ * UIProcess/ios/WKActionSheetAssistant.mm:
+ (-[WKActionSheetAssistant interactionDidStart]):
+ (-[WKActionSheetAssistant _createSheetWithElementActions:defaultTitle:showLinkTitle:]):
+ (-[WKActionSheetAssistant showImageSheet]):
+ (-[WKActionSheetAssistant showLinkSheet]):
+ (-[WKActionSheetAssistant showDataDetectorsSheet]):
+ (-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Deleted.
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView _webTouchEventsRecognized:]):
+:
2019-03-12 Zalan Bujtas <[email protected]>
[Synthetic Click] Dispatch mouseout soon after mouseup
Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h (242800 => 242801)
--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h 2019-03-12 17:41:59 UTC (rev 242801)
@@ -79,6 +79,7 @@
- (RetainPtr<NSArray>)defaultActionsForLinkSheet:(_WKActivatedElementInfo *)elementInfo;
- (RetainPtr<NSArray>)defaultActionsForImageSheet:(_WKActivatedElementInfo *)elementInfo;
- (BOOL)isShowingSheet;
+- (void)interactionDidStartWithPositionInformation:(const WebKit::InteractionInformationAtPosition&)information;
- (NSArray *)currentAvailableActionTitles;
@end
Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm (242800 => 242801)
--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm 2019-03-12 17:41:59 UTC (rev 242801)
@@ -166,6 +166,19 @@
return [self superviewForSheet];
}
+- (_WKElementAction *)_elementActionForDDAction:(DDAction *)action
+{
+ auto retainedSelf = retainPtr(self);
+ _WKElementAction *elementAction = [_WKElementAction elementActionWithTitle:action.localizedName actionHandler:^(_WKActivatedElementInfo *actionInfo) {
+ retainedSelf->_isPresentingDDUserInterface = action.hasUserInterface;
+ [[getDDDetectionControllerClass() sharedController] performAction:action fromAlertController:retainedSelf->_interactionSheet.get() interactionDelegate:retainedSelf.get()];
+ }];
+ elementAction.dismissalHandler = ^BOOL {
+ return !action.hasUserInterface;
+ };
+ return elementAction;
+}
+
static const CGFloat presentationElementRectPadding = 15;
- (CGRect)presentationRectForElementUsingClosestIndicatedRect
@@ -269,6 +282,25 @@
return _interactionSheet != nil;
}
+- (void)interactionDidStartWithPositionInformation:(const WebKit::InteractionInformationAtPosition&)information
+{
+#if ENABLE(DATA_DETECTION)
+ if (!_delegate)
+ return;
+
+ if (!WebCore::DataDetection::canBePresentedByDataDetectors(information.url))
+ return;
+
+ NSURL *targetURL = information.url;
+ if (!targetURL)
+ return;
+
+ auto *controller = [getDDDetectionControllerClass() sharedController];
+ if ([controller respondsToSelector:@selector(interactionDidStartForURL:)])
+ [controller interactionDidStartForURL:targetURL];
+#endif
+}
+
- (NSArray *)currentAvailableActionTitles
{
if (!_interactionSheet)
@@ -282,7 +314,7 @@
return array;
}
-- (void)_createSheetWithElementActions:(NSArray *)actions showLinkTitle:(BOOL)showLinkTitle
+- (void)_createSheetWithElementActions:(NSArray *)actions defaultTitle:(NSString *)defaultTitle showLinkTitle:(BOOL)showLinkTitle
{
auto delegate = _delegate.get();
if (!delegate)
@@ -309,7 +341,9 @@
titleString = WTF::userVisibleString(targetURL);
titleIsURL = YES;
}
- } else
+ } else if (defaultTitle)
+ titleString = defaultTitle;
+ else
titleString = _positionInformation->title;
if ([titleString length]) {
@@ -370,7 +404,7 @@
return;
}
- [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
+ [self _createSheetWithElementActions:actions.get() defaultTitle:nil showLinkTitle:YES];
if (!_interactionSheet)
return;
@@ -516,9 +550,7 @@
- (void)showLinkSheet
{
ASSERT(!_elementInfo);
-
- auto delegate = _delegate.get();
- if (!delegate)
+ if (!_delegate)
return;
_needsLinkIndicator = YES;
@@ -532,7 +564,7 @@
}
auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink URL:targetURL location:_positionInformation->request.point title:_positionInformation->title ID:_positionInformation->idAttribute rect:_positionInformation->bounds image:_positionInformation->image.get()]);
- if ([delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] && [delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()]) {
+ if ([_delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] && [_delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()]) {
_needsLinkIndicator = NO;
return;
}
@@ -539,7 +571,7 @@
auto defaultActions = [self defaultActionsForLinkSheet:elementInfo.get()];
- RetainPtr<NSArray> actions = [delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTFMove(defaultActions)];
+ RetainPtr<NSArray> actions = [_delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTFMove(defaultActions)];
if (![actions count]) {
_needsLinkIndicator = NO;
@@ -546,7 +578,7 @@
return;
}
- [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
+ [self _createSheetWithElementActions:actions.get() defaultTitle:nil showLinkTitle:YES];
if (!_interactionSheet) {
_needsLinkIndicator = NO;
return;
@@ -561,8 +593,7 @@
- (void)showDataDetectorsSheet
{
#if ENABLE(DATA_DETECTION)
- auto delegate = _delegate.get();
- if (!delegate)
+ if (!_delegate)
return;
if (![self synchronouslyRetrievePositionInformation])
@@ -580,10 +611,10 @@
NSString *textAtSelection = nil;
RetainPtr<NSMutableDictionary> extendedContext;
- if ([delegate respondsToSelector:@selector(dataDetectionContextForActionSheetAssistant:)])
- context = [delegate dataDetectionContextForActionSheetAssistant:self];
- if ([delegate respondsToSelector:@selector(selectedTextForActionSheetAssistant:)])
- textAtSelection = [delegate selectedTextForActionSheetAssistant:self];
+ if ([_delegate respondsToSelector:@selector(dataDetectionContextForActionSheetAssistant:)])
+ context = [_delegate dataDetectionContextForActionSheetAssistant:self];
+ if ([_delegate respondsToSelector:@selector(selectedTextForActionSheetAssistant:)])
+ textAtSelection = [_delegate selectedTextForActionSheetAssistant:self];
if (!_positionInformation->textBefore.isEmpty() || !_positionInformation->textAfter.isEmpty()) {
extendedContext = adoptNS([@{
getkDataDetectorsLeadingText() : _positionInformation->textBefore,
@@ -594,6 +625,14 @@
[extendedContext addEntriesFromDictionary:context];
context = extendedContext.get();
}
+
+ if ([controller respondsToSelector:@selector(shouldImmediatelyLaunchDefaultActionForURL:)] && [controller shouldImmediatelyLaunchDefaultActionForURL:targetURL]) {
+ auto action = "" defaultActionForURL:targetURL results:nil context:context];
+ auto *elementAction = [self _elementActionForDDAction:action];
+ [elementAction _runActionWithElementInfo:_elementInfo.get() forActionSheetAssistant:self];
+ return;
+ }
+
NSArray *dataDetectorsActions = [controller actionsForURL:targetURL identifier:_positionInformation->dataDetectorIdentifier selectedText:textAtSelection results:_positionInformation->dataDetectorResults.get() context:context];
if ([dataDetectorsActions count] == 0)
return;
@@ -601,18 +640,12 @@
NSMutableArray *elementActions = [NSMutableArray array];
for (NSUInteger actionNumber = 0; actionNumber < [dataDetectorsActions count]; actionNumber++) {
DDAction *action = "" objectAtIndex:actionNumber];
- RetainPtr<WKActionSheetAssistant> retainedSelf = self;
- _WKElementAction *elementAction = [_WKElementAction elementActionWithTitle:[action localizedName] actionHandler:^(_WKActivatedElementInfo *actionInfo) {
- retainedSelf.get()->_isPresentingDDUserInterface = action.hasUserInterface;
- [[getDDDetectionControllerClass() sharedController] performAction:action fromAlertController:retainedSelf.get()->_interactionSheet.get() interactionDelegate:retainedSelf.get()];
- }];
- elementAction.dismissalHandler = ^{
- return (BOOL)!action.hasUserInterface;
- };
+ auto *elementAction = [self _elementActionForDDAction:action];
[elementActions addObject:elementAction];
}
- [self _createSheetWithElementActions:elementActions showLinkTitle:NO];
+ NSString *title = [controller titleForURL:targetURL results:nil context:context];
+ [self _createSheetWithElementActions:elementActions defaultTitle:title showLinkTitle:NO];
if (!_interactionSheet)
return;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (242800 => 242801)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-03-12 17:23:00 UTC (rev 242800)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-03-12 17:41:59 UTC (rev 242801)
@@ -1220,6 +1220,10 @@
if (lastTouchEvent->type == UIWebTouchEventTouchBegin) {
[self _handleDOMPasteRequestWithResult:WebCore::DOMPasteAccessResponse::DeniedForGesture];
_layerTreeTransactionIdAtLastTouchStart = downcast<WebKit::RemoteLayerTreeDrawingAreaProxy>(*_page->drawingArea()).lastCommittedLayerTreeTransactionID();
+
+ [self doAfterPositionInformationUpdate:[assistant = WeakObjCPtr<WKActionSheetAssistant>(_actionSheetAssistant.get())] (WebKit::InteractionInformationAtPosition information) {
+ [assistant interactionDidStartWithPositionInformation:information];
+ } forRequest:WebKit::InteractionInformationRequest(WebCore::IntPoint(_lastInteractionLocation))];
}
#if ENABLE(TOUCH_EVENTS)