Chromium Code Reviews| Index: third_party/WebKit/Source/modules/sensor/Accelerometer.cpp |
| diff --git a/third_party/WebKit/Source/modules/sensor/Accelerometer.cpp b/third_party/WebKit/Source/modules/sensor/Accelerometer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..96eefb22477450eb68a32ab625af2931a0906ac0 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/sensor/Accelerometer.cpp |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/sensor/Accelerometer.h" |
| + |
| +#include "bindings/core/v8/ScriptPromise.h" |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "modules/sensor/AccelerometerReading.h" |
| + |
| +using device::mojom::blink::SensorType; |
| + |
| +namespace blink { |
| + |
| +Accelerometer* Accelerometer::create(ScriptState* scriptState, |
| + const AccelerometerOptions& options, |
| + ExceptionState& exceptionState) { |
| + return new Accelerometer(scriptState, options, exceptionState); |
| +} |
| + |
| +// static |
| +Accelerometer* Accelerometer::create(ScriptState* scriptState, |
| + ExceptionState& exceptionState) { |
| + return create(scriptState, AccelerometerOptions(), exceptionState); |
| +} |
| + |
| +Accelerometer::Accelerometer(ScriptState* scriptState, |
| + const AccelerometerOptions& options, |
| + ExceptionState& exceptionState) |
| + : Sensor(scriptState, options, exceptionState, SensorType::ACCELEROMETER), |
|
shalamov
2016/11/02 14:25:14
Sensor(scriptState, options, exceptionState, optio
|
| + m_accelerometerOptions(options) {} |
| + |
| +AccelerometerReading* Accelerometer::reading() const { |
| + return static_cast<AccelerometerReading*>(Sensor::reading()); |
| +} |
| + |
| +bool Accelerometer::includesGravity() const { |
| + return m_accelerometerOptions.includeGravity(); |
| +} |
| + |
| +SensorReading* Accelerometer::createSensorReading(SensorProxy* proxy) { |
| + return AccelerometerReading::create(proxy); |
| +} |
| + |
| +auto Accelerometer::createSensorConfig(const SensorOptions& options, |
| + const SensorConfiguration& defaultConfig) |
| + -> SensorConfigurationPtr { |
| + auto result = device::mojom::blink::SensorConfiguration::New(); |
| + result->frequency = |
| + options.hasFrequency() ? options.frequency() : defaultConfig.frequency; |
| + return result; |
| +} |
| + |
| +DEFINE_TRACE(Accelerometer) { |
| + Sensor::trace(visitor); |
| +} |
| + |
| +} // namespace blink |