| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/sensor/AccelerometerReading.h" |
| 6 |
| 7 #include "modules/sensor/SensorProxy.h" |
| 8 #include "wtf/CurrentTime.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 namespace { |
| 13 device::SensorReading ToReadingData(const AccelerometerReadingInit& init) { |
| 14 device::SensorReading result; |
| 15 result.timestamp = WTF::monotonicallyIncreasingTime(); |
| 16 if (init.hasX()) |
| 17 result.values[0] = init.x(); |
| 18 if (init.hasY()) |
| 19 result.values[1] = init.y(); |
| 20 if (init.hasZ()) |
| 21 result.values[2] = init.z(); |
| 22 return result; |
| 23 } |
| 24 } // namespace |
| 25 |
| 26 AccelerometerReading::AccelerometerReading(const AccelerometerReadingInit& init) |
| 27 : SensorReading(ToReadingData(init)) {} |
| 28 |
| 29 AccelerometerReading::AccelerometerReading(const device::SensorReading& data) |
| 30 : SensorReading(data) {} |
| 31 |
| 32 AccelerometerReading::~AccelerometerReading() = default; |
| 33 |
| 34 double AccelerometerReading::x() const { |
| 35 return data().values[0]; |
| 36 } |
| 37 |
| 38 double AccelerometerReading::y() const { |
| 39 return data().values[1]; |
| 40 } |
| 41 |
| 42 double AccelerometerReading::z() const { |
| 43 return data().values[2]; |
| 44 } |
| 45 |
| 46 bool AccelerometerReading::isReadingUpdated( |
| 47 const device::SensorReading& previous) const { |
| 48 return (previous.values[0] != x() || previous.values[1] != y() || |
| 49 previous.values[2] != z()); |
| 50 } |
| 51 |
| 52 DEFINE_TRACE(AccelerometerReading) { |
| 53 SensorReading::trace(visitor); |
| 54 } |
| 55 |
| 56 } // namespace blink |
| OLD | NEW |