2013-09-24 03:04:15 -07: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:
|
2013-10-17 23:10:20 -07:00
|
|
|
virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-09-24 03:04:15 -07:00
|
|
|
WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage,
|
2014-08-03 22:28:52 -07:00
|
|
|
nsIWidget *aWidget)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eGestureNotifyEventClass)
|
|
|
|
, panDirection(ePanNone)
|
|
|
|
, displayPanFeedback(false)
|
2013-09-24 03:04:15 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-26 22:10:44 -08:00
|
|
|
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
|
|
|
|
{
|
2014-03-27 06:53:19 -07: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-03 22:28:52 -07:00
|
|
|
MOZ_ASSERT(mClass == eGestureNotifyEventClass,
|
2014-03-27 06:53:19 -07:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetGestureNotifyEvent* result =
|
|
|
|
new WidgetGestureNotifyEvent(false, message, nullptr);
|
|
|
|
result->AssignGestureNotifyEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
2014-01-26 22:10:44 -08:00
|
|
|
}
|
|
|
|
|
2013-09-24 03:04:15 -07:00
|
|
|
enum ePanDirection
|
|
|
|
{
|
|
|
|
ePanNone,
|
|
|
|
ePanVertical,
|
|
|
|
ePanHorizontal,
|
|
|
|
ePanBoth
|
|
|
|
};
|
|
|
|
|
|
|
|
ePanDirection panDirection;
|
|
|
|
bool displayPanFeedback;
|
2014-03-27 06:53:19 -07:00
|
|
|
|
|
|
|
void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
|
|
|
panDirection = aEvent.panDirection;
|
|
|
|
displayPanFeedback = aEvent.displayPanFeedback;
|
|
|
|
}
|
2013-09-24 03:04:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetTouchEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetSimpleGestureEvent : public WidgetMouseEventBase
|
|
|
|
{
|
|
|
|
public:
|
2013-10-17 23:10:20 -07:00
|
|
|
virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-09-24 03:04:15 -07:00
|
|
|
WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage,
|
2014-02-14 17:06:06 -08:00
|
|
|
nsIWidget* aWidget)
|
|
|
|
: WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
|
|
|
|
NS_SIMPLE_GESTURE_EVENT)
|
|
|
|
, allowedDirections(0)
|
|
|
|
, direction(0)
|
|
|
|
, delta(0.0)
|
|
|
|
, clickCount(0)
|
2013-09-24 03:04:15 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-14 17:06:06 -08:00
|
|
|
WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther)
|
|
|
|
: WidgetMouseEventBase(aOther.mFlags.mIsTrusted, aOther.message,
|
|
|
|
aOther.widget, NS_SIMPLE_GESTURE_EVENT)
|
|
|
|
, allowedDirections(aOther.allowedDirections)
|
|
|
|
, direction(aOther.direction)
|
|
|
|
, delta(aOther.delta)
|
|
|
|
, clickCount(0)
|
2013-09-24 03:04:15 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-26 22:10:44 -08:00
|
|
|
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
|
|
|
|
{
|
2014-08-03 22:28:46 -07:00
|
|
|
MOZ_ASSERT(mClass == NS_SIMPLE_GESTURE_EVENT,
|
2014-01-26 22:10:44 -08:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetSimpleGestureEvent* result =
|
2014-02-14 17:06:06 -08:00
|
|
|
new WidgetSimpleGestureEvent(false, message, nullptr);
|
2014-01-26 22:10:44 -08:00
|
|
|
result->AssignSimpleGestureEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-24 03:04:15 -07: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:
|
2014-07-08 13:48:18 -07:00
|
|
|
typedef nsTArray<nsRefPtr<mozilla::dom::Touch>> TouchArray;
|
2014-07-09 09:17:05 -07:00
|
|
|
typedef nsAutoTArray<nsRefPtr<mozilla::dom::Touch>, 10> AutoTouchArray;
|
2014-07-08 13:48:18 -07:00
|
|
|
|
2013-10-17 23:10:20 -07:00
|
|
|
virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; }
|
|
|
|
|
2013-09-24 03:04:15 -07:00
|
|
|
WidgetTouchEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-06 09:26:23 -08:00
|
|
|
WidgetTouchEvent(const WidgetTouchEvent& aOther) :
|
|
|
|
WidgetInputEvent(aOther.mFlags.mIsTrusted, aOther.message, aOther.widget,
|
|
|
|
NS_TOUCH_EVENT)
|
|
|
|
{
|
|
|
|
modifiers = aOther.modifiers;
|
|
|
|
time = aOther.time;
|
2014-06-05 22:29:49 -07:00
|
|
|
timeStamp = aOther.timeStamp;
|
2014-01-06 09:26:23 -08:00
|
|
|
touches.AppendElements(aOther.touches);
|
2014-02-27 16:13:05 -08:00
|
|
|
mFlags.mCancelable = message != NS_TOUCH_CANCEL;
|
2014-01-06 09:26:23 -08:00
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
|
|
|
}
|
|
|
|
|
2013-09-24 03:04:15 -07:00
|
|
|
WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
|
|
|
|
WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_TOUCH_EVENT)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(WidgetTouchEvent);
|
2014-02-27 16:13:05 -08:00
|
|
|
mFlags.mCancelable = message != NS_TOUCH_CANCEL;
|
2013-09-24 03:04:15 -07:00
|
|
|
}
|
|
|
|
|
2013-10-17 23:10:20 -07:00
|
|
|
virtual ~WidgetTouchEvent()
|
2013-09-24 03:04:15 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(WidgetTouchEvent);
|
|
|
|
}
|
|
|
|
|
2014-01-26 22:10:44 -08:00
|
|
|
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
|
|
|
|
{
|
2014-08-03 22:28:46 -07:00
|
|
|
MOZ_ASSERT(mClass == NS_TOUCH_EVENT,
|
2014-01-26 22:10:44 -08:00
|
|
|
"Duplicate() must be overridden by sub class");
|
2014-02-10 21:35:25 -08:00
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetTouchEvent* result = new WidgetTouchEvent(false, message, nullptr);
|
2014-01-26 22:10:44 -08:00
|
|
|
result->AssignTouchEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-08 13:48:18 -07:00
|
|
|
TouchArray touches;
|
2013-09-24 03:04:15 -07:00
|
|
|
|
2013-09-26 23:20:57 -07:00
|
|
|
void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets)
|
2013-09-24 03:04:15 -07:00
|
|
|
{
|
|
|
|
AssignInputEventData(aEvent, aCopyTargets);
|
|
|
|
|
2014-02-10 21:35:25 -08:00
|
|
|
// Assign*EventData() assume that they're called only new instance.
|
|
|
|
MOZ_ASSERT(touches.IsEmpty());
|
|
|
|
touches.AppendElements(aEvent.touches);
|
2013-09-24 03:04:15 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_TouchEvents_h__
|