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

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

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: Comments from Alex Created 3 years, 9 months 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/OrientationSensor.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp b/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..15b9c2d24c6b6fdc4fb03a16cb6d88f5114faa60
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp
@@ -0,0 +1,75 @@
+// Copyright 2017 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/OrientationSensor.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+
+using device::mojom::blink::SensorType;
+
+namespace blink {
+
+Vector<double> OrientationSensor::quaternion(bool& isNull) {
+ m_readingDirty = false;
+ isNull = !canReturnReadings();
+ return isNull ? Vector<double>()
+ : Vector<double>({readingValueUnchecked(3), // W
+ readingValueUnchecked(0), // Vx
+ readingValueUnchecked(1), // Vy
+ readingValueUnchecked(2)}); // Vz
+}
+
+void OrientationSensor::populateMatrix(DOMFloat32Array* buffer,
+ ExceptionState& exceptionState) {
+ if (buffer->length() < 16) {
+ exceptionState.throwTypeError(
+ "Target buffer must have minimal size of 16.");
Reilly Grant (use Gerrit) 2017/03/24 15:10:33 "Target buffer must have at least 16 elements."
Mikhail 2017/03/24 16:30:31 Done.
+ return;
+ }
+ if (!isActivated()) {
+ exceptionState.throwDOMException(
+ InvalidStateError, "The Sensor must be in 'connected' state.");
Reilly Grant (use Gerrit) 2017/03/24 15:10:33 Sensor -> sensor
Mikhail 2017/03/24 16:30:31 Done.
+ return;
+ }
+ if (!canReturnReadings())
+ return;
+
+ float x = readingValueUnchecked(0);
+ float y = readingValueUnchecked(1);
+ float z = readingValueUnchecked(2);
+ float w = readingValueUnchecked(3);
+
+ float* out = buffer->data();
+ out[0] = 1.0 - 2 * (y * y - z * z);
+ out[1] = 2 * (x * y - z * w);
+ out[2] = 2 * (x * z + y * w);
+ out[4] = 2 * (x * y + z * w);
+ out[5] = 1.0 - 2 * (x * x - z * z);
+ out[6] = 2 * (y * z - x * w);
+ out[8] = 2 * (x * z - y * w);
+ out[9] = 2 * (y * z + x * w);
+ out[10] = 1.0 - 2 * (x * x - y * y);
+ out[15] = 1.0;
Reilly Grant (use Gerrit) 2017/03/24 15:10:33 If callers are passing in arbitrary buffers we sho
Alexander Shalamov 2017/03/24 16:16:47 Mikhail@ I think Reilly is right. If I remember co
Mikhail 2017/03/24 16:30:31 Other elements are not updated on purpose: matrix
+}
+
+bool OrientationSensor::isReadingDirty() const {
+ return m_readingDirty || !canReturnReadings();
+}
+
+OrientationSensor::OrientationSensor(ExecutionContext* executionContext,
+ const SensorOptions& options,
+ ExceptionState& exceptionState,
+ device::mojom::blink::SensorType type)
+ : Sensor(executionContext, options, exceptionState, type),
+ m_readingDirty(true) {}
+
+void OrientationSensor::onSensorReadingChanged() {
+ m_readingDirty = true;
+}
+
+DEFINE_TRACE(OrientationSensor) {
+ Sensor::trace(visitor);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698