Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
megangardner committed Jan 13, 2022
1 parent e63c454 commit df3b35e
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 18 deletions.
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2022-01-12 Megan Gardner <megan_gardner@apple.com>

Add to Contact menu item does nothing on mac.
https://bugs.webkit.org/show_bug.cgi?id=235154

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):

2022-01-12 Wenson Hsieh <wenson_hsieh@apple.com>

Live Text is sometimes horizontally clipped when injecting TextRecognitionBlockData
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/ChromeClient.h
Expand Up @@ -524,7 +524,7 @@ class ChromeClient {
#endif

#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
virtual void handleTelephoneNumberClick(const String&, const IntPoint&) { }
virtual void handleTelephoneNumberClick(const String&, const IntPoint&, const IntRect&) { }
#endif

#if ENABLE(DATA_DETECTION)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/mac/ServicesOverlayController.mm
Expand Up @@ -647,7 +647,7 @@ static void compactRectsWithGapRects(Vector<LayoutRect>& rects, const Vector<Gap

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

Frame& ServicesOverlayController::mainFrame() const
Expand Down
31 changes: 31 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,34 @@
2022-01-12 Megan Gardner <megan_gardner@apple.com>

Add to Contact menu item does nothing on mac.
https://bugs.webkit.org/show_bug.cgi?id=235154
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):

2022-01-12 J Pascoe <j_pascoe@apple.com>

[WebAuthn] Fix freebie call without user gesture not being given
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/Platform/mac/MenuUtilities.h
Expand Up @@ -26,13 +26,14 @@
#ifndef MenuUtilities_h
#define MenuUtilities_h

#import <WebCore/IntRect.h>
#import <wtf/text/WTFString.h>

namespace WebKit {

#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
NSMenuItem *menuItemForTelephoneNumber(const String& telephoneNumber);
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber);
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber, NSView *webView, const WebCore::IntRect&);
NSString *menuItemTitleForTelephoneNumberGroup();
#endif

Expand Down
33 changes: 28 additions & 5 deletions Source/WebKit/Platform/mac/MenuUtilities.mm
Expand Up @@ -44,13 +44,35 @@
#import <pal/mac/DataDetectorsSoftLink.h>

@interface WKEmptyPresenterHighlightDelegate : NSObject <RVPresenterHighlightDelegate>

- (instancetype)initWithRect:(NSRect)rect;

@property NSRect rect;

@end

@implementation WKEmptyPresenterHighlightDelegate

- (instancetype)initWithRect:(NSRect)rect
{
if (!(self = [super init]))
return nil;

_rect = rect;
return self;
}


- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item
{
return @[ ];
return @[ [NSValue valueWithRect:self.rect] ];
}

- (BOOL)revealContext:(RVPresentingContext *)context shouldUseDefaultHighlightForItem:(RVItem *)item
{
UNUSED_PARAM(context);
UNUSED_PARAM(item);
return NO;
}

@end
Expand Down Expand Up @@ -107,20 +129,21 @@ @implementation WKEmptyPresenterHighlightDelegate
return nil;
}

RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber)
RetainPtr<NSMenu> menuForTelephoneNumber(const String& telephoneNumber, NSView *webView, const WebCore::IntRect& rect)
{
if (!PAL::isRevealFrameworkAvailable() || !PAL::isRevealCoreFrameworkAvailable())
return nil;

RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]);
auto viewForPresenter = adoptNS([[NSView alloc] init]);
auto urlComponents = adoptNS([[NSURLComponents alloc] init]);
[urlComponents setScheme:@"tel"];
[urlComponents setPath:telephoneNumber];
auto item = adoptNS([PAL::allocRVItemInstance() initWithURL:[urlComponents URL] rangeInContext:NSMakeRange(0, telephoneNumber.length())]);
auto presenter = adoptNS([PAL::allocRVPresenterInstance() init]);
auto delegate = adoptNS([[WKEmptyPresenterHighlightDelegate alloc] init]);
auto context = adoptNS([PAL::allocRVPresentingContextInstance() initWithPointerLocationInView:NSZeroPoint inView:viewForPresenter.get() highlightDelegate:delegate.get()]);
auto delegate = adoptNS([[WKEmptyPresenterHighlightDelegate alloc] initWithRect:rect]);
auto context = adoptNS([PAL::allocRVPresentingContextInstance() initWithPointerLocationInView:NSZeroPoint inView:webView highlightDelegate:delegate.get()]);
static char wkRevealDelegateKey;
objc_setAssociatedObject(context.get(), &wkRevealDelegateKey, delegate.get(), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
NSArray *proposedMenuItems = [presenter menuItemsForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];

[menu setItemArray:proposedMenuItems];
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/PageClient.h
Expand Up @@ -432,6 +432,8 @@ class PageClient : public CanMakeWeakPtr<PageClient> {
virtual CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const = 0;

virtual WebCore::DestinationColorSpace colorSpace() = 0;

virtual NSView *viewForPresentingRevealPopover() const = 0;

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

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/WebPageProxy.h
Expand Up @@ -2298,7 +2298,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>

#if ENABLE(TELEPHONE_NUMBER_DETECTION)
#if PLATFORM(MAC)
void showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint&);
void showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint&, const WebCore::IntRect&);
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/WebPageProxy.messages.in
Expand Up @@ -434,7 +434,7 @@ messages -> WebPageProxy {

#if ENABLE(TELEPHONE_NUMBER_DETECTION)
#if PLATFORM(MAC)
ShowTelephoneNumberMenu(String telephoneNumber, WebCore::IntPoint point)
ShowTelephoneNumberMenu(String telephoneNumber, WebCore::IntPoint point, WebCore::IntRect rect)
#endif
#endif

Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/mac/PageClientImplMac.h
Expand Up @@ -229,6 +229,7 @@ class PageClientImpl final : public PageClientImplCocoa

NSView *activeView() const;
NSWindow *activeWindow() const;
NSView *viewForPresentingRevealPopover() const override { return activeView(); }

void didStartProvisionalLoadForMainFrame() override;
void didFirstVisuallyNonEmptyLayoutForMainFrame() override;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Expand Up @@ -542,9 +542,9 @@ static inline bool expectsLegacyImplicitRubberBandControl()
#endif

#if ENABLE(TELEPHONE_NUMBER_DETECTION)
void WebPageProxy::showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint& point)
void WebPageProxy::showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint& point, const WebCore::IntRect& rect)
{
RetainPtr<NSMenu> menu = menuForTelephoneNumber(telephoneNumber);
RetainPtr<NSMenu> menu = menuForTelephoneNumber(telephoneNumber, pageClient().viewForPresentingRevealPopover(), rect);
pageClient().showPlatformContextMenu(menu.get(), point);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Expand Up @@ -1318,9 +1318,9 @@ String WebChromeClient::signedPublicKeyAndChallengeString(unsigned keySizeIndex,

#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)

void WebChromeClient::handleTelephoneNumberClick(const String& number, const IntPoint& point)
void WebChromeClient::handleTelephoneNumberClick(const String& number, const IntPoint& point, const IntRect& rect)
{
m_page.handleTelephoneNumberClick(number, point);
m_page.handleTelephoneNumberClick(number, point, rect);
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Expand Up @@ -371,7 +371,7 @@ class WebChromeClient final : public WebCore::ChromeClient {
String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challengeString, const URL&) const final;

#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&) final;
void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&, const WebCore::IntRect&) final;
#endif

#if ENABLE(DATA_DETECTION)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/WebPage.h
Expand Up @@ -1195,7 +1195,7 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
void getSamplingProfilerOutput(CompletionHandler<void(const String&)>&&);

#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&, const WebCore::IntRect&);
void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&);
void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable, const WebCore::IntRect&, const String& attachmentID);
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
Expand Up @@ -760,9 +760,9 @@ static void drawPDFPage(PDFDocument *pdfDocument, CFIndex pageIndex, CGContextRe
#endif // ENABLE(WEBGL)

#if ENABLE(TELEPHONE_NUMBER_DETECTION)
void WebPage::handleTelephoneNumberClick(const String& number, const IntPoint& point)
void WebPage::handleTelephoneNumberClick(const String& number, const IntPoint& point, const IntRect& rect)
{
send(Messages::WebPageProxy::ShowTelephoneNumberMenu(number, point));
send(Messages::WebPageProxy::ShowTelephoneNumberMenu(number, point, rect));
}
#endif

Expand Down

0 comments on commit df3b35e

Please sign in to comment.