dom/events/DeviceMotionEvent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/DeviceMotionEvent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_dom_DeviceMotionEvent_h_
     1.9 +#define mozilla_dom_DeviceMotionEvent_h_
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "mozilla/dom/DeviceMotionEventBinding.h"
    1.13 +#include "mozilla/dom/Event.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace dom {
    1.17 +
    1.18 +class DeviceRotationRate MOZ_FINAL : public nsWrapperCache
    1.19 +{
    1.20 +public:
    1.21 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate)
    1.22 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceRotationRate)
    1.23 +
    1.24 +  DeviceRotationRate(DeviceMotionEvent* aOwner,
    1.25 +                     Nullable<double> aAlpha, Nullable<double> aBeta,
    1.26 +                     Nullable<double> aGamma);
    1.27 +
    1.28 +  DeviceMotionEvent* GetParentObject() const
    1.29 +  {
    1.30 +    return mOwner;
    1.31 +  }
    1.32 +
    1.33 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    1.34 +  {
    1.35 +    return DeviceRotationRateBinding::Wrap(aCx, this);
    1.36 +  }
    1.37 +
    1.38 +  Nullable<double> GetAlpha() const { return mAlpha; }
    1.39 +  Nullable<double> GetBeta() const { return mBeta; }
    1.40 +  Nullable<double> GetGamma() const { return mGamma; }
    1.41 +
    1.42 +private:
    1.43 +  ~DeviceRotationRate();
    1.44 +
    1.45 +protected:
    1.46 +  nsRefPtr<DeviceMotionEvent> mOwner;
    1.47 +  Nullable<double> mAlpha, mBeta, mGamma;
    1.48 +};
    1.49 +
    1.50 +class DeviceAcceleration MOZ_FINAL : public nsWrapperCache
    1.51 +{
    1.52 +public:
    1.53 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration)
    1.54 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceAcceleration)
    1.55 +
    1.56 +  DeviceAcceleration(DeviceMotionEvent* aOwner,
    1.57 +                     Nullable<double> aX, Nullable<double> aY,
    1.58 +                     Nullable<double> aZ);
    1.59 +
    1.60 +  DeviceMotionEvent* GetParentObject() const
    1.61 +  {
    1.62 +    return mOwner;
    1.63 +  }
    1.64 +
    1.65 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    1.66 +  {
    1.67 +    return DeviceAccelerationBinding::Wrap(aCx, this);
    1.68 +  }
    1.69 +
    1.70 +  Nullable<double> GetX() const { return mX; }
    1.71 +  Nullable<double> GetY() const { return mY; }
    1.72 +  Nullable<double> GetZ() const { return mZ; }
    1.73 +
    1.74 +private:
    1.75 +  ~DeviceAcceleration();
    1.76 +
    1.77 +protected:
    1.78 +  nsRefPtr<DeviceMotionEvent> mOwner;
    1.79 +  Nullable<double> mX, mY, mZ;
    1.80 +};
    1.81 +
    1.82 +class DeviceMotionEvent MOZ_FINAL : public Event
    1.83 +{
    1.84 +public:
    1.85 +
    1.86 +  DeviceMotionEvent(EventTarget* aOwner,
    1.87 +                    nsPresContext* aPresContext,
    1.88 +                    WidgetEvent* aEvent)
    1.89 +    : Event(aOwner, aPresContext, aEvent)
    1.90 +  {
    1.91 +  }
    1.92 +
    1.93 +  NS_DECL_ISUPPORTS_INHERITED
    1.94 +
    1.95 +  // Forward to Event
    1.96 +  NS_FORWARD_TO_EVENT
    1.97 +
    1.98 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent, Event)
    1.99 +
   1.100 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
   1.101 +  {
   1.102 +    return DeviceMotionEventBinding::Wrap(aCx, this);
   1.103 +  }
   1.104 +
   1.105 +  DeviceAcceleration* GetAcceleration() const
   1.106 +  {
   1.107 +    return mAcceleration;
   1.108 +  }
   1.109 +
   1.110 +  DeviceAcceleration* GetAccelerationIncludingGravity() const
   1.111 +  {
   1.112 +    return mAccelerationIncludingGravity;
   1.113 +  }
   1.114 +
   1.115 +  DeviceRotationRate* GetRotationRate() const
   1.116 +  {
   1.117 +    return mRotationRate;
   1.118 +  }
   1.119 +
   1.120 +  Nullable<double> GetInterval() const
   1.121 +  {
   1.122 +    return mInterval;
   1.123 +  }
   1.124 +
   1.125 +  void InitDeviceMotionEvent(
   1.126 +         const nsAString& aType,
   1.127 +         bool aCanBubble,
   1.128 +         bool aCancelable,
   1.129 +         const DeviceAccelerationInit& aAcceleration,
   1.130 +         const DeviceAccelerationInit& aAccelerationIncludingGravity,
   1.131 +         const DeviceRotationRateInit& aRotationRate,
   1.132 +         Nullable<double> aInterval,
   1.133 +         ErrorResult& aRv);
   1.134 +
   1.135 +  static already_AddRefed<DeviceMotionEvent>
   1.136 +  Constructor(const GlobalObject& aGlobal,
   1.137 +              const nsAString& aType,
   1.138 +              const DeviceMotionEventInit& aEventInitDict,
   1.139 +              ErrorResult& aRv);
   1.140 +
   1.141 +protected:
   1.142 +  nsRefPtr<DeviceAcceleration> mAcceleration;
   1.143 +  nsRefPtr<DeviceAcceleration> mAccelerationIncludingGravity;
   1.144 +  nsRefPtr<DeviceRotationRate> mRotationRate;
   1.145 +  Nullable<double> mInterval;
   1.146 +};
   1.147 +
   1.148 +} // namespace dom
   1.149 +} // namespace mozilla
   1.150 +
   1.151 +#endif // mozilla_dom_DeviceMotionEvent_h_

mercurial