Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/TouchEvents.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef mozilla_TouchEvents_h__
7
#define mozilla_TouchEvents_h__
8
9
#include <stdint.h>
10
11
#include "mozilla/dom/Touch.h"
12
#include "mozilla/MouseEvents.h"
13
#include "mozilla/RefPtr.h"
14
#include "nsTArray.h"
15
16
namespace mozilla {
17
18
/******************************************************************************
19
 * mozilla::WidgetGestureNotifyEvent
20
 *
21
 * This event is the first event generated when the user touches
22
 * the screen with a finger, and it's meant to decide what kind
23
 * of action we'll use for that touch interaction.
24
 *
25
 * The event is dispatched to the layout and based on what is underneath
26
 * the initial contact point it's then decided if we should pan
27
 * (finger scrolling) or drag the target element.
28
 ******************************************************************************/
29
30
class WidgetGestureNotifyEvent : public WidgetGUIEvent
31
{
32
public:
33
  virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() override
34
0
  {
35
0
    return this;
36
0
  }
37
38
  WidgetGestureNotifyEvent(bool aIsTrusted, EventMessage aMessage,
39
                           nsIWidget *aWidget)
40
    : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eGestureNotifyEventClass)
41
    , mPanDirection(ePanNone)
42
    , mDisplayPanFeedback(false)
43
0
  {
44
0
  }
45
46
  virtual WidgetEvent* Duplicate() const override
47
0
  {
48
0
    // XXX Looks like this event is handled only in PostHandleEvent() of
49
0
    //     EventStateManager.  Therefore, it might be possible to handle this
50
0
    //     in PreHandleEvent() and not to dispatch as a DOM event into the DOM
51
0
    //     tree like ContentQueryEvent.  Then, this event doesn't need to
52
0
    //     support Duplicate().
53
0
    MOZ_ASSERT(mClass == eGestureNotifyEventClass,
54
0
               "Duplicate() must be overridden by sub class");
55
0
    // Not copying widget, it is a weak reference.
56
0
    WidgetGestureNotifyEvent* result =
57
0
      new WidgetGestureNotifyEvent(false, mMessage, nullptr);
58
0
    result->AssignGestureNotifyEventData(*this, true);
59
0
    result->mFlags = mFlags;
60
0
    return result;
61
0
  }
62
63
  typedef int8_t PanDirectionType;
64
  enum PanDirection : PanDirectionType
65
  {
66
    ePanNone,
67
    ePanVertical,
68
    ePanHorizontal,
69
    ePanBoth
70
  };
71
72
  PanDirection mPanDirection;
73
  bool mDisplayPanFeedback;
74
75
  void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
76
                                    bool aCopyTargets)
77
0
  {
78
0
    AssignGUIEventData(aEvent, aCopyTargets);
79
0
80
0
    mPanDirection = aEvent.mPanDirection;
81
0
    mDisplayPanFeedback = aEvent.mDisplayPanFeedback;
82
0
  }
83
};
84
85
/******************************************************************************
86
 * mozilla::WidgetSimpleGestureEvent
87
 ******************************************************************************/
88
89
class WidgetSimpleGestureEvent : public WidgetMouseEventBase
90
{
91
public:
92
  virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() override
93
0
  {
94
0
    return this;
95
0
  }
96
97
  WidgetSimpleGestureEvent(bool aIsTrusted, EventMessage aMessage,
98
                           nsIWidget* aWidget)
99
    : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
100
                           eSimpleGestureEventClass)
101
    , mAllowedDirections(0)
102
    , mDirection(0)
103
    , mClickCount(0)
104
    , mDelta(0.0)
105
0
  {
106
0
  }
107
108
  WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther)
109
    : WidgetMouseEventBase(aOther.IsTrusted(), aOther.mMessage,
110
                           aOther.mWidget, eSimpleGestureEventClass)
111
    , mAllowedDirections(aOther.mAllowedDirections)
112
    , mDirection(aOther.mDirection)
113
    , mClickCount(0)
114
    , mDelta(aOther.mDelta)
115
0
  {
116
0
  }
117
118
  virtual WidgetEvent* Duplicate() const override
119
0
  {
120
0
    MOZ_ASSERT(mClass == eSimpleGestureEventClass,
121
0
               "Duplicate() must be overridden by sub class");
122
0
    // Not copying widget, it is a weak reference.
123
0
    WidgetSimpleGestureEvent* result =
124
0
      new WidgetSimpleGestureEvent(false, mMessage, nullptr);
125
0
    result->AssignSimpleGestureEventData(*this, true);
126
0
    result->mFlags = mFlags;
127
0
    return result;
128
0
  }
129
130
  // See SimpleGestureEvent.webidl for values
131
  uint32_t mAllowedDirections;
132
  // See SimpleGestureEvent.webidl for values
133
  uint32_t mDirection;
134
  // The number of taps for tap events
135
  uint32_t mClickCount;
136
  // Delta for magnify and rotate events
137
  double mDelta;
138
139
  // XXX Not tested by test_assign_event_data.html
140
  void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent,
141
                                    bool aCopyTargets)
142
0
  {
143
0
    AssignMouseEventBaseData(aEvent, aCopyTargets);
144
0
145
0
    // mAllowedDirections isn't copied
146
0
    mDirection = aEvent.mDirection;
147
0
    mDelta = aEvent.mDelta;
148
0
    mClickCount = aEvent.mClickCount;
149
0
  }
150
};
151
152
/******************************************************************************
153
 * mozilla::WidgetTouchEvent
154
 ******************************************************************************/
155
156
class WidgetTouchEvent : public WidgetInputEvent
157
{
158
public:
159
  typedef nsTArray<RefPtr<mozilla::dom::Touch>> TouchArray;
160
  typedef AutoTArray<RefPtr<mozilla::dom::Touch>, 10> AutoTouchArray;
161
162
0
  virtual WidgetTouchEvent* AsTouchEvent() override { return this; }
163
164
  WidgetTouchEvent()
165
0
  {
166
0
    MOZ_COUNT_CTOR(WidgetTouchEvent);
167
0
  }
168
169
  WidgetTouchEvent(const WidgetTouchEvent& aOther)
170
    : WidgetInputEvent(aOther.IsTrusted(), aOther.mMessage, aOther.mWidget,
171
                       eTouchEventClass)
172
0
  {
173
0
    MOZ_COUNT_CTOR(WidgetTouchEvent);
174
0
    mModifiers = aOther.mModifiers;
175
0
    mTime = aOther.mTime;
176
0
    mTimeStamp = aOther.mTimeStamp;
177
0
    mTouches.AppendElements(aOther.mTouches);
178
0
    mFlags.mCancelable = mMessage != eTouchCancel;
179
0
    mFlags.mHandledByAPZ = aOther.mFlags.mHandledByAPZ;
180
0
  }
181
182
  WidgetTouchEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
183
    : WidgetInputEvent(aIsTrusted, aMessage, aWidget, eTouchEventClass)
184
0
  {
185
0
    MOZ_COUNT_CTOR(WidgetTouchEvent);
186
0
    mFlags.mCancelable = mMessage != eTouchCancel;
187
0
  }
188
189
  virtual ~WidgetTouchEvent()
190
0
  {
191
0
    MOZ_COUNT_DTOR(WidgetTouchEvent);
192
0
  }
193
194
  virtual WidgetEvent* Duplicate() const override
195
0
  {
196
0
    MOZ_ASSERT(mClass == eTouchEventClass,
197
0
               "Duplicate() must be overridden by sub class");
198
0
    // Not copying widget, it is a weak reference.
199
0
    WidgetTouchEvent* result = new WidgetTouchEvent(false, mMessage, nullptr);
200
0
    result->AssignTouchEventData(*this, true);
201
0
    result->mFlags = mFlags;
202
0
    return result;
203
0
  }
204
205
  TouchArray mTouches;
206
207
  void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets)
208
0
  {
209
0
    AssignInputEventData(aEvent, aCopyTargets);
210
0
211
0
    // Assign*EventData() assume that they're called only new instance.
212
0
    MOZ_ASSERT(mTouches.IsEmpty());
213
0
    mTouches.AppendElements(aEvent.mTouches);
214
0
  }
215
};
216
217
} // namespace mozilla
218
219
#endif // mozilla_TouchEvents_h__