Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2017 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef DeviceMotionDispatcher_h | 31 #ifndef WebDeviceMotionData_h |
| 32 #define DeviceMotionDispatcher_h | 32 #define WebDeviceMotionData_h |
| 33 | 33 |
| 34 #include "core/frame/PlatformEventDispatcher.h" | 34 #include <string.h> |
| 35 #include "platform/heap/Handle.h" | |
| 36 #include "platform/wtf/RefPtr.h" | |
| 37 #include "public/platform/modules/device_orientation/WebDeviceMotionListener.h" | |
| 38 | |
| 39 namespace device { | |
| 40 class MotionData; | |
| 41 } | |
| 42 | 35 |
| 43 namespace blink { | 36 namespace blink { |
| 44 | 37 |
| 45 class DeviceMotionData; | 38 #pragma pack(push, 1) |
| 46 | 39 |
| 47 // This class listens to device motion data and notifies all registered | 40 class WebDeviceMotionData { |
| 48 // controllers. | 41 public: |
| 49 class DeviceMotionDispatcher final | 42 WebDeviceMotionData() |
| 50 : public GarbageCollectedFinalized<DeviceMotionDispatcher>, | 43 : has_acceleration_x(false), |
| 51 public PlatformEventDispatcher, | 44 has_acceleration_y(false), |
| 52 public WebDeviceMotionListener { | 45 has_acceleration_z(false), |
| 53 USING_GARBAGE_COLLECTED_MIXIN(DeviceMotionDispatcher); | 46 has_acceleration_including_gravity_x(false), |
| 47 has_acceleration_including_gravity_y(false), | |
| 48 has_acceleration_including_gravity_z(false), | |
| 49 has_rotation_rate_alpha(false), | |
| 50 has_rotation_rate_beta(false), | |
| 51 has_rotation_rate_gamma(false) {} | |
| 52 WebDeviceMotionData(const WebDeviceMotionData& other) = default; | |
| 53 ~WebDeviceMotionData() {} | |
| 54 | 54 |
| 55 public: | 55 double acceleration_x; |
| 56 static DeviceMotionDispatcher& Instance(); | 56 double acceleration_y; |
| 57 ~DeviceMotionDispatcher() override; | 57 double acceleration_z; |
| 58 | 58 |
| 59 // Note that the returned object is owned by this class. | 59 double acceleration_including_gravity_x; |
| 60 // FIXME: make the return value const, see crbug.com/233174. | 60 double acceleration_including_gravity_y; |
| 61 DeviceMotionData* LatestDeviceMotionData(); | 61 double acceleration_including_gravity_z; |
| 62 | 62 |
| 63 // Inherited from WebDeviceMotionListener. | 63 double rotation_rate_alpha; |
| 64 void DidChangeDeviceMotion(const device::MotionData&) override; | 64 double rotation_rate_beta; |
| 65 double rotation_rate_gamma; | |
| 65 | 66 |
| 66 DECLARE_VIRTUAL_TRACE(); | 67 double interval; |
| 67 | 68 |
| 68 private: | 69 bool has_acceleration_x : 1; |
| 69 DeviceMotionDispatcher(); | 70 bool has_acceleration_y : 1; |
| 71 bool has_acceleration_z : 1; | |
| 70 | 72 |
| 71 // Inherited from PlatformEventDispatcher. | 73 bool has_acceleration_including_gravity_x : 1; |
| 72 void StartListening() override; | 74 bool has_acceleration_including_gravity_y : 1; |
| 73 void StopListening() override; | 75 bool has_acceleration_including_gravity_z : 1; |
| 74 | 76 |
| 75 Member<DeviceMotionData> last_device_motion_data_; | 77 bool has_rotation_rate_alpha : 1; |
| 78 bool has_rotation_rate_beta : 1; | |
| 79 bool has_rotation_rate_gamma : 1; | |
| 76 }; | 80 }; |
| 77 | 81 |
| 82 static_assert(sizeof(WebDeviceMotionData) == | |
| 83 (10 * sizeof(double) + 2 * sizeof(char)), | |
| 84 "WebDeviceMotionData has wrong size"); | |
|
Reilly Grant (use Gerrit)
2017/05/22 20:29:46
This struct isn't used in shared memory so packing
juncai
2017/05/23 02:30:24
Done.
| |
| 85 | |
| 86 #pragma pack(pop) | |
| 87 | |
| 78 } // namespace blink | 88 } // namespace blink |
| 79 | 89 |
| 80 #endif // DeviceMotionDispatcher_h | 90 #endif // WebDeviceMotionData_h |
| OLD | NEW |