Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Unified Diff: third_party/WebKit/Source/modules/sensor/Accelerometer.cpp

Issue 2471003002: [sensors] Accelerometer sensor bindings implementation (Closed)
Patch Set: Rebased after splitting the refactor for the tests. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8e07474ae517b36e160b942a98f1cef32c40a017
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/Accelerometer.cpp
@@ -0,0 +1,55 @@
+// 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,
+ options.includeGravity() ? SensorType::ACCELEROMETER
+ : SensorType::LINEAR_ACCELERATION),
+ m_accelerometerOptions(options) {}
+
+AccelerometerReading* Accelerometer::reading() const {
+ return static_cast<AccelerometerReading*>(Sensor::reading());
+}
+
+bool Accelerometer::includesGravity() const {
+ return m_accelerometerOptions.includeGravity();
+}
+
+std::unique_ptr<SensorReadingFactory>
+Accelerometer::createSensorReadingFactory() {
+ return std::unique_ptr<SensorReadingFactory>(
+ new SensorReadingFactoryImpl<AccelerometerReading>());
+}
+
+DEFINE_TRACE(Accelerometer) {
+ Sensor::trace(visitor);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Accelerometer.h ('k') | third_party/WebKit/Source/modules/sensor/Accelerometer.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698