Home | History | Annotate | Download | only in device_orientation
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef DeviceMotionData_h
     27 #define DeviceMotionData_h
     28 
     29 #include "platform/heap/Handle.h"
     30 
     31 namespace blink {
     32 
     33 class WebDeviceMotionData;
     34 
     35 class DeviceMotionData FINAL : public GarbageCollected<DeviceMotionData> {
     36 public:
     37 
     38     class Acceleration FINAL : public GarbageCollected<DeviceMotionData::Acceleration> {
     39     public:
     40         static Acceleration* create(bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z);
     41         void trace(Visitor*) { }
     42 
     43         bool canProvideX() const { return m_canProvideX; }
     44         bool canProvideY() const { return m_canProvideY; }
     45         bool canProvideZ() const { return m_canProvideZ; }
     46 
     47         double x() const { return m_x; }
     48         double y() const { return m_y; }
     49         double z() const { return m_z; }
     50 
     51     private:
     52         Acceleration(bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z);
     53 
     54         double m_x;
     55         double m_y;
     56         double m_z;
     57 
     58         bool m_canProvideX;
     59         bool m_canProvideY;
     60         bool m_canProvideZ;
     61     };
     62 
     63     class RotationRate FINAL : public GarbageCollected<DeviceMotionData::RotationRate> {
     64     public:
     65         static RotationRate* create(bool canProvideAlpha, double alpha, bool canProvideBeta,  double beta, bool canProvideGamma, double gamma);
     66         void trace(Visitor*) { }
     67 
     68         bool canProvideAlpha() const { return m_canProvideAlpha; }
     69         bool canProvideBeta() const { return m_canProvideBeta; }
     70         bool canProvideGamma() const { return m_canProvideGamma; }
     71 
     72         double alpha() const { return m_alpha; }
     73         double beta() const { return m_beta; }
     74         double gamma() const { return m_gamma; }
     75 
     76     private:
     77         RotationRate(bool canProvideAlpha, double alpha, bool canProvideBeta,  double beta, bool canProvideGamma, double gamma);
     78 
     79         double m_alpha;
     80         double m_beta;
     81         double m_gamma;
     82 
     83         bool m_canProvideAlpha;
     84         bool m_canProvideBeta;
     85         bool m_canProvideGamma;
     86     };
     87 
     88     static DeviceMotionData* create();
     89     static DeviceMotionData* create(
     90         Acceleration*,
     91         Acceleration* accelerationIncludingGravity,
     92         RotationRate*,
     93         bool canProvideInterval,
     94         double interval);
     95     static DeviceMotionData* create(const WebDeviceMotionData&);
     96     void trace(Visitor*);
     97 
     98     Acceleration* acceleration() const { return m_acceleration.get(); }
     99     Acceleration* accelerationIncludingGravity() const { return m_accelerationIncludingGravity.get(); }
    100     RotationRate* rotationRate() const { return m_rotationRate.get(); }
    101 
    102     bool canProvideInterval() const { return m_canProvideInterval; }
    103     double interval() const { return m_interval; }
    104 
    105     bool canProvideEventData() const;
    106 
    107 private:
    108     DeviceMotionData();
    109     DeviceMotionData(Acceleration*, Acceleration* accelerationIncludingGravity, RotationRate*, bool canProvideInterval, double interval);
    110 
    111     Member<Acceleration> m_acceleration;
    112     Member<Acceleration> m_accelerationIncludingGravity;
    113     Member<RotationRate> m_rotationRate;
    114     bool m_canProvideInterval;
    115     double m_interval;
    116 };
    117 
    118 } // namespace blink
    119 
    120 #endif // DeviceMotionData_h
    121