Index: content/renderer/device_sensors/device_orientation_absolute_event_pump.cc |
diff --git a/content/renderer/device_sensors/device_orientation_absolute_event_pump.cc b/content/renderer/device_sensors/device_orientation_absolute_event_pump.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c84af06489f50c064fb318d51c467c7467e22c9f |
--- /dev/null |
+++ b/content/renderer/device_sensors/device_orientation_absolute_event_pump.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2014 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 "content/renderer/device_sensors/device_orientation_absolute_event_pump.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "content/public/renderer/render_thread.h" |
+#include "content/renderer/device_sensors/device_orientation_util.h" |
+#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationListener.h" |
+ |
+namespace content { |
+ |
+DeviceOrientationAbsoluteEventPump::DeviceOrientationAbsoluteEventPump( |
+ RenderThread* thread) |
+ : DeviceSensorEventPump<blink::WebDeviceOrientationListener>(thread) {} |
+ |
+DeviceOrientationAbsoluteEventPump::~DeviceOrientationAbsoluteEventPump() {} |
+ |
+void DeviceOrientationAbsoluteEventPump::SendStartMessage() { |
+ sensors_.push_back(base::MakeUnique<SensorEntry>(this)); |
+ GetSensor(device::mojom::SensorType::ABSOLUTE_ORIENTATION, sensors_[0].get()); |
Reilly Grant (use Gerrit)
2017/05/19 20:20:10
Can you combine these two lines into a single call
juncai
2017/05/20 00:55:02
Fixed it in a new CL:
https://codereview.chromium.
|
+} |
+ |
+void DeviceOrientationAbsoluteEventPump::SendFakeDataForTesting( |
+ void* fake_data) { |
+ blink::WebDeviceOrientationData data = |
+ *static_cast<blink::WebDeviceOrientationData*>(fake_data); |
+ listener()->DidChangeDeviceOrientation(data); |
+} |
+ |
+bool DeviceOrientationAbsoluteEventPump::CanStart() const { |
+ DCHECK_EQ(1u, sensors_.size()); |
+ return sensors_[0]->active; |
+} |
+ |
+void DeviceOrientationAbsoluteEventPump::FireEvent() { |
+ blink::WebDeviceOrientationData data; |
+ |
+ DCHECK(listener()); |
+ |
+ if (GetDataFromSharedMemory(&data) && IsSignificantlyDifferent(data_, data)) { |
+ data_ = data; |
+ listener()->DidChangeDeviceOrientation(data); |
+ } |
+} |
+ |
+bool DeviceOrientationAbsoluteEventPump::GetDataFromSharedMemory( |
+ blink::WebDeviceOrientationData* data) { |
+ DCHECK_EQ(1u, sensors_.size()); |
+ DCHECK_EQ(device::mojom::SensorType::ABSOLUTE_ORIENTATION, sensors_[0]->type); |
+ |
+ if (!sensors_[0]->SensorReadingUpdated()) |
+ return false; |
+ |
+ ComputeDeviceOrientationFromQuaternion(sensors_[0]->reading.values[0].value(), |
+ sensors_[0]->reading.values[1].value(), |
+ sensors_[0]->reading.values[2].value(), |
+ sensors_[0]->reading.values[3].value(), |
+ &data->alpha, &data->beta, |
+ &data->gamma); |
+ data->has_alpha = true; |
+ data->has_beta = true; |
+ data->has_gamma = true; |
+ data->absolute = true; |
+ return true; |
+} |
+ |
+} // namespace content |