[webkit-changes] [WebKit/WebKit] 676b1c: [visionOS] Fix the drag preview of the <model> ele...

Ada Chan noreply at github.com
Fri Feb 14 23:48:31 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 676b1c75b77ea731918213ca6853ff55aaccec61
      https://github.com/WebKit/WebKit/commit/676b1c75b77ea731918213ca6853ff55aaccec61
  Author: Ada Chan <adachan at apple.com>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M Source/WebCore/Modules/model-element/HTMLModelElement.h
    M Source/WebCore/page/DragController.cpp
    M Source/WebCore/platform/DragItem.h
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h
    M Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
    M Source/WebKit/UIProcess/Model/ModelPresentationManagerProxy.h
    M Source/WebKit/UIProcess/Model/ModelPresentationManagerProxy.mm
    M Source/WebKit/UIProcess/ios/DragDropInteractionState.h
    M Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/ios/WKPageHostedModelView.mm
    M Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/WebKit/simple-model-page.html
    M Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm
    M Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h
    M Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm

  Log Message:
  -----------
  [visionOS] Fix the drag preview of the <model> element
https://bugs.webkit.org/show_bug.cgi?id=287525
rdar://141165213

Reviewed by Wenson Hsieh and Abrar Rahman Protyasha.

For UITargetedDragPreview to capture the snapshot of a view
with entity-based content properly, we need to pass the _UIRemoteView
hosting the model content directly when constructing the UITargetedDragPreview.
To do that, we need to pass the model element’s PlatformLayerIdentifier
in the DragItem, so we can use it to retrieve the _UIRemoteView hosting
the model entity from ModelPresentationManagerProxy in the UI process
to stage the drag session with.
In DragDropInteractionState::createDragPreviewInternal(), if the drag
preview content is the _UIRemoteView rather than an image, create the
UITargetedDragPreview with that view directly.

Handle the edge case where the model element is removed while
it’s being dragged by adding it to the WKContentView’s drag previews
container view.

* Source/WebCore/Modules/model-element/HTMLModelElement.h:
* Source/WebCore/page/DragController.cpp:
(WebCore::DragController::doSystemDrag):
If the dragged element is an HTMLModelElement, save off its
PlatformLayerIdentifier in the DragItem.
* Source/WebCore/platform/DragItem.h:
Include the model element’s PlatformLayerIdentifier
in the DragItem struct.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _willInvalidateDraggedModelWithContainerView:]):
* Source/WebKit/UIProcess/Model/ModelPresentationManagerProxy.h:
* Source/WebKit/UIProcess/Model/ModelPresentationManagerProxy.mm:
(WebKit::ModelPresentationManagerProxy::startDragForModel):
Add the dragged model’s layer identifier to m_activelyDraggedModelLayerIDs.
Return the _UIRemoteView hosting the model entity.
(WebKit::ModelPresentationManagerProxy::doneWithCurrentDragSession):
Clear m_activelyDraggedModelLayerIDs.
(WebKit::ModelPresentationManagerProxy::invalidateModel):
If the model layer being removed is currently being dragged, call
-[WKWebView _willInvalidateDraggedModelWithContainerView:] with the
model container view so it can be re-parented to the window’s
view hierarchy.
* Source/WebKit/UIProcess/ios/DragDropInteractionState.h:
DragSourceState now stores content with the DragPreviewContentType
which is either a UIImage or a UIView.
* Source/WebKit/UIProcess/ios/DragDropInteractionState.mm:
(WebKit::shouldUseDragImageToCreatePreviewForDragSource):
(WebKit::DragDropInteractionState::previewForCancelling):
The UITargetedDragPreview’s view is the _UIRemoteView’s that’s
already in the remote layer tree’s view hierarchy if the dragged
element is a model element. Only add UITargetedDragPreview’s view
to m_previewViewsForDragCancel if its superview is the preview container.
(WebKit::DragDropInteractionState::createDragPreviewInternal const):
If the drag preview content is a UIView (which is the case for a
dragged model), create a UITargetedDragPreview with that UIView.
(WebKit::DragDropInteractionState::stageDragItem):
(WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _startDrag:item:]):
If the dragged item has a model layer identifier, stage the drag
item with the _UIRemoteView returned from the page’s ModelPresentationManagerProxy.
(-[WKContentView cleanUpDragSourceSessionState]):
Clear the dragged models tracked in ModelPresentationManagerProxy.
(-[WKContentView _willInvalidateDraggedModelWithContainerView:]):
This is called when the dragged model is being removed from the document.
We need to keep its container view in the window by hiding it and
adding it to the WKContentView’s _dragPreviewContainerView.
* Source/WebKit/UIProcess/ios/WKPageHostedModelView.mm:
(-[WKPageHostedModelView init]):
Add some nil checks which are needed for TestWebKitAPI model drag
and drop tests.
* Tools/TestRunnerShared/spi/UIKitSPIForTesting.h:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKit/simple-model-page.html: Added.
Simple test page with a model. Posts messages when the model is
loaded and when it’s ready.
* Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
(-[ModelLoadingMessageHandler userContentController:didReceiveScriptMessage:]):
Teach ModelLoadingMessageHandler to catch both the model loaded
event and the model ready event.
(TestWebKitAPI::TEST(DragAndDropTests, CanStartDragOnModel)):
Update test to load the new simple-model-page.html.
(TestWebKitAPI::TEST(DragAndDropTests, CheckModelDragPreview)):
Simulate the dragging of a model element and verify that the resulting
UITargetedDragPreview’s view is a _UIRemoteView. In the middle of the
drag, remove the model from the document and make sure the _UIRemoteView
is still in the window’s view hierarchy. We have to test this scenario
while the drag is still in progress because the page’s drag preview
container view gets removed from the window at the end of the drag session.
* Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h:
* Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm:
(-[DragAndDropSimulator _advanceProgress]):
Call _dragProgressMidPointReachedBlock if it's set when the
drag progress has passed the midway point.

Canonical link: https://commits.webkit.org/290437@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list