| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device_orientation_event_pump.h" | 5 #include "device_orientation_event_pump.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 bool hasAngle2, double angle2) { | 34 bool hasAngle2, double angle2) { |
| 35 if (hasAngle1 != hasAngle2) | 35 if (hasAngle1 != hasAngle2) |
| 36 return true; | 36 return true; |
| 37 return (hasAngle1 && | 37 return (hasAngle1 && |
| 38 std::fabs(angle1 - angle2) >= | 38 std::fabs(angle1 - angle2) >= |
| 39 DeviceOrientationEventPumpBase::kOrientationThreshold); | 39 DeviceOrientationEventPumpBase::kOrientationThreshold); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool DeviceOrientationEventPumpBase::ShouldFireEvent( | 42 bool DeviceOrientationEventPumpBase::ShouldFireEvent( |
| 43 const device::OrientationData& data) const { | 43 const device::OrientationData& data) const { |
| 44 if (!data.allAvailableSensorsAreActive) | 44 if (!data.all_available_sensors_are_active) |
| 45 return false; | 45 return false; |
| 46 | 46 |
| 47 if (!data.hasAlpha && !data.hasBeta && !data.hasGamma) { | 47 if (!data.has_alpha && !data.has_beta && !data.has_gamma) { |
| 48 // no data can be provided, this is an all-null event. | 48 // no data can be provided, this is an all-null event. |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 return IsSignificantlyDifferent( | 52 return IsSignificantlyDifferent(data_.has_alpha, data_.alpha, data.has_alpha, |
| 53 data_.hasAlpha, data_.alpha, data.hasAlpha, data.alpha) || | 53 data.alpha) || |
| 54 IsSignificantlyDifferent( | 54 IsSignificantlyDifferent(data_.has_beta, data_.beta, data.has_beta, |
| 55 data_.hasBeta, data_.beta, data.hasBeta, data.beta) || | 55 data.beta) || |
| 56 IsSignificantlyDifferent( | 56 IsSignificantlyDifferent(data_.has_gamma, data_.gamma, data.has_gamma, |
| 57 data_.hasGamma, data_.gamma, data.hasGamma, data.gamma); | 57 data.gamma); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool DeviceOrientationEventPumpBase::InitializeReader( | 60 bool DeviceOrientationEventPumpBase::InitializeReader( |
| 61 base::SharedMemoryHandle handle) { | 61 base::SharedMemoryHandle handle) { |
| 62 memset(&data_, 0, sizeof(data_)); | 62 memset(&data_, 0, sizeof(data_)); |
| 63 if (!reader_) | 63 if (!reader_) |
| 64 reader_.reset(new DeviceOrientationSharedMemoryReader()); | 64 reader_.reset(new DeviceOrientationSharedMemoryReader()); |
| 65 return reader_->Initialize(handle); | 65 return reader_->Initialize(handle); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void DeviceOrientationEventPumpBase::SendFakeDataForTesting(void* fake_data) { | 68 void DeviceOrientationEventPumpBase::SendFakeDataForTesting(void* fake_data) { |
| 69 device::OrientationData data = | 69 device::OrientationData data = |
| 70 *static_cast<device::OrientationData*>(fake_data); | 70 *static_cast<device::OrientationData*>(fake_data); |
| 71 | 71 |
| 72 listener()->didChangeDeviceOrientation(data); | 72 listener()->didChangeDeviceOrientation(data); |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace content | 75 } // namespace content |
| OLD | NEW |