Skip to content

Commit

Permalink
[Site Isolation][macOS] Propagate drag events to isolated frames
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264502
rdar://118184993

Reviewed by Wenson Hsieh.

This follows the same pattern as mouse events, where IPC is sent between the UI process and web
processes until the target frame is reached.

* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/loader/EmptyClients.cpp:
* Source/WebCore/page/DragClient.h:

* Source/WebCore/page/DragController.cpp:
(WebCore::DragController::dragExited):
(WebCore::DragController::dragEnteredOrUpdated):
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::tryDHTMLDrag):
(WebCore::DragController::doSystemDrag):
(WebCore::DragController::dragEntered): Deleted.
(WebCore::DragController::dragUpdated): Deleted.
* Source/WebCore/page/DragController.h:

There were several places in `DragController` where drag functions would always be called on the main
frame’s event handler. This won’t work when the main frame is being hosted in another process. I
changed these functions to pass the frame which the drag is happening in, and instead call functions
on the event handler of that frame.

There were also places where we were down casting frames to local when we didn’t need to. In
`doSystemDrag()` and `tryDHTMLDrag()` all functions called on the main frame and main frame view are
accessible even if the frame is out-of-process.

`dragEntered()` and `dragUpdated()` didn’t seem like a useful abstraction, so I removed them.

* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::mouseEventDataForRemoteFrame):
(WebCore::EventHandler::dragSourceEndedAt):
* Source/WebCore/page/EventHandler.h:

I changed `dragSourceEndedAt()` to return a `FrameIdentifier` if the hit test leads to a remote frame.

* Source/WebCore/page/HandleMouseEventResult.h:
(WebCore::HandleMouseEventResult::HandleMouseEventResult):
(WebCore::HandleMouseEventResult::remoteInputEventData):
(WebCore::HandleMouseEventResult::remoteMouseEventData): Deleted.
* Source/WebCore/page/RemoteUserInputEventData.h: Renamed from Source/WebCore/page/RemoteMouseEventData.h.

I renamed `RemoteMouseEventData` to `RemoteUserInputEventData` since we can use the struct for things other
than mouse events. I used it here for drag events, and can likely be used for touch events too.

* Source/WebCore/platform/DragData.h:
(WebCore::DragData::setClientPosition):

I added `setClientPosition` to update the client positions coordinates on `DragData` when passing a drag
event to a remote frame.

* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
(WebKit::WebPasteboardProxy::determineDataOwner const):

When dragging in a isolated frame, each of the `MESSAGE_CHECK_COMPLETION(dataOwner, completionHandler())`
would fail. This is because `determineDataOwner()` is only checking for a `WebPageProxy` associated with
the `WebProcessProxy`, which may not exist. We also need to check each `RemotePageProxy`.

* Source/WebKit/UIProcess/RemotePageProxy.cpp:
(WebKit::RemotePageProxy::sendMouseEvent):

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::performDragOperation):
(WebKit::WebPageProxy::performDragControllerAction):
(WebKit::WebPageProxy::dragEnded):
(WebKit::WebPageProxy::handleMouseEventReply):
(WebKit::WebPageProxy::sendMouseEvent):
* Source/WebKit/UIProcess/WebPageProxy.h:

The completion handler in `performDragControllerAction()` and `dragEnded()` is where the drag is
forwarded to the iframe process. I also added a frame identifier as a parameter so the same function
could be used to send the next drag.

`TestWebKitAPI.DragAndDropTests.DragAndDropOnEmptyView` expects drag events to be sent for empty webviews,
so we still need to send the drag IPC even if `m_mainFrame` is null. I made `FrameIdentifier` optional in
the drag IPC messages to the web page which will default to the main frame, since we don't know the frame
identifier of the main frame in the UI process in this case.

* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::remotePages const):
* Source/WebKit/UIProcess/WebProcessProxy.h:

I added `remotePages()` so they could be accessed in `WebPasteboardProxyCocoa`.

* Source/WebKit/WebProcess/WebCoreSupport/WebDragClient.cpp:
(WebKit::WebDragClient::startDrag):
* Source/WebKit/WebProcess/WebCoreSupport/WebDragClient.h:
* Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
(WebKit::WebDragClient::startDrag):
* Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::convertDragImageToBitmap):
(WebKit::WebDragClient::startDrag):
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::performDragControllerAction):
(WebKit::WebPage::dragEnded):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:

Change these functions to expect a frame identifier to be passed. If the frame identifer is null, use the
main frame.

* Source/WebKitLegacy/mac/WebCoreSupport/WebDragClient.h:
* Source/WebKitLegacy/mac/WebCoreSupport/WebDragClient.mm:
(WebDragClient::startDrag):
* Source/WebKitLegacy/mac/WebView/WebFrame.mm:
* Source/WebKitLegacy/mac/WebView/WebView.mm:
(-[WebView _enteredDataInteraction:client:global:operation:]):
(-[WebView _updatedDataInteraction:client:global:operation:]):
(-[WebView _exitedDataInteraction:client:global:operation:]):
(-[WebView draggingEntered:]):
(-[WebView draggingUpdated:]):
(-[WebView draggingExited:]):

* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/270614@main
  • Loading branch information
charliewolfe committed Nov 12, 2023
1 parent d53d6d2 commit a1ad995
Show file tree
Hide file tree
Showing 31 changed files with 308 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
page/RemoteFrame.h
page/RemoteFrameClient.h
page/RemoteFrameView.h
page/RemoteMouseEventData.h
page/RemoteUserInputEventData.h
page/RenderingUpdateScheduler.h
page/ScreenOrientationLockType.h
page/ScreenOrientationType.h
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
021D763929C2A43B00063684 /* ScrollbarsController.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F02245226F15D5F000265C3 /* ScrollbarsController.h */; settings = {ATTRIBUTES = (Private, ); }; };
021D763A29C2AC6B00063684 /* ScrollbarsControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F02245326F15D75000265C3 /* ScrollbarsControllerMac.mm */; };
0223E06D2AAECC2200AF30FB /* HandleMouseEventResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 0223E06C2AAEBBCF00AF30FB /* HandleMouseEventResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
0223E0742AAED62200AF30FB /* RemoteMouseEventData.h in Headers */ = {isa = PBXBuildFile; fileRef = 0223E0732AAED62200AF30FB /* RemoteMouseEventData.h */; settings = {ATTRIBUTES = (Private, ); }; };
0223E0742AAED62200AF30FB /* RemoteUserInputEventData.h in Headers */ = {isa = PBXBuildFile; fileRef = 0223E0732AAED62200AF30FB /* RemoteUserInputEventData.h */; settings = {ATTRIBUTES = (Private, ); }; };
0245150C297CAFA300DFD845 /* LinkDecorationFilteringData.h in Headers */ = {isa = PBXBuildFile; fileRef = 0245150B297CAF7700DFD845 /* LinkDecorationFilteringData.h */; settings = {ATTRIBUTES = (Private, ); }; };
02E536BD2984EA6800417C02 /* ScrollerPairMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 024E5F7429844DBD009CC5FC /* ScrollerPairMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
02E536C12984ECE200417C02 /* ScrollerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 024E5F7129844DBC009CC5FC /* ScrollerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -6577,7 +6577,7 @@
016F380929AA33E300167F2E /* ApplePayLaterAvailability.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ApplePayLaterAvailability.idl; sourceTree = "<group>"; };
016F380D29AA36A200167F2E /* ApplePayLaterAvailability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayLaterAvailability.h; sourceTree = "<group>"; };
0223E06C2AAEBBCF00AF30FB /* HandleMouseEventResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HandleMouseEventResult.h; sourceTree = "<group>"; };
0223E0732AAED62200AF30FB /* RemoteMouseEventData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteMouseEventData.h; sourceTree = "<group>"; };
0223E0732AAED62200AF30FB /* RemoteUserInputEventData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteUserInputEventData.h; sourceTree = "<group>"; };
0245150B297CAF7700DFD845 /* LinkDecorationFilteringData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LinkDecorationFilteringData.h; sourceTree = "<group>"; };
024E5F7129844DBC009CC5FC /* ScrollerMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollerMac.h; sourceTree = "<group>"; };
024E5F7229844DBD009CC5FC /* ScrollerMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollerMac.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -27312,7 +27312,7 @@
5C2397D22949213600BB4E10 /* RemoteFrameClient.h */,
5C6F7689296CBC5400799B41 /* RemoteFrameView.cpp */,
5C907EB929528A4300B3402D /* RemoteFrameView.h */,
0223E0732AAED62200AF30FB /* RemoteMouseEventData.h */,
0223E0732AAED62200AF30FB /* RemoteUserInputEventData.h */,
556C7C4922123943009B06CA /* RenderingUpdateScheduler.cpp */,
556C7C4722123942009B06CA /* RenderingUpdateScheduler.h */,
58B2F9F22232D43F00938D63 /* ResizeObservation.cpp */,
Expand Down Expand Up @@ -41033,9 +41033,9 @@
46B9519A207D635400A7D2DD /* RemoteFrame.h in Headers */,
5C2397D72949288700BB4E10 /* RemoteFrameClient.h in Headers */,
5C6F768D296CC7DD00799B41 /* RemoteFrameView.h in Headers */,
0223E0742AAED62200AF30FB /* RemoteMouseEventData.h in Headers */,
CDC312E922FCD7C0001204EC /* RemotePlayback.h in Headers */,
CDC312EB22FCD7C9001204EC /* RemotePlaybackAvailabilityCallback.h in Headers */,
0223E0742AAED62200AF30FB /* RemoteUserInputEventData.h in Headers */,
D06C0D8F0CFD11460065F43F /* RemoveFormatCommand.h in Headers */,
93309E05099E64920056E581 /* RemoveNodeCommand.h in Headers */,
93309E07099E64920056E581 /* RemoveNodePreservingChildrenCommand.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/EmptyClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class EmptyDragClient final : public DragClient {
void willPerformDragDestinationAction(DragDestinationAction, const DragData&) final { }
void willPerformDragSourceAction(DragSourceAction, const IntPoint&, DataTransfer&) final { }
OptionSet<DragSourceAction> dragSourceActionMaskForPoint(const IntPoint&) final { return { }; }
void startDrag(DragItem, DataTransfer&, LocalFrame&) final { }
void startDrag(DragItem, DataTransfer&, Frame&) final { }
};

#endif // ENABLE(DRAG_SUPPORT)
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/page/DragClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace WebCore {

class DataTransfer;
class Element;
class Frame;
class Image;
class LocalFrame;

Expand All @@ -52,7 +53,7 @@ class DragClient {
virtual void didConcludeEditDrag() { }
virtual OptionSet<DragSourceAction> dragSourceActionMaskForPoint(const IntPoint& rootViewPoint) = 0;

virtual void startDrag(DragItem, DataTransfer&, LocalFrame&) = 0;
virtual void startDrag(DragItem, DataTransfer&, Frame&) = 0;
virtual void dragEnded() { }

virtual void beginDrag(DragItem, LocalFrame&, const IntPoint&, const IntPoint&, DataTransfer&, DragSourceAction) { }
Expand Down
70 changes: 30 additions & 40 deletions Source/WebCore/page/DragController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "SVGAElement.h"
#include "SVGElementTypeHelpers.h"


#if ENABLE(DRAG_SUPPORT)
#include "CachedImage.h"
#include "CachedResourceLoader.h"
Expand Down Expand Up @@ -80,6 +79,8 @@
#include "Position.h"
#include "PromisedAttachmentInfo.h"
#include "Range.h"
#include "RemoteFrame.h"
#include "RemoteUserInputEventData.h"
#include "RenderAttachment.h"
#include "RenderFileUploadControl.h"
#include "RenderImage.h"
Expand Down Expand Up @@ -210,30 +211,17 @@ void DragController::dragEnded()
client().dragEnded();
}

std::optional<DragOperation> DragController::dragEntered(DragData&& dragData)
{
return dragEnteredOrUpdated(WTFMove(dragData));
}

void DragController::dragExited(DragData&& dragData)
void DragController::dragExited(LocalFrame& frame, DragData&& dragData)
{
disallowFileAccessIfNeeded(dragData);
auto* localMainFrame = dynamicDowncast<LocalFrame>(m_page.mainFrame());
if (!localMainFrame)
return;
if (localMainFrame->view())
localMainFrame->eventHandler().cancelDragAndDrop(createMouseEvent(dragData), Pasteboard::create(dragData), dragData.draggingSourceOperationMask(), dragData.containsFiles());
if (frame.view())
frame.eventHandler().cancelDragAndDrop(createMouseEvent(dragData), Pasteboard::create(dragData), dragData.draggingSourceOperationMask(), dragData.containsFiles());
mouseMovedIntoDocument(nullptr);
if (m_fileInputElementUnderMouse)
m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
m_fileInputElementUnderMouse = nullptr;
}

std::optional<DragOperation> DragController::dragUpdated(DragData&& dragData)
{
return dragEnteredOrUpdated(WTFMove(dragData));
}

inline static bool dragIsHandledByDocument(DragHandlingMethod dragHandlingMethod)
{
return dragHandlingMethod != DragHandlingMethod::None && dragHandlingMethod != DragHandlingMethod::PageLoad;
Expand Down Expand Up @@ -317,12 +305,21 @@ void DragController::mouseMovedIntoDocument(Document* newDocument)
m_documentUnderMouse = newDocument;
}

std::optional<DragOperation> DragController::dragEnteredOrUpdated(DragData&& dragData)
std::variant<std::optional<DragOperation>, RemoteUserInputEventData> DragController::dragEnteredOrUpdated(LocalFrame& frame, DragData&& dragData)
{
auto* localMainFrame = dynamicDowncast<LocalFrame>(m_page.mainFrame());
if (!localMainFrame)
return std::nullopt;
mouseMovedIntoDocument(localMainFrame->documentAtPoint(dragData.clientPosition()));
auto point = frame.protectedView()->windowToContents(dragData.clientPosition());
auto hitTestResult = HitTestResult(point);
if (frame.contentRenderer()) {
constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::DisallowUserAgentShadowContent, HitTestRequest::Type::AllowChildFrameContent };
hitTestResult = frame.checkedEventHandler()->hitTestResultAtPoint(point, hitType);
}

if (RefPtr remoteSubframe = dynamicDowncast<RemoteFrame>(frame.checkedEventHandler()->subframeForTargetNode(hitTestResult.targetNode()))) {
// FIXME(264611): These mouse coordinates need to be correctly transformed.
return RemoteUserInputEventData { remoteSubframe->frameID(), dragData.clientPosition() };
}

mouseMovedIntoDocument(hitTestResult.innerNode() ? &hitTestResult.innerNode()->document() : nullptr);

m_dragDestinationActionMask = dragData.dragDestinationActionMask();
if (m_dragDestinationActionMask.isEmpty()) {
Expand All @@ -333,7 +330,7 @@ std::optional<DragOperation> DragController::dragEnteredOrUpdated(DragData&& dra
disallowFileAccessIfNeeded(dragData);

std::optional<DragOperation> dragOperation;
m_dragHandlingMethod = tryDocumentDrag(dragData, m_dragDestinationActionMask, dragOperation);
m_dragHandlingMethod = tryDocumentDrag(frame, dragData, m_dragDestinationActionMask, dragOperation);
if (m_dragHandlingMethod == DragHandlingMethod::None && (m_dragDestinationActionMask.contains(DragDestinationAction::Load))) {
dragOperation = operationForLoad(dragData);
if (dragOperation)
Expand Down Expand Up @@ -411,7 +408,7 @@ void DragController::updateSupportedTypeIdentifiersForDragHandlingMethod(DragHan

#endif

DragHandlingMethod DragController::tryDocumentDrag(const DragData& dragData, OptionSet<DragDestinationAction> destinationActionMask, std::optional<DragOperation>& dragOperation)
DragHandlingMethod DragController::tryDocumentDrag(LocalFrame& frame, const DragData& dragData, OptionSet<DragDestinationAction> destinationActionMask, std::optional<DragOperation>& dragOperation)
{
if (!m_documentUnderMouse)
return DragHandlingMethod::None;
Expand All @@ -421,7 +418,7 @@ DragHandlingMethod DragController::tryDocumentDrag(const DragData& dragData, Opt

bool isHandlingDrag = false;
if (destinationActionMask.contains(DragDestinationAction::DHTML)) {
isHandlingDrag = tryDHTMLDrag(dragData, dragOperation);
isHandlingDrag = tryDHTMLDrag(frame, dragData, dragOperation);
// Do not continue if m_documentUnderMouse has been reset by tryDHTMLDrag.
// tryDHTMLDrag fires dragenter event. The event listener that listens
// to this event may create a nested message loop (open a modal dialog),
Expand Down Expand Up @@ -736,20 +733,16 @@ static std::optional<DragOperation> defaultOperationForDrag(OptionSet<DragOperat
return DragOperation::Generic;
}

bool DragController::tryDHTMLDrag(const DragData& dragData, std::optional<DragOperation>& operation)
bool DragController::tryDHTMLDrag(LocalFrame& frame, const DragData& dragData, std::optional<DragOperation>& operation)
{
ASSERT(m_documentUnderMouse);
auto* localMainFrame = dynamicDowncast<LocalFrame>(m_page.mainFrame());
if (!localMainFrame)
return false;

Ref protectedLocalMainFrame(*localMainFrame);
RefPtr viewProtector = protectedLocalMainFrame->view();
Ref protectedFrame(frame);
RefPtr viewProtector = protectedFrame->view();
if (!viewProtector)
return false;

auto sourceOperationMask = dragData.draggingSourceOperationMask();
auto targetResponse = protectedLocalMainFrame->eventHandler().updateDragAndDrop(createMouseEvent(dragData), [&dragData]() {
auto targetResponse = protectedFrame->eventHandler().updateDragAndDrop(createMouseEvent(dragData), [&dragData]() {
return Pasteboard::create(dragData);
}, sourceOperationMask, dragData.containsFiles());
if (!targetResponse.accept)
Expand Down Expand Up @@ -1400,12 +1393,9 @@ void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, cons
{
m_didInitiateDrag = true;
m_dragInitiator = frame.document();
auto* localMainFrame = dynamicDowncast<LocalFrame>(m_page.mainFrame());
if (!localMainFrame)
return;
// Protect this frame and view, as a load may occur mid drag and attempt to unload this frame
Ref protectedLocalMainFrame(*localMainFrame);
RefPtr viewProtector = protectedLocalMainFrame->view();
Ref protectedMainFrame(m_page.mainFrame());
RefPtr viewProtector = protectedMainFrame->virtualView();

DragItem item;
item.image = WTFMove(image);
Expand Down Expand Up @@ -1443,9 +1433,9 @@ void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, cons
item.url = frame.document()->completeURL(link->getAttribute(HTMLNames::hrefAttr));
}
}
client().startDrag(WTFMove(item), *state.dataTransfer, protectedLocalMainFrame.get());
client().startDrag(WTFMove(item), *state.dataTransfer, protectedMainFrame.get());
// DragClient::startDrag can cause our Page to dispear, deallocating |this|.
if (!protectedLocalMainFrame->page())
if (!protectedMainFrame->page())
return;

cleanupAfterSystemDrag();
Expand Down
11 changes: 5 additions & 6 deletions Source/WebCore/page/DragController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PlatformMouseEvent;
struct DragItem;
struct DragState;
struct PromisedAttachmentInfo;
struct RemoteUserInputEventData;

class DragController {
WTF_MAKE_NONCOPYABLE(DragController); WTF_MAKE_FAST_ALLOCATED;
Expand All @@ -61,9 +62,8 @@ class DragController {

static DragOperation platformGenericDragOperation();

WEBCORE_EXPORT std::optional<DragOperation> dragEntered(DragData&&);
WEBCORE_EXPORT void dragExited(DragData&&);
WEBCORE_EXPORT std::optional<DragOperation> dragUpdated(DragData&&);
WEBCORE_EXPORT std::variant<std::optional<DragOperation>, RemoteUserInputEventData> dragEnteredOrUpdated(LocalFrame&, DragData&&);
WEBCORE_EXPORT void dragExited(LocalFrame&, DragData&&);
WEBCORE_EXPORT bool performDragOperation(DragData&&);
WEBCORE_EXPORT void dragCancelled();

Expand Down Expand Up @@ -110,10 +110,9 @@ class DragController {
bool dispatchTextInputEventFor(LocalFrame*, const DragData&);
bool canProcessDrag(const DragData&);
bool concludeEditDrag(const DragData&);
std::optional<DragOperation> dragEnteredOrUpdated(DragData&&);
std::optional<DragOperation> operationForLoad(const DragData&);
DragHandlingMethod tryDocumentDrag(const DragData&, OptionSet<DragDestinationAction>, std::optional<DragOperation>&);
bool tryDHTMLDrag(const DragData&, std::optional<DragOperation>&);
DragHandlingMethod tryDocumentDrag(LocalFrame&, const DragData&, OptionSet<DragDestinationAction>, std::optional<DragOperation>&);
bool tryDHTMLDrag(LocalFrame&, const DragData&, std::optional<DragOperation>&);
std::optional<DragOperation> dragOperation(const DragData&);
void clearDragCaret();
bool dragIsMove(FrameSelection&, const DragData&);
Expand Down
14 changes: 10 additions & 4 deletions Source/WebCore/page/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#include "Range.h"
#include "RemoteFrame.h"
#include "RemoteFrameView.h"
#include "RemoteUserInputEventData.h"
#include "RenderFrameSet.h"
#include "RenderImage.h"
#include "RenderLayer.h"
Expand Down Expand Up @@ -1739,7 +1740,7 @@ static LayoutPoint documentPointForWindowPoint(LocalFrame& frame, const IntPoint
return view ? view->windowToContents(windowPoint) : windowPoint;
}

std::optional<RemoteMouseEventData> EventHandler::mouseEventDataForRemoteFrame(const RemoteFrame* remoteFrame, const IntPoint& pointInFrame)
std::optional<RemoteUserInputEventData> EventHandler::mouseEventDataForRemoteFrame(const RemoteFrame* remoteFrame, const IntPoint& pointInFrame)
{
if (!remoteFrame)
return std::nullopt;
Expand All @@ -1752,7 +1753,7 @@ std::optional<RemoteMouseEventData> EventHandler::mouseEventDataForRemoteFrame(c
if (!remoteFrameView)
return std::nullopt;

return RemoteMouseEventData {
return RemoteUserInputEventData {
remoteFrame->frameID(),
remoteFrameView->rootViewToContents(frameView->contentsToRootView(pointInFrame))
};
Expand Down Expand Up @@ -4161,10 +4162,14 @@ void EventHandler::didStartDrag()
#endif
}

void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, OptionSet<DragOperation> dragOperationMask, MayExtendDragSession mayExtendDragSession)
std::optional<RemoteUserInputEventData> EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, OptionSet<DragOperation> dragOperationMask, MayExtendDragSession mayExtendDragSession)
{
// Send a hit test request so that RenderLayer gets a chance to update the :hover and :active pseudoclasses.
prepareMouseEvent(OptionSet<HitTestRequest::Type> { HitTestRequest::Type::Release, HitTestRequest::Type::DisallowUserAgentShadowContent }, event);
auto mouseEvent = prepareMouseEvent(OptionSet<HitTestRequest::Type> { HitTestRequest::Type::Release, HitTestRequest::Type::DisallowUserAgentShadowContent }, event);
if (RefPtr remoteSubframe = dynamicDowncast<RemoteFrame>(subframeForHitTestResult(mouseEvent))) {
// FIXME(264611): These mouse coordinates need to be correctly transformed.
return RemoteUserInputEventData { remoteSubframe->frameID(), mouseEvent.hitTestResult().roundedPointInInnerNodeFrame() };
}

if (shouldDispatchEventsToDragSourceElement()) {
dragState().dataTransfer->setDestinationOperationMask(dragOperationMask);
Expand All @@ -4181,6 +4186,7 @@ void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, OptionSet<
// In case the drag was ended due to an escape key press we need to ensure
// that consecutive mousemove events don't reinitiate the drag and drop.
m_mouseDownMayStartDrag = false;
return std::nullopt;
}

void EventHandler::updateDragStateAfterEditDragIfNeeded(Element& rootEditableElement)
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/page/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class WheelEvent;
class Widget;

struct DragState;
struct RemoteMouseEventData;
struct RemoteUserInputEventData;

enum class WheelEventProcessingSteps : uint8_t;
enum class WheelScrollGestureState : uint8_t;
Expand Down Expand Up @@ -284,7 +284,7 @@ class EventHandler : public CanMakeCheckedPtr {

WEBCORE_EXPORT void didStartDrag();
WEBCORE_EXPORT void dragCancelled();
WEBCORE_EXPORT void dragSourceEndedAt(const PlatformMouseEvent&, OptionSet<DragOperation>, MayExtendDragSession = MayExtendDragSession::No);
WEBCORE_EXPORT std::optional<RemoteUserInputEventData> dragSourceEndedAt(const PlatformMouseEvent&, OptionSet<DragOperation>, MayExtendDragSession = MayExtendDragSession::No);
#endif

void focusDocumentView();
Expand Down Expand Up @@ -599,7 +599,7 @@ class EventHandler : public CanMakeCheckedPtr {
bool canMouseDownStartSelect(const MouseEventWithHitTestResults&);
bool mouseDownMayStartSelect() const;

std::optional<RemoteMouseEventData> mouseEventDataForRemoteFrame(const RemoteFrame*, const IntPoint&);
std::optional<RemoteUserInputEventData> mouseEventDataForRemoteFrame(const RemoteFrame*, const IntPoint&);

bool isCapturingMouseEventsElement() const { return m_capturingMouseEventsElement || m_isCapturingRootElementForMouseEvents; }
void resetCapturingMouseEventsElement()
Expand Down

0 comments on commit a1ad995

Please sign in to comment.