diff options
Diffstat (limited to 'dom/events/PointerEventHandler.cpp')
-rw-r--r-- | dom/events/PointerEventHandler.cpp | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/dom/events/PointerEventHandler.cpp b/dom/events/PointerEventHandler.cpp index ef6f2b12c0..f631b6e494 100644 --- a/dom/events/PointerEventHandler.cpp +++ b/dom/events/PointerEventHandler.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowserParent.h" #include "mozilla/dom/Document.h" +#include "mozilla/dom/DocumentInlines.h" #include "mozilla/dom/MouseEventBinding.h" namespace mozilla { @@ -80,7 +81,8 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent, // In this case we have to know information about available mouse pointers sActivePointersIds->InsertOrUpdate( aEvent->pointerId, - MakeUnique<PointerInfo>(false, aEvent->mInputSource, true, nullptr)); + MakeUnique<PointerInfo>(false, aEvent->mInputSource, true, false, + nullptr)); MaybeCacheSpoofedPointerID(aEvent->mInputSource, aEvent->pointerId); break; @@ -94,6 +96,7 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent, pointerEvent->pointerId, MakeUnique<PointerInfo>( true, pointerEvent->mInputSource, pointerEvent->mIsPrimary, + pointerEvent->mFromTouchEvent, aTargetContent ? aTargetContent->OwnerDoc() : nullptr)); MaybeCacheSpoofedPointerID(pointerEvent->mInputSource, pointerEvent->pointerId); @@ -112,7 +115,8 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent, sActivePointersIds->InsertOrUpdate( pointerEvent->pointerId, MakeUnique<PointerInfo>(false, pointerEvent->mInputSource, - pointerEvent->mIsPrimary, nullptr)); + pointerEvent->mIsPrimary, + pointerEvent->mFromTouchEvent, nullptr)); } else { sActivePointersIds->Remove(pointerEvent->pointerId); } @@ -314,7 +318,7 @@ void PointerEventHandler::ProcessPointerCaptureForTouch( continue; } WidgetPointerEvent event(aEvent->IsTrusted(), eVoidEvent, aEvent->mWidget); - InitPointerEventFromTouch(event, *aEvent, *touch, i == 0); + InitPointerEventFromTouch(event, *aEvent, *touch); CheckPointerCaptureState(&event); } } @@ -461,11 +465,13 @@ Element* PointerEventHandler::GetPointerCapturingElement( void PointerEventHandler::ReleaseIfCaptureByDescendant(nsIContent* aContent) { // We should check that aChild does not contain pointer capturing elements. // If it does we should release the pointer capture for the elements. - for (const auto& entry : *sPointerCaptureList) { - PointerCaptureInfo* data = entry.GetWeak(); - if (data && data->mPendingElement && - data->mPendingElement->IsInclusiveDescendantOf(aContent)) { - ReleasePointerCaptureById(entry.GetKey()); + if (!sPointerCaptureList->IsEmpty()) { + for (const auto& entry : *sPointerCaptureList) { + PointerCaptureInfo* data = entry.GetWeak(); + if (data && data->mPendingElement && + data->mPendingElement->IsInclusiveDescendantOf(aContent)) { + ReleasePointerCaptureById(entry.GetKey()); + } } } } @@ -546,7 +552,7 @@ void PointerEventHandler::InitPointerEventFromMouse( /* static */ void PointerEventHandler::InitPointerEventFromTouch( WidgetPointerEvent& aPointerEvent, const WidgetTouchEvent& aTouchEvent, - const mozilla::dom::Touch& aTouch, bool aIsPrimary) { + const mozilla::dom::Touch& aTouch) { // Use mButton/mButtons only when mButton got a value (from pen input) int16_t button = aTouchEvent.mMessage == eTouchMove ? MouseButton::eNotPressed : aTouchEvent.mButton != MouseButton::eNotPressed @@ -558,7 +564,10 @@ void PointerEventHandler::InitPointerEventFromTouch( ? aTouchEvent.mButtons : MouseButtonsFlag::ePrimaryFlag; - aPointerEvent.mIsPrimary = aIsPrimary; + // Only the first touch would be the primary pointer. + aPointerEvent.mIsPrimary = aTouchEvent.mMessage == eTouchStart + ? !HasActiveTouchPointer() + : GetPointerPrimaryState(aTouch.Identifier()); aPointerEvent.pointerId = aTouch.Identifier(); aPointerEvent.mRefPoint = aTouch.mRefPoint; aPointerEvent.mModifiers = aTouchEvent.mModifiers; @@ -679,7 +688,7 @@ void PointerEventHandler::DispatchPointerFromMouseOrTouch( WidgetPointerEvent event(touchEvent->IsTrusted(), pointerMessage, touchEvent->mWidget); - InitPointerEventFromTouch(event, *touchEvent, *touch, i == 0); + InitPointerEventFromTouch(event, *touchEvent, *touch); event.convertToPointer = touch->convertToPointer = false; event.mCoalescedWidgetEvents = touch->mCoalescedWidgetEvents; if (aMouseOrTouchEvent->mMessage == eTouchStart) { @@ -739,6 +748,15 @@ void PointerEventHandler::NotifyDestroyPresContext( iter.Remove(); } } + // Clean up active pointer info + for (auto iter = sActivePointersIds->Iter(); !iter.Done(); iter.Next()) { + PointerInfo* data = iter.UserData(); + MOZ_ASSERT(data, "how could we have a null PointerInfo here?"); + if (data->mActiveDocument && + data->mActiveDocument->GetPresContext() == aPresContext) { + iter.Remove(); + } + } } bool PointerEventHandler::IsDragAndDropEnabled(WidgetMouseEvent& aEvent) { @@ -771,6 +789,16 @@ bool PointerEventHandler::GetPointerPrimaryState(uint32_t aPointerId) { } /* static */ +bool PointerEventHandler::HasActiveTouchPointer() { + for (auto iter = sActivePointersIds->ConstIter(); !iter.Done(); iter.Next()) { + if (iter.Data()->mFromTouchEvent) { + return true; + } + } + return false; +} + +/* static */ void PointerEventHandler::DispatchGotOrLostPointerCaptureEvent( bool aIsGotCapture, const WidgetPointerEvent* aPointerEvent, Element* aCaptureTarget) { |