Commit 8c64076d authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

Replace usages of device::OrientationData with DeviceOrientationData

Since DeviceOrientationData class has all the information from
device::OrientationData, and DeviceOrientationEventPump is now in blink,
DeviceOrientationData is now passed to DeviceOrientationDispatcher.
device::OrientationData will be removed in a subsequent change.

Bug: 861923
Change-Id: If1cb812502f85dd46011398a54f45bba2353044d
Reviewed-on: https://chromium-review.googlesource.com/1142459Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577985}
parent 67332adc
...@@ -33,16 +33,14 @@ ...@@ -33,16 +33,14 @@
#include "third_party/blink/public/platform/web_platform_event_listener.h" #include "third_party/blink/public/platform/web_platform_event_listener.h"
namespace device {
class OrientationData;
}
namespace blink { namespace blink {
class DeviceOrientationData;
class WebDeviceOrientationListener : public WebPlatformEventListener { class WebDeviceOrientationListener : public WebPlatformEventListener {
public: public:
// This method is called every time new device orientation data is available. // This method is called every time new device orientation data is available.
virtual void DidChangeDeviceOrientation(const device::OrientationData&) = 0; virtual void DidChangeDeviceOrientation(DeviceOrientationData*) = 0;
~WebDeviceOrientationListener() override = default; ~WebDeviceOrientationListener() override = default;
}; };
......
include_rules = [ include_rules = [
"+base/run_loop.h", "+base/run_loop.h",
"+mojo/public/cpp/bindings/binding.h", "+mojo/public/cpp/bindings/binding.h",
# NOTE: These files are POD structs used to interpret shared memory across
# the Device Sensors implementation and the Blink client.
"+services/device/public/cpp/generic_sensor/orientation_data.h",
"+services/device/public/mojom/sensor.mojom-blink.h", "+services/device/public/mojom/sensor.mojom-blink.h",
"+services/device/public/mojom/sensor_provider.mojom-blink.h", "+services/device/public/mojom/sensor_provider.mojom-blink.h",
"+services/device/public/cpp/test/fake_sensor_and_provider.h", "+services/device/public/cpp/test/fake_sensor_and_provider.h",
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_data.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_data.h"
#include "services/device/public/cpp/generic_sensor/orientation_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_init.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_init.h"
namespace blink { namespace blink {
...@@ -56,20 +55,6 @@ DeviceOrientationData* DeviceOrientationData::Create( ...@@ -56,20 +55,6 @@ DeviceOrientationData* DeviceOrientationData::Create(
return DeviceOrientationData::Create(alpha, beta, gamma, init.absolute()); return DeviceOrientationData::Create(alpha, beta, gamma, init.absolute());
} }
DeviceOrientationData* DeviceOrientationData::Create(
const device::OrientationData& data) {
base::Optional<double> alpha;
base::Optional<double> beta;
base::Optional<double> gamma;
if (data.has_alpha)
alpha = data.alpha;
if (data.has_beta)
beta = data.beta;
if (data.has_gamma)
gamma = data.gamma;
return DeviceOrientationData::Create(alpha, beta, gamma, data.absolute);
}
DeviceOrientationData::DeviceOrientationData() : absolute_(false) {} DeviceOrientationData::DeviceOrientationData() : absolute_(false) {}
DeviceOrientationData::DeviceOrientationData( DeviceOrientationData::DeviceOrientationData(
......
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class OrientationData;
}
namespace blink { namespace blink {
class DeviceOrientationEventInit; class DeviceOrientationEventInit;
...@@ -47,7 +43,6 @@ class MODULES_EXPORT DeviceOrientationData final ...@@ -47,7 +43,6 @@ class MODULES_EXPORT DeviceOrientationData final
const base::Optional<double>& gamma, const base::Optional<double>& gamma,
bool absolute); bool absolute);
static DeviceOrientationData* Create(const DeviceOrientationEventInit&); static DeviceOrientationData* Create(const DeviceOrientationEventInit&);
static DeviceOrientationData* Create(const device::OrientationData&);
void Trace(blink::Visitor* visitor) {} void Trace(blink::Visitor* visitor) {}
double Alpha() const; double Alpha() const;
......
...@@ -78,8 +78,8 @@ void DeviceOrientationDispatcher::StopListening() { ...@@ -78,8 +78,8 @@ void DeviceOrientationDispatcher::StopListening() {
} }
void DeviceOrientationDispatcher::DidChangeDeviceOrientation( void DeviceOrientationDispatcher::DidChangeDeviceOrientation(
const device::OrientationData& motion) { DeviceOrientationData* orientation) {
last_device_orientation_data_ = DeviceOrientationData::Create(motion); last_device_orientation_data_ = orientation;
NotifyControllers(); NotifyControllers();
} }
......
...@@ -36,10 +36,6 @@ ...@@ -36,10 +36,6 @@
#include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h" #include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class OrientationData;
}
namespace blink { namespace blink {
class DeviceOrientationData; class DeviceOrientationData;
...@@ -62,7 +58,7 @@ class DeviceOrientationDispatcher final ...@@ -62,7 +58,7 @@ class DeviceOrientationDispatcher final
DeviceOrientationData* LatestDeviceOrientationData(); DeviceOrientationData* LatestDeviceOrientationData();
// Inherited from WebDeviceOrientationListener. // Inherited from WebDeviceOrientationListener.
void DidChangeDeviceOrientation(const device::OrientationData&) override; void DidChangeDeviceOrientation(DeviceOrientationData*) override;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
......
...@@ -7,30 +7,28 @@ ...@@ -7,30 +7,28 @@
#include "services/device/public/mojom/sensor.mojom-blink.h" #include "services/device/public/mojom/sensor.mojom-blink.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_pump.h" #include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_pump.h"
namespace { namespace {
bool IsAngleDifferentThreshold(bool has_angle1, bool IsAngleDifferentThreshold(double angle1, double angle2) {
double angle1, return (std::fabs(angle1 - angle2) >=
bool has_angle2,
double angle2) {
if (has_angle1 != has_angle2)
return true;
return (has_angle1 &&
std::fabs(angle1 - angle2) >=
blink::DeviceOrientationEventPump::kOrientationThreshold); blink::DeviceOrientationEventPump::kOrientationThreshold);
} }
bool IsSignificantlyDifferent(const device::OrientationData& data1, bool IsSignificantlyDifferent(const blink::DeviceOrientationData* data1,
const device::OrientationData& data2) { const blink::DeviceOrientationData* data2) {
return IsAngleDifferentThreshold(data1.has_alpha, data1.alpha, if (data1->CanProvideAlpha() != data2->CanProvideAlpha() ||
data2.has_alpha, data2.alpha) || data1->CanProvideBeta() != data2->CanProvideBeta() ||
IsAngleDifferentThreshold(data1.has_beta, data1.beta, data2.has_beta, data1->CanProvideGamma() != data2->CanProvideGamma())
data2.beta) || return true;
IsAngleDifferentThreshold(data1.has_gamma, data1.gamma, return (data1->CanProvideAlpha() &&
data2.has_gamma, data2.gamma); IsAngleDifferentThreshold(data1->Alpha(), data2->Alpha())) ||
(data1->CanProvideBeta() &&
IsAngleDifferentThreshold(data1->Beta(), data2->Beta())) ||
(data1->CanProvideGamma() &&
IsAngleDifferentThreshold(data1->Gamma(), data2->Gamma()));
} }
} // namespace } // namespace
...@@ -105,15 +103,13 @@ void DeviceOrientationEventPump::SendStopMessage() { ...@@ -105,15 +103,13 @@ void DeviceOrientationEventPump::SendStopMessage() {
// data when stopping. If we don't reset here as well, then when starting back // data when stopping. If we don't reset here as well, then when starting back
// up we won't notify DeviceOrientationDispatcher of the orientation, since // up we won't notify DeviceOrientationDispatcher of the orientation, since
// we think it hasn't changed. // we think it hasn't changed.
data_ = device::OrientationData(); data_ = nullptr;
} }
void DeviceOrientationEventPump::FireEvent(TimerBase*) { void DeviceOrientationEventPump::FireEvent(TimerBase*) {
device::OrientationData data;
DCHECK(listener()); DCHECK(listener());
GetDataFromSharedMemory(&data); DeviceOrientationData* data = GetDataFromSharedMemory();
if (ShouldFireEvent(data)) { if (ShouldFireEvent(data)) {
data_ = data; data_ = data;
...@@ -152,60 +148,67 @@ bool DeviceOrientationEventPump::SensorsReadyOrErrored() const { ...@@ -152,60 +148,67 @@ bool DeviceOrientationEventPump::SensorsReadyOrErrored() const {
return true; return true;
} }
void DeviceOrientationEventPump::GetDataFromSharedMemory( DeviceOrientationData* DeviceOrientationEventPump::GetDataFromSharedMemory() {
device::OrientationData* data) { base::Optional<double> alpha;
data->all_available_sensors_are_active = true; base::Optional<double> beta;
base::Optional<double> gamma;
bool absolute = false;
if (!absolute_ && relative_orientation_sensor_.SensorReadingCouldBeRead()) { if (!absolute_ && relative_orientation_sensor_.SensorReadingCouldBeRead()) {
// For DeviceOrientation Event, this provides relative orientation data. // For DeviceOrientation Event, this provides relative orientation data.
data->all_available_sensors_are_active = if (relative_orientation_sensor_.reading.timestamp() == 0.0)
relative_orientation_sensor_.reading.timestamp() != 0.0; return nullptr;
if (!data->all_available_sensors_are_active)
return; if (!std::isnan(
data->alpha = relative_orientation_sensor_.reading.orientation_euler.z; relative_orientation_sensor_.reading.orientation_euler.z.value()))
data->beta = relative_orientation_sensor_.reading.orientation_euler.x; alpha = relative_orientation_sensor_.reading.orientation_euler.z;
data->gamma = relative_orientation_sensor_.reading.orientation_euler.y;
data->has_alpha = !std::isnan( if (!std::isnan(
relative_orientation_sensor_.reading.orientation_euler.z.value()); relative_orientation_sensor_.reading.orientation_euler.x.value()))
data->has_beta = !std::isnan( beta = relative_orientation_sensor_.reading.orientation_euler.x;
relative_orientation_sensor_.reading.orientation_euler.x.value());
data->has_gamma = !std::isnan( if (!std::isnan(
relative_orientation_sensor_.reading.orientation_euler.y.value()); relative_orientation_sensor_.reading.orientation_euler.y.value()))
data->absolute = false; gamma = relative_orientation_sensor_.reading.orientation_euler.y;
} else if (absolute_orientation_sensor_.SensorReadingCouldBeRead()) { } else if (absolute_orientation_sensor_.SensorReadingCouldBeRead()) {
// For DeviceOrientationAbsolute Event, this provides absolute orientation // For DeviceOrientationAbsolute Event, this provides absolute orientation
// data. // data.
// //
// For DeviceOrientation Event, this provides absolute orientation data if // For DeviceOrientation Event, this provides absolute orientation data if
// relative orientation data is not available. // relative orientation data is not available.
data->all_available_sensors_are_active = if (absolute_orientation_sensor_.reading.timestamp() == 0.0)
absolute_orientation_sensor_.reading.timestamp() != 0.0; return nullptr;
if (!data->all_available_sensors_are_active)
return; if (!std::isnan(
data->alpha = absolute_orientation_sensor_.reading.orientation_euler.z; absolute_orientation_sensor_.reading.orientation_euler.z.value()))
data->beta = absolute_orientation_sensor_.reading.orientation_euler.x; alpha = absolute_orientation_sensor_.reading.orientation_euler.z;
data->gamma = absolute_orientation_sensor_.reading.orientation_euler.y;
data->has_alpha = !std::isnan( if (!std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.z.value()); absolute_orientation_sensor_.reading.orientation_euler.x.value()))
data->has_beta = !std::isnan( beta = absolute_orientation_sensor_.reading.orientation_euler.x;
absolute_orientation_sensor_.reading.orientation_euler.x.value());
data->has_gamma = !std::isnan( if (!std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.y.value()); absolute_orientation_sensor_.reading.orientation_euler.y.value()))
data->absolute = true; gamma = absolute_orientation_sensor_.reading.orientation_euler.y;
absolute = true;
} else { } else {
data->absolute = absolute_; absolute = absolute_;
} }
return DeviceOrientationData::Create(alpha, beta, gamma, absolute);
} }
bool DeviceOrientationEventPump::ShouldFireEvent( bool DeviceOrientationEventPump::ShouldFireEvent(
const device::OrientationData& data) const { const DeviceOrientationData* data) const {
if (!data.all_available_sensors_are_active) // |data| is null if not all sensors are active
if (!data)
return false; return false;
if (!data.has_alpha && !data.has_beta && !data.has_gamma) { // when the state changes from not having data to having data,
// no data can be provided, this is an all-null event. // the event should be fired
if (!data_)
return true; return true;
}
return IsSignificantlyDifferent(data_, data); return IsSignificantlyDifferent(data_, data);
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_H_
#include "base/macros.h" #include "base/macros.h"
#include "services/device/public/cpp/generic_sensor/orientation_data.h"
#include "third_party/blink/public/platform/modules/device_orientation/web_device_orientation_listener.h" #include "third_party/blink/public/platform/modules/device_orientation/web_device_orientation_listener.h"
#include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h" #include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
...@@ -44,14 +43,14 @@ class MODULES_EXPORT DeviceOrientationEventPump ...@@ -44,14 +43,14 @@ class MODULES_EXPORT DeviceOrientationEventPump
// DeviceSensorEventPump: // DeviceSensorEventPump:
bool SensorsReadyOrErrored() const override; bool SensorsReadyOrErrored() const override;
void GetDataFromSharedMemory(device::OrientationData* data); DeviceOrientationData* GetDataFromSharedMemory();
bool ShouldFireEvent(const device::OrientationData& data) const; bool ShouldFireEvent(const DeviceOrientationData* data) const;
bool absolute_; bool absolute_;
bool fall_back_to_absolute_orientation_sensor_; bool fall_back_to_absolute_orientation_sensor_;
bool should_suspend_absolute_orientation_sensor_ = false; bool should_suspend_absolute_orientation_sensor_ = false;
device::OrientationData data_; Persistent<DeviceOrientationData> data_;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump); DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPump);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment