Skip to content

Commit

Permalink
_WKHitTestResult should expose a hasLocalDataForLinkURL property
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267643
rdar://120443960

Reviewed by Aditya Keerthi.

Add hasLocalDataForLinkURL to WebHitTestResultData and expose it via a property on _WKHitTestResult.

* Source/WebKit/Shared/API/Cocoa/_WKHitTestResult.h:
Added hasLocalDataForLinkURL.

* Source/WebKit/Shared/API/Cocoa/_WKHitTestResult.mm:
(-[_WKHitTestResult hasLocalDataForLinkURL]):
Added.

* Source/WebKit/Shared/WebHitTestResultData.cpp:
(WebKit::WebHitTestResultData::WebHitTestResultData):
Initialize hasLocalDataForLinkURL.

* Source/WebKit/Shared/WebHitTestResultData.h:
Added hasLocalDataForLinkURL.

* Source/WebKit/Shared/WebHitTestResultData.serialization.in:
Added hasLocalDataForLinkURL.

* Source/WebKit/UIProcess/API/APIHitTestResult.h:
(API::HitTestResult::hasLocalDataForLinkURL const):
Added.

* Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
(TestWebKitAPI::TEST):
Added HitTestResultHasLocalDataForLinkURL, loads an image inside a link to itself and verifies that
hasLocalDataForLinkURL is true.

Canonical link: https://commits.webkit.org/273166@main
  • Loading branch information
jeffmapple committed Jan 18, 2024
1 parent f31c5c1 commit d370d11
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/Shared/API/Cocoa/_WKHitTestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ WK_CLASS_AVAILABLE(macos(10.12), ios(16.0))

@property (nonatomic, readonly, copy) NSURL *absolutePDFURL;
@property (nonatomic, readonly, copy) NSURL *absoluteLinkURL;
@property (nonatomic, readonly) BOOL hasLocalDataForLinkURL WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
@property (nonatomic, readonly, copy) NSString *linkLocalDataMIMEType WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
@property (nonatomic, readonly, copy) NSURL *absoluteMediaURL;

Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/Shared/API/Cocoa/_WKHitTestResult.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ - (NSURL *)absoluteLinkURL
return URLFromString(_hitTestResult->absoluteLinkURL());
}

- (BOOL)hasLocalDataForLinkURL
{
return _hitTestResult->hasLocalDataForLinkURL();
}

- (NSString *)linkLocalDataMIMEType
{
return _hitTestResult->linkLocalDataMIMEType();
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/Shared/WebHitTestResultData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ WebHitTestResultData::WebHitTestResultData(const HitTestResult& hitTestResult, c
, elementType(ElementType::None)
, frameInfo(frameInfoDataFromHitTestResult(hitTestResult))
, toolTipText(toolTipText)
, hasLocalDataForLinkURL(hitTestResult.hasLocalDataForLinkURL())
{
if (auto* scrollbar = hitTestResult.scrollbar())
isScrollbar = scrollbar->orientation() == ScrollbarOrientation::Horizontal ? IsScrollbar::Horizontal : IsScrollbar::Vertical;
Expand All @@ -117,6 +118,7 @@ WebHitTestResultData::WebHitTestResultData(const HitTestResult& hitTestResult, b
, mediaIsInFullscreen(hitTestResult.mediaIsInFullscreen())
, elementType(ElementType::None)
, frameInfo(frameInfoDataFromHitTestResult(hitTestResult))
, hasLocalDataForLinkURL(hitTestResult.hasLocalDataForLinkURL())
{
if (auto* scrollbar = hitTestResult.scrollbar())
isScrollbar = scrollbar->orientation() == ScrollbarOrientation::Horizontal ? IsScrollbar::Horizontal : IsScrollbar::Vertical;
Expand Down Expand Up @@ -154,7 +156,7 @@ WebHitTestResultData::WebHitTestResultData(const HitTestResult& hitTestResult, b
}
}

WebHitTestResultData::WebHitTestResultData(const String& absoluteImageURL, const String& absolutePDFURL, const String& absoluteLinkURL, const String& absoluteMediaURL, const String& linkLabel, const String& linkTitle, const String& linkSuggestedFilename, bool isContentEditable, const WebCore::IntRect& elementBoundingBox, const WebKit::WebHitTestResultData::IsScrollbar& isScrollbar, bool isSelected, bool isTextNode, bool isOverTextInsideFormControlElement, bool isDownloadableMedia, bool mediaIsInFullscreen, const WebHitTestResultData::ElementType& elementType, std::optional<FrameInfoData>&& frameInfo, const String& lookupText, const String& toolTipText, const String& imageText, std::optional<WebKit::SharedMemory::Handle>&& imageHandle, const RefPtr<WebKit::ShareableBitmap>& imageBitmap, const String& sourceImageMIMEType, const String& linkLocalDataMIMEType,
WebHitTestResultData::WebHitTestResultData(const String& absoluteImageURL, const String& absolutePDFURL, const String& absoluteLinkURL, const String& absoluteMediaURL, const String& linkLabel, const String& linkTitle, const String& linkSuggestedFilename, bool isContentEditable, const WebCore::IntRect& elementBoundingBox, const WebKit::WebHitTestResultData::IsScrollbar& isScrollbar, bool isSelected, bool isTextNode, bool isOverTextInsideFormControlElement, bool isDownloadableMedia, bool mediaIsInFullscreen, const WebHitTestResultData::ElementType& elementType, std::optional<FrameInfoData>&& frameInfo, const String& lookupText, const String& toolTipText, const String& imageText, std::optional<WebKit::SharedMemory::Handle>&& imageHandle, const RefPtr<WebKit::ShareableBitmap>& imageBitmap, const String& sourceImageMIMEType, const String& linkLocalDataMIMEType, bool hasLocalDataForLinkURL,
#if PLATFORM(MAC)
const WebHitTestResultPlatformData& platformData,
#endif
Expand Down Expand Up @@ -182,6 +184,7 @@ WebHitTestResultData::WebHitTestResultData(const String& absoluteImageURL, const
, imageBitmap(imageBitmap)
, sourceImageMIMEType(sourceImageMIMEType)
, linkLocalDataMIMEType(linkLocalDataMIMEType)
, hasLocalDataForLinkURL(hasLocalDataForLinkURL)
#if PLATFORM(MAC)
, platformData(platformData)
#endif
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/Shared/WebHitTestResultData.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct WebHitTestResultData {
RefPtr<ShareableBitmap> imageBitmap;
String sourceImageMIMEType;
String linkLocalDataMIMEType;
bool hasLocalDataForLinkURL;

#if PLATFORM(MAC)
WebHitTestResultPlatformData platformData;
Expand All @@ -113,7 +114,7 @@ struct WebHitTestResultData {
WebHitTestResultData& operator=(const WebHitTestResultData&) = default;
WebHitTestResultData(const WebCore::HitTestResult&, const String& toolTipText);
WebHitTestResultData(const WebCore::HitTestResult&, bool includeImage);
WebHitTestResultData(const String& absoluteImageURL, const String& absolutePDFURL, const String& absoluteLinkURL, const String& absoluteMediaURL, const String& linkLabel, const String& linkTitle, const String& linkSuggestedFilename, bool isContentEditable, const WebCore::IntRect& elementBoundingBox, const WebKit::WebHitTestResultData::IsScrollbar&, bool isSelected, bool isTextNode, bool isOverTextInsideFormControlElement, bool isDownloadableMedia, bool mediaIsInFullscreen, const WebKit::WebHitTestResultData::ElementType&, std::optional<FrameInfoData>&&, const String& lookupText, const String& toolTipText, const String& imageText, std::optional<WebKit::SharedMemory::Handle>&& imageHandle, const RefPtr<WebKit::ShareableBitmap>& imageBitmap, const String& sourceImageMIMEType, const String& linkLocalDataMIMEType,
WebHitTestResultData(const String& absoluteImageURL, const String& absolutePDFURL, const String& absoluteLinkURL, const String& absoluteMediaURL, const String& linkLabel, const String& linkTitle, const String& linkSuggestedFilename, bool isContentEditable, const WebCore::IntRect& elementBoundingBox, const WebKit::WebHitTestResultData::IsScrollbar&, bool isSelected, bool isTextNode, bool isOverTextInsideFormControlElement, bool isDownloadableMedia, bool mediaIsInFullscreen, const WebKit::WebHitTestResultData::ElementType&, std::optional<FrameInfoData>&&, const String& lookupText, const String& toolTipText, const String& imageText, std::optional<WebKit::SharedMemory::Handle>&& imageHandle, const RefPtr<WebKit::ShareableBitmap>& imageBitmap, const String& sourceImageMIMEType, const String& linkLocalDataMIMEType, bool hasLocalDataForLinkURL,
#if PLATFORM(MAC)
const WebHitTestResultPlatformData&,
#endif
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/Shared/WebHitTestResultData.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct WebKit::WebHitTestResultData {
RefPtr<WebKit::ShareableBitmap> imageBitmap;
String sourceImageMIMEType;
String linkLocalDataMIMEType;

bool hasLocalDataForLinkURL;

#if PLATFORM(MAC)
WebKit::WebHitTestResultPlatformData platformData;
#endif
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/API/APIHitTestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class HitTestResult : public API::ObjectImpl<API::Object::Type::HitTestResult> {

const std::optional<WebKit::FrameInfoData>& frameInfo() const { return m_data.frameInfo; }

bool hasLocalDataForLinkURL() const { return m_data.hasLocalDataForLinkURL; }

private:
explicit HitTestResult(const WebKit::WebHitTestResultData& hitTestResultData, WebKit::WebPageProxy* page)
: m_data(hitTestResultData)
Expand Down
21 changes: 21 additions & 0 deletions Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,27 @@ static void swizzledOrderFrontColorPanel(id, SEL, id)
Util::run(&gotProposedMenu);
}

TEST(ContextMenuTests, HitTestResultHasLocalDataForLinkURL)
{
auto delegate = adoptNS([[TestUIDelegate alloc] init]);

__block bool gotProposedMenu = false;
[delegate setGetContextMenuFromProposedMenu:^(NSMenu *menu, _WKContextMenuElementInfo *elementInfo, id<NSSecureCoding>, void (^completion)(NSMenu *)) {
EXPECT_NOT_NULL(elementInfo.hitTestResult);
EXPECT_TRUE(elementInfo.hitTestResult.hasLocalDataForLinkURL);
completion(nil);
gotProposedMenu = true;
}];

auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
[webView setUIDelegate:delegate.get()];
[webView synchronouslyLoadHTMLString:@"<a href='sunset-in-cupertino-600px.jpg'><img src='sunset-in-cupertino-600px.jpg'></img></a>"];

[webView mouseDownAtPoint:NSMakePoint(200, 200) simulatePressure:NO withFlags:0 eventType:NSEventTypeRightMouseDown];
[webView mouseUpAtPoint:NSMakePoint(200, 200) withFlags:0 eventType:NSEventTypeRightMouseUp];
Util::run(&gotProposedMenu);
}

} // namespace TestWebKitAPI

#endif // PLATFORM(MAC)

0 comments on commit d370d11

Please sign in to comment.