Bug 1505880 - set mGestureDownPoint when receiving 'touchstart' event. r=smaug

We should set the 'mGestureDownPoint' correctly when receiving 'touchstart' so that we can
distinguish whether the 'touchend' comes from dragging or simply touching by calling
'IsEventOutsideDragThreshold()'.

Differential Revision: https://phabricator.services.mozilla.com/D11395

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2018-11-15 21:22:49 +00:00
Родитель cfab10d500
Коммит 8772ab4639
2 изменённых файлов: 25 добавлений и 7 удалений

Просмотреть файл

@ -844,6 +844,9 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
compositionEvent->mData = selectedText.mReply.mString;
}
break;
case eTouchStart:
SetGestureDownPoint(aEvent->AsTouchEvent());
break;
case eTouchEnd:
NotifyTargetUserActivation(aEvent, aTargetContent);
break;
@ -1688,8 +1691,7 @@ EventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
// Note that |inDownEvent| could be either a mouse down event or a
// synthesized mouse move event.
mGestureDownPoint =
inDownEvent->mRefPoint + inDownEvent->mWidget->WidgetToScreenOffset();
SetGestureDownPoint(inDownEvent);
if (inDownFrame) {
inDownFrame->GetContentForEvent(inDownEvent,
@ -1709,6 +1711,21 @@ EventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
}
}
void
EventStateManager::SetGestureDownPoint(WidgetGUIEvent* aEvent)
{
mGestureDownPoint =
GetEventRefPoint(aEvent) + aEvent->mWidget->WidgetToScreenOffset();
}
LayoutDeviceIntPoint
EventStateManager::GetEventRefPoint(WidgetEvent* aEvent) const
{
auto touchEvent = aEvent->AsTouchEvent();
return (touchEvent && !touchEvent->mTouches.IsEmpty()) ?
aEvent->AsTouchEvent()->mTouches[0]->mRefPoint : aEvent->mRefPoint;
}
void
EventStateManager::BeginTrackingRemoteDragGesture(nsIContent* aContent)
{
@ -1808,11 +1825,8 @@ EventStateManager::IsEventOutsideDragThreshold(WidgetInputEvent* aEvent) const
sPixelThresholdY = 5;
}
auto touchEvent = aEvent->AsTouchEvent();
LayoutDeviceIntPoint pt = aEvent->mWidget->WidgetToScreenOffset() +
((touchEvent && !touchEvent->mTouches.IsEmpty())
? aEvent->AsTouchEvent()->mTouches[0]->mRefPoint
: aEvent->mRefPoint);
LayoutDeviceIntPoint pt =
aEvent->mWidget->WidgetToScreenOffset() + GetEventRefPoint(aEvent);
LayoutDeviceIntPoint distance = pt - mGestureDownPoint;
return
Abs(distance.x) > AssertedCast<uint32_t>(sPixelThresholdX) ||

Просмотреть файл

@ -1096,6 +1096,10 @@ protected:
WidgetMouseEvent* aDownEvent,
nsIFrame* aDownFrame);
void SetGestureDownPoint(WidgetGUIEvent* aEvent);
LayoutDeviceIntPoint GetEventRefPoint(WidgetEvent* aEvent) const;
friend class mozilla::dom::TabParent;
void BeginTrackingRemoteDragGesture(nsIContent* aContent);
void StopTrackingDragGesture();