mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 05:45:33 +00:00
Bug 1094913 - Set pointerType to got/lostpointercapture events. r=smaug
This commit is contained in:
parent
a2f293b9fc
commit
2663f2a50d
@ -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>
|
||||
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
|
||||
|
@ -48,6 +48,8 @@ public:
|
||||
void GetPointerType(nsAString& aPointerType);
|
||||
};
|
||||
|
||||
void ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest);
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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<nsIContent> 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<mozilla::dom::PointerEvent> event;
|
||||
event = PointerEvent::Constructor(aCaptureTarget,
|
||||
aIsGotCapture
|
||||
|
Loading…
x
Reference in New Issue
Block a user