From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- gfx/layers/ipc/APZInputBridgeChild.cpp | 74 +++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'gfx/layers/ipc/APZInputBridgeChild.cpp') diff --git a/gfx/layers/ipc/APZInputBridgeChild.cpp b/gfx/layers/ipc/APZInputBridgeChild.cpp index bf059143ec..f9de8575a6 100644 --- a/gfx/layers/ipc/APZInputBridgeChild.cpp +++ b/gfx/layers/ipc/APZInputBridgeChild.cpp @@ -12,6 +12,14 @@ #include "mozilla/layers/APZThreadUtils.h" #include "mozilla/layers/SynchronousTask.h" +#include "mozilla/layers/GeckoContentController.h" // for GeckoContentController +#include "mozilla/layers/DoubleTapToZoom.h" // for DoubleTapToZoomMetrics +#include "mozilla/layers/RemoteCompositorSession.h" // for RemoteCompositorSession +#include "mozilla/dom/BrowserParent.h" // for BrowserParent +#ifdef MOZ_WIDGET_ANDROID +# include "mozilla/jni/Utils.h" // for DispatchToGeckoPriorityQueue +#endif + namespace mozilla { namespace layers { @@ -31,13 +39,20 @@ RefPtr APZInputBridgeChild::Create( } APZInputBridgeChild::APZInputBridgeChild(const uint64_t& aProcessToken) - : mIsOpen(false), mProcessToken(aProcessToken) { + : mIsOpen(false), + mProcessToken(aProcessToken), + mCompositorSession(nullptr) { MOZ_ASSERT(XRE_IsParentProcess()); MOZ_ASSERT(NS_IsMainThread()); } APZInputBridgeChild::~APZInputBridgeChild() = default; +void APZInputBridgeChild::SetCompositorSession( + RemoteCompositorSession* aSession) { + mCompositorSession = aSession; +} + void APZInputBridgeChild::Open(Endpoint&& aEndpoint) { APZThreadUtils::AssertOnControllerThread(); @@ -176,6 +191,63 @@ APZEventResult APZInputBridgeChild::ReceiveInputEvent( return res; } +void APZInputBridgeChild::HandleTapOnMainThread( + const TapType& aType, const LayoutDevicePoint& aPoint, + const Modifiers& aModifiers, const ScrollableLayerGuid& aGuid, + const uint64_t& aInputBlockId, + const Maybe& aDoubleTapToZoomMetrics) { + if (mCompositorSession && + mCompositorSession->RootLayerTreeId() == aGuid.mLayersId && + mCompositorSession->GetContentController()) { + RefPtr controller = + mCompositorSession->GetContentController(); + controller->HandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId, + aDoubleTapToZoomMetrics); + return; + } + dom::BrowserParent* tab = + dom::BrowserParent::GetBrowserParentFromLayersId(aGuid.mLayersId); + if (tab) { +#ifdef MOZ_WIDGET_ANDROID + // On Android, touch events are dispatched from the UI thread to the main + // thread using the Android priority queue. It is possible that this tap has + // made it to the GPU process and back before they have been processed. We + // must therefore dispatch this message to the same queue, otherwise the tab + // may receive the tap event before the touch events that synthesized it. + mozilla::jni::DispatchToGeckoPriorityQueue( + NewRunnableMethod>( + "dom::BrowserParent::SendHandleTap", tab, + &dom::BrowserParent::SendHandleTap, aType, aPoint, aModifiers, + aGuid, aInputBlockId, aDoubleTapToZoomMetrics)); +#else + tab->SendHandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId, + aDoubleTapToZoomMetrics); +#endif + } +} + +mozilla::ipc::IPCResult APZInputBridgeChild::RecvHandleTap( + const TapType& aType, const LayoutDevicePoint& aPoint, + const Modifiers& aModifiers, const ScrollableLayerGuid& aGuid, + const uint64_t& aInputBlockId, + const Maybe& aDoubleTapToZoomMetrics) { + if (NS_IsMainThread()) { + HandleTapOnMainThread(aType, aPoint, aModifiers, aGuid, aInputBlockId, + aDoubleTapToZoomMetrics); + } else { + NS_DispatchToMainThread( + NewRunnableMethod>( + "layers::APZInputBridgeChild::HandleTapOnMainThread", this, + &APZInputBridgeChild::HandleTapOnMainThread, aType, aPoint, + aModifiers, aGuid, aInputBlockId, aDoubleTapToZoomMetrics)); + } + return IPC_OK(); +} + mozilla::ipc::IPCResult APZInputBridgeChild::RecvCallInputBlockCallback( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { auto it = mInputBlockCallbacks.find(aInputBlockId); -- cgit v1.2.3