Skip to content
Permalink
Browse files
[Model] [macOS] Add support for interaction on macOS
https://bugs.webkit.org/show_bug.cgi?id=233105
<rdar://problem/80079386>

Reviewed by Wenson Hsieh.

Source/WebCore:

Capture mouse events after the mouse button is pressed over a <model> element,
unless preventDefault() is called, and forward those events through ModelPlayer
to the UI process.

* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::defaultEventHandler):
(WebCore::HTMLModelElement::dragDidStart):
(WebCore::HTMLModelElement::dragDidChange):
(WebCore::HTMLModelElement::dragDidEnd):
* Modules/model-element/HTMLModelElement.h:
* Modules/model-element/ModelPlayer.cpp:
(WebCore::ModelPlayer::supportsMouseInteraction):
* Modules/model-element/ModelPlayer.h:
* Modules/model-element/dummy/DummyModelPlayer.cpp:
(WebCore::DummyModelPlayer::handleMouseDown):
(WebCore::DummyModelPlayer::handleMouseMove):
(WebCore::DummyModelPlayer::handleMouseUp):
* Modules/model-element/dummy/DummyModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.mm:
(WebCore::SceneKitModelPlayer::handleMouseDown):
(WebCore::SceneKitModelPlayer::handleMouseMove):
(WebCore::SceneKitModelPlayer::handleMouseUp):

Source/WebCore/PAL:

Add new ARQL SPIs.

* pal/spi/mac/SystemPreviewSPI.h:

Source/WebKit:

Forward mouse events captured in the Web process to the matching ASVInlinePreview.

* UIProcess/Cocoa/ModelElementControllerCocoa.mm:
(WebKit::ModelElementController::previewForUUID):
(WebKit::ModelElementController::handleMouseDownForModelElement):
(WebKit::ModelElementController::handleMouseMoveForModelElement):
(WebKit::ModelElementController::handleMouseUpForModelElement):
* UIProcess/ModelElementController.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleMouseDownForModelElement):
(WebKit::WebPageProxy::handleMouseMoveForModelElement):
(WebKit::WebPageProxy::handleMouseUpForModelElement):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h:
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm:
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseDown):
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseMove):
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseUp):
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h:
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm:
(WebKit::ARKitInlinePreviewModelPlayerMac::supportsMouseInteraction):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseDown):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseMove):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseUp):


Canonical link: https://commits.webkit.org/244383@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285986 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
graouts committed Nov 18, 2021
1 parent 3375ab9 commit 2b6f86b23fcdbcad3f2593f188bd3ff88511b1e0
Showing 21 changed files with 301 additions and 0 deletions.
@@ -1,3 +1,35 @@
2021-11-18 Antoine Quint <graouts@webkit.org>

[Model] [macOS] Add support for interaction on macOS
https://bugs.webkit.org/show_bug.cgi?id=233105
<rdar://problem/80079386>

Reviewed by Wenson Hsieh.

Capture mouse events after the mouse button is pressed over a <model> element,
unless preventDefault() is called, and forward those events through ModelPlayer
to the UI process.

* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::defaultEventHandler):
(WebCore::HTMLModelElement::dragDidStart):
(WebCore::HTMLModelElement::dragDidChange):
(WebCore::HTMLModelElement::dragDidEnd):
* Modules/model-element/HTMLModelElement.h:
* Modules/model-element/ModelPlayer.cpp:
(WebCore::ModelPlayer::supportsMouseInteraction):
* Modules/model-element/ModelPlayer.h:
* Modules/model-element/dummy/DummyModelPlayer.cpp:
(WebCore::DummyModelPlayer::handleMouseDown):
(WebCore::DummyModelPlayer::handleMouseMove):
(WebCore::DummyModelPlayer::handleMouseUp):
* Modules/model-element/dummy/DummyModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.mm:
(WebCore::SceneKitModelPlayer::handleMouseDown):
(WebCore::SceneKitModelPlayer::handleMouseMove):
(WebCore::SceneKitModelPlayer::handleMouseUp):

2021-11-17 Youenn Fablet <youenn@apple.com>

Audio Rate Gets Messed up With Safari WebRTC and Bluetooth Switching
@@ -33,6 +33,8 @@
#include "Document.h"
#include "ElementChildIterator.h"
#include "ElementInlines.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "GraphicsLayer.h"
#include "GraphicsLayerCA.h"
#include "HTMLNames.h"
@@ -43,7 +45,9 @@
#include "Model.h"
#include "ModelPlayer.h"
#include "ModelPlayerProvider.h"
#include "MouseEvent.h"
#include "Page.h"
#include "PlatformMouseEvent.h"
#include "RenderLayer.h"
#include "RenderLayerBacking.h"
#include "RenderLayerModelObject.h"
@@ -289,6 +293,73 @@ void HTMLModelElement::enterFullscreen()
m_modelPlayer->enterFullscreen();
}

// MARK: - Interaction support.

void HTMLModelElement::defaultEventHandler(Event& event)
{
if (!m_modelPlayer || !m_modelPlayer->supportsMouseInteraction())
return;

auto type = event.type();
if (type != eventNames().mousedownEvent && type != eventNames().mousemoveEvent && type != eventNames().mouseupEvent)
return;

ASSERT(is<MouseEvent>(event));
auto& mouseEvent = downcast<MouseEvent>(event);

if (mouseEvent.button() != LeftButton)
return;

if (type == eventNames().mousedownEvent && !m_isDragging && !event.defaultPrevented())
dragDidStart(mouseEvent);
else if (type == eventNames().mousemoveEvent && m_isDragging)
dragDidChange(mouseEvent);
else if (type == eventNames().mouseupEvent && m_isDragging)
dragDidEnd(mouseEvent);
}

void HTMLModelElement::dragDidStart(MouseEvent& event)
{
ASSERT(!m_isDragging);

RefPtr frame = document().frame();
if (!frame)
return;

frame->eventHandler().setCapturingMouseEventsElement(this);
event.setDefaultHandled();
m_isDragging = true;

if (m_modelPlayer)
m_modelPlayer->handleMouseDown(event.pageLocation(), event.timeStamp());
}

void HTMLModelElement::dragDidChange(MouseEvent& event)
{
ASSERT(m_isDragging);

event.setDefaultHandled();

if (m_modelPlayer)
m_modelPlayer->handleMouseMove(event.pageLocation(), event.timeStamp());
}

void HTMLModelElement::dragDidEnd(MouseEvent& event)
{
ASSERT(m_isDragging);

RefPtr frame = document().frame();
if (!frame)
return;

frame->eventHandler().setCapturingMouseEventsElement(nullptr);
event.setDefaultHandled();
m_isDragging = false;

if (m_modelPlayer)
m_modelPlayer->handleMouseUp(event.pageLocation(), event.timeStamp());
}

}

#endif // ENABLE(MODEL_ELEMENT)
@@ -40,8 +40,10 @@

namespace WebCore {

class Event;
class Model;
class ModelPlayer;
class MouseEvent;

template<typename IDLType> class DOMPromiseProxyWithResolveCallback;

@@ -92,12 +94,18 @@ class HTMLModelElement final : public HTMLElement, private CachedRawResourceClie
void didFailLoading(ModelPlayer&, const ResourceError&) final;
GraphicsLayer::PlatformLayerID platformLayerID() final;

void defaultEventHandler(Event&) final;
void dragDidStart(MouseEvent&);
void dragDidChange(MouseEvent&);
void dragDidEnd(MouseEvent&);

URL m_sourceURL;
CachedResourceHandle<CachedRawResource> m_resource;
RefPtr<SharedBuffer> m_data;
RefPtr<Model> m_model;
UniqueRef<ReadyPromise> m_readyPromise;
bool m_dataComplete { false };
bool m_isDragging { false };

RefPtr<ModelPlayer> m_modelPlayer;
};
@@ -30,4 +30,9 @@ namespace WebCore {

ModelPlayer::~ModelPlayer() = default;

bool ModelPlayer::supportsMouseInteraction()
{
return false;
}

}
@@ -25,9 +25,11 @@

#pragma once

#include "LayoutPoint.h"
#include "LayoutSize.h"
#include "PlatformLayer.h"
#include <wtf/Forward.h>
#include <wtf/MonotonicTime.h>

namespace WebCore {

@@ -41,6 +43,11 @@ class WEBCORE_EXPORT ModelPlayer : public RefCounted<ModelPlayer> {
virtual void load(Model&, LayoutSize) = 0;
virtual PlatformLayer* layer() = 0;
virtual void enterFullscreen() = 0;
virtual bool supportsMouseInteraction();
virtual void handleMouseDown(const LayoutPoint&, MonotonicTime) = 0;
virtual void handleMouseMove(const LayoutPoint&, MonotonicTime) = 0;
virtual void handleMouseUp(const LayoutPoint&, MonotonicTime) = 0;

};

}
@@ -58,4 +58,16 @@ void DummyModelPlayer::enterFullscreen()
{
}

void DummyModelPlayer::handleMouseDown(const LayoutPoint&, MonotonicTime)
{
}

void DummyModelPlayer::handleMouseMove(const LayoutPoint&, MonotonicTime)
{
}

void DummyModelPlayer::handleMouseUp(const LayoutPoint&, MonotonicTime)
{
}

}
@@ -44,6 +44,9 @@ class WEBCORE_EXPORT DummyModelPlayer final : public ModelPlayer {
void load(Model&, LayoutSize) override;
PlatformLayer* layer() override;
void enterFullscreen() override;
void handleMouseDown(const LayoutPoint&, MonotonicTime) override;
void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
void handleMouseUp(const LayoutPoint&, MonotonicTime) override;

WeakPtr<ModelPlayerClient> m_client;
};
@@ -58,6 +58,9 @@ class WEBCORE_EXPORT SceneKitModelPlayer final : public ModelPlayer, public Scen
void load(Model&, LayoutSize) override;
CALayer *layer() override;
void enterFullscreen() override;
void handleMouseDown(const LayoutPoint&, MonotonicTime) override;
void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
void handleMouseUp(const LayoutPoint&, MonotonicTime) override;

// SceneKitModelLoaderClient overrides.
virtual void didFinishLoading(SceneKitModelLoader&, Ref<SceneKitModel>) override;
@@ -76,6 +76,18 @@
{
}

void SceneKitModelPlayer::handleMouseDown(const LayoutPoint&, MonotonicTime)
{
}

void SceneKitModelPlayer::handleMouseMove(const LayoutPoint&, MonotonicTime)
{
}

void SceneKitModelPlayer::handleMouseUp(const LayoutPoint&, MonotonicTime)
{
}

// MARK: - SceneKitModelLoaderClient overrides.

void SceneKitModelPlayer::didFinishLoading(SceneKitModelLoader& loader, Ref<SceneKitModel> model)
@@ -1,3 +1,15 @@
2021-11-18 Antoine Quint <graouts@webkit.org>

[Model] [macOS] Add support for interaction on macOS
https://bugs.webkit.org/show_bug.cgi?id=233105
<rdar://problem/80079386>

Reviewed by Wenson Hsieh.

Add new ARQL SPIs.

* pal/spi/mac/SystemPreviewSPI.h:

2021-11-17 Myles C. Maxfield <mmaxfield@apple.com>

[WebGPU] Add IPC message handlers for WebGPU
@@ -48,6 +48,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)preparePreviewOfFileAtURL:(NSURL *)url completionHandler:(void (^)(NSError * _Nullable error))handler;
- (void)setRemoteContext:(uint32_t)contextId;

- (void)mouseDownAtLocation:(CGPoint)location timestamp:(NSTimeInterval)timestamp;
- (void)mouseDraggedAtLocation:(CGPoint)location timestamp:(NSTimeInterval)timestamp;
- (void)mouseUpAtLocation:(CGPoint)location timestamp:(NSTimeInterval)timestamp;

@end

#endif // ENABLE(ARKIT_INLINE_PREVIEW_MAC)
@@ -1,3 +1,37 @@
2021-11-18 Antoine Quint <graouts@webkit.org>

[Model] [macOS] Add support for interaction on macOS
https://bugs.webkit.org/show_bug.cgi?id=233105
<rdar://problem/80079386>

Reviewed by Wenson Hsieh.

Forward mouse events captured in the Web process to the matching ASVInlinePreview.

* UIProcess/Cocoa/ModelElementControllerCocoa.mm:
(WebKit::ModelElementController::previewForUUID):
(WebKit::ModelElementController::handleMouseDownForModelElement):
(WebKit::ModelElementController::handleMouseMoveForModelElement):
(WebKit::ModelElementController::handleMouseUpForModelElement):
* UIProcess/ModelElementController.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleMouseDownForModelElement):
(WebKit::WebPageProxy::handleMouseMoveForModelElement):
(WebKit::WebPageProxy::handleMouseUpForModelElement):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h:
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm:
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseDown):
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseMove):
(WebKit::ARKitInlinePreviewModelPlayerIOS::handleMouseUp):
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h:
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm:
(WebKit::ARKitInlinePreviewModelPlayerMac::supportsMouseInteraction):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseDown):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseMove):
(WebKit::ARKitInlinePreviewModelPlayerMac::handleMouseUp):

2021-11-17 Youenn Fablet <youenn@apple.com>

Add support for more rvfc metadata
@@ -42,9 +42,12 @@
#endif

#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
#import <WebCore/LayoutPoint.h>
#import <WebCore/LayoutUnit.h>
#import <WebCore/ResourceError.h>
#import <pal/spi/mac/SystemPreviewSPI.h>
#import <wtf/MainThread.h>
#import <wtf/MonotonicTime.h>
#endif

SOFT_LINK_PRIVATE_FRAMEWORK(AssetViewer);
@@ -188,6 +191,29 @@
}).get()];
}

RetainPtr<ASVInlinePreview> ModelElementController::previewForUUID(const String& uuid)
{
return m_inlinePreviews.get(uuid);
}

void ModelElementController::handleMouseDownForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
if (auto preview = previewForUUID(uuid))
[preview mouseDownAtLocation:CGPointMake(locationInPageCoordinates.x().toFloat(), locationInPageCoordinates.y().toFloat()) timestamp:timestamp.secondsSinceEpoch().value()];
}

void ModelElementController::handleMouseMoveForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
if (auto preview = previewForUUID(uuid))
[preview mouseDraggedAtLocation:CGPointMake(locationInPageCoordinates.x().toFloat(), locationInPageCoordinates.y().toFloat()) timestamp:timestamp.secondsSinceEpoch().value()];
}

void ModelElementController::handleMouseUpForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
if (auto preview = previewForUUID(uuid))
[preview mouseUpAtLocation:CGPointMake(locationInPageCoordinates.x().toFloat(), locationInPageCoordinates.y().toFloat()) timestamp:timestamp.secondsSinceEpoch().value()];
}

#endif

}
@@ -53,11 +53,15 @@ class ModelElementController : public CanMakeWeakPtr<ModelElementController> {
#endif
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
void modelElementDidCreatePreview(URL, String, WebCore::FloatSize, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
void handleMouseDownForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
void handleMouseMoveForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
void handleMouseUpForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
#endif

private:
WebPageProxy& m_webPageProxy;
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
RetainPtr<ASVInlinePreview> previewForUUID(const String&);
HashMap<String, RetainPtr<ASVInlinePreview>> m_inlinePreviews;
#endif
};
@@ -10844,6 +10844,21 @@ void WebPageProxy::modelElementDidCreatePreview(const URL& url, const String& uu
{
modelElementController()->modelElementDidCreatePreview(url, uuid, size, WTFMove(completionHandler));
}

void WebPageProxy::handleMouseDownForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
modelElementController()->handleMouseDownForModelElement(uuid, locationInPageCoordinates, timestamp);
}

void WebPageProxy::handleMouseMoveForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
modelElementController()->handleMouseMoveForModelElement(uuid, locationInPageCoordinates, timestamp);
}

void WebPageProxy::handleMouseUpForModelElement(const String& uuid, const WebCore::LayoutPoint& locationInPageCoordinates, MonotonicTime timestamp)
{
modelElementController()->handleMouseUpForModelElement(uuid, locationInPageCoordinates, timestamp);
}
#endif

#if !PLATFORM(COCOA)

0 comments on commit 2b6f86b

Please sign in to comment.