From eec655d1f0a412cc71eb0010fed08b193eb2a5ff Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Fri, 29 Jan 2016 16:31:15 -0500 Subject: [PATCH] Bug 1242690 - Ensure that mouse events have the callback transform applied. r=botond --HG-- extra : commitid : IXh9rbTOf5R --- dom/ipc/TabChild.cpp | 32 ++++++++++++---------- gfx/layers/apz/src/APZCTreeManager.cpp | 5 ++-- gfx/layers/apz/util/APZCCallbackHelper.cpp | 14 +++++++--- gfx/layers/apz/util/APZCCallbackHelper.h | 6 ++-- widget/nsBaseWidget.cpp | 20 ++++---------- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index aad8c8d3ff32..215b8a2a1a74 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -1795,35 +1795,37 @@ TabChild::RecvMouseEvent(const nsString& aType, } bool -TabChild::RecvRealMouseMoveEvent(const WidgetMouseEvent& event, +TabChild::RecvRealMouseMoveEvent(const WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId) { - return RecvRealMouseButtonEvent(event, aGuid, aInputBlockId); + return RecvRealMouseButtonEvent(aEvent, aGuid, aInputBlockId); } bool -TabChild::RecvSynthMouseMoveEvent(const WidgetMouseEvent& event, +TabChild::RecvSynthMouseMoveEvent(const WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId) { - return RecvRealMouseButtonEvent(event, aGuid, aInputBlockId); + return RecvRealMouseButtonEvent(aEvent, aGuid, aInputBlockId); } bool -TabChild::RecvRealMouseButtonEvent(const WidgetMouseEvent& event, +TabChild::RecvRealMouseButtonEvent(const WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId) { nsEventStatus unused; InputAPZContext context(aGuid, aInputBlockId, unused); - WidgetMouseEvent localEvent(event); + WidgetMouseEvent localEvent(aEvent); localEvent.widget = mPuppetWidget; + APZCCallbackHelper::ApplyCallbackTransform(localEvent, aGuid, + mPuppetWidget->GetDefaultScale()); APZCCallbackHelper::DispatchWidgetEvent(localEvent); - if (event.mFlags.mHandledByAPZ) { - mAPZEventState->ProcessMouseEvent(event, aGuid, aInputBlockId); + if (aEvent.mFlags.mHandledByAPZ) { + mAPZEventState->ProcessMouseEvent(aEvent, aGuid, aInputBlockId); } return true; } @@ -1839,16 +1841,18 @@ TabChild::RecvMouseWheelEvent(const WidgetWheelEvent& aEvent, mPuppetWidget, document, aEvent, aGuid, aInputBlockId); } - WidgetWheelEvent event(aEvent); - event.widget = mPuppetWidget; - APZCCallbackHelper::DispatchWidgetEvent(event); + WidgetWheelEvent localEvent(aEvent); + localEvent.widget = mPuppetWidget; + APZCCallbackHelper::ApplyCallbackTransform(localEvent, aGuid, + mPuppetWidget->GetDefaultScale()); + APZCCallbackHelper::DispatchWidgetEvent(localEvent); - if (event.mCanTriggerSwipe) { - SendRespondStartSwipeEvent(aInputBlockId, event.TriggersSwipe()); + if (localEvent.mCanTriggerSwipe) { + SendRespondStartSwipeEvent(aInputBlockId, localEvent.TriggersSwipe()); } if (aEvent.mFlags.mHandledByAPZ) { - mAPZEventState->ProcessWheelEvent(event, aGuid, aInputBlockId); + mAPZEventState->ProcessWheelEvent(localEvent, aGuid, aInputBlockId); } return true; } diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index ea23b50c0f5a..d59a1ae6ff46 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -1087,10 +1087,9 @@ APZCTreeManager::ReceiveInputEvent(WidgetInputEvent& aEvent, ScrollableLayerGuid* aOutTargetGuid, uint64_t* aOutInputBlockId) { - // This function will be removed once metro code is modified to use the - // InputData version of ReceiveInputEvent. // In general it is preferable to use the version of ReceiveInputEvent - // that takes an InputData, as that is usable from off-main-thread. + // that takes an InputData, as that is usable from off-main-thread. On some + // platforms OMT input isn't possible, and there we can use this version. MOZ_ASSERT(NS_IsMainThread()); APZThreadUtils::AssertOnControllerThread(); diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index 37dc8a47f27a..2e2cd6f8d916 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -532,13 +532,19 @@ APZCCallbackHelper::ApplyCallbackTransform(const LayoutDeviceIntPoint& aPoint, } void -APZCCallbackHelper::ApplyCallbackTransform(WidgetTouchEvent& aEvent, +APZCCallbackHelper::ApplyCallbackTransform(WidgetEvent& aEvent, const ScrollableLayerGuid& aGuid, const CSSToLayoutDeviceScale& aScale) { - for (size_t i = 0; i < aEvent.touches.Length(); i++) { - aEvent.touches[i]->mRefPoint = ApplyCallbackTransform( - aEvent.touches[i]->mRefPoint, aGuid, aScale); + if (aEvent.AsTouchEvent()) { + WidgetTouchEvent& event = *(aEvent.AsTouchEvent()); + for (size_t i = 0; i < event.touches.Length(); i++) { + event.touches[i]->mRefPoint = ApplyCallbackTransform( + event.touches[i]->mRefPoint, aGuid, aScale); + } + } else { + aEvent.refPoint = ApplyCallbackTransform( + aEvent.refPoint, aGuid, aScale); } } diff --git a/gfx/layers/apz/util/APZCCallbackHelper.h b/gfx/layers/apz/util/APZCCallbackHelper.h index 2b64e67b7ae9..1932245af3dd 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.h +++ b/gfx/layers/apz/util/APZCCallbackHelper.h @@ -99,9 +99,9 @@ public: const ScrollableLayerGuid& aGuid, const CSSToLayoutDeviceScale& aScale); - /* Convenience function for applying a callback transform to all touch - * points of a touch event. */ - static void ApplyCallbackTransform(WidgetTouchEvent& aEvent, + /* Convenience function for applying a callback transform to all refpoints + * in the input event. */ + static void ApplyCallbackTransform(WidgetEvent& aEvent, const ScrollableLayerGuid& aGuid, const CSSToLayoutDeviceScale& aScale); diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 59d902a03e1a..9e472a7036a7 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -1012,14 +1012,13 @@ nsBaseWidget::ProcessUntransformedAPZEvent(WidgetInputEvent* aEvent, MOZ_ASSERT(NS_IsMainThread()); InputAPZContext context(aGuid, aInputBlockId, aApzResponse); - // If this is a touch event and APZ has targeted it to an APZC in the root + // If this is an event that the APZ has targeted to an APZC in the root // process, apply that APZC's callback-transform before dispatching the // event. If the event is instead targeted to an APZC in the child process, // the transform will be applied in the child process before dispatching // the event there (see e.g. TabChild::RecvRealTouchEvent()). - // TODO: Do other types of events (than touch) need this? - if (aEvent->AsTouchEvent() && aGuid.mLayersId == mCompositorParent->RootLayerTreeId()) { - APZCCallbackHelper::ApplyCallbackTransform(*aEvent->AsTouchEvent(), aGuid, + if (aGuid.mLayersId == mCompositorParent->RootLayerTreeId()) { + APZCCallbackHelper::ApplyCallbackTransform(*aEvent, aGuid, GetDefaultScale()); } @@ -1030,7 +1029,7 @@ nsBaseWidget::ProcessUntransformedAPZEvent(WidgetInputEvent* aEvent, UniquePtr original(aEvent->Duplicate()); DispatchEvent(aEvent, status); - if (mAPZC && !context.WasRoutedToChildProcess()) { + if (mAPZC && !context.WasRoutedToChildProcess() && aInputBlockId) { // EventStateManager did not route the event into the child process. // It's safe to communicate to APZ that the event has been processed. // TODO: Eventually we'll be able to move the SendSetTargetAPZCNotification @@ -1067,16 +1066,7 @@ nsBaseWidget::ProcessUntransformedAPZEvent(WidgetInputEvent* aEvent, nsEventStatus nsBaseWidget::DispatchInputEvent(WidgetInputEvent* aEvent) { - if (mAPZC) { - nsEventStatus result = mAPZC->ReceiveInputEvent(*aEvent, nullptr, nullptr); - if (result == nsEventStatus_eConsumeNoDefault) { - return result; - } - } - - nsEventStatus status; - DispatchEvent(aEvent, status); - return status; + return DispatchAPZAwareEvent(aEvent); } class DispatchWheelEventOnMainThread : public Task