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

Changeset 242801 in webkit


Ignore:
Timestamp:
Mar 12, 2019, 10:41:59 AM (7 years ago)
Author:
commit-queue@webkit.org
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 <jennifer.moore@apple.com> 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:]):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r242776 r242801  
     12019-03-12  Jennifer Moore  <jennifer.moore@apple.com>
     2
     3        Check whether to launch a default action instead of action sheet
     4        https://bugs.webkit.org/show_bug.cgi?id=195225
     5        <rdar://problem/47715544>
     6
     7        Reviewed by Daniel Bates.
     8
     9        Add new SPI declarations.
     10
     11        * pal/spi/ios/DataDetectorsUISPI.h:
     12
    1132019-03-11  Ross Kirsling  <ross.kirsling@sony.com>
    214
  • trunk/Source/WebCore/PAL/pal/spi/ios/DataDetectorsUISPI.h

    r237266 r242801  
    6363#endif
    6464
     65@interface DDDetectionController (Staging_48014858)
     66- (NSString *)titleForURL:(NSURL *)url results:(NSArray *)results context:(NSDictionary *)context;
     67- (DDAction *)defaultActionForURL:(NSURL *)url results:(NSArray *)results context:(NSDictionary *)context;
     68- (void)interactionDidStartForURL:(NSURL *)url;
     69- (BOOL)shouldImmediatelyLaunchDefaultActionForURL:(NSURL *)url;
     70@end
     71
    6572SOFT_LINK_PRIVATE_FRAMEWORK(DataDetectorsUI)
    6673SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController)
  • trunk/Source/WebKit/ChangeLog

    r242798 r242801  
     12019-03-12  Jennifer Moore  <jennifer.moore@apple.com>
     2
     3        Check whether to launch a default action instead of action sheet
     4        https://bugs.webkit.org/show_bug.cgi?id=195225
     5        <rdar://problem/47715544>
     6
     7        Reviewed by Daniel Bates and Tim Horton.
     8
     9        Notify DataDetectors at the start of a touch on a link, and check whether to immediately
     10        launch the default action instead of an action sheet.
     11
     12        * UIProcess/ios/WKActionSheetAssistant.h:
     13        * UIProcess/ios/WKActionSheetAssistant.mm:
     14        (-[WKActionSheetAssistant interactionDidStart]):
     15        (-[WKActionSheetAssistant _createSheetWithElementActions:defaultTitle:showLinkTitle:]):
     16        (-[WKActionSheetAssistant showImageSheet]):
     17        (-[WKActionSheetAssistant showLinkSheet]):
     18        (-[WKActionSheetAssistant showDataDetectorsSheet]):
     19        (-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Deleted.
     20        * UIProcess/ios/WKContentViewInteraction.mm:
     21        (-[WKContentView _webTouchEventsRecognized:]):
     22:
    1232019-03-12  Zalan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h

    r239427 r242801  
    8080- (RetainPtr<NSArray>)defaultActionsForImageSheet:(_WKActivatedElementInfo *)elementInfo;
    8181- (BOOL)isShowingSheet;
     82- (void)interactionDidStartWithPositionInformation:(const WebKit::InteractionInformationAtPosition&)information;
    8283- (NSArray *)currentAvailableActionTitles;
    8384@end
  • trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm

    r240798 r242801  
    167167}
    168168
     169- (_WKElementAction *)_elementActionForDDAction:(DDAction *)action
     170{
     171    auto retainedSelf = retainPtr(self);
     172    _WKElementAction *elementAction = [_WKElementAction elementActionWithTitle:action.localizedName actionHandler:^(_WKActivatedElementInfo *actionInfo) {
     173        retainedSelf->_isPresentingDDUserInterface = action.hasUserInterface;
     174        [[getDDDetectionControllerClass() sharedController] performAction:action fromAlertController:retainedSelf->_interactionSheet.get() interactionDelegate:retainedSelf.get()];
     175    }];
     176    elementAction.dismissalHandler = ^BOOL {
     177        return !action.hasUserInterface;
     178    };
     179    return elementAction;
     180}
     181
    169182static const CGFloat presentationElementRectPadding = 15;
    170183
     
    268281{
    269282    return _interactionSheet != nil;
     283}
     284
     285- (void)interactionDidStartWithPositionInformation:(const WebKit::InteractionInformationAtPosition&)information
     286{
     287#if ENABLE(DATA_DETECTION)
     288    if (!_delegate)
     289        return;
     290
     291    if (!WebCore::DataDetection::canBePresentedByDataDetectors(information.url))
     292        return;
     293
     294    NSURL *targetURL = information.url;
     295    if (!targetURL)
     296        return;
     297
     298    auto *controller = [getDDDetectionControllerClass() sharedController];
     299    if ([controller respondsToSelector:@selector(interactionDidStartForURL:)])
     300        [controller interactionDidStartForURL:targetURL];
     301#endif
    270302}
    271303
     
    283315}
    284316
    285 - (void)_createSheetWithElementActions:(NSArray *)actions showLinkTitle:(BOOL)showLinkTitle
     317- (void)_createSheetWithElementActions:(NSArray *)actions defaultTitle:(NSString *)defaultTitle showLinkTitle:(BOOL)showLinkTitle
    286318{
    287319    auto delegate = _delegate.get();
     
    310342            titleIsURL = YES;
    311343        }
    312     } else
     344    } else if (defaultTitle)
     345        titleString = defaultTitle;
     346    else
    313347        titleString = _positionInformation->title;
    314348
     
    371405        }
    372406
    373         [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
     407        [self _createSheetWithElementActions:actions.get() defaultTitle:nil showLinkTitle:YES];
    374408        if (!_interactionSheet)
    375409            return;
     
    517551{
    518552    ASSERT(!_elementInfo);
    519 
    520     auto delegate = _delegate.get();
    521     if (!delegate)
     553    if (!_delegate)
    522554        return;
    523555
     
    533565
    534566    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()]);
    535     if ([delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] && [delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()]) {
     567    if ([_delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] && [_delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()]) {
    536568        _needsLinkIndicator = NO;
    537569        return;
     
    540572    auto defaultActions = [self defaultActionsForLinkSheet:elementInfo.get()];
    541573
    542     RetainPtr<NSArray> actions = [delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTFMove(defaultActions)];
     574    RetainPtr<NSArray> actions = [_delegate actionSheetAssistant:self decideActionsForElement:elementInfo.get() defaultActions:WTFMove(defaultActions)];
    543575
    544576    if (![actions count]) {
     
    547579    }
    548580
    549     [self _createSheetWithElementActions:actions.get() showLinkTitle:YES];
     581    [self _createSheetWithElementActions:actions.get() defaultTitle:nil showLinkTitle:YES];
    550582    if (!_interactionSheet) {
    551583        _needsLinkIndicator = NO;
     
    562594{
    563595#if ENABLE(DATA_DETECTION)
    564     auto delegate = _delegate.get();
    565     if (!delegate)
     596    if (!_delegate)
    566597        return;
    567598
     
    581612    RetainPtr<NSMutableDictionary> extendedContext;
    582613
    583     if ([delegate respondsToSelector:@selector(dataDetectionContextForActionSheetAssistant:)])
    584         context = [delegate dataDetectionContextForActionSheetAssistant:self];
    585     if ([delegate respondsToSelector:@selector(selectedTextForActionSheetAssistant:)])
    586         textAtSelection = [delegate selectedTextForActionSheetAssistant:self];
     614    if ([_delegate respondsToSelector:@selector(dataDetectionContextForActionSheetAssistant:)])
     615        context = [_delegate dataDetectionContextForActionSheetAssistant:self];
     616    if ([_delegate respondsToSelector:@selector(selectedTextForActionSheetAssistant:)])
     617        textAtSelection = [_delegate selectedTextForActionSheetAssistant:self];
    587618    if (!_positionInformation->textBefore.isEmpty() || !_positionInformation->textAfter.isEmpty()) {
    588619        extendedContext = adoptNS([@{
     
    595626        context = extendedContext.get();
    596627    }
     628
     629    if ([controller respondsToSelector:@selector(shouldImmediatelyLaunchDefaultActionForURL:)] && [controller shouldImmediatelyLaunchDefaultActionForURL:targetURL]) {
     630        auto action = [controller defaultActionForURL:targetURL results:nil context:context];
     631        auto *elementAction = [self _elementActionForDDAction:action];
     632        [elementAction _runActionWithElementInfo:_elementInfo.get() forActionSheetAssistant:self];
     633        return;
     634    }
     635
    597636    NSArray *dataDetectorsActions = [controller actionsForURL:targetURL identifier:_positionInformation->dataDetectorIdentifier selectedText:textAtSelection results:_positionInformation->dataDetectorResults.get() context:context];
    598637    if ([dataDetectorsActions count] == 0)
     
    602641    for (NSUInteger actionNumber = 0; actionNumber < [dataDetectorsActions count]; actionNumber++) {
    603642        DDAction *action = [dataDetectorsActions objectAtIndex:actionNumber];
    604         RetainPtr<WKActionSheetAssistant> retainedSelf = self;
    605         _WKElementAction *elementAction = [_WKElementAction elementActionWithTitle:[action localizedName] actionHandler:^(_WKActivatedElementInfo *actionInfo) {
    606             retainedSelf.get()->_isPresentingDDUserInterface = action.hasUserInterface;
    607             [[getDDDetectionControllerClass() sharedController] performAction:action fromAlertController:retainedSelf.get()->_interactionSheet.get() interactionDelegate:retainedSelf.get()];
    608         }];
    609         elementAction.dismissalHandler = ^{
    610             return (BOOL)!action.hasUserInterface;
    611         };
     643        auto *elementAction = [self _elementActionForDDAction:action];
    612644        [elementActions addObject:elementAction];
    613645    }
    614646
    615     [self _createSheetWithElementActions:elementActions showLinkTitle:NO];
     647    NSString *title = [controller titleForURL:targetURL results:nil context:context];
     648    [self _createSheetWithElementActions:elementActions defaultTitle:title showLinkTitle:NO];
    616649    if (!_interactionSheet)
    617650        return;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r242796 r242801  
    12211221        [self _handleDOMPasteRequestWithResult:WebCore::DOMPasteAccessResponse::DeniedForGesture];
    12221222        _layerTreeTransactionIdAtLastTouchStart = downcast<WebKit::RemoteLayerTreeDrawingAreaProxy>(*_page->drawingArea()).lastCommittedLayerTreeTransactionID();
     1223
     1224        [self doAfterPositionInformationUpdate:[assistant = WeakObjCPtr<WKActionSheetAssistant>(_actionSheetAssistant.get())] (WebKit::InteractionInformationAtPosition information) {
     1225            [assistant interactionDidStartWithPositionInformation:information];
     1226        } forRequest:WebKit::InteractionInformationRequest(WebCore::IntPoint(_lastInteractionLocation))];
    12231227    }
    12241228
Note: See TracChangeset for help on using the changeset viewer.