| 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 | #pragma once |
| 27 | |
| 28 | #include <wtf/Optional.h> |
| 29 | #include <wtf/RefCounted.h> |
| 30 | #include <wtf/RefPtr.h> |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | class DeviceMotionData : public RefCounted<DeviceMotionData> { |
| 35 | public: |
| 36 | class Acceleration : public RefCounted<DeviceMotionData::Acceleration> { |
| 37 | public: |
| 38 | static Ref<Acceleration> create() |
| 39 | { |
| 40 | return adoptRef(*new Acceleration); |
| 41 | } |
| 42 | static Ref<Acceleration> create(Optional<double> x, Optional<double> y, Optional<double> z) |
| 43 | { |
| 44 | return adoptRef(*new Acceleration(x, y, z)); |
| 45 | } |
| 46 | |
| 47 | Optional<double> x() const { return m_x; } |
| 48 | Optional<double> y() const { return m_y; } |
| 49 | Optional<double> z() const { return m_z; } |
| 50 | |
| 51 | private: |
| 52 | Acceleration() = default; |
| 53 | Acceleration(Optional<double> x, Optional<double> y, Optional<double> z) |
| 54 | : m_x(x) |
| 55 | , m_y(y) |
| 56 | , m_z(z) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | Optional<double> m_x; |
| 61 | Optional<double> m_y; |
| 62 | Optional<double> m_z; |
| 63 | }; |
| 64 | |
| 65 | class RotationRate : public RefCounted<DeviceMotionData::RotationRate> { |
| 66 | public: |
| 67 | static Ref<RotationRate> create() |
| 68 | { |
| 69 | return adoptRef(*new RotationRate); |
| 70 | } |
| 71 | static Ref<RotationRate> create(Optional<double> alpha, Optional<double> beta, Optional<double> gamma) |
| 72 | { |
| 73 | return adoptRef(*new RotationRate(alpha, beta, gamma)); |
| 74 | } |
| 75 | |
| 76 | Optional<double> alpha() const { return m_alpha; } |
| 77 | Optional<double> beta() const { return m_beta; } |
| 78 | Optional<double> gamma() const { return m_gamma; } |
| 79 | |
| 80 | private: |
| 81 | RotationRate() = default; |
| 82 | RotationRate(Optional<double> alpha, Optional<double> beta, Optional<double> gamma) |
| 83 | : m_alpha(alpha) |
| 84 | , m_beta(beta) |
| 85 | , m_gamma(gamma) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | Optional<double> m_alpha; |
| 90 | Optional<double> m_beta; |
| 91 | Optional<double> m_gamma; |
| 92 | }; |
| 93 | |
| 94 | WEBCORE_EXPORT static Ref<DeviceMotionData> create(); |
| 95 | WEBCORE_EXPORT static Ref<DeviceMotionData> create(RefPtr<Acceleration>&&, RefPtr<Acceleration>&& accelerationIncludingGravity, RefPtr<RotationRate>&&, Optional<double> interval); |
| 96 | |
| 97 | const Acceleration* acceleration() const { return m_acceleration.get(); } |
| 98 | const Acceleration* accelerationIncludingGravity() const { return m_accelerationIncludingGravity.get(); } |
| 99 | const RotationRate* rotationRate() const { return m_rotationRate.get(); } |
| 100 | |
| 101 | Optional<double> interval() const { return m_interval; } |
| 102 | |
| 103 | private: |
| 104 | DeviceMotionData() = default; |
| 105 | DeviceMotionData(RefPtr<Acceleration>&&, RefPtr<Acceleration>&& accelerationIncludingGravity, RefPtr<RotationRate>&&, Optional<double> interval); |
| 106 | |
| 107 | RefPtr<Acceleration> m_acceleration; |
| 108 | RefPtr<Acceleration> m_accelerationIncludingGravity; |
| 109 | RefPtr<RotationRate> m_rotationRate; |
| 110 | Optional<double> m_interval; |
| 111 | }; |
| 112 | |
| 113 | } // namespace WebCore |
| 114 | |