Bug 1866894 - Update failing subtest for content-visibility-auto-resize.html. r=fredw
[gecko.git] / dom / events / TouchEvent.h
blobeb88aa5868b965f8cf01aa7419fa051a1858bfb1
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_
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"
19 namespace mozilla::dom {
21 class TouchList final : public nsISupports, public nsWrapperCache {
22 public:
23 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
24 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TouchList)
26 explicit TouchList(nsISupports* aParent) : mParent(aParent) {
27 nsJSContext::LikelyShortLivingObjectCreated();
29 TouchList(nsISupports* aParent, const WidgetTouchEvent::TouchArray& aTouches)
30 : mParent(aParent), mPoints(aTouches.Clone()) {
31 nsJSContext::LikelyShortLivingObjectCreated();
34 void Append(Touch* aPoint) { mPoints.AppendElement(aPoint); }
36 virtual JSObject* WrapObject(JSContext* aCx,
37 JS::Handle<JSObject*> aGivenProto) override;
39 nsISupports* GetParentObject() const { return mParent; }
41 static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
43 uint32_t Length() const { return mPoints.Length(); }
44 Touch* Item(uint32_t aIndex) const { return mPoints.SafeElementAt(aIndex); }
45 Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const {
46 aFound = aIndex < mPoints.Length();
47 if (!aFound) {
48 return nullptr;
50 return mPoints[aIndex];
53 void Clear() { mPoints.Clear(); }
55 protected:
56 ~TouchList() = default;
58 nsCOMPtr<nsISupports> mParent;
59 WidgetTouchEvent::TouchArray mPoints;
62 class TouchEvent : public UIEvent {
63 public:
64 TouchEvent(EventTarget* aOwner, nsPresContext* aPresContext,
65 WidgetTouchEvent* aEvent);
67 NS_DECL_ISUPPORTS_INHERITED
68 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
70 virtual JSObject* WrapObjectInternal(
71 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
72 return TouchEvent_Binding::Wrap(aCx, this, aGivenProto);
75 already_AddRefed<TouchList> CopyTouches(
76 const Sequence<OwningNonNull<Touch>>& aTouches);
78 TouchList* Touches();
79 // TargetTouches() populates mTargetTouches from widget event's touch list.
80 TouchList* TargetTouches();
81 // GetExistingTargetTouches just returns the existing target touches list.
82 TouchList* GetExistingTargetTouches() { return mTargetTouches; }
83 TouchList* ChangedTouches();
85 bool AltKey();
86 bool MetaKey();
87 bool CtrlKey();
88 bool ShiftKey();
90 void InitTouchEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
91 nsGlobalWindowInner* aView, int32_t aDetail,
92 bool aCtrlKey, bool aAltKey, bool aShiftKey,
93 bool aMetaKey, TouchList* aTouches,
94 TouchList* aTargetTouches, TouchList* aChangedTouches);
96 static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
97 static bool PrefEnabled(nsIDocShell* aDocShell);
98 static bool LegacyAPIEnabled(JSContext* aCx, JSObject* aGlobal);
99 static bool LegacyAPIEnabled(nsIDocShell* aDocShell, bool aCallerIsSystem);
101 static already_AddRefed<TouchEvent> Constructor(const GlobalObject& aGlobal,
102 const nsAString& aType,
103 const TouchEventInit& aParam);
105 protected:
106 ~TouchEvent() = default;
108 void AssignTouchesToWidgetEvent(TouchList* aList, bool aCheckDuplicates);
110 RefPtr<TouchList> mTouches;
111 RefPtr<TouchList> mTargetTouches;
112 RefPtr<TouchList> mChangedTouches;
115 } // namespace mozilla::dom
117 already_AddRefed<mozilla::dom::TouchEvent> NS_NewDOMTouchEvent(
118 mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
119 mozilla::WidgetTouchEvent* aEvent);
121 #endif // mozilla_dom_TouchEvent_h_