Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "content/renderer/device_motion_dispatcher.h" | |
| 6 | |
| 7 #include "content/common/device_motion_messages.h" | |
| 8 #include "content/renderer/render_view_impl.h" | |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionData .h" | |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionDete ctorClient.h" | |
| 11 | |
| 12 DeviceMotionDispatcher::DeviceMotionDispatcher( | |
| 13 RenderViewImpl* render_view) | |
| 14 : content::RenderViewObserver(render_view), | |
| 15 client_(NULL), | |
| 16 started_(false) { | |
| 17 } | |
| 18 | |
| 19 DeviceMotionDispatcher::~DeviceMotionDispatcher() { | |
| 20 if (started_) | |
| 21 stopUpdating(); | |
| 22 } | |
| 23 | |
| 24 bool DeviceMotionDispatcher::OnMessageReceived(const IPC::Message& msg) { | |
| 25 bool handled = true; | |
| 26 IPC_BEGIN_MESSAGE_MAP(DeviceMotionDispatcher, msg) | |
| 27 IPC_MESSAGE_HANDLER(DeviceMotionMsg_Updated, OnDeviceMotionUpdated) | |
| 28 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 29 IPC_END_MESSAGE_MAP() | |
| 30 return handled; | |
| 31 } | |
| 32 | |
| 33 void DeviceMotionDispatcher::startUpdating( | |
| 34 WebKit::WebDeviceMotionDetectorClient* client) { | |
| 35 client_.reset(client); | |
| 36 Send(new DeviceMotionHostMsg_StartUpdating(routing_id())); | |
| 37 started_ = true; | |
| 38 } | |
| 39 | |
| 40 void DeviceMotionDispatcher::stopUpdating() { | |
| 41 Send(new DeviceMotionHostMsg_StopUpdating(routing_id())); | |
| 42 started_ = false; | |
| 43 } | |
| 44 | |
| 45 WebKit::WebDeviceMotionData DeviceMotionDispatcher::lastMotion() | |
| 46 const { | |
| 47 return last_motion_; | |
| 48 } | |
| 49 | |
| 50 void DeviceMotionDispatcher::OnDeviceMotionUpdated( | |
| 51 const DeviceMotionMsg_Updated_Params& p) { | |
| 52 if (client_ == NULL) | |
| 53 return; | |
| 54 | |
|
hans
2012/08/16 16:38:40
should last_motion_ be reset here before we start
aousterh
2012/08/16 17:21:05
Good point. Done.
| |
| 55 if (p.can_provide_acceleration_x || p.can_provide_acceleration_y || | |
| 56 p.can_provide_acceleration_z) | |
| 57 last_motion_.initializeAcceleration(p.can_provide_acceleration_x, | |
| 58 p.acceleration_x, | |
| 59 p.can_provide_acceleration_y, | |
| 60 p.acceleration_y, | |
| 61 p.can_provide_acceleration_z, | |
| 62 p.acceleration_z); | |
| 63 | |
| 64 if (p.can_provide_acceleration_including_gravity_x || | |
| 65 p.can_provide_acceleration_including_gravity_y || | |
| 66 p.can_provide_acceleration_including_gravity_z) | |
| 67 last_motion_.initializeAccelerationIncludingGravity( | |
| 68 p.can_provide_acceleration_including_gravity_x, | |
| 69 p.acceleration_including_gravity_x, | |
| 70 p.can_provide_acceleration_including_gravity_y, | |
| 71 p.acceleration_including_gravity_y, | |
| 72 p.can_provide_acceleration_including_gravity_z, | |
| 73 p.acceleration_including_gravity_z); | |
| 74 | |
| 75 if (p.can_provide_rotation_rate_alpha || p.can_provide_rotation_rate_beta || | |
| 76 p.can_provide_rotation_rate_gamma) | |
| 77 last_motion_.initializeRotationRate(p.can_provide_rotation_rate_alpha, | |
| 78 p.rotation_rate_alpha, | |
| 79 p.can_provide_rotation_rate_beta, | |
| 80 p.rotation_rate_beta, | |
| 81 p.can_provide_rotation_rate_gamma, | |
| 82 p.rotation_rate_gamma); | |
| 83 if (p.can_provide_interval) | |
| 84 last_motion_.initializeInterval(p.interval); | |
| 85 | |
| 86 client_->didDetectDeviceMotion(last_motion_); | |
| 87 } | |
| OLD | NEW |