2012-07-20 06:48:25 +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 InputData_h__
|
|
|
|
#define InputData_h__
|
|
|
|
|
|
|
|
#include "nsDebug.h"
|
2013-01-23 23:30:48 +00:00
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsTArray.h"
|
2013-06-11 22:13:11 +00:00
|
|
|
#include "Units.h"
|
2013-09-24 10:04:14 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
|
|
|
|
enum InputType
|
|
|
|
{
|
|
|
|
MULTITOUCH_INPUT,
|
|
|
|
PINCHGESTURE_INPUT,
|
|
|
|
TAPGESTURE_INPUT
|
|
|
|
};
|
|
|
|
|
|
|
|
class MultiTouchInput;
|
|
|
|
class PinchGestureInput;
|
|
|
|
class TapGestureInput;
|
|
|
|
|
|
|
|
// This looks unnecessary now, but as we add more and more classes that derive
|
2013-09-25 11:21:22 +00:00
|
|
|
// from InputType (eventually probably almost as many as *Events.h has), it
|
2012-07-20 06:48:25 +00:00
|
|
|
// will be more and more clear what's going on with a macro that shortens the
|
|
|
|
// definition of the RTTI functions.
|
|
|
|
#define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
|
|
|
|
const type& As##type() const \
|
|
|
|
{ \
|
|
|
|
NS_ABORT_IF_FALSE(mInputType == enumID, "Invalid cast of InputData."); \
|
|
|
|
return (const type&) *this; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Base input data class. Should never be instantiated. */
|
|
|
|
class InputData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputType mInputType;
|
|
|
|
// Time in milliseconds that this data is relevant to. This only really
|
2012-08-22 15:56:38 +00:00
|
|
|
// matters when this data is used as an event. We use uint32_t instead of
|
2013-10-01 07:23:02 +00:00
|
|
|
// TimeStamp because it is easier to convert from WidgetInputEvent. The time
|
|
|
|
// is platform-specific but it in the case of B2G and Fennec it is since
|
|
|
|
// startup.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mTime;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
|
|
|
|
INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
|
|
|
|
INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
|
|
|
|
|
2013-01-23 23:30:48 +00:00
|
|
|
InputData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
InputData(InputType aInputType, uint32_t aTime)
|
2012-07-20 06:48:25 +00:00
|
|
|
: mInputType(aInputType),
|
|
|
|
mTime(aTime)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-04-05 08:49:00 +00:00
|
|
|
* Data container for a single touch input. Similar to dom::Touch, but used in
|
2012-07-20 06:48:25 +00:00
|
|
|
* off-main-thread situations. This is more for just storing touch data, whereas
|
2013-08-05 04:51:22 +00:00
|
|
|
* dom::Touch is more useful for dispatching through the DOM (which can only
|
|
|
|
* happen on the main thread). dom::Touch also bears the problem of storing
|
|
|
|
* pointers to nsIWidget instances which can only be used on the main thread,
|
|
|
|
* so if instead we used dom::Touch and ever set these pointers
|
|
|
|
* off-main-thread, Bad Things Can Happen(tm).
|
2012-07-20 06:48:25 +00:00
|
|
|
*
|
|
|
|
* Note that this doesn't inherit from InputData because this itself is not an
|
|
|
|
* event. It is only a container/struct that should have any number of instances
|
|
|
|
* within a MultiTouchInput.
|
|
|
|
*
|
2013-04-05 08:49:00 +00:00
|
|
|
* fixme/bug 775746: Make dom::Touch inherit from this class.
|
2012-07-20 06:48:25 +00:00
|
|
|
*/
|
|
|
|
class SingleTouchData
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
SingleTouchData(int32_t aIdentifier,
|
2013-06-11 22:13:11 +00:00
|
|
|
ScreenIntPoint aScreenPoint,
|
|
|
|
ScreenSize aRadius,
|
2012-07-20 06:48:25 +00:00
|
|
|
float aRotationAngle,
|
|
|
|
float aForce)
|
|
|
|
: mIdentifier(aIdentifier),
|
|
|
|
mScreenPoint(aScreenPoint),
|
|
|
|
mRadius(aRadius),
|
|
|
|
mRotationAngle(aRotationAngle),
|
|
|
|
mForce(aForce)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-23 23:30:48 +00:00
|
|
|
SingleTouchData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
// A unique number assigned to each SingleTouchData within a MultiTouchInput so
|
|
|
|
// that they can be easily distinguished when handling a touch start/move/end.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mIdentifier;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Point on the screen that the touch hit, in device pixels. They are
|
|
|
|
// coordinates on the screen.
|
2013-06-11 22:13:11 +00:00
|
|
|
ScreenIntPoint mScreenPoint;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Radius that the touch covers, i.e. if you're using your thumb it will
|
|
|
|
// probably be larger than using your pinky, even with the same force.
|
|
|
|
// Radius can be different along x and y. For example, if you press down with
|
|
|
|
// your entire finger vertically, the y radius will be much larger than the x
|
|
|
|
// radius.
|
2013-06-11 22:13:11 +00:00
|
|
|
ScreenSize mRadius;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
float mRotationAngle;
|
|
|
|
|
|
|
|
// How hard the screen is being pressed.
|
|
|
|
float mForce;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-09-27 06:20:57 +00:00
|
|
|
* Similar to WidgetTouchEvent, but for use off-main-thread. Also only stores a
|
|
|
|
* screen touch point instead of the many different coordinate spaces
|
|
|
|
* WidgetTouchEvent stores its touch point in. This includes a way to initialize
|
|
|
|
* itself from a WidgetTouchEvent by copying all relevant data over. Note that
|
|
|
|
* this copying from WidgetTouchEvent functionality can only be used on the main
|
|
|
|
* thread.
|
2012-07-20 06:48:25 +00:00
|
|
|
*
|
|
|
|
* Stores an array of SingleTouchData.
|
|
|
|
*/
|
|
|
|
class MultiTouchInput : public InputData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum MultiTouchType
|
|
|
|
{
|
|
|
|
MULTITOUCH_START,
|
|
|
|
MULTITOUCH_MOVE,
|
|
|
|
MULTITOUCH_END,
|
|
|
|
MULTITOUCH_ENTER,
|
|
|
|
MULTITOUCH_LEAVE,
|
|
|
|
MULTITOUCH_CANCEL
|
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
MultiTouchInput(MultiTouchType aType, uint32_t aTime)
|
2012-07-20 06:48:25 +00:00
|
|
|
: InputData(MULTITOUCH_INPUT, aTime),
|
|
|
|
mType(aType)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-23 23:30:48 +00:00
|
|
|
MultiTouchInput()
|
2012-07-20 06:48:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-27 06:20:57 +00:00
|
|
|
MultiTouchInput(const WidgetTouchEvent& aTouchEvent);
|
2013-01-23 23:30:48 +00:00
|
|
|
|
2013-10-02 06:38:27 +00:00
|
|
|
// This conversion from WidgetMouseEvent to MultiTouchInput is needed because
|
|
|
|
// on the B2G emulator we can only receive mouse events, but we need to be
|
|
|
|
// able to pan correctly. To do this, we convert the events into a format that
|
|
|
|
// the panning code can handle. This code is very limited and only supports
|
2012-07-20 06:48:25 +00:00
|
|
|
// SingleTouchData. It also sends garbage for the identifier, radius, force
|
|
|
|
// and rotation angle.
|
2013-10-02 06:38:27 +00:00
|
|
|
MultiTouchInput(const WidgetMouseEvent& aMouseEvent);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
MultiTouchType mType;
|
|
|
|
nsTArray<SingleTouchData> mTouches;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encapsulation class for pinch events. In general, these will be generated by
|
|
|
|
* a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
|
|
|
|
* determining whether or not the user was trying to do a gesture.
|
|
|
|
*/
|
|
|
|
class PinchGestureInput : public InputData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum PinchGestureType
|
|
|
|
{
|
|
|
|
PINCHGESTURE_START,
|
|
|
|
PINCHGESTURE_SCALE,
|
|
|
|
PINCHGESTURE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
PinchGestureInput(PinchGestureType aType,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aTime,
|
2013-06-11 22:13:11 +00:00
|
|
|
const ScreenPoint& aFocusPoint,
|
2012-07-20 06:48:25 +00:00
|
|
|
float aCurrentSpan,
|
|
|
|
float aPreviousSpan)
|
|
|
|
: InputData(PINCHGESTURE_INPUT, aTime),
|
|
|
|
mType(aType),
|
|
|
|
mFocusPoint(aFocusPoint),
|
|
|
|
mCurrentSpan(aCurrentSpan),
|
|
|
|
mPreviousSpan(aPreviousSpan)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PinchGestureType mType;
|
|
|
|
|
|
|
|
// Center point of the pinch gesture. That is, if there are two fingers on the
|
|
|
|
// screen, it is their midpoint. In the case of more than two fingers, the
|
|
|
|
// point is implementation-specific, but can for example be the midpoint
|
|
|
|
// between the very first and very last touch. This is in device pixels and
|
|
|
|
// are the coordinates on the screen of this midpoint.
|
2013-06-11 22:13:11 +00:00
|
|
|
ScreenPoint mFocusPoint;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// The distance in device pixels (though as a float for increased precision
|
|
|
|
// and because it is the distance along both the x and y axis) between the
|
|
|
|
// touches responsible for the pinch gesture.
|
|
|
|
float mCurrentSpan;
|
|
|
|
|
|
|
|
// The previous |mCurrentSpan| in the PinchGestureInput preceding this one.
|
|
|
|
// This is only really relevant during a PINCHGESTURE_SCALE because when it is
|
|
|
|
// of this type then there must have been a history of spans.
|
|
|
|
float mPreviousSpan;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encapsulation class for tap events. In general, these will be generated by
|
|
|
|
* a gesture listener by looking at SingleTouchData/MultiTouchInput instances and
|
|
|
|
* determining whether or not the user was trying to do a gesture.
|
|
|
|
*/
|
|
|
|
class TapGestureInput : public InputData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum TapGestureType
|
|
|
|
{
|
|
|
|
TAPGESTURE_LONG,
|
|
|
|
TAPGESTURE_UP,
|
|
|
|
TAPGESTURE_CONFIRMED,
|
|
|
|
TAPGESTURE_DOUBLE,
|
|
|
|
TAPGESTURE_CANCEL
|
|
|
|
};
|
|
|
|
|
2013-06-11 22:13:11 +00:00
|
|
|
TapGestureInput(TapGestureType aType, uint32_t aTime, const ScreenIntPoint& aPoint)
|
2012-07-20 06:48:25 +00:00
|
|
|
: InputData(TAPGESTURE_INPUT, aTime),
|
|
|
|
mType(aType),
|
|
|
|
mPoint(aPoint)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TapGestureType mType;
|
2013-06-11 22:13:11 +00:00
|
|
|
ScreenIntPoint mPoint;
|
2012-07-20 06:48:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // InputData_h__
|