2013-09-24 14:04:15 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_TouchEvents_h__
|
|
|
|
#define mozilla_TouchEvents_h__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "mozilla/dom/Touch.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIDOMSimpleGestureEvent.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetGestureNotifyEvent
|
|
|
|
*
|
|
|
|
* This event is the first event generated when the user touches
|
|
|
|
* the screen with a finger, and it's meant to decide what kind
|
|
|
|
* of action we'll use for that touch interaction.
|
|
|
|
*
|
|
|
|
* The event is dispatched to the layout and based on what is underneath
|
|
|
|
* the initial contact point it's then decided if we should pan
|
|
|
|
* (finger scrolling) or drag the target element.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetGestureNotifyEvent : public WidgetGUIEvent
|
|
|
|
{
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() override
|
2013-10-18 10:10:20 +04:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetGestureNotifyEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-08-04 09:28:52 +04:00
|
|
|
nsIWidget *aWidget)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eGestureNotifyEventClass)
|
|
|
|
, panDirection(ePanNone)
|
|
|
|
, displayPanFeedback(false)
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 10:10:44 +04:00
|
|
|
{
|
2014-03-27 17:53:19 +04:00
|
|
|
// XXX Looks like this event is handled only in PostHandleEvent() of
|
|
|
|
// EventStateManager. Therefore, it might be possible to handle this
|
|
|
|
// in PreHandleEvent() and not to dispatch as a DOM event into the DOM
|
|
|
|
// tree like ContentQueryEvent. Then, this event doesn't need to
|
|
|
|
// support Duplicate().
|
2014-08-04 09:28:52 +04:00
|
|
|
MOZ_ASSERT(mClass == eGestureNotifyEventClass,
|
2014-03-27 17:53:19 +04:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetGestureNotifyEvent* result =
|
2015-08-22 04:34:51 +03:00
|
|
|
new WidgetGestureNotifyEvent(false, mMessage, nullptr);
|
2014-03-27 17:53:19 +04:00
|
|
|
result->AssignGestureNotifyEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
2014-01-27 10:10:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-24 14:04:15 +04:00
|
|
|
enum ePanDirection
|
|
|
|
{
|
|
|
|
ePanNone,
|
|
|
|
ePanVertical,
|
|
|
|
ePanHorizontal,
|
|
|
|
ePanBoth
|
|
|
|
};
|
|
|
|
|
|
|
|
ePanDirection panDirection;
|
|
|
|
bool displayPanFeedback;
|
2014-03-27 17:53:19 +04:00
|
|
|
|
|
|
|
void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
|
|
|
panDirection = aEvent.panDirection;
|
|
|
|
displayPanFeedback = aEvent.displayPanFeedback;
|
|
|
|
}
|
2013-09-24 14:04:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
2016-02-23 18:17:46 +03:00
|
|
|
* mozilla::WidgetSimpleGestureEvent
|
2013-09-24 14:04:15 +04:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetSimpleGestureEvent : public WidgetMouseEventBase
|
|
|
|
{
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() override
|
2013-10-18 10:10:20 +04:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetSimpleGestureEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-02-15 05:06:06 +04:00
|
|
|
nsIWidget* aWidget)
|
|
|
|
: WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
|
2014-08-04 09:28:53 +04:00
|
|
|
eSimpleGestureEventClass)
|
2014-02-15 05:06:06 +04:00
|
|
|
, allowedDirections(0)
|
|
|
|
, direction(0)
|
|
|
|
, delta(0.0)
|
|
|
|
, clickCount(0)
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:06:06 +04:00
|
|
|
WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther)
|
2016-03-17 10:01:30 +03:00
|
|
|
: WidgetMouseEventBase(aOther.IsTrusted(), aOther.mMessage,
|
2014-08-04 09:28:53 +04:00
|
|
|
aOther.widget, eSimpleGestureEventClass)
|
2014-02-15 05:06:06 +04:00
|
|
|
, allowedDirections(aOther.allowedDirections)
|
|
|
|
, direction(aOther.direction)
|
|
|
|
, delta(aOther.delta)
|
|
|
|
, clickCount(0)
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 10:10:44 +04:00
|
|
|
{
|
2014-08-04 09:28:53 +04:00
|
|
|
MOZ_ASSERT(mClass == eSimpleGestureEventClass,
|
2014-01-27 10:10:44 +04:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetSimpleGestureEvent* result =
|
2015-08-22 04:34:51 +03:00
|
|
|
new WidgetSimpleGestureEvent(false, mMessage, nullptr);
|
2014-01-27 10:10:44 +04:00
|
|
|
result->AssignSimpleGestureEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:04:15 +04:00
|
|
|
// See nsIDOMSimpleGestureEvent for values
|
|
|
|
uint32_t allowedDirections;
|
|
|
|
// See nsIDOMSimpleGestureEvent for values
|
|
|
|
uint32_t direction;
|
|
|
|
// Delta for magnify and rotate events
|
|
|
|
double delta;
|
|
|
|
// The number of taps for tap events
|
|
|
|
uint32_t clickCount;
|
|
|
|
|
|
|
|
// XXX Not tested by test_assign_event_data.html
|
|
|
|
void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignMouseEventBaseData(aEvent, aCopyTargets);
|
|
|
|
|
|
|
|
// allowedDirections isn't copied
|
|
|
|
direction = aEvent.direction;
|
|
|
|
delta = aEvent.delta;
|
|
|
|
clickCount = aEvent.clickCount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetTouchEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetTouchEvent : public WidgetInputEvent
|
|
|
|
{
|
|
|
|
public:
|
2015-10-18 08:24:48 +03:00
|
|
|
typedef nsTArray<RefPtr<mozilla::dom::Touch>> TouchArray;
|
2016-02-02 18:36:30 +03:00
|
|
|
typedef AutoTArray<RefPtr<mozilla::dom::Touch>, 10> AutoTouchArray;
|
2014-07-09 00:48:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetTouchEvent* AsTouchEvent() override { return this; }
|
2013-10-18 10:10:20 +04:00
|
|
|
|
2013-09-24 14:04:15 +04:00
|
|
|
WidgetTouchEvent()
|
|
|
|
{
|
2016-02-23 18:17:46 +03:00
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2013-09-24 14:04:15 +04:00
|
|
|
}
|
|
|
|
|
2014-08-04 09:28:53 +04:00
|
|
|
WidgetTouchEvent(const WidgetTouchEvent& aOther)
|
2016-03-17 10:01:30 +03:00
|
|
|
: WidgetInputEvent(aOther.IsTrusted(), aOther.mMessage, aOther.widget,
|
2014-08-04 09:28:53 +04:00
|
|
|
eTouchEventClass)
|
2014-01-06 21:26:23 +04:00
|
|
|
{
|
2016-02-23 18:17:46 +03:00
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2014-01-06 21:26:23 +04:00
|
|
|
modifiers = aOther.modifiers;
|
|
|
|
time = aOther.time;
|
2014-06-06 09:29:49 +04:00
|
|
|
timeStamp = aOther.timeStamp;
|
2014-01-06 21:26:23 +04:00
|
|
|
touches.AppendElements(aOther.touches);
|
2015-09-14 18:14:35 +03:00
|
|
|
mFlags.mCancelable = mMessage != eTouchCancel;
|
2015-10-28 19:53:34 +03:00
|
|
|
mFlags.mHandledByAPZ = aOther.mFlags.mHandledByAPZ;
|
2014-01-06 21:26:23 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetTouchEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
|
2014-08-04 09:28:53 +04:00
|
|
|
: WidgetInputEvent(aIsTrusted, aMessage, aWidget, eTouchEventClass)
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2015-09-14 18:14:35 +03:00
|
|
|
mFlags.mCancelable = mMessage != eTouchCancel;
|
2013-09-24 14:04:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:20 +04:00
|
|
|
virtual ~WidgetTouchEvent()
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(WidgetTouchEvent);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 10:10:44 +04:00
|
|
|
{
|
2014-08-04 09:28:53 +04:00
|
|
|
MOZ_ASSERT(mClass == eTouchEventClass,
|
2014-01-27 10:10:44 +04:00
|
|
|
"Duplicate() must be overridden by sub class");
|
2014-02-11 09:35:25 +04:00
|
|
|
// Not copying widget, it is a weak reference.
|
2015-08-22 04:34:51 +03:00
|
|
|
WidgetTouchEvent* result = new WidgetTouchEvent(false, mMessage, nullptr);
|
2014-01-27 10:10:44 +04:00
|
|
|
result->AssignTouchEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-09 00:48:18 +04:00
|
|
|
TouchArray touches;
|
2013-09-24 14:04:15 +04:00
|
|
|
|
2013-09-27 10:20:57 +04:00
|
|
|
void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets)
|
2013-09-24 14:04:15 +04:00
|
|
|
{
|
|
|
|
AssignInputEventData(aEvent, aCopyTargets);
|
|
|
|
|
2014-02-11 09:35:25 +04:00
|
|
|
// Assign*EventData() assume that they're called only new instance.
|
|
|
|
MOZ_ASSERT(touches.IsEmpty());
|
|
|
|
touches.AppendElements(aEvent.touches);
|
2013-09-24 14:04:15 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_TouchEvents_h__
|