Skip to content

Commit

Permalink
Add WebKit API scaffolding to request targeted elements for remote in…
Browse files Browse the repository at this point in the history
…spection

https://bugs.webkit.org/show_bug.cgi?id=271333

Reviewed by Aditya Keerthi.

Add WebKit API objects and SPI stubs to hit-test DOM elements for improved element targeting when
the web view is in element selection mode. See below for more details.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/page/ElementTargeting.cpp: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
(WebCore::findTargetedElements):
* Source/WebCore/page/ElementTargeting.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* Source/WebCore/page/ElementTargetingTypes.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.

Add a header declaring the new core types in WebCore: `TargetedElementInfo` (which corresponds to
the API object of the same name in WebKit) and `TargetedElementRequest` (which corresponds to
`_WKTargetedElementRequest`).

* Source/WebKit/Scripts/webkit/messages.py:
(headers_for_type):
* Source/WebKit/Shared/API/APIObject.h:
* Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h:

Add the new private headers to the umbrella.

* Source/WebKit/Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Sources.txt:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/UIProcess/API/APITargetedElementInfo.cpp: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
(API::TargetedElementInfo::TargetedElementInfo):

Add an API object to represent a single targeted element retrieved via the new SPI, which is wrapped
by the Objective-C SPI object `_WKTargetedElementInfo`.

(API::TargetedElementInfo::isSameElement const):
(API::TargetedElementInfo::boundsInWebView const):
* Source/WebKit/UIProcess/API/APITargetedElementInfo.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _requestTargetedElementInfo:completionHandler:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKRectEdge.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.

Move the existing macOS-specific declaration of `_WKRectEdge` out to a separate header, and make it
available on iOS as well. This allows us to reuse this type for the new property on
`_WKTargetedElementInfo`.

* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm: Added.
(-[_WKTargetedElementInfo dealloc]):
(-[_WKTargetedElementInfo _apiObject]):
(-[_WKTargetedElementInfo positionType]):
(-[_WKTargetedElementInfo bounds]):
(-[_WKTargetedElementInfo selectors]):
(-[_WKTargetedElementInfo renderedText]):
(-[_WKTargetedElementInfo offsetEdges]):
(-[_WKTargetedElementInfo hasBottomOffset]):
(-[_WKTargetedElementInfo hasLeftOffset]):
(-[_WKTargetedElementInfo hasRightOffset]):
(-[_WKTargetedElementInfo isSameElement:]):
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfoInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementRequest.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementRequest.mm: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h.

I opted to avoid making a new API object to represent the request object, since it's only a single
`CGPoint` (and may include another boolean parameter in the future). If these request options become
more complex, we can consider introducing an intermediate `API::TargetedElementRequest` class to
represent this.

* Source/WebKit/UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm:
* Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.mm:

Some build fixes here, due to unified source order changes.

* Source/WebKit/UIProcess/PageClient.h:
(WebKit::PageClient::rootViewToWebView const):

Add a client helper method to map the given rect from root view coordinates to web view coordinates.
On iOS, this maps from `WKContentView`'s coordinate space to `WKWebView`.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::requestTargetedElement):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::rootViewToWebView const):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::requestTargetedElement):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:

Canonical link: https://commits.webkit.org/276475@main
  • Loading branch information
whsieh committed Mar 21, 2024
1 parent 8b127d8 commit 3aef7bc
Show file tree
Hide file tree
Showing 34 changed files with 692 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
page/DragController.h
page/DummySpeechRecognitionProvider.h
page/EditorClient.h
page/ElementTargeting.h
page/ElementTargetingTypes.h
page/EventHandler.h
page/FocusController.h
page/FocusDirection.h
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,7 @@ page/DeviceController.cpp
page/DiagnosticLoggingKeys.cpp
page/DisabledAdaptations.cpp
page/DragController.cpp
page/ElementTargeting.cpp
page/EventHandler.cpp
page/EventSource.cpp
page/FocusController.cpp
Expand Down
10 changes: 10 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6248,6 +6248,8 @@
F446EDE8265DD8900031DA8F /* DataDetectorElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F446EDE7265DD8900031DA8F /* DataDetectorElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
F44A5F591FED38F2007F5944 /* LegacyNSPasteboardTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = F44A5F571FED3830007F5944 /* LegacyNSPasteboardTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
F44EBBD91DB5D21400277334 /* StaticRange.h in Headers */ = {isa = PBXBuildFile; fileRef = F44EBBD81DB5D21400277334 /* StaticRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
F454C1342BA3B57500871551 /* ElementTargetingTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = F454C1322BA3B54C00871551 /* ElementTargetingTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
F454C13A2BA3F91100871551 /* ElementTargeting.h in Headers */ = {isa = PBXBuildFile; fileRef = F454C1382BA3F8FB00871551 /* ElementTargeting.h */; settings = {ATTRIBUTES = (Private, ); }; };
F45EAC7D2A8ADFC4009B986E /* PlatformScreen.serialization.in in Headers */ = {isa = PBXBuildFile; fileRef = F45EAC7B2A8ADE03009B986E /* PlatformScreen.serialization.in */; settings = {ATTRIBUTES = (Private, ); }; };
F45EAC822A8AEED2009B986E /* InbandTextTrackPrivate.serialization.in in Headers */ = {isa = PBXBuildFile; fileRef = F45EAC812A8AEED2009B986E /* InbandTextTrackPrivate.serialization.in */; settings = {ATTRIBUTES = (Private, ); }; };
F45EAC872A8C1A65009B986E /* LayoutMilestones.serialization.in in Headers */ = {isa = PBXBuildFile; fileRef = F45EAC862A8C1972009B986E /* LayoutMilestones.serialization.in */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -20138,6 +20140,9 @@
F44EBBD61DB5D1B600277334 /* StaticRange.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StaticRange.idl; sourceTree = "<group>"; };
F44EBBD81DB5D21400277334 /* StaticRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticRange.h; sourceTree = "<group>"; };
F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticRange.cpp; sourceTree = "<group>"; };
F454C1322BA3B54C00871551 /* ElementTargetingTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElementTargetingTypes.h; sourceTree = "<group>"; };
F454C1382BA3F8FB00871551 /* ElementTargeting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElementTargeting.h; sourceTree = "<group>"; };
F454C1392BA3F8FB00871551 /* ElementTargeting.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ElementTargeting.cpp; sourceTree = "<group>"; };
F45EAC7B2A8ADE03009B986E /* PlatformScreen.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = PlatformScreen.serialization.in; sourceTree = "<group>"; };
F45EAC812A8AEED2009B986E /* InbandTextTrackPrivate.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = InbandTextTrackPrivate.serialization.in; sourceTree = "<group>"; };
F45EAC862A8C1972009B986E /* LayoutMilestones.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = LayoutMilestones.serialization.in; sourceTree = "<group>"; };
Expand Down Expand Up @@ -27403,6 +27408,9 @@
81F65FF513788FAA00FF6F2D /* DragState.h */,
93D6B7A62551D3ED0058DD3A /* DummySpeechRecognitionProvider.h */,
1AF326770D78B9440068F0C4 /* EditorClient.h */,
F454C1392BA3F8FB00871551 /* ElementTargeting.cpp */,
F454C1382BA3F8FB00871551 /* ElementTargeting.h */,
F454C1322BA3B54C00871551 /* ElementTargetingTypes.h */,
E36D701E27B71F04006531B7 /* EmptyAttachmentElementClient.h */,
93C09A800B064F00005ABD4D /* EventHandler.cpp */,
93C09A520B064DB3005ABD4D /* EventHandler.h */,
Expand Down Expand Up @@ -38960,6 +38968,8 @@
CD814C2B2996B903005A780A /* ElementIteratorInlines.h in Headers */,
63F5D4F70E8C4B7100C0BD04 /* ElementRareData.h in Headers */,
FBDB619F16D6036500BB3394 /* ElementRuleCollector.h in Headers */,
F454C13A2BA3F91100871551 /* ElementTargeting.h in Headers */,
F454C1342BA3B57500871551 /* ElementTargetingTypes.h in Headers */,
E4D58EBB17B8F12800CBDCA8 /* ElementTraversal.h in Headers */,
6FD1EBC028AEECC700FFF5D2 /* EllipsisBoxPainter.h in Headers */,
F55B3DBC1251F12D003EF269 /* EmailInputType.h in Headers */,
Expand Down
36 changes: 36 additions & 0 deletions Source/WebCore/page/ElementTargeting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "ElementTargeting.h"

namespace WebCore {

Vector<TargetedElementInfo> findTargetedElements(Page&, TargetedElementRequest&&)
{
return { };
}

} // namespace WebCore
37 changes: 37 additions & 0 deletions Source/WebCore/page/ElementTargeting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "ElementTargetingTypes.h"
#include <wtf/Vector.h>

namespace WebCore {

class Page;

WEBCORE_EXPORT Vector<TargetedElementInfo> findTargetedElements(Page&, TargetedElementRequest&&);

} // namespace WebCore
53 changes: 53 additions & 0 deletions Source/WebCore/page/ElementTargetingTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "ElementIdentifier.h"
#include "FloatPoint.h"
#include "FloatRect.h"
#include "RectEdges.h"
#include "RenderStyleConstants.h"
#include "ScriptExecutionContextIdentifier.h"
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

struct TargetedElementRequest {
FloatPoint pointInRootView;
};

struct TargetedElementInfo {
ElementIdentifier elementIdentifier;
ScriptExecutionContextIdentifier documentIdentifier;
RectEdges<bool> offsetEdges;
String renderedText;
Vector<String> selectors;
FloatRect boundsInRootView;
PositionType positionType { PositionType::Static };
};

} // namespace WebCore
2 changes: 2 additions & 0 deletions Source/WebKit/Scripts/webkit/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ def headers_for_type(type):
'WebCore::SupportedPluginIdentifier': ['<WebCore/PluginData.h>'],
'WebCore::SWServerConnectionIdentifier': ['<WebCore/ServiceWorkerTypes.h>'],
'WebCore::SystemPreviewInfo': ['<WebCore/FrameLoaderTypes.h>'],
'WebCore::TargetedElementInfo': ['<WebCore/ElementTargetingTypes.h>'],
'WebCore::TargetedElementRequest': ['<WebCore/ElementTargetingTypes.h>'],
'WebCore::TextCheckingRequestData': ['<WebCore/TextChecking.h>'],
'WebCore::TextCheckingResult': ['<WebCore/TextCheckerClient.h>'],
'WebCore::TextCheckingType': ['<WebCore/TextChecking.h>'],
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/API/APIObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Object
SessionState,
SerializedScriptValue,
String,
TargetedElementInfo,
URL,
URLRequest,
URLResponse,
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#import <WebKit/_WKFormInputSession.h>
#import <WebKit/_WKInputDelegate.h>
#import <WebKit/_WKProcessPoolConfiguration.h>
#import <WebKit/_WKTargetedElementInfo.h>
#import <WebKit/_WKTargetedElementRequest.h>
#import <WebKit/_WKThumbnailView.h>
#import <WebKit/_WKVisitedLinkStore.h>
5 changes: 5 additions & 0 deletions Source/WebKit/Shared/Cocoa/APIObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#import "_WKResourceLoadInfoInternal.h"
#import "_WKResourceLoadStatisticsFirstPartyInternal.h"
#import "_WKResourceLoadStatisticsThirdPartyInternal.h"
#import "_WKTargetedElementInfoInternal.h"
#import "_WKUserContentWorldInternal.h"
#import "_WKUserInitiatedActionInternal.h"
#import "_WKUserStyleSheetInternal.h"
Expand Down Expand Up @@ -382,6 +383,10 @@
wrapper = [WKContentWorld alloc];
break;

case Type::TargetedElementInfo:
wrapper = [_WKTargetedElementInfo alloc];
break;

case Type::UserInitiatedAction:
wrapper = [_WKUserInitiatedAction alloc];
break;
Expand Down
25 changes: 25 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,31 @@ struct WebCore::ShareData {

enum class WebCore::ShareDataOriginator : bool

header: <WebCore/ElementTargetingTypes.h>
[CustomHeader] struct WebCore::TargetedElementRequest {
WebCore::FloatPoint pointInRootView
};

header: <WebCore/ElementTargetingTypes.h>
[CustomHeader] struct WebCore::TargetedElementInfo {
WebCore::ElementIdentifier elementIdentifier
WebCore::ScriptExecutionContextIdentifier documentIdentifier
WebCore::RectEdges<bool> offsetEdges
String renderedText
Vector<String> selectors
WebCore::FloatRect boundsInRootView
WebCore::PositionType positionType
};

header: <WebCore/RenderStyleConstants.h>
[CustomHeader] enum class WebCore::PositionType : uint8_t {
Static,
Relative,
Absolute,
Sticky,
Fixed
};

[CustomHeader] struct WebCore::RawFile {
String fileName;
RefPtr<WebCore::SharedBuffer> fileData;
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ UIProcess/API/APIPageConfiguration.cpp
UIProcess/API/APIProcessPoolConfiguration.cpp
UIProcess/API/APIOpenPanelParameters.cpp
UIProcess/API/APISessionState.cpp
UIProcess/API/APITargetedElementInfo.cpp
UIProcess/API/APIUIClient.cpp
UIProcess/API/APIUserScript.cpp
UIProcess/API/APIUserStyleSheet.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm
UIProcess/API/Cocoa/_WKResourceLoadInfo.mm
UIProcess/API/Cocoa/_WKSessionState.mm
UIProcess/API/Cocoa/_WKSystemPreferences.mm
UIProcess/API/Cocoa/_WKTargetedElementInfo.mm
UIProcess/API/Cocoa/_WKTargetedElementRequest.mm
UIProcess/API/Cocoa/_WKTextInputContext.mm
UIProcess/API/Cocoa/_WKTextManipulationConfiguration.mm
UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm
Expand Down
55 changes: 55 additions & 0 deletions Source/WebKit/UIProcess/API/APITargetedElementInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "APITargetedElementInfo.h"

#include "PageClient.h"
#include "WebPageProxy.h"

namespace API {
using namespace WebKit;

TargetedElementInfo::TargetedElementInfo(WebPageProxy& page, WebCore::TargetedElementInfo&& info)
: m_info(WTFMove(info))
, m_page(page)
{
}

bool TargetedElementInfo::isSameElement(const TargetedElementInfo& other) const
{
return m_info.elementIdentifier == other.m_info.elementIdentifier
&& m_info.documentIdentifier == other.m_info.documentIdentifier;
}

WebCore::FloatRect TargetedElementInfo::boundsInWebView() const
{
RefPtr page = m_page.get();
if (!page)
return { };
return page->pageClient().rootViewToWebView(boundsInRootView());
}

} // namespace API
66 changes: 66 additions & 0 deletions Source/WebKit/UIProcess/API/APITargetedElementInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "APIObject.h"
#include <WebCore/ElementTargetingTypes.h>
#include <wtf/Forward.h>
#include <wtf/WeakPtr.h>

namespace WebKit {
class WebPageProxy;
}

namespace API {

class TargetedElementInfo final : public ObjectImpl<Object::Type::TargetedElementInfo> {
public:
static Ref<TargetedElementInfo> create(WebKit::WebPageProxy& page, WebCore::TargetedElementInfo&& info)
{
return adoptRef(*new TargetedElementInfo(page, WTFMove(info)));
}

explicit TargetedElementInfo(WebKit::WebPageProxy&, WebCore::TargetedElementInfo&&);

WebCore::RectEdges<bool> offsetEdges() const { return m_info.offsetEdges; }

const WTF::String& renderedText() const { return m_info.renderedText; }
const Vector<WTF::String>& selectors() const { return m_info.selectors; }
WebCore::PositionType positionType() const { return m_info.positionType; }
WebCore::FloatRect boundsInRootView() const { return m_info.boundsInRootView; }
WebCore::FloatRect boundsInWebView() const;

bool isSameElement(const TargetedElementInfo&) const;

WebCore::ElementIdentifier elementIdentifier() const { return m_info.elementIdentifier; }
WebCore::ScriptExecutionContextIdentifier documentIdentifier() const { return m_info.documentIdentifier; }

private:
WebCore::TargetedElementInfo m_info;
WeakPtr<WebKit::WebPageProxy> m_page;
};

} // namespace API
Loading

0 comments on commit 3aef7bc

Please sign in to comment.