Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/TouchEvent.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
#ifndef mozilla_dom_TouchEvent_h_
7
#define mozilla_dom_TouchEvent_h_
8
9
#include "mozilla/dom/Touch.h"
10
#include "mozilla/dom/TouchEventBinding.h"
11
#include "mozilla/dom/UIEvent.h"
12
#include "mozilla/Attributes.h"
13
#include "mozilla/EventForwards.h"
14
#include "mozilla/TouchEvents.h"
15
#include "nsJSEnvironment.h"
16
#include "nsStringFwd.h"
17
#include "nsWrapperCache.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
class TouchList final : public nsISupports
23
                      , public nsWrapperCache
24
{
25
public:
26
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList)
28
29
  explicit TouchList(nsISupports* aParent)
30
    : mParent(aParent)
31
0
  {
32
0
    nsJSContext::LikelyShortLivingObjectCreated();
33
0
  }
34
  TouchList(nsISupports* aParent,
35
            const WidgetTouchEvent::TouchArray& aTouches)
36
    : mParent(aParent)
37
    , mPoints(aTouches)
38
0
  {
39
0
    nsJSContext::LikelyShortLivingObjectCreated();
40
0
  }
41
42
  void Append(Touch* aPoint)
43
0
  {
44
0
    mPoints.AppendElement(aPoint);
45
0
  }
46
47
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
48
49
  nsISupports* GetParentObject() const
50
0
  {
51
0
    return mParent;
52
0
  }
53
54
  static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
55
56
  uint32_t Length() const
57
0
  {
58
0
    return mPoints.Length();
59
0
  }
60
  Touch* Item(uint32_t aIndex) const
61
0
  {
62
0
    return mPoints.SafeElementAt(aIndex);
63
0
  }
64
  Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const
65
0
  {
66
0
    aFound = aIndex < mPoints.Length();
67
0
    if (!aFound) {
68
0
      return nullptr;
69
0
    }
70
0
    return mPoints[aIndex];
71
0
  }
72
73
  void Clear()
74
0
  {
75
0
    mPoints.Clear();
76
0
  }
77
78
protected:
79
0
  ~TouchList() {}
80
81
  nsCOMPtr<nsISupports> mParent;
82
  WidgetTouchEvent::TouchArray mPoints;
83
};
84
85
class TouchEvent : public UIEvent
86
{
87
public:
88
  TouchEvent(EventTarget* aOwner,
89
             nsPresContext* aPresContext,
90
             WidgetTouchEvent* aEvent);
91
92
  NS_DECL_ISUPPORTS_INHERITED
93
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
94
95
  virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
96
0
  {
97
0
    return TouchEvent_Binding::Wrap(aCx, this, aGivenProto);
98
0
  }
99
100
  already_AddRefed<TouchList>
101
  CopyTouches(const Sequence<OwningNonNull<Touch>>& aTouches);
102
103
  TouchList* Touches();
104
  // TargetTouches() populates mTargetTouches from widget event's touch list.
105
  TouchList* TargetTouches();
106
  // GetExistingTargetTouches just returns the existing target touches list.
107
  TouchList* GetExistingTargetTouches()
108
0
  {
109
0
    return mTargetTouches;
110
0
  }
111
  TouchList* ChangedTouches();
112
113
  bool AltKey();
114
  bool MetaKey();
115
  bool CtrlKey();
116
  bool ShiftKey();
117
118
  void InitTouchEvent(const nsAString& aType,
119
                      bool aCanBubble,
120
                      bool aCancelable,
121
                      nsGlobalWindowInner* aView,
122
                      int32_t aDetail,
123
                      bool aCtrlKey,
124
                      bool aAltKey,
125
                      bool aShiftKey,
126
                      bool aMetaKey,
127
                      TouchList* aTouches,
128
                      TouchList* aTargetTouches,
129
                      TouchList* aChangedTouches);
130
131
  static bool PlatformSupportsTouch();
132
  static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
133
  static bool PrefEnabled(nsIDocShell* aDocShell);
134
135
  static already_AddRefed<TouchEvent> Constructor(const GlobalObject& aGlobal,
136
                                                  const nsAString& aType,
137
                                                  const TouchEventInit& aParam,
138
                                                  ErrorResult& aRv);
139
140
protected:
141
0
  ~TouchEvent() {}
142
143
  void AssignTouchesToWidgetEvent(TouchList* aList, bool aCheckDuplicates);
144
145
  RefPtr<TouchList> mTouches;
146
  RefPtr<TouchList> mTargetTouches;
147
  RefPtr<TouchList> mChangedTouches;
148
};
149
150
} // namespace dom
151
} // namespace mozilla
152
153
already_AddRefed<mozilla::dom::TouchEvent>
154
NS_NewDOMTouchEvent(mozilla::dom::EventTarget* aOwner,
155
                    nsPresContext* aPresContext,
156
                    mozilla::WidgetTouchEvent* aEvent);
157
158
#endif // mozilla_dom_TouchEvent_h_