|
44 | 44 | #import <pal/mac/DataDetectorsSoftLink.h> |
45 | 45 |
|
46 | 46 | @interface WKEmptyPresenterHighlightDelegate : NSObject <RVPresenterHighlightDelegate> |
| 47 | + |
| 48 | +- (instancetype)initWithRect:(NSRect)rect; |
| 49 | + |
| 50 | +@property NSRect rect; |
| 51 | + |
47 | 52 | @end |
48 | 53 |
|
49 | 54 | @implementation WKEmptyPresenterHighlightDelegate |
50 | 55 |
|
| 56 | +- (instancetype)initWithRect:(NSRect)rect |
| 57 | +{ |
| 58 | + if (!(self = [super init])) |
| 59 | + return nil; |
| 60 | + |
| 61 | + _rect = rect; |
| 62 | + return self; |
| 63 | +} |
| 64 | + |
| 65 | + |
51 | 66 | - (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item |
52 | 67 | { |
53 | | - return @[ ]; |
| 68 | + return @[ [NSValue valueWithRect:self.rect] ]; |
| 69 | +} |
| 70 | + |
| 71 | +- (BOOL)revealContext:(RVPresentingContext *)context shouldUseDefaultHighlightForItem:(RVItem *)item |
| 72 | +{ |
| 73 | + UNUSED_PARAM(context); |
| 74 | + UNUSED_PARAM(item); |
| 75 | + return NO; |
54 | 76 | } |
55 | 77 |
|
56 | 78 | @end |
@@ -107,20 +129,21 @@ @implementation WKEmptyPresenterHighlightDelegate |
107 | 129 | return nil; |
108 | 130 | } |
109 | 131 |
|
110 | | -RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber) |
| 132 | +RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber, NSView *webView, const WebCore::IntRect& rect) |
111 | 133 | { |
112 | 134 | if (!PAL::isRevealFrameworkAvailable() || !PAL::isRevealCoreFrameworkAvailable()) |
113 | 135 | return nil; |
114 | 136 |
|
115 | 137 | RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]); |
116 | | - auto viewForPresenter = adoptNS([[NSView alloc] init]); |
117 | 138 | auto urlComponents = adoptNS([[NSURLComponents alloc] init]); |
118 | 139 | [urlComponents setScheme:@"tel"]; |
119 | 140 | [urlComponents setPath:telephoneNumber]; |
120 | 141 | auto item = adoptNS([PAL::allocRVItemInstance() initWithURL:[urlComponents URL] rangeInContext:NSMakeRange(0, telephoneNumber.length())]); |
121 | 142 | auto presenter = adoptNS([PAL::allocRVPresenterInstance() init]); |
122 | | - auto delegate = adoptNS([[WKEmptyPresenterHighlightDelegate alloc] init]); |
123 | | - auto context = adoptNS([PAL::allocRVPresentingContextInstance() initWithPointerLocationInView:NSZeroPoint inView:viewForPresenter.get() highlightDelegate:delegate.get()]); |
| 143 | + auto delegate = adoptNS([[WKEmptyPresenterHighlightDelegate alloc] initWithRect:rect]); |
| 144 | + auto context = adoptNS([PAL::allocRVPresentingContextInstance() initWithPointerLocationInView:NSZeroPoint inView:webView highlightDelegate:delegate.get()]); |
| 145 | + static char wkRevealDelegateKey; |
| 146 | + objc_setAssociatedObject(context.get(), &wkRevealDelegateKey, delegate.get(), OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
124 | 147 | NSArray *proposedMenuItems = [presenter menuItemsForItem:item.get() documentContext:nil presentingContext:context.get() options:nil]; |
125 | 148 |
|
126 | 149 | [menu setItemArray:proposedMenuItems]; |
|
0 commit comments