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
|
|
|
}
|
|
|
|
|
2015-02-20 10:12:00 +03:00
|
|
|
void
|
|
|
|
TouchManager::Init(PresShell* aPresShell, nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mPresShell = aPresShell;
|
|
|
|
mDocument = aDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TouchManager::Destroy()
|
|
|
|
{
|
|
|
|
EvictTouches();
|
|
|
|
mDocument = nullptr;
|
|
|
|
mPresShell = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-18 14:13:29 +03:00
|
|
|
static nsIContent*
|
2016-11-30 06:14:27 +03:00
|
|
|
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-08-18 14:13:28 +03:00
|
|
|
/*static*/ void
|
2016-11-30 06:14:27 +03:00
|
|
|
TouchManager::EvictTouchPoint(RefPtr<Touch>& aTouch,
|
2016-08-18 14:13:28 +03:00
|
|
|
nsIDocument* aLimitToDocument)
|
2015-02-20 10:12:00 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->mTarget));
|
|
|
|
if (node) {
|
2016-03-31 14:46:32 +03:00
|
|
|
nsIDocument* doc = node->GetUncomposedDoc();
|
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)
|
2015-02-20 10:12:00 +03:00
|
|
|
{
|
2016-08-18 14:13:29 +03:00
|
|
|
for (auto iter = sCaptureTouchList->Iter();
|
2016-01-25 05:45:29 +03:00
|
|
|
!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
|
|
|
}
|
2017-12-09 05:06:18 +03:00
|
|
|
touch->SetTarget(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) {
|
|
|
|
touch->SetTarget(oldTouch->mTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(touch->mTarget);
|
|
|
|
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(touch->GetTarget());
|
|
|
|
nsIFrame* targetFrame = targetContent->GetPrimaryFrame();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
targetFrame->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
|
|
|
while (targetContent && !targetContent->IsElement()) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
|
|
|
touch->SetTarget(targetContent);
|
|
|
|
}
|
|
|
|
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;
|
2017-02-16 10:05:09 +03:00
|
|
|
TouchInfo info = { touch, GetNonAnonymousAncestor(touch->mTarget),
|
|
|
|
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;
|
|
|
|
}
|
2016-11-30 06:14:27 +03:00
|
|
|
RefPtr<Touch> oldTouch = info.mTouch;
|
2015-02-20 10:12:00 +03:00
|
|
|
if (!touch->Equals(oldTouch)) {
|
|
|
|
touch->mChanged = true;
|
|
|
|
haveChanged = true;
|
|
|
|
}
|
|
|
|
|
2016-11-30 06:14:27 +03:00
|
|
|
nsCOMPtr<EventTarget> targetPtr = oldTouch->mTarget;
|
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()) {
|
|
|
|
targetPtr = do_QueryInterface(info.mNonAnonymousTarget);
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
touch->SetTarget(targetPtr);
|
|
|
|
|
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;
|
|
|
|
}
|
2016-08-18 14:13:29 +03:00
|
|
|
nsCOMPtr<EventTarget> targetPtr = info.mTouch->mTarget;
|
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()) {
|
2016-08-18 14:13:29 +03:00
|
|
|
targetPtr = do_QueryInterface(info.mNonAnonymousTarget);
|
|
|
|
}
|
2015-02-20 10:12:00 +03:00
|
|
|
|
|
|
|
aCurrentEventContent = do_QueryInterface(targetPtr);
|
|
|
|
touch->SetTarget(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
|
|
|
}
|
|
|
|
|
2016-11-30 06:14:27 +03:00
|
|
|
/*static*/ already_AddRefed<Touch>
|
2016-08-18 14:13:28 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return info.mConvertToPointer;
|
|
|
|
}
|
|
|
|
|
2015-12-22 09:14:12 +03:00
|
|
|
} // namespace mozilla
|