tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DeviceMotionEvent.h (4490B)


      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 
      7 #ifndef mozilla_dom_DeviceMotionEvent_h_
      8 #define mozilla_dom_DeviceMotionEvent_h_
      9 
     10 #include "mozilla/dom/DeviceMotionEventBinding.h"
     11 #include "mozilla/dom/Event.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 class DeviceRotationRate final : public nsWrapperCache {
     16 public:
     17  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate)
     18  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceRotationRate)
     19 
     20  DeviceRotationRate(DeviceMotionEvent* aOwner, const Nullable<double>& aAlpha,
     21                     const Nullable<double>& aBeta,
     22                     const Nullable<double>& aGamma);
     23 
     24  DeviceMotionEvent* GetParentObject() const { return mOwner; }
     25 
     26  virtual JSObject* WrapObject(JSContext* aCx,
     27                               JS::Handle<JSObject*> aGivenProto) override {
     28    return DeviceRotationRate_Binding::Wrap(aCx, this, aGivenProto);
     29  }
     30 
     31  Nullable<double> GetAlpha() const { return mAlpha; }
     32  Nullable<double> GetBeta() const { return mBeta; }
     33  Nullable<double> GetGamma() const { return mGamma; }
     34 
     35 private:
     36  ~DeviceRotationRate();
     37 
     38 protected:
     39  RefPtr<DeviceMotionEvent> mOwner;
     40  Nullable<double> mAlpha, mBeta, mGamma;
     41 };
     42 
     43 class DeviceAcceleration final : public nsWrapperCache {
     44 public:
     45  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration)
     46  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceAcceleration)
     47 
     48  DeviceAcceleration(DeviceMotionEvent* aOwner, const Nullable<double>& aX,
     49                     const Nullable<double>& aY, const Nullable<double>& aZ);
     50 
     51  DeviceMotionEvent* GetParentObject() const { return mOwner; }
     52 
     53  virtual JSObject* WrapObject(JSContext* aCx,
     54                               JS::Handle<JSObject*> aGivenProto) override {
     55    return DeviceAcceleration_Binding::Wrap(aCx, this, aGivenProto);
     56  }
     57 
     58  Nullable<double> GetX() const { return mX; }
     59  Nullable<double> GetY() const { return mY; }
     60  Nullable<double> GetZ() const { return mZ; }
     61 
     62 private:
     63  ~DeviceAcceleration();
     64 
     65 protected:
     66  RefPtr<DeviceMotionEvent> mOwner;
     67  Nullable<double> mX, mY, mZ;
     68 };
     69 
     70 class DeviceMotionEvent final : public Event {
     71 public:
     72  DeviceMotionEvent(EventTarget* aOwner, nsPresContext* aPresContext,
     73                    WidgetEvent* aEvent)
     74      : Event(aOwner, aPresContext, aEvent) {}
     75 
     76  NS_DECL_ISUPPORTS_INHERITED
     77 
     78  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent, Event)
     79 
     80  virtual JSObject* WrapObjectInternal(
     81      JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
     82    return DeviceMotionEvent_Binding::Wrap(aCx, this, aGivenProto);
     83  }
     84 
     85  DeviceAcceleration* GetAcceleration() const { return mAcceleration; }
     86 
     87  DeviceAcceleration* GetAccelerationIncludingGravity() const {
     88    return mAccelerationIncludingGravity;
     89  }
     90 
     91  DeviceRotationRate* GetRotationRate() const { return mRotationRate; }
     92 
     93  Nullable<double> GetInterval() const { return mInterval; }
     94 
     95  void InitDeviceMotionEvent(
     96      const nsAString& aType, bool aCanBubble, bool aCancelable,
     97      const DeviceAccelerationInit& aAcceleration,
     98      const DeviceAccelerationInit& aAccelerationIncludingGravity,
     99      const DeviceRotationRateInit& aRotationRate,
    100      const Nullable<double>& aInterval);
    101 
    102  void InitDeviceMotionEvent(
    103      const nsAString& aType, bool aCanBubble, bool aCancelable,
    104      const DeviceAccelerationInit& aAcceleration,
    105      const DeviceAccelerationInit& aAccelerationIncludingGravity,
    106      const DeviceRotationRateInit& aRotationRate,
    107      const Nullable<double>& aInterval, const Nullable<uint64_t>& aTimeStamp);
    108 
    109  static already_AddRefed<DeviceMotionEvent> Constructor(
    110      const GlobalObject& aGlobal, const nsAString& aType,
    111      const DeviceMotionEventInit& aEventInitDict);
    112 
    113 protected:
    114  ~DeviceMotionEvent() = default;
    115 
    116  RefPtr<DeviceAcceleration> mAcceleration;
    117  RefPtr<DeviceAcceleration> mAccelerationIncludingGravity;
    118  RefPtr<DeviceRotationRate> mRotationRate;
    119  Nullable<double> mInterval;
    120 };
    121 
    122 }  // namespace mozilla::dom
    123 
    124 already_AddRefed<mozilla::dom::DeviceMotionEvent> NS_NewDOMDeviceMotionEvent(
    125    mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
    126    mozilla::WidgetEvent* aEvent);
    127 
    128 #endif  // mozilla_dom_DeviceMotionEvent_h_