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 @@
#include "third_party/blink/public/platform/web_platform_event_listener.h"
namespace device {
class OrientationData;
}
namespace blink {
class DeviceOrientationData;
class WebDeviceOrientationListener : public WebPlatformEventListener {
public:
// 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;
};
......
include_rules = [
"+base/run_loop.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_provider.mojom-blink.h",
"+services/device/public/cpp/test/fake_sensor_and_provider.h",
......
......@@ -25,7 +25,6 @@
#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"
namespace blink {
......@@ -56,20 +55,6 @@ DeviceOrientationData* DeviceOrientationData::Create(
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(
......
......@@ -30,10 +30,6 @@
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class OrientationData;
}
namespace blink {
class DeviceOrientationEventInit;
......@@ -47,7 +43,6 @@ class MODULES_EXPORT DeviceOrientationData final
const base::Optional<double>& gamma,
bool absolute);
static DeviceOrientationData* Create(const DeviceOrientationEventInit&);
static DeviceOrientationData* Create(const device::OrientationData&);
void Trace(blink::Visitor* visitor) {}
double Alpha() const;
......
......@@ -78,8 +78,8 @@ void DeviceOrientationDispatcher::StopListening() {
}
void DeviceOrientationDispatcher::DidChangeDeviceOrientation(
const device::OrientationData& motion) {
last_device_orientation_data_ = DeviceOrientationData::Create(motion);
DeviceOrientationData* orientation) {
last_device_orientation_data_ = orientation;
NotifyControllers();
}
......
......@@ -36,10 +36,6 @@
#include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace device {
class OrientationData;
}
namespace blink {
class DeviceOrientationData;
......@@ -62,7 +58,7 @@ class DeviceOrientationDispatcher final
DeviceOrientationData* LatestDeviceOrientationData();
// Inherited from WebDeviceOrientationListener.
void DidChangeDeviceOrientation(const device::OrientationData&) override;
void DidChangeDeviceOrientation(DeviceOrientationData*) override;
void Trace(blink::Visitor*) override;
......
......@@ -7,30 +7,28 @@
#include "services/device/public/mojom/sensor.mojom-blink.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/modules/device_orientation/device_orientation_data.h"
#include "third_party/blink/renderer/modules/device_orientation/device_orientation_event_pump.h"
namespace {
bool IsAngleDifferentThreshold(bool has_angle1,
double angle1,
bool has_angle2,
double angle2) {
if (has_angle1 != has_angle2)
return true;
return (has_angle1 &&
std::fabs(angle1 - angle2) >=
bool IsAngleDifferentThreshold(double angle1, double angle2) {
return (std::fabs(angle1 - angle2) >=
blink::DeviceOrientationEventPump::kOrientationThreshold);
}
bool IsSignificantlyDifferent(const device::OrientationData& data1,
const device::OrientationData& data2) {
return IsAngleDifferentThreshold(data1.has_alpha, data1.alpha,
data2.has_alpha, data2.alpha) ||
IsAngleDifferentThreshold(data1.has_beta, data1.beta, data2.has_beta,
data2.beta) ||
IsAngleDifferentThreshold(data1.has_gamma, data1.gamma,
data2.has_gamma, data2.gamma);
bool IsSignificantlyDifferent(const blink::DeviceOrientationData* data1,
const blink::DeviceOrientationData* data2) {
if (data1->CanProvideAlpha() != data2->CanProvideAlpha() ||
data1->CanProvideBeta() != data2->CanProvideBeta() ||
data1->CanProvideGamma() != data2->CanProvideGamma())
return true;
return (data1->CanProvideAlpha() &&
IsAngleDifferentThreshold(data1->Alpha(), data2->Alpha())) ||
(data1->CanProvideBeta() &&
IsAngleDifferentThreshold(data1->Beta(), data2->Beta())) ||
(data1->CanProvideGamma() &&
IsAngleDifferentThreshold(data1->Gamma(), data2->Gamma()));
}
} // namespace
......@@ -105,15 +103,13 @@ void DeviceOrientationEventPump::SendStopMessage() {
// 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
// we think it hasn't changed.
data_ = device::OrientationData();
data_ = nullptr;
}
void DeviceOrientationEventPump::FireEvent(TimerBase*) {
device::OrientationData data;
DCHECK(listener());
GetDataFromSharedMemory(&data);
DeviceOrientationData* data = GetDataFromSharedMemory();
if (ShouldFireEvent(data)) {
data_ = data;
......@@ -152,60 +148,67 @@ bool DeviceOrientationEventPump::SensorsReadyOrErrored() const {
return true;
}
void DeviceOrientationEventPump::GetDataFromSharedMemory(
device::OrientationData* data) {
data->all_available_sensors_are_active = true;
DeviceOrientationData* DeviceOrientationEventPump::GetDataFromSharedMemory() {
base::Optional<double> alpha;
base::Optional<double> beta;
base::Optional<double> gamma;
bool absolute = false;
if (!absolute_ && relative_orientation_sensor_.SensorReadingCouldBeRead()) {
// For DeviceOrientation Event, this provides relative orientation data.
data->all_available_sensors_are_active =
relative_orientation_sensor_.reading.timestamp() != 0.0;
if (!data->all_available_sensors_are_active)
return;
data->alpha = relative_orientation_sensor_.reading.orientation_euler.z;
data->beta = relative_orientation_sensor_.reading.orientation_euler.x;
data->gamma = relative_orientation_sensor_.reading.orientation_euler.y;
data->has_alpha = !std::isnan(
relative_orientation_sensor_.reading.orientation_euler.z.value());
data->has_beta = !std::isnan(
relative_orientation_sensor_.reading.orientation_euler.x.value());
data->has_gamma = !std::isnan(
relative_orientation_sensor_.reading.orientation_euler.y.value());
data->absolute = false;
if (relative_orientation_sensor_.reading.timestamp() == 0.0)
return nullptr;
if (!std::isnan(
relative_orientation_sensor_.reading.orientation_euler.z.value()))
alpha = relative_orientation_sensor_.reading.orientation_euler.z;
if (!std::isnan(
relative_orientation_sensor_.reading.orientation_euler.x.value()))
beta = relative_orientation_sensor_.reading.orientation_euler.x;
if (!std::isnan(
relative_orientation_sensor_.reading.orientation_euler.y.value()))
gamma = relative_orientation_sensor_.reading.orientation_euler.y;
} else if (absolute_orientation_sensor_.SensorReadingCouldBeRead()) {
// For DeviceOrientationAbsolute Event, this provides absolute orientation
// data.
//
// For DeviceOrientation Event, this provides absolute orientation data if
// relative orientation data is not available.
data->all_available_sensors_are_active =
absolute_orientation_sensor_.reading.timestamp() != 0.0;
if (!data->all_available_sensors_are_active)
return;
data->alpha = absolute_orientation_sensor_.reading.orientation_euler.z;
data->beta = absolute_orientation_sensor_.reading.orientation_euler.x;
data->gamma = absolute_orientation_sensor_.reading.orientation_euler.y;
data->has_alpha = !std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.z.value());
data->has_beta = !std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.x.value());
data->has_gamma = !std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.y.value());
data->absolute = true;
if (absolute_orientation_sensor_.reading.timestamp() == 0.0)
return nullptr;
if (!std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.z.value()))
alpha = absolute_orientation_sensor_.reading.orientation_euler.z;
if (!std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.x.value()))
beta = absolute_orientation_sensor_.reading.orientation_euler.x;
if (!std::isnan(
absolute_orientation_sensor_.reading.orientation_euler.y.value()))
gamma = absolute_orientation_sensor_.reading.orientation_euler.y;
absolute = true;
} else {
data->absolute = absolute_;
absolute = absolute_;
}
return DeviceOrientationData::Create(alpha, beta, gamma, absolute);
}
bool DeviceOrientationEventPump::ShouldFireEvent(
const device::OrientationData& data) const {
if (!data.all_available_sensors_are_active)
const DeviceOrientationData* data) const {
// |data| is null if not all sensors are active
if (!data)
return false;
if (!data.has_alpha && !data.has_beta && !data.has_gamma) {
// no data can be provided, this is an all-null event.
// when the state changes from not having data to having data,
// the event should be fired
if (!data_)
return true;
}
return IsSignificantlyDifferent(data_, data);
}
......
......@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_ORIENTATION_EVENT_PUMP_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/renderer/modules/device_orientation/device_sensor_event_pump.h"
#include "third_party/blink/renderer/modules/modules_export.h"
......@@ -44,14 +43,14 @@ class MODULES_EXPORT DeviceOrientationEventPump
// DeviceSensorEventPump:
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 fall_back_to_absolute_orientation_sensor_;
bool should_suspend_absolute_orientation_sensor_ = false;
device::OrientationData data_;
Persistent<DeviceOrientationData> data_;
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