From 2663f2a50dd6f02286ab04bca467b226fac6b1ae Mon Sep 17 00:00:00 2001 From: Maksim Lebedev Date: Tue, 11 Nov 2014 08:29:00 +0100 Subject: [PATCH] Bug 1094913 - Set pointerType to got/lostpointercapture events. r=smaug --- dom/events/PointerEvent.cpp | 34 ++++++++++++++++++++-------------- dom/events/PointerEvent.h | 2 ++ layout/base/nsIPresShell.h | 2 ++ layout/base/nsPresShell.cpp | 24 ++++++++++++++++++------ 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/dom/events/PointerEvent.cpp b/dom/events/PointerEvent.cpp index 8b30870dbb77..3b3878ddffd8 100644 --- a/dom/events/PointerEvent.cpp +++ b/dom/events/PointerEvent.cpp @@ -48,6 +48,25 @@ ConvertStringToPointerType(const nsAString& aPointerTypeArg) return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; } +void +ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest) +{ + switch (aPointerTypeSrc) { + case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE: + aPointerTypeDest.AssignLiteral("mouse"); + break; + case nsIDOMMouseEvent::MOZ_SOURCE_PEN: + aPointerTypeDest.AssignLiteral("pen"); + break; + case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH: + aPointerTypeDest.AssignLiteral("touch"); + break; + default: + aPointerTypeDest.Truncate(); + break; + } +} + // static already_AddRefed PointerEvent::Constructor(EventTarget* aOwner, @@ -93,20 +112,7 @@ PointerEvent::Constructor(const GlobalObject& aGlobal, void PointerEvent::GetPointerType(nsAString& aPointerType) { - switch (mEvent->AsPointerEvent()->inputSource) { - case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE: - aPointerType.AssignLiteral("mouse"); - break; - case nsIDOMMouseEvent::MOZ_SOURCE_PEN: - aPointerType.AssignLiteral("pen"); - break; - case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH: - aPointerType.AssignLiteral("touch"); - break; - case nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN: - aPointerType.Truncate(); - break; - } + ConvertPointerTypeToString(mEvent->AsPointerEvent()->inputSource, aPointerType); } int32_t diff --git a/dom/events/PointerEvent.h b/dom/events/PointerEvent.h index 41d80a89483f..18d33ff8db9b 100644 --- a/dom/events/PointerEvent.h +++ b/dom/events/PointerEvent.h @@ -48,6 +48,8 @@ public: void GetPointerType(nsAString& aPointerType); }; +void ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest); + } // namespace dom } // namespace mozilla diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 230d504aeb5b..e256da2dd6f0 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1287,10 +1287,12 @@ public: static void DispatchGotOrLostPointerCaptureEvent(bool aIsGotCapture, uint32_t aPointerId, + uint16_t aPointerType, nsIContent* aCaptureTarget); static void SetPointerCapturingContent(uint32_t aPointerId, nsIContent* aContent); static void ReleasePointerCapturingContent(uint32_t aPointerId, nsIContent* aContent); static nsIContent* GetPointerCapturingContent(uint32_t aPointerId); + static uint16_t GetPointerType(uint32_t aPointerId); // CheckPointerCaptureState checks cases, when got/lostpointercapture events should be fired. // Function returns true, if any of events was fired; false, if no one event was fired. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index ac8193b28937..04de56b1d8ac 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6404,10 +6404,7 @@ nsIPresShell::SetPointerCapturingContent(uint32_t aPointerId, nsIContent* aConte gPointerCaptureList->Get(aPointerId, &pointerCaptureInfo); nsIContent* content = pointerCaptureInfo ? pointerCaptureInfo->mOverrideContent : nullptr; - PointerInfo* pointerInfo = nullptr; - if (!content && gActivePointersIds->Get(aPointerId, &pointerInfo) && - pointerInfo && - nsIDOMMouseEvent::MOZ_SOURCE_MOUSE == pointerInfo->mPointerType) { + if (!content && (nsIDOMMouseEvent::MOZ_SOURCE_MOUSE == GetPointerType(aPointerId))) { SetCapturingContent(aContent, CAPTURE_PREVENTDRAG); } @@ -6445,6 +6442,16 @@ nsIPresShell::GetPointerCapturingContent(uint32_t aPointerId) return nullptr; } +/* static */ uint16_t +nsIPresShell::GetPointerType(uint32_t aPointerId) +{ + PointerInfo* pointerInfo = nullptr; + if (gActivePointersIds->Get(aPointerId, &pointerInfo) && pointerInfo) { + return pointerInfo->mPointerType; + } + return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; +} + /* static */ bool nsIPresShell::CheckPointerCaptureState(uint32_t aPointerId) { @@ -6455,6 +6462,7 @@ nsIPresShell::CheckPointerCaptureState(uint32_t aPointerId) // we should dispatch lostpointercapture event to overrideContent if it exist if (pointerCaptureInfo->mPendingContent || pointerCaptureInfo->mReleaseContent) { if (pointerCaptureInfo->mOverrideContent) { + uint16_t pointerType = GetPointerType(aPointerId); nsCOMPtr content; pointerCaptureInfo->mOverrideContent.swap(content); if (pointerCaptureInfo->mReleaseContent) { @@ -6463,7 +6471,7 @@ nsIPresShell::CheckPointerCaptureState(uint32_t aPointerId) if (pointerCaptureInfo->Empty()) { gPointerCaptureList->Remove(aPointerId); } - DispatchGotOrLostPointerCaptureEvent(false, aPointerId, content); + DispatchGotOrLostPointerCaptureEvent(false, aPointerId, pointerType, content); didDispatchEvent = true; } else if (pointerCaptureInfo->mPendingContent && pointerCaptureInfo->mReleaseContent) { // If anybody calls element.releasePointerCapture @@ -6479,7 +6487,9 @@ nsIPresShell::CheckPointerCaptureState(uint32_t aPointerId) pointerCaptureInfo->mOverrideContent = pointerCaptureInfo->mPendingContent; pointerCaptureInfo->mPendingContent = nullptr; pointerCaptureInfo->mReleaseContent = false; - DispatchGotOrLostPointerCaptureEvent(true, aPointerId, pointerCaptureInfo->mOverrideContent); + DispatchGotOrLostPointerCaptureEvent(true, aPointerId, + GetPointerType(aPointerId), + pointerCaptureInfo->mOverrideContent); didDispatchEvent = true; } } @@ -8234,11 +8244,13 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) void nsIPresShell::DispatchGotOrLostPointerCaptureEvent(bool aIsGotCapture, uint32_t aPointerId, + uint16_t aPointerType, nsIContent* aCaptureTarget) { PointerEventInit init; init.mPointerId = aPointerId; init.mBubbles = true; + ConvertPointerTypeToString(aPointerType, init.mPointerType); nsRefPtr event; event = PointerEvent::Constructor(aCaptureTarget, aIsGotCapture