| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/sensor/Accelerometer.h" | 5 #include "modules/sensor/Accelerometer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "modules/sensor/AccelerometerReading.h" | |
| 10 | 9 |
| 11 using device::mojom::blink::SensorType; | 10 using device::mojom::blink::SensorType; |
| 12 | 11 |
| 13 namespace blink { | 12 namespace blink { |
| 14 | 13 |
| 15 Accelerometer* Accelerometer::create(ExecutionContext* executionContext, | 14 Accelerometer* Accelerometer::create(ExecutionContext* executionContext, |
| 16 const AccelerometerOptions& options, | 15 const AccelerometerOptions& options, |
| 17 ExceptionState& exceptionState) { | 16 ExceptionState& exceptionState) { |
| 18 return new Accelerometer(executionContext, options, exceptionState); | 17 return new Accelerometer(executionContext, options, exceptionState); |
| 19 } | 18 } |
| 20 | 19 |
| 21 // static | 20 // static |
| 22 Accelerometer* Accelerometer::create(ExecutionContext* executionContext, | 21 Accelerometer* Accelerometer::create(ExecutionContext* executionContext, |
| 23 ExceptionState& exceptionState) { | 22 ExceptionState& exceptionState) { |
| 24 return create(executionContext, AccelerometerOptions(), exceptionState); | 23 return create(executionContext, AccelerometerOptions(), exceptionState); |
| 25 } | 24 } |
| 26 | 25 |
| 27 Accelerometer::Accelerometer(ExecutionContext* executionContext, | 26 Accelerometer::Accelerometer(ExecutionContext* executionContext, |
| 28 const AccelerometerOptions& options, | 27 const AccelerometerOptions& options, |
| 29 ExceptionState& exceptionState) | 28 ExceptionState& exceptionState) |
| 30 : Sensor(executionContext, | 29 : Sensor(executionContext, |
| 31 options, | 30 options, |
| 32 exceptionState, | 31 exceptionState, |
| 33 options.includeGravity() ? SensorType::ACCELEROMETER | 32 options.includeGravity() ? SensorType::ACCELEROMETER |
| 34 : SensorType::LINEAR_ACCELERATION), | 33 : SensorType::LINEAR_ACCELERATION), |
| 35 m_accelerometerOptions(options) {} | 34 m_accelerometerOptions(options) {} |
| 36 | 35 |
| 37 AccelerometerReading* Accelerometer::reading() const { | 36 double Accelerometer::x(bool& isNull) const { |
| 38 return static_cast<AccelerometerReading*>(Sensor::reading()); | 37 return readingValue(0, isNull); |
| 38 } |
| 39 |
| 40 double Accelerometer::y(bool& isNull) const { |
| 41 return readingValue(1, isNull); |
| 42 } |
| 43 |
| 44 double Accelerometer::z(bool& isNull) const { |
| 45 return readingValue(2, isNull); |
| 39 } | 46 } |
| 40 | 47 |
| 41 bool Accelerometer::includesGravity() const { | 48 bool Accelerometer::includesGravity() const { |
| 42 return m_accelerometerOptions.includeGravity(); | 49 return m_accelerometerOptions.includeGravity(); |
| 43 } | 50 } |
| 44 | 51 |
| 45 std::unique_ptr<SensorReadingFactory> | |
| 46 Accelerometer::createSensorReadingFactory() { | |
| 47 return std::unique_ptr<SensorReadingFactory>( | |
| 48 new SensorReadingFactoryImpl<AccelerometerReading>()); | |
| 49 } | |
| 50 | |
| 51 DEFINE_TRACE(Accelerometer) { | 52 DEFINE_TRACE(Accelerometer) { |
| 52 Sensor::trace(visitor); | 53 Sensor::trace(visitor); |
| 53 } | 54 } |
| 54 | 55 |
| 55 } // namespace blink | 56 } // namespace blink |
| OLD | NEW |