Skip to content

Commit df3b35e

Browse files
committed
Add to Contact menu item does nothing on mac.
https://bugs.webkit.org/show_bug.cgi?id=235154 Source/WebCore: Reviewed by Tim Horton. Add to Context menu item for telephone numbers did not actually show the contact card. This was because the delgate did not tell the menu where to display the card from, so it just failed. Plumbing that information through fixes the issue. * page/ChromeClient.h: (WebCore::ChromeClient::handleTelephoneNumberClick): * page/mac/ServicesOverlayController.mm: (WebCore::ServicesOverlayController::handleClick): Source/WebKit: rdar://80213097 Reviewed by Tim Horton. Add to Context menu item for telephone numbers did not actually show the contact card. This was because the delgate did not tell the menu where to display the card from, so it just failed. Plumbing that information through fixes the issue. * Platform/mac/MenuUtilities.h: * Platform/mac/MenuUtilities.mm: (-[WKEmptyPresenterHighlightDelegate initWithRect:]): (-[WKEmptyPresenterHighlightDelegate revealContext:rectsForItem:]): (-[WKEmptyPresenterHighlightDelegate revealContext:shouldUseDefaultHighlightForItem:]): (WebKit::menuForTelephoneNumber): * UIProcess/PageClient.h: * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/mac/PageClientImplMac.h: * UIProcess/mac/WebPageProxyMac.mm: (WebKit::WebPageProxy::showTelephoneNumberMenu): * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::handleTelephoneNumberClick): * WebProcess/WebCoreSupport/WebChromeClient.h: * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/mac/WebPageMac.mm: (WebKit::WebPage::handleTelephoneNumberClick): Canonical link: https://commits.webkit.org/245988@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287959 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent e63c454 commit df3b35e

15 files changed

Lines changed: 92 additions & 18 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2022-01-12 Megan Gardner <megan_gardner@apple.com>
2+
3+
Add to Contact menu item does nothing on mac.
4+
https://bugs.webkit.org/show_bug.cgi?id=235154
5+
6+
Reviewed by Tim Horton.
7+
8+
Add to Context menu item for telephone numbers did not actually show the contact card.
9+
This was because the delgate did not tell the menu where to display the card from, so it just failed.
10+
Plumbing that information through fixes the issue.
11+
12+
* page/ChromeClient.h:
13+
(WebCore::ChromeClient::handleTelephoneNumberClick):
14+
* page/mac/ServicesOverlayController.mm:
15+
(WebCore::ServicesOverlayController::handleClick):
16+
117
2022-01-12 Wenson Hsieh <wenson_hsieh@apple.com>
218

319
Live Text is sometimes horizontally clipped when injecting TextRecognitionBlockData

Source/WebCore/page/ChromeClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class ChromeClient {
524524
#endif
525525

526526
#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
527-
virtual void handleTelephoneNumberClick(const String&, const IntPoint&) { }
527+
virtual void handleTelephoneNumberClick(const String&, const IntPoint&, const IntRect&) { }
528528
#endif
529529

530530
#if ENABLE(DATA_DETECTION)

Source/WebCore/page/mac/ServicesOverlayController.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static void compactRectsWithGapRects(Vector<LayoutRect>& rects, const Vector<Gap
647647

648648
m_page.chrome().client().handleSelectionServiceClick(CheckedRef(m_page.focusController())->focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint);
649649
} else if (highlight.type() == DataDetectorHighlight::Type::TelephoneNumber)
650-
m_page.chrome().client().handleTelephoneNumberClick(plainText(highlight.range()), windowPoint);
650+
m_page.chrome().client().handleTelephoneNumberClick(plainText(highlight.range()), windowPoint, frameView->contentsToWindow(CheckedRef(m_page.focusController())->focusedOrMainFrame().editor().firstRectForRange(highlight.range())));
651651
}
652652

653653
Frame& ServicesOverlayController::mainFrame() const

Source/WebKit/ChangeLog

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
2022-01-12 Megan Gardner <megan_gardner@apple.com>
2+
3+
Add to Contact menu item does nothing on mac.
4+
https://bugs.webkit.org/show_bug.cgi?id=235154
5+
rdar://80213097
6+
7+
Reviewed by Tim Horton.
8+
9+
Add to Context menu item for telephone numbers did not actually show the contact card.
10+
This was because the delgate did not tell the menu where to display the card from, so it just failed.
11+
Plumbing that information through fixes the issue.
12+
13+
* Platform/mac/MenuUtilities.h:
14+
* Platform/mac/MenuUtilities.mm:
15+
(-[WKEmptyPresenterHighlightDelegate initWithRect:]):
16+
(-[WKEmptyPresenterHighlightDelegate revealContext:rectsForItem:]):
17+
(-[WKEmptyPresenterHighlightDelegate revealContext:shouldUseDefaultHighlightForItem:]):
18+
(WebKit::menuForTelephoneNumber):
19+
* UIProcess/PageClient.h:
20+
* UIProcess/WebPageProxy.h:
21+
* UIProcess/WebPageProxy.messages.in:
22+
* UIProcess/mac/PageClientImplMac.h:
23+
* UIProcess/mac/WebPageProxyMac.mm:
24+
(WebKit::WebPageProxy::showTelephoneNumberMenu):
25+
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
26+
(WebKit::WebChromeClient::handleTelephoneNumberClick):
27+
* WebProcess/WebCoreSupport/WebChromeClient.h:
28+
* WebProcess/WebPage/WebPage.h:
29+
* WebProcess/WebPage/mac/WebPageMac.mm:
30+
(WebKit::WebPage::handleTelephoneNumberClick):
31+
132
2022-01-12 J Pascoe <j_pascoe@apple.com>
233

334
[WebAuthn] Fix freebie call without user gesture not being given

Source/WebKit/Platform/mac/MenuUtilities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
#ifndef MenuUtilities_h
2727
#define MenuUtilities_h
2828

29+
#import <WebCore/IntRect.h>
2930
#import <wtf/text/WTFString.h>
3031

3132
namespace WebKit {
3233

3334
#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
3435
NSMenuItem *menuItemForTelephoneNumber(const String& telephoneNumber);
35-
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber);
36+
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber, NSView *webView, const WebCore::IntRect&);
3637
NSString *menuItemTitleForTelephoneNumberGroup();
3738
#endif
3839

Source/WebKit/Platform/mac/MenuUtilities.mm

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,35 @@
4444
#import <pal/mac/DataDetectorsSoftLink.h>
4545

4646
@interface WKEmptyPresenterHighlightDelegate : NSObject <RVPresenterHighlightDelegate>
47+
48+
- (instancetype)initWithRect:(NSRect)rect;
49+
50+
@property NSRect rect;
51+
4752
@end
4853

4954
@implementation WKEmptyPresenterHighlightDelegate
5055

56+
- (instancetype)initWithRect:(NSRect)rect
57+
{
58+
if (!(self = [super init]))
59+
return nil;
60+
61+
_rect = rect;
62+
return self;
63+
}
64+
65+
5166
- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item
5267
{
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;
5476
}
5577

5678
@end
@@ -107,20 +129,21 @@ @implementation WKEmptyPresenterHighlightDelegate
107129
return nil;
108130
}
109131

110-
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber)
132+
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber, NSView *webView, const WebCore::IntRect& rect)
111133
{
112134
if (!PAL::isRevealFrameworkAvailable() || !PAL::isRevealCoreFrameworkAvailable())
113135
return nil;
114136

115137
RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]);
116-
auto viewForPresenter = adoptNS([[NSView alloc] init]);
117138
auto urlComponents = adoptNS([[NSURLComponents alloc] init]);
118139
[urlComponents setScheme:@"tel"];
119140
[urlComponents setPath:telephoneNumber];
120141
auto item = adoptNS([PAL::allocRVItemInstance() initWithURL:[urlComponents URL] rangeInContext:NSMakeRange(0, telephoneNumber.length())]);
121142
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);
124147
NSArray *proposedMenuItems = [presenter menuItemsForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
125148

126149
[menu setItemArray:proposedMenuItems];

Source/WebKit/UIProcess/PageClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ class PageClient : public CanMakeWeakPtr<PageClient> {
432432
virtual CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const = 0;
433433

434434
virtual WebCore::DestinationColorSpace colorSpace() = 0;
435+
436+
virtual NSView *viewForPresentingRevealPopover() const = 0;
435437

436438
virtual void showPlatformContextMenu(NSMenu *, WebCore::IntPoint) = 0;
437439

Source/WebKit/UIProcess/WebPageProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
22982298

22992299
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
23002300
#if PLATFORM(MAC)
2301-
void showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint&);
2301+
void showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint&, const WebCore::IntRect&);
23022302
#endif
23032303
#endif
23042304

Source/WebKit/UIProcess/WebPageProxy.messages.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ messages -> WebPageProxy {
434434

435435
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
436436
#if PLATFORM(MAC)
437-
ShowTelephoneNumberMenu(String telephoneNumber, WebCore::IntPoint point)
437+
ShowTelephoneNumberMenu(String telephoneNumber, WebCore::IntPoint point, WebCore::IntRect rect)
438438
#endif
439439
#endif
440440

Source/WebKit/UIProcess/mac/PageClientImplMac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class PageClientImpl final : public PageClientImplCocoa
229229

230230
NSView *activeView() const;
231231
NSWindow *activeWindow() const;
232+
NSView *viewForPresentingRevealPopover() const override { return activeView(); }
232233

233234
void didStartProvisionalLoadForMainFrame() override;
234235
void didFirstVisuallyNonEmptyLayoutForMainFrame() override;

0 commit comments

Comments
 (0)