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

Changeset 278330 in webkit


Ignore:
Timestamp:
Jun 1, 2021, 3:36:13 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Adopt Reveal for phone numbers
https://bugs.webkit.org/show_bug.cgi?id=226383
rdar://78482517
Source/WebCore/PAL:

Patch by Dana Estra <destra@apple.com> on 2021-06-01
Reviewed by Tim Horton.

Add declaration for RVItem method initWithURL.

  • pal/spi/cocoa/RevealSPI.h:

Source/WebKit:

Patch by Dana Estra <destra@apple.com> on 2021-06-01
Reviewed by Tim Horton.

Manually tested by selecting text containing phone numbers in Safari and viewing dropdown menu.

Switch to Reveal framework to show a dropdown menu for telephone numbers with more options.

  • Platform/mac/MenuUtilities.mm:

(-[WKEmptyPresenterHighlightDelegate revealContext:rectsForItem:]):
(WebKit::menuForTelephoneNumber):

Location:
trunk/Source
Files:
4 edited

Legend:

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

    r278253 r278330  
     12021-06-01  Dana Estra  <destra@apple.com>
     2
     3        Adopt Reveal for phone numbers
     4        https://bugs.webkit.org/show_bug.cgi?id=226383
     5        rdar://78482517
     6       
     7        Reviewed by Tim Horton.
     8       
     9        Add declaration for RVItem method initWithURL.
     10
     11        * pal/spi/cocoa/RevealSPI.h:
     12
    1132021-05-30  Darin Adler  <darin@apple.com>
    214
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h

    r278190 r278330  
    5050- (instancetype)initWithText:(NSString *)text selectedRange:(NSRange)selectedRange NS_DESIGNATED_INITIALIZER;
    5151- (instancetype)initWithDDResult:(DDScannerResult *)result NS_DESIGNATED_INITIALIZER;
     52- (instancetype)initWithURL:(NSURL *)url rangeInContext:(NSRange)rangeInContext;
    5253@property (readonly, nonatomic) NSRange highlightRange;
    5354@end
  • trunk/Source/WebKit/ChangeLog

    r278320 r278330  
     12021-06-01  Dana Estra  <destra@apple.com>
     2
     3        Adopt Reveal for phone numbers
     4        https://bugs.webkit.org/show_bug.cgi?id=226383
     5        rdar://78482517
     6
     7        Reviewed by Tim Horton.
     8
     9        Manually tested by selecting text containing phone numbers in Safari and viewing dropdown menu.
     10       
     11        Switch to Reveal framework to show a dropdown menu for telephone numbers with more options.
     12
     13        * Platform/mac/MenuUtilities.mm:
     14        (-[WKEmptyPresenterHighlightDelegate revealContext:rectsForItem:]):
     15        (WebKit::menuForTelephoneNumber):
     16
    1172021-06-01  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebKit/Platform/mac/MenuUtilities.mm

    r274380 r278330  
    2626#import "config.h"
    2727#import "MenuUtilities.h"
     28#import <pal/cocoa/RevealSoftLink.h>
    2829
    2930#if PLATFORM(MAC)
     
    4041SOFT_LINK_CLASS(TelephonyUtilities, TUCall)
    4142#endif
     43
     44@interface WKEmptyPresenterHighlightDelegate : NSObject <RVPresenterHighlightDelegate>
     45@end
     46
     47@implementation WKEmptyPresenterHighlightDelegate
     48
     49- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item
     50{
     51    return @[ ];
     52}
     53
     54@end
    4255
    4356namespace WebKit {
     
    95108RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber)
    96109{
    97     if (!DataDetectorsLibrary())
     110    if (!PAL::isRevealFrameworkAvailable() || !PAL::isRevealCoreFrameworkAvailable())
    98111        return nil;
    99112
    100113    RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]);
    101     NSMutableArray *faceTimeItems = [NSMutableArray array];
    102     NSMenuItem *dialItem = nil;
    103 
    104     RetainPtr<DDActionContext> actionContext = adoptNS([allocDDActionContextInstance() init]);
    105     [actionContext setAllowedActionUTIs:@[ @"com.apple.dial", @"com.apple.facetime", @"com.apple.facetimeaudio" ]];
    106 
    107     NSArray *proposedMenuItems = [[getDDActionsManagerClass() sharedManager] menuItemsForValue:(NSString *)telephoneNumber type:getDDBinderPhoneNumberKey() service:nil context:actionContext.get()];
    108     for (NSMenuItem *item in proposedMenuItems) {
    109         auto action = actionForMenuItem(item);
    110         if ([action.actionUTI hasPrefix:@"com.apple.dial"])
    111             dialItem = item;
    112         else if ([action.actionUTI hasPrefix:@"com.apple.facetime"])
    113             [faceTimeItems addObject:item];
    114     }
    115 
    116     if (dialItem)
    117         [menu addItem:dialItem];
    118 
    119     if (faceTimeItems.count) {
    120         if ([menu numberOfItems])
    121             [menu addItem:[NSMenuItem separatorItem]];
    122         for (NSMenuItem *item in faceTimeItems)
    123             [menu addItem:item];
    124     }
     114    auto viewForPresenter = adoptNS([[NSView alloc] init]);
     115    auto urlComponents = adoptNS([[NSURLComponents alloc] init]);
     116    [urlComponents setScheme:@"tel"];
     117    [urlComponents setPath:telephoneNumber];
     118    auto item = adoptNS([PAL::allocRVItemInstance() initWithURL:[urlComponents URL] rangeInContext:NSMakeRange(0, telephoneNumber.length())]);
     119    auto presenter = adoptNS([PAL::allocRVPresenterInstance() init]);
     120    auto delegate = adoptNS([[WKEmptyPresenterHighlightDelegate alloc] init]);
     121    auto context = adoptNS([PAL::allocRVPresentingContextInstance() initWithPointerLocationInView:NSZeroPoint inView:viewForPresenter.get() highlightDelegate:delegate.get()]);
     122    NSArray *proposedMenuItems = [presenter menuItemsForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
     123   
     124    [menu setItemArray:proposedMenuItems];
    125125
    126126    return menu;
Note: See TracChangeset for help on using the changeset viewer.