Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / events / DeviceMotionEvent.h
blob3e0debba88db623576d67e6fbcfe9f97914ee06b
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/. */
7 #ifndef mozilla_dom_DeviceMotionEvent_h_
8 #define mozilla_dom_DeviceMotionEvent_h_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/DeviceMotionEventBinding.h"
12 #include "mozilla/dom/Event.h"
14 namespace mozilla::dom {
16 class DeviceRotationRate final : public nsWrapperCache {
17 public:
18 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate)
19 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceRotationRate)
21 DeviceRotationRate(DeviceMotionEvent* aOwner, const Nullable<double>& aAlpha,
22 const Nullable<double>& aBeta,
23 const Nullable<double>& aGamma);
25 DeviceMotionEvent* GetParentObject() const { return mOwner; }
27 virtual JSObject* WrapObject(JSContext* aCx,
28 JS::Handle<JSObject*> aGivenProto) override {
29 return DeviceRotationRate_Binding::Wrap(aCx, this, aGivenProto);
32 Nullable<double> GetAlpha() const { return mAlpha; }
33 Nullable<double> GetBeta() const { return mBeta; }
34 Nullable<double> GetGamma() const { return mGamma; }
36 private:
37 ~DeviceRotationRate();
39 protected:
40 RefPtr<DeviceMotionEvent> mOwner;
41 Nullable<double> mAlpha, mBeta, mGamma;
44 class DeviceAcceleration final : public nsWrapperCache {
45 public:
46 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration)
47 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceAcceleration)
49 DeviceAcceleration(DeviceMotionEvent* aOwner, const Nullable<double>& aX,
50 const Nullable<double>& aY, const Nullable<double>& aZ);
52 DeviceMotionEvent* GetParentObject() const { return mOwner; }
54 virtual JSObject* WrapObject(JSContext* aCx,
55 JS::Handle<JSObject*> aGivenProto) override {
56 return DeviceAcceleration_Binding::Wrap(aCx, this, aGivenProto);
59 Nullable<double> GetX() const { return mX; }
60 Nullable<double> GetY() const { return mY; }
61 Nullable<double> GetZ() const { return mZ; }
63 private:
64 ~DeviceAcceleration();
66 protected:
67 RefPtr<DeviceMotionEvent> mOwner;
68 Nullable<double> mX, mY, mZ;
71 class DeviceMotionEvent final : public Event {
72 public:
73 DeviceMotionEvent(EventTarget* aOwner, nsPresContext* aPresContext,
74 WidgetEvent* aEvent)
75 : Event(aOwner, aPresContext, aEvent) {}
77 NS_DECL_ISUPPORTS_INHERITED
79 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent, Event)
81 virtual JSObject* WrapObjectInternal(
82 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
83 return DeviceMotionEvent_Binding::Wrap(aCx, this, aGivenProto);
86 DeviceAcceleration* GetAcceleration() const { return mAcceleration; }
88 DeviceAcceleration* GetAccelerationIncludingGravity() const {
89 return mAccelerationIncludingGravity;
92 DeviceRotationRate* GetRotationRate() const { return mRotationRate; }
94 Nullable<double> GetInterval() const { return mInterval; }
96 void InitDeviceMotionEvent(
97 const nsAString& aType, bool aCanBubble, bool aCancelable,
98 const DeviceAccelerationInit& aAcceleration,
99 const DeviceAccelerationInit& aAccelerationIncludingGravity,
100 const DeviceRotationRateInit& aRotationRate,
101 const Nullable<double>& aInterval);
103 void InitDeviceMotionEvent(
104 const nsAString& aType, bool aCanBubble, bool aCancelable,
105 const DeviceAccelerationInit& aAcceleration,
106 const DeviceAccelerationInit& aAccelerationIncludingGravity,
107 const DeviceRotationRateInit& aRotationRate,
108 const Nullable<double>& aInterval, const Nullable<uint64_t>& aTimeStamp);
110 static already_AddRefed<DeviceMotionEvent> Constructor(
111 const GlobalObject& aGlobal, const nsAString& aType,
112 const DeviceMotionEventInit& aEventInitDict);
114 protected:
115 ~DeviceMotionEvent() = default;
117 RefPtr<DeviceAcceleration> mAcceleration;
118 RefPtr<DeviceAcceleration> mAccelerationIncludingGravity;
119 RefPtr<DeviceRotationRate> mRotationRate;
120 Nullable<double> mInterval;
123 } // namespace mozilla::dom
125 already_AddRefed<mozilla::dom::DeviceMotionEvent> NS_NewDOMDeviceMotionEvent(
126 mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
127 mozilla::WidgetEvent* aEvent);
129 #endif // mozilla_dom_DeviceMotionEvent_h_