| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * * Redistributions of source code must retain the above copyright | 7 * * Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * * Redistributions in binary form must reproduce the above copyright | 9 * * Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/device_orientation/DeviceMotionData.h" | 26 #include "modules/device_orientation/DeviceMotionData.h" |
| 27 |
| 28 #include "modules/device_orientation/DeviceAccelerationInit.h" |
| 29 #include "modules/device_orientation/DeviceMotionEventInit.h" |
| 30 #include "modules/device_orientation/DeviceRotationRateInit.h" |
| 27 #include "public/platform/modules/device_orientation/WebDeviceMotionData.h" | 31 #include "public/platform/modules/device_orientation/WebDeviceMotionData.h" |
| 28 | 32 |
| 29 namespace blink { | 33 namespace blink { |
| 30 | 34 |
| 31 DeviceMotionData::Acceleration* DeviceMotionData::Acceleration::create( | 35 DeviceMotionData::Acceleration* DeviceMotionData::Acceleration::create( |
| 32 bool canProvideX, | 36 bool canProvideX, |
| 33 double x, | 37 double x, |
| 34 bool canProvideY, | 38 bool canProvideY, |
| 35 double y, | 39 double y, |
| 36 bool canProvideZ, | 40 bool canProvideZ, |
| 37 double z) { | 41 double z) { |
| 38 return new DeviceMotionData::Acceleration(canProvideX, x, canProvideY, y, | 42 return new DeviceMotionData::Acceleration(canProvideX, x, canProvideY, y, |
| 39 canProvideZ, z); | 43 canProvideZ, z); |
| 40 } | 44 } |
| 41 | 45 |
| 46 DeviceMotionData::Acceleration* DeviceMotionData::Acceleration::create( |
| 47 const DeviceAccelerationInit& init) { |
| 48 return new DeviceMotionData::Acceleration( |
| 49 init.hasX(), init.hasX() ? init.x() : 0, init.hasY(), |
| 50 init.hasY() ? init.y() : 0, init.hasZ(), init.hasZ() ? init.z() : 0); |
| 51 } |
| 52 |
| 42 DeviceMotionData::Acceleration::Acceleration(bool canProvideX, | 53 DeviceMotionData::Acceleration::Acceleration(bool canProvideX, |
| 43 double x, | 54 double x, |
| 44 bool canProvideY, | 55 bool canProvideY, |
| 45 double y, | 56 double y, |
| 46 bool canProvideZ, | 57 bool canProvideZ, |
| 47 double z) | 58 double z) |
| 48 : m_x(x), | 59 : m_x(x), |
| 49 m_y(y), | 60 m_y(y), |
| 50 m_z(z), | 61 m_z(z), |
| 51 m_canProvideX(canProvideX), | 62 m_canProvideX(canProvideX), |
| 52 m_canProvideY(canProvideY), | 63 m_canProvideY(canProvideY), |
| 53 m_canProvideZ(canProvideZ) | 64 m_canProvideZ(canProvideZ) |
| 54 | 65 |
| 55 {} | 66 {} |
| 56 | 67 |
| 57 DeviceMotionData::RotationRate* DeviceMotionData::RotationRate::create( | 68 DeviceMotionData::RotationRate* DeviceMotionData::RotationRate::create( |
| 58 bool canProvideAlpha, | 69 bool canProvideAlpha, |
| 59 double alpha, | 70 double alpha, |
| 60 bool canProvideBeta, | 71 bool canProvideBeta, |
| 61 double beta, | 72 double beta, |
| 62 bool canProvideGamma, | 73 bool canProvideGamma, |
| 63 double gamma) { | 74 double gamma) { |
| 64 return new DeviceMotionData::RotationRate( | 75 return new DeviceMotionData::RotationRate( |
| 65 canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); | 76 canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); |
| 66 } | 77 } |
| 67 | 78 |
| 79 DeviceMotionData::RotationRate* DeviceMotionData::RotationRate::create( |
| 80 const DeviceRotationRateInit& init) { |
| 81 return new DeviceMotionData::RotationRate( |
| 82 init.hasAlpha(), init.hasAlpha() ? init.alpha() : 0, init.hasBeta(), |
| 83 init.hasBeta() ? init.beta() : 0, init.hasGamma(), |
| 84 init.hasGamma() ? init.gamma() : 0); |
| 85 } |
| 86 |
| 68 DeviceMotionData::RotationRate::RotationRate(bool canProvideAlpha, | 87 DeviceMotionData::RotationRate::RotationRate(bool canProvideAlpha, |
| 69 double alpha, | 88 double alpha, |
| 70 bool canProvideBeta, | 89 bool canProvideBeta, |
| 71 double beta, | 90 double beta, |
| 72 bool canProvideGamma, | 91 bool canProvideGamma, |
| 73 double gamma) | 92 double gamma) |
| 74 : m_alpha(alpha), | 93 : m_alpha(alpha), |
| 75 m_beta(beta), | 94 m_beta(beta), |
| 76 m_gamma(gamma), | 95 m_gamma(gamma), |
| 77 m_canProvideAlpha(canProvideAlpha), | 96 m_canProvideAlpha(canProvideAlpha), |
| 78 m_canProvideBeta(canProvideBeta), | 97 m_canProvideBeta(canProvideBeta), |
| 79 m_canProvideGamma(canProvideGamma) {} | 98 m_canProvideGamma(canProvideGamma) {} |
| 80 | 99 |
| 81 DeviceMotionData* DeviceMotionData::create() { | 100 DeviceMotionData* DeviceMotionData::create() { |
| 82 return new DeviceMotionData; | 101 return new DeviceMotionData; |
| 83 } | 102 } |
| 84 | 103 |
| 85 DeviceMotionData* DeviceMotionData::create( | 104 DeviceMotionData* DeviceMotionData::create( |
| 86 Acceleration* acceleration, | 105 Acceleration* acceleration, |
| 87 Acceleration* accelerationIncludingGravity, | 106 Acceleration* accelerationIncludingGravity, |
| 88 RotationRate* rotationRate, | 107 RotationRate* rotationRate, |
| 89 bool canProvideInterval, | 108 bool canProvideInterval, |
| 90 double interval) { | 109 double interval) { |
| 91 return new DeviceMotionData(acceleration, accelerationIncludingGravity, | 110 return new DeviceMotionData(acceleration, accelerationIncludingGravity, |
| 92 rotationRate, canProvideInterval, interval); | 111 rotationRate, canProvideInterval, interval); |
| 93 } | 112 } |
| 94 | 113 |
| 114 DeviceMotionData* DeviceMotionData::create(const DeviceMotionEventInit& init) { |
| 115 return DeviceMotionData::create( |
| 116 init.hasAcceleration() |
| 117 ? DeviceMotionData::Acceleration::create(init.acceleration()) |
| 118 : nullptr, |
| 119 init.hasAccelerationIncludingGravity() |
| 120 ? DeviceMotionData::Acceleration::create( |
| 121 init.accelerationIncludingGravity()) |
| 122 : nullptr, |
| 123 init.hasRotationRate() |
| 124 ? DeviceMotionData::RotationRate::create(init.rotationRate()) |
| 125 : nullptr, |
| 126 init.hasInterval(), init.hasInterval() ? init.interval() : 0); |
| 127 } |
| 128 |
| 95 DeviceMotionData* DeviceMotionData::create(const WebDeviceMotionData& data) { | 129 DeviceMotionData* DeviceMotionData::create(const WebDeviceMotionData& data) { |
| 96 return DeviceMotionData::create( | 130 return DeviceMotionData::create( |
| 97 DeviceMotionData::Acceleration::create( | 131 DeviceMotionData::Acceleration::create( |
| 98 data.hasAccelerationX, data.accelerationX, data.hasAccelerationY, | 132 data.hasAccelerationX, data.accelerationX, data.hasAccelerationY, |
| 99 data.accelerationY, data.hasAccelerationZ, data.accelerationZ), | 133 data.accelerationY, data.hasAccelerationZ, data.accelerationZ), |
| 100 DeviceMotionData::Acceleration::create( | 134 DeviceMotionData::Acceleration::create( |
| 101 data.hasAccelerationIncludingGravityX, | 135 data.hasAccelerationIncludingGravityX, |
| 102 data.accelerationIncludingGravityX, | 136 data.accelerationIncludingGravityX, |
| 103 data.hasAccelerationIncludingGravityY, | 137 data.hasAccelerationIncludingGravityY, |
| 104 data.accelerationIncludingGravityY, | 138 data.accelerationIncludingGravityY, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 m_accelerationIncludingGravity->canProvideZ()); | 177 m_accelerationIncludingGravity->canProvideZ()); |
| 144 const bool hasRotationRate = | 178 const bool hasRotationRate = |
| 145 m_rotationRate && | 179 m_rotationRate && |
| 146 (m_rotationRate->canProvideAlpha() || m_rotationRate->canProvideBeta() || | 180 (m_rotationRate->canProvideAlpha() || m_rotationRate->canProvideBeta() || |
| 147 m_rotationRate->canProvideGamma()); | 181 m_rotationRate->canProvideGamma()); |
| 148 | 182 |
| 149 return hasAcceleration || hasAccelerationIncludingGravity || hasRotationRate; | 183 return hasAcceleration || hasAccelerationIncludingGravity || hasRotationRate; |
| 150 } | 184 } |
| 151 | 185 |
| 152 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |