2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2015-02-20 10:12:00 +03:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TouchManager.h"
|
2015-12-22 09:14:12 +03:00
|
|
|
|
2017-11-22 06:36:35 +03:00
|
|
|
#include "gfxPrefs.h"
|
2015-12-22 09:14:12 +03:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2016-11-30 06:14:28 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2016-11-30 06:14:28 +03:00
|
|
|
#include "nsIFrame.h"
|
2015-12-22 09:14:12 +03:00
|
|
|
#include "nsView.h"
|
2017-11-22 06:36:35 +03:00
|
|
|
#include "PositionedEventTargeting.h"
|
2015-12-22 09:14:12 +03:00
|
|
|
|
2016-11-30 06:14:27 +03:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-12-22 09:14:12 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-08-18 14:13:29 +03:00
|
|
|
nsDataHashtable<nsUint32HashKey, TouchManager::TouchInfo>*
|
|
|
|
TouchManager::sCaptureTouchList;
|
2015-02-25 06:20:00 +03:00
|
|
|
|
|
|
|
/*static*/ void TouchManager::InitializeStatics() {
|
2016-08-18 14:13:29 +03:00
|
|
|
NS_ASSERTION(!sCaptureTouchList, "InitializeStatics called multiple times!");
|
2016-08-18 14:13:29 +03:00
|
|
|
sCaptureTouchList =
|
|
|
|
new nsDataHashtable<nsUint32HashKey, TouchManager::TouchInfo>;
|
2015-02-25 06:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void TouchManager::ReleaseStatics() {
|
2016-08-18 14:13:29 +03:00
|
|
|
NS_ASSERTION(sCaptureTouchList, "ReleaseStatics called without Initialize!");
|
|
|
|
delete sCaptureTouchList;
|
|
|
|
sCaptureTouchList = nullptr;
|
2015-02-25 06:20:00 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void TouchManager::Init(PresShell* aPresShell, Document* aDocument) {
|
2015-02-20 10:12:00 +03:00
|
|
|
mPresShell = aPresShell;
|
|
|
|
mDocument = aDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchManager::Destroy() {
|
|
|
|
EvictTouches();
|
|
|
|
mDocument = nullptr;
|
|
|
|
mPresShell = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-30 06:14:27 +03:00
|
|
|
static nsIContent* GetNonAnonymousAncestor(EventTarget* aTarget) {
|
2016-08-18 14:13:29 +03:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aTarget));
|
|
|
|
if (content && content->IsInNativeAnonymousSubtree()) {
|
|
|
|
content = content->FindFirstNonChromeOnlyAccessContent();
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2016-11-30 06:14:27 +03:00
|
|
|
/*static*/ void TouchManager::EvictTouchPoint(RefPtr<Touch>& aTouch,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLimitToDocument) {
|
2018-05-25 18:02:59 +03:00
|
|
|
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->mOriginalTarget));
|
2015-02-20 10:12:00 +03:00
|
|
|
if (node) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = node->GetComposedDoc();
|
2015-02-20 10:12:00 +03:00
|
|
|
if (doc && (!aLimitToDocument || aLimitToDocument == doc)) {
|
|
|
|
nsIPresShell* presShell = doc->GetShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsIFrame* frame = presShell->GetRootFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsPoint pt(aTouch->mRefPoint.x, aTouch->mRefPoint.y);
|
|
|
|
nsCOMPtr<nsIWidget> widget = frame->GetView()->GetNearestWidget(&pt);
|
|
|
|
if (widget) {
|
2015-09-14 18:14:35 +03:00
|
|
|
WidgetTouchEvent event(true, eTouchEnd, widget);
|
2016-03-28 07:29:42 +03:00
|
|
|
event.mTime = PR_IntervalNow();
|
2016-03-30 12:44:28 +03:00
|
|
|
event.mTouches.AppendElement(aTouch);
|
2015-02-20 10:12:00 +03:00
|
|
|
nsEventStatus status;
|
|
|
|
widget->DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!node || !aLimitToDocument || node->OwnerDoc() == aLimitToDocument) {
|
2016-08-18 14:13:29 +03:00
|
|
|
sCaptureTouchList->Remove(aTouch->Identifier());
|
2015-02-20 10:12:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 14:13:28 +03:00
|
|
|
/*static*/ void TouchManager::AppendToTouchList(
|
|
|
|
WidgetTouchEvent::TouchArray* aTouchList) {
|
2016-08-18 14:13:29 +03:00
|
|
|
for (auto iter = sCaptureTouchList->Iter(); !iter.Done(); iter.Next()) {
|
2016-11-30 06:14:27 +03:00
|
|
|
RefPtr<Touch>& touch = iter.Data().mTouch;
|
2016-01-25 05:45:29 +03:00
|
|
|
touch->mChanged = false;
|
|
|
|
aTouchList->AppendElement(touch);
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchManager::EvictTouches() {
|
|
|
|
WidgetTouchEvent::AutoTouchArray touches;
|
2016-01-25 05:45:29 +03:00
|
|
|
AppendToTouchList(&touches);
|
2015-02-20 10:12:00 +03:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
EvictTouchPoint(touches[i], mDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 06:36:35 +03:00
|
|
|
/* static */ nsIFrame* TouchManager::SetupTarget(WidgetTouchEvent* aEvent,
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
|
|
|
|
if (!aEvent || aEvent->mMessage != eTouchStart) {
|
|
|
|
// All touch events except for touchstart use a captured target.
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = 0;
|
|
|
|
// Setting this flag will skip the scrollbars on the root frame from
|
|
|
|
// participating in hit-testing, and we only want that to happen on
|
|
|
|
// zoomable platforms (for now).
|
|
|
|
if (gfxPrefs::APZAllowZooming()) {
|
|
|
|
flags |= INPUT_IGNORE_ROOT_SCROLL_FRAME;
|
|
|
|
}
|
|
|
|
|
2017-12-09 05:06:18 +03:00
|
|
|
nsIFrame* target = aFrame;
|
2017-11-22 06:36:35 +03:00
|
|
|
for (int32_t i = aEvent->mTouches.Length(); i;) {
|
|
|
|
--i;
|
|
|
|
dom::Touch* touch = aEvent->mTouches[i];
|
|
|
|
|
|
|
|
int32_t id = touch->Identifier();
|
|
|
|
if (!TouchManager::HasCapturedTouch(id)) {
|
|
|
|
// find the target for this touch
|
2017-12-09 05:06:18 +03:00
|
|
|
nsPoint eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
|
|
|
|
aEvent, touch->mRefPoint, aFrame);
|
|
|
|
target = FindFrameTargetedByInputEvent(aEvent, aFrame, eventPoint, flags);
|
|
|
|
if (target) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
target->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
|
|
|
while (targetContent && !targetContent->IsElement()) {
|
|
|
|
targetContent = targetContent->GetParent();
|
2017-11-22 06:36:35 +03:00
|
|
|
}
|
2018-05-25 18:02:59 +03:00
|
|
|
touch->SetTouchTarget(targetContent);
|
2017-11-22 06:36:35 +03:00
|
|
|
} else {
|
2017-12-09 05:06:18 +03:00
|
|
|
aEvent->mTouches.RemoveElementAt(i);
|
2017-11-22 06:36:35 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This touch is an old touch, we need to ensure that is not
|
|
|
|
// marked as changed and set its target correctly
|
|
|
|
touch->mChanged = false;
|
|
|
|
RefPtr<dom::Touch> oldTouch = TouchManager::GetCapturedTouch(id);
|
|
|
|
if (oldTouch) {
|
2018-05-25 18:02:59 +03:00
|
|
|
touch->SetTouchTarget(oldTouch->mOriginalTarget);
|
2017-11-22 06:36:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-09 05:06:18 +03:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsIFrame* TouchManager::SuppressInvalidPointsAndGetTargetedFrame(
|
|
|
|
WidgetTouchEvent* aEvent) {
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
|
|
|
|
if (!aEvent || aEvent->mMessage != eTouchStart) {
|
|
|
|
// All touch events except for touchstart use a captured target.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this is a continuing session, ensure that all these events are
|
|
|
|
// in the same document by taking the target of the events already in
|
|
|
|
// the capture list
|
|
|
|
nsCOMPtr<nsIContent> anyTarget;
|
|
|
|
if (aEvent->mTouches.Length() > 1) {
|
|
|
|
anyTarget = TouchManager::GetAnyCapturedTouchTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = nullptr;
|
|
|
|
for (int32_t i = aEvent->mTouches.Length(); i;) {
|
|
|
|
--i;
|
|
|
|
dom::Touch* touch = aEvent->mTouches[i];
|
|
|
|
if (TouchManager::HasCapturedTouch(touch->Identifier())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
MOZ_ASSERT(touch->mOriginalTarget);
|
2017-12-09 05:06:18 +03:00
|
|
|
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(touch->GetTarget());
|
2019-01-07 16:05:11 +03:00
|
|
|
nsIFrame* targetFrame =
|
|
|
|
targetContent ? targetContent->GetPrimaryFrame() : nullptr;
|
2017-12-09 05:06:18 +03:00
|
|
|
if (targetFrame && !anyTarget) {
|
|
|
|
anyTarget = targetContent;
|
|
|
|
} else {
|
|
|
|
nsIFrame* newTargetFrame = nullptr;
|
|
|
|
for (nsIFrame* f = targetFrame; f;
|
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(f)) {
|
|
|
|
if (f->PresContext()->Document() == anyTarget->OwnerDoc()) {
|
|
|
|
newTargetFrame = f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// We must be in a subdocument so jump directly to the root frame.
|
|
|
|
// GetParentOrPlaceholderForCrossDoc gets called immediately to
|
|
|
|
// jump up to the containing document.
|
|
|
|
f = f->PresShell()->GetRootFrame();
|
|
|
|
}
|
|
|
|
// if we couldn't find a target frame in the same document as
|
|
|
|
// anyTarget, remove the touch from the capture touch list, as
|
|
|
|
// well as the event->mTouches array. touchmove events that aren't
|
|
|
|
// in the captured touch list will be discarded
|
|
|
|
if (!newTargetFrame) {
|
|
|
|
touch->mIsTouchEventSuppressed = true;
|
|
|
|
} else {
|
|
|
|
targetFrame = newTargetFrame;
|
2017-12-20 18:32:52 +03:00
|
|
|
targetFrame->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
|
|
|
while (targetContent && !targetContent->IsElement()) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
2018-05-25 18:02:59 +03:00
|
|
|
touch->SetTouchTarget(targetContent);
|
2017-12-09 05:06:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (targetFrame) {
|
|
|
|
frame = targetFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return frame;
|
2017-11-22 06:36:35 +03:00
|
|
|
}
|
|
|
|
|
2015-02-20 10:12:00 +03:00
|
|
|
bool TouchManager::PreHandleEvent(WidgetEvent* aEvent, nsEventStatus* aStatus,
|
|
|
|
bool& aTouchIsNew, bool& aIsHandlingUserInput,
|
|
|
|
nsCOMPtr<nsIContent>& aCurrentEventContent) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent->mMessage) {
|
2015-09-14 18:14:34 +03:00
|
|
|
case eTouchStart: {
|
2015-02-20 10:12:00 +03:00
|
|
|
aIsHandlingUserInput = true;
|
|
|
|
WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
|
|
|
|
// if there is only one touch in this touchstart event, assume that it is
|
|
|
|
// the start of a new touch session and evict any old touches in the
|
|
|
|
// queue
|
2016-03-30 12:44:28 +03:00
|
|
|
if (touchEvent->mTouches.Length() == 1) {
|
2015-02-20 10:12:00 +03:00
|
|
|
WidgetTouchEvent::AutoTouchArray touches;
|
2016-01-25 05:45:29 +03:00
|
|
|
AppendToTouchList(&touches);
|
2015-02-20 10:12:00 +03:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
EvictTouchPoint(touches[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add any new touches to the queue
|
2017-12-09 05:06:18 +03:00
|
|
|
WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
|
|
|
for (int32_t i = touches.Length(); i;) {
|
|
|
|
--i;
|
|
|
|
Touch* touch = touches[i];
|
2015-02-20 10:12:00 +03:00
|
|
|
int32_t id = touch->Identifier();
|
2016-08-18 14:13:29 +03:00
|
|
|
if (!sCaptureTouchList->Get(id, nullptr)) {
|
2015-02-20 10:12:00 +03:00
|
|
|
// If it is not already in the queue, it is a new touch
|
|
|
|
touch->mChanged = true;
|
|
|
|
}
|
2015-08-22 04:34:51 +03:00
|
|
|
touch->mMessage = aEvent->mMessage;
|
2018-05-25 18:02:59 +03:00
|
|
|
TouchInfo info = {
|
|
|
|
touch, GetNonAnonymousAncestor(touch->mOriginalTarget), true};
|
2016-08-18 14:13:29 +03:00
|
|
|
sCaptureTouchList->Put(id, info);
|
2017-12-09 05:06:18 +03:00
|
|
|
if (touch->mIsTouchEventSuppressed) {
|
|
|
|
// We're going to dispatch touch event. Remove this touch instance if
|
|
|
|
// it is suppressed.
|
|
|
|
touches.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-09-14 18:14:35 +03:00
|
|
|
case eTouchMove: {
|
2015-02-20 10:12:00 +03:00
|
|
|
// Check for touches that changed. Mark them add to queue
|
|
|
|
WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
|
2016-03-30 12:44:28 +03:00
|
|
|
WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
2015-02-20 10:12:00 +03:00
|
|
|
bool haveChanged = false;
|
|
|
|
for (int32_t i = touches.Length(); i;) {
|
|
|
|
--i;
|
2016-11-30 06:14:27 +03:00
|
|
|
Touch* touch = touches[i];
|
2015-02-20 10:12:00 +03:00
|
|
|
if (!touch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int32_t id = touch->Identifier();
|
2015-08-22 04:34:51 +03:00
|
|
|
touch->mMessage = aEvent->mMessage;
|
2015-02-20 10:12:00 +03:00
|
|
|
|
2016-08-18 14:13:29 +03:00
|
|
|
TouchInfo info;
|
|
|
|
if (!sCaptureTouchList->Get(id, &info)) {
|
2015-02-20 10:12:00 +03:00
|
|
|
touches.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-15 19:28:35 +03:00
|
|
|
const RefPtr<Touch> oldTouch = info.mTouch;
|
|
|
|
if (!oldTouch->Equals(touch)) {
|
2015-02-20 10:12:00 +03:00
|
|
|
touch->mChanged = true;
|
|
|
|
haveChanged = true;
|
|
|
|
}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
nsCOMPtr<EventTarget> targetPtr = oldTouch->mOriginalTarget;
|
2015-02-20 10:12:00 +03:00
|
|
|
if (!targetPtr) {
|
|
|
|
touches.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-18 14:13:29 +03:00
|
|
|
nsCOMPtr<nsINode> targetNode(do_QueryInterface(targetPtr));
|
|
|
|
if (!targetNode->IsInComposedDoc()) {
|
2018-10-02 00:38:01 +03:00
|
|
|
targetPtr = info.mNonAnonymousTarget;
|
2016-08-18 14:13:29 +03:00
|
|
|
}
|
2018-05-25 18:02:59 +03:00
|
|
|
touch->SetTouchTarget(targetPtr);
|
2015-02-20 10:12:00 +03:00
|
|
|
|
2016-08-18 14:13:29 +03:00
|
|
|
info.mTouch = touch;
|
|
|
|
// info.mNonAnonymousTarget is still valid from above
|
|
|
|
sCaptureTouchList->Put(id, info);
|
2015-02-20 10:12:00 +03:00
|
|
|
// if we're moving from touchstart to touchmove for this touch
|
|
|
|
// we allow preventDefault to prevent mouse events
|
|
|
|
if (oldTouch->mMessage != touch->mMessage) {
|
|
|
|
aTouchIsNew = true;
|
|
|
|
}
|
2017-12-09 05:06:18 +03:00
|
|
|
if (oldTouch->mIsTouchEventSuppressed) {
|
|
|
|
touch->mIsTouchEventSuppressed = true;
|
|
|
|
touches.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
}
|
|
|
|
// is nothing has changed, we should just return
|
|
|
|
if (!haveChanged) {
|
|
|
|
if (aTouchIsNew) {
|
|
|
|
// however, if this is the first touchmove after a touchstart,
|
|
|
|
// it is special in that preventDefault is allowed on it, so
|
|
|
|
// we must dispatch it to content even if nothing changed. we
|
|
|
|
// arbitrarily pick the first touch point to be the "changed"
|
|
|
|
// touch because firing an event with no changed events doesn't
|
|
|
|
// work.
|
2016-03-30 12:44:28 +03:00
|
|
|
for (uint32_t i = 0; i < touchEvent->mTouches.Length(); ++i) {
|
|
|
|
if (touchEvent->mTouches[i]) {
|
|
|
|
touchEvent->mTouches[i]->mChanged = true;
|
2015-02-20 10:12:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-09-14 18:14:35 +03:00
|
|
|
case eTouchEnd:
|
2015-02-20 10:12:00 +03:00
|
|
|
aIsHandlingUserInput = true;
|
|
|
|
// Fall through to touchcancel code
|
2015-11-23 08:33:47 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2015-09-14 18:14:35 +03:00
|
|
|
case eTouchCancel: {
|
2015-02-20 10:12:00 +03:00
|
|
|
// Remove the changed touches
|
|
|
|
// need to make sure we only remove touches that are ending here
|
|
|
|
WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
|
2016-03-30 12:44:28 +03:00
|
|
|
WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
2017-12-09 05:06:18 +03:00
|
|
|
for (int32_t i = touches.Length(); i;) {
|
|
|
|
--i;
|
2016-11-30 06:14:27 +03:00
|
|
|
Touch* touch = touches[i];
|
2015-02-20 10:12:00 +03:00
|
|
|
if (!touch) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-22 04:34:51 +03:00
|
|
|
touch->mMessage = aEvent->mMessage;
|
2015-02-20 10:12:00 +03:00
|
|
|
touch->mChanged = true;
|
|
|
|
|
|
|
|
int32_t id = touch->Identifier();
|
2016-08-18 14:13:29 +03:00
|
|
|
TouchInfo info;
|
|
|
|
if (!sCaptureTouchList->Get(id, &info)) {
|
2015-02-20 10:12:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-05-25 18:02:59 +03:00
|
|
|
nsCOMPtr<EventTarget> targetPtr = info.mTouch->mOriginalTarget;
|
2016-08-18 14:13:29 +03:00
|
|
|
nsCOMPtr<nsINode> targetNode(do_QueryInterface(targetPtr));
|
2016-08-31 17:36:13 +03:00
|
|
|
if (targetNode && !targetNode->IsInComposedDoc()) {
|
2018-10-02 00:38:01 +03:00
|
|
|
targetPtr = info.mNonAnonymousTarget;
|
2016-08-18 14:13:29 +03:00
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
|
|
|
|
aCurrentEventContent = do_QueryInterface(targetPtr);
|
2018-05-25 18:02:59 +03:00
|
|
|
touch->SetTouchTarget(targetPtr);
|
2016-08-18 14:13:29 +03:00
|
|
|
sCaptureTouchList->Remove(id);
|
2017-12-09 05:06:18 +03:00
|
|
|
if (info.mTouch->mIsTouchEventSuppressed) {
|
|
|
|
touches.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
}
|
|
|
|
// add any touches left in the touch list, but ensure changed=false
|
2016-01-25 05:45:29 +03:00
|
|
|
AppendToTouchList(&touches);
|
2015-02-20 10:12:00 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-02-16 10:05:09 +03:00
|
|
|
case eTouchPointerCancel: {
|
|
|
|
// Don't generate pointer events by touch events after eTouchPointerCancel
|
|
|
|
// is received.
|
|
|
|
WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
|
|
|
|
WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
Touch* touch = touches[i];
|
|
|
|
if (!touch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int32_t id = touch->Identifier();
|
|
|
|
TouchInfo info;
|
|
|
|
if (!sCaptureTouchList->Get(id, &info)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info.mConvertToPointer = false;
|
|
|
|
sCaptureTouchList->Put(id, info);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-22 09:14:12 +03:00
|
|
|
|
2016-08-18 14:13:28 +03:00
|
|
|
/*static*/ already_AddRefed<nsIContent>
|
|
|
|
TouchManager::GetAnyCapturedTouchTarget() {
|
|
|
|
nsCOMPtr<nsIContent> result = nullptr;
|
2016-08-18 14:13:29 +03:00
|
|
|
if (sCaptureTouchList->Count() == 0) {
|
2016-08-18 14:13:28 +03:00
|
|
|
return result.forget();
|
|
|
|
}
|
2016-08-18 14:13:29 +03:00
|
|
|
for (auto iter = sCaptureTouchList->Iter(); !iter.Done(); iter.Next()) {
|
2016-11-30 06:14:27 +03:00
|
|
|
RefPtr<Touch>& touch = iter.Data().mTouch;
|
2016-08-18 14:13:28 +03:00
|
|
|
if (touch) {
|
2016-11-30 06:14:27 +03:00
|
|
|
EventTarget* target = touch->GetTarget();
|
2016-08-18 14:13:28 +03:00
|
|
|
if (target) {
|
|
|
|
result = do_QueryInterface(target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool TouchManager::HasCapturedTouch(int32_t aId) {
|
2016-08-18 14:13:29 +03:00
|
|
|
return sCaptureTouchList->Contains(aId);
|
2016-08-18 14:13:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ already_AddRefed<Touch> TouchManager::GetCapturedTouch(int32_t aId) {
|
2016-11-30 06:14:27 +03:00
|
|
|
RefPtr<Touch> touch;
|
2016-08-18 14:13:29 +03:00
|
|
|
TouchInfo info;
|
|
|
|
if (sCaptureTouchList->Get(aId, &info)) {
|
|
|
|
touch = info.mTouch;
|
|
|
|
}
|
2016-08-18 14:13:28 +03:00
|
|
|
return touch.forget();
|
|
|
|
}
|
|
|
|
|
2017-02-16 10:05:09 +03:00
|
|
|
/*static*/ bool TouchManager::ShouldConvertTouchToPointer(
|
|
|
|
const Touch* aTouch, const WidgetTouchEvent* aEvent) {
|
|
|
|
if (!aTouch || !aTouch->convertToPointer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TouchInfo info;
|
|
|
|
if (!sCaptureTouchList->Get(aTouch->Identifier(), &info)) {
|
|
|
|
// This check runs before the TouchManager has the touch registered in its
|
|
|
|
// touch list. It's because we dispatching pointer events before handling
|
|
|
|
// touch events. So we convert eTouchStart to pointerdown even it's not
|
|
|
|
// registered.
|
|
|
|
// Check WidgetTouchEvent::mMessage because Touch::mMessage is assigned when
|
|
|
|
// pre-handling touch events.
|
|
|
|
return aEvent->mMessage == eTouchStart;
|
|
|
|
}
|
2019-02-16 01:04:13 +03:00
|
|
|
|
|
|
|
if (!info.mConvertToPointer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent->mMessage) {
|
|
|
|
case eTouchStart: {
|
|
|
|
// We don't want to fire duplicated pointerdown.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case eTouchMove: {
|
|
|
|
// Always fire first pointermove event.
|
|
|
|
return info.mTouch->mMessage != eTouchMove ||
|
|
|
|
!aTouch->Equals(info.mTouch);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2017-02-16 10:05:09 +03:00
|
|
|
}
|
|
|
|
|
2015-12-22 09:14:12 +03:00
|
|
|
} // namespace mozilla
|