2013-09-24 10:04:15 +00: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"
|
2016-04-19 20:51:25 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
#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 16:28:04 +00:00
|
|
|
virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() override {
|
2013-10-18 06:10:20 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetGestureNotifyEvent(bool aIsTrusted, EventMessage aMessage,
|
2023-08-09 10:29:39 +00:00
|
|
|
nsIWidget* aWidget,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eGestureNotifyEventClass,
|
|
|
|
aTime),
|
2016-04-29 10:34:46 +00:00
|
|
|
mPanDirection(ePanNone),
|
2016-05-15 01:03:50 +00:00
|
|
|
mDisplayPanFeedback(false) {}
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override {
|
2014-03-27 13:53:19 +00: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 05:28:52 +00:00
|
|
|
MOZ_ASSERT(mClass == eGestureNotifyEventClass,
|
2014-03-27 13:53:19 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetGestureNotifyEvent* result =
|
2023-08-09 10:29:39 +00:00
|
|
|
new WidgetGestureNotifyEvent(false, mMessage, nullptr, this);
|
2014-03-27 13:53:19 +00:00
|
|
|
result->AssignGestureNotifyEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
2014-01-27 06:10:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 02:32:59 +00:00
|
|
|
typedef int8_t PanDirectionType;
|
|
|
|
enum PanDirection : PanDirectionType {
|
2013-09-24 10:04:15 +00:00
|
|
|
ePanNone,
|
|
|
|
ePanVertical,
|
|
|
|
ePanHorizontal,
|
|
|
|
ePanBoth
|
|
|
|
};
|
|
|
|
|
2016-04-29 10:34:46 +00:00
|
|
|
PanDirection mPanDirection;
|
2016-05-15 01:03:50 +00:00
|
|
|
bool mDisplayPanFeedback;
|
2014-03-27 13:53:19 +00:00
|
|
|
|
|
|
|
void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
|
|
|
|
bool aCopyTargets) {
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
2016-04-29 10:34:46 +00:00
|
|
|
mPanDirection = aEvent.mPanDirection;
|
2016-05-15 01:03:50 +00:00
|
|
|
mDisplayPanFeedback = aEvent.mDisplayPanFeedback;
|
2014-03-27 13:53:19 +00:00
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
2016-02-23 15:17:46 +00:00
|
|
|
* mozilla::WidgetSimpleGestureEvent
|
2013-09-24 10:04:15 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetSimpleGestureEvent : public WidgetMouseEventBase {
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() override {
|
2013-10-18 06:10:20 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetSimpleGestureEvent(bool aIsTrusted, EventMessage aMessage,
|
2023-08-09 10:29:39 +00:00
|
|
|
nsIWidget* aWidget,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
2014-02-15 01:06:06 +00:00
|
|
|
: WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
|
2023-08-09 10:29:39 +00:00
|
|
|
eSimpleGestureEventClass, aTime),
|
2016-05-09 19:16:54 +00:00
|
|
|
mAllowedDirections(0),
|
2016-05-09 19:16:54 +00:00
|
|
|
mDirection(0),
|
2016-05-09 19:16:54 +00:00
|
|
|
mClickCount(0),
|
2016-05-09 19:16:55 +00:00
|
|
|
mDelta(0.0) {}
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2014-02-15 01:06:06 +00:00
|
|
|
WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther)
|
2016-03-17 07:01:30 +00:00
|
|
|
: WidgetMouseEventBase(aOther.IsTrusted(), aOther.mMessage,
|
2016-04-14 08:03:14 +00:00
|
|
|
aOther.mWidget, eSimpleGestureEventClass),
|
2016-05-09 19:16:54 +00:00
|
|
|
mAllowedDirections(aOther.mAllowedDirections),
|
2016-05-09 19:16:54 +00:00
|
|
|
mDirection(aOther.mDirection),
|
2016-05-09 19:16:54 +00:00
|
|
|
mClickCount(0),
|
2016-05-09 19:16:55 +00:00
|
|
|
mDelta(aOther.mDelta) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override {
|
2014-08-04 05:28:53 +00:00
|
|
|
MOZ_ASSERT(mClass == eSimpleGestureEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetSimpleGestureEvent* result =
|
2023-08-09 10:29:39 +00:00
|
|
|
new WidgetSimpleGestureEvent(false, mMessage, nullptr, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignSimpleGestureEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:17:10 +00:00
|
|
|
// See SimpleGestureEvent.webidl for values
|
2016-05-09 19:16:54 +00:00
|
|
|
uint32_t mAllowedDirections;
|
2018-02-09 16:17:10 +00:00
|
|
|
// See SimpleGestureEvent.webidl for values
|
2016-05-09 19:16:54 +00:00
|
|
|
uint32_t mDirection;
|
2013-09-24 10:04:15 +00:00
|
|
|
// The number of taps for tap events
|
2016-05-09 19:16:54 +00:00
|
|
|
uint32_t mClickCount;
|
2016-05-09 19:16:54 +00:00
|
|
|
// Delta for magnify and rotate events
|
2016-05-09 19:16:55 +00:00
|
|
|
double mDelta;
|
2013-09-24 10:04:15 +00:00
|
|
|
|
|
|
|
// XXX Not tested by test_assign_event_data.html
|
|
|
|
void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent,
|
|
|
|
bool aCopyTargets) {
|
|
|
|
AssignMouseEventBaseData(aEvent, aCopyTargets);
|
|
|
|
|
2016-05-09 19:16:54 +00:00
|
|
|
// mAllowedDirections isn't copied
|
2016-05-09 19:16:54 +00:00
|
|
|
mDirection = aEvent.mDirection;
|
2016-05-09 19:16:55 +00:00
|
|
|
mDelta = aEvent.mDelta;
|
2016-05-09 19:16:54 +00:00
|
|
|
mClickCount = aEvent.mClickCount;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetTouchEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
2023-02-04 11:12:36 +00:00
|
|
|
class WidgetTouchEvent final : public WidgetInputEvent {
|
2013-09-24 10:04:15 +00:00
|
|
|
public:
|
2020-05-07 08:49:18 +00:00
|
|
|
typedef nsTArray<RefPtr<mozilla::dom::Touch>> TouchArray;
|
2016-02-02 15:36:30 +00:00
|
|
|
typedef AutoTArray<RefPtr<mozilla::dom::Touch>, 10> AutoTouchArray;
|
2020-04-30 09:38:38 +00:00
|
|
|
typedef AutoTouchArray::base_type TouchArrayBase;
|
2014-07-08 20:48:18 +00:00
|
|
|
|
2023-02-04 11:12:36 +00:00
|
|
|
WidgetTouchEvent* AsTouchEvent() override { return this; }
|
2013-10-18 06:10:20 +00:00
|
|
|
|
2020-02-20 11:40:14 +00:00
|
|
|
MOZ_COUNTED_DEFAULT_CTOR(WidgetTouchEvent)
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2014-08-04 05:28:53 +00:00
|
|
|
WidgetTouchEvent(const WidgetTouchEvent& aOther)
|
2016-04-14 08:03:14 +00:00
|
|
|
: WidgetInputEvent(aOther.IsTrusted(), aOther.mMessage, aOther.mWidget,
|
2021-05-31 13:39:18 +00:00
|
|
|
eTouchEventClass) {
|
2016-02-23 15:17:46 +00:00
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers = aOther.mModifiers;
|
2016-03-28 04:49:02 +00:00
|
|
|
mTimeStamp = aOther.mTimeStamp;
|
2016-03-30 09:44:28 +00:00
|
|
|
mTouches.AppendElements(aOther.mTouches);
|
2021-05-31 13:39:18 +00:00
|
|
|
mInputSource = aOther.mInputSource;
|
|
|
|
mButton = aOther.mButton;
|
|
|
|
mButtons = aOther.mButtons;
|
2015-09-14 15:14:35 +00:00
|
|
|
mFlags.mCancelable = mMessage != eTouchCancel;
|
2015-10-28 16:53:34 +00:00
|
|
|
mFlags.mHandledByAPZ = aOther.mFlags.mHandledByAPZ;
|
2014-01-06 17:26:23 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 11:12:36 +00:00
|
|
|
WidgetTouchEvent(WidgetTouchEvent&& aOther)
|
|
|
|
: WidgetInputEvent(std::move(aOther)) {
|
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
|
|
|
mModifiers = aOther.mModifiers;
|
|
|
|
mTimeStamp = aOther.mTimeStamp;
|
|
|
|
mTouches = std::move(aOther.mTouches);
|
|
|
|
mInputSource = aOther.mInputSource;
|
|
|
|
mButton = aOther.mButton;
|
|
|
|
mButtons = aOther.mButtons;
|
|
|
|
mFlags = aOther.mFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetTouchEvent& operator=(WidgetTouchEvent&&) = default;
|
|
|
|
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetTouchEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetInputEvent(aIsTrusted, aMessage, aWidget, eTouchEventClass,
|
|
|
|
aTime) {
|
2013-09-24 10:04:15 +00:00
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2015-09-14 15:14:35 +00:00
|
|
|
mFlags.mCancelable = mMessage != eTouchCancel;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 11:40:14 +00:00
|
|
|
MOZ_COUNTED_DTOR_OVERRIDE(WidgetTouchEvent)
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2023-02-04 11:12:36 +00:00
|
|
|
WidgetEvent* Duplicate() const override {
|
2014-08-04 05:28:53 +00:00
|
|
|
MOZ_ASSERT(mClass == eTouchEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
2014-02-11 05:35:25 +00:00
|
|
|
// Not copying widget, it is a weak reference.
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetTouchEvent* result =
|
|
|
|
new WidgetTouchEvent(false, mMessage, nullptr, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignTouchEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-30 09:44:28 +00:00
|
|
|
TouchArray mTouches;
|
2021-05-07 18:01:27 +00:00
|
|
|
uint16_t mInputSource = 5; // MouseEvent_Binding::MOZ_SOURCE_TOUCH
|
2021-05-31 13:39:18 +00:00
|
|
|
int16_t mButton = eNotPressed;
|
|
|
|
int16_t mButtons = 0;
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2013-09-27 06:20:57 +00:00
|
|
|
void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets) {
|
2013-09-24 10:04:15 +00:00
|
|
|
AssignInputEventData(aEvent, aCopyTargets);
|
|
|
|
|
2014-02-11 05:35:25 +00:00
|
|
|
// Assign*EventData() assume that they're called only new instance.
|
2016-03-30 09:44:28 +00:00
|
|
|
MOZ_ASSERT(mTouches.IsEmpty());
|
|
|
|
mTouches.AppendElements(aEvent.mTouches);
|
2021-05-07 18:01:27 +00:00
|
|
|
mInputSource = aEvent.mInputSource;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_TouchEvents_h__
|