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, | |
| 28 OnDeviceMotionUpdated) | |
|
hans
2012/08/13 13:35:19
i think this might fit on one line and still be <
aousterh
2012/08/16 15:23:49
Done.
| |
| 29 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 30 IPC_END_MESSAGE_MAP() | |
| 31 return handled; | |
| 32 } | |
| 33 | |
| 34 void DeviceMotionDispatcher::startUpdating( | |
| 35 WebKit::WebDeviceMotionDetectorClient* client) { | |
| 36 client_.reset(client); | |
| 37 Send(new DeviceMotionHostMsg_StartUpdating(routing_id())); | |
| 38 started_ = true; | |
| 39 } | |
| 40 | |
| 41 void DeviceMotionDispatcher::stopUpdating() { | |
| 42 Send(new DeviceMotionHostMsg_StopUpdating(routing_id())); | |
| 43 started_ = false; | |
| 44 } | |
| 45 | |
| 46 WebKit::WebDeviceMotionData DeviceMotionDispatcher::lastMotion() | |
| 47 const { | |
| 48 return last_motion_; | |
|
hans
2012/08/13 13:35:19
ultra nit: indent should be two spaces, but it loo
aousterh
2012/08/16 15:23:49
Done.
| |
| 49 } | |
| 50 | |
| 51 void DeviceMotionDispatcher::OnDeviceMotionUpdated( | |
| 52 const DeviceMotionMsg_Updated_Params& p) { | |
| 53 if (client_ == NULL) | |
| 54 return; | |
| 55 | |
| 56 last_motion_.setNull(false); | |
| 57 if (p.can_provide_acceleration_x) | |
| 58 last_motion_.setAccelerationX(p.acceleration_x); | |
| 59 if (p.can_provide_acceleration_y) | |
| 60 last_motion_.setAccelerationY(p.acceleration_y); | |
| 61 if (p.can_provide_acceleration_z) | |
| 62 last_motion_.setAccelerationZ(p.acceleration_z); | |
| 63 | |
| 64 if (p.can_provide_acceleration_including_gravity_x) { | |
| 65 last_motion_.setAccelerationIncludingGravityX( | |
| 66 p.acceleration_including_gravity_x); | |
| 67 } | |
| 68 if (p.can_provide_acceleration_including_gravity_y) { | |
| 69 last_motion_.setAccelerationIncludingGravityY( | |
| 70 p.acceleration_including_gravity_y); | |
| 71 } | |
| 72 if (p.can_provide_acceleration_including_gravity_z) { | |
| 73 last_motion_.setAccelerationIncludingGravityZ( | |
| 74 p.acceleration_including_gravity_z); | |
| 75 } | |
| 76 | |
| 77 if (p.can_provide_rotation_rate_alpha) | |
| 78 last_motion_.setRotationRateAlpha(p.rotation_rate_alpha); | |
| 79 if (p.can_provide_rotation_rate_beta) | |
| 80 last_motion_.setRotationRateBeta(p.rotation_rate_beta); | |
| 81 if (p.can_provide_rotation_rate_gamma) | |
| 82 last_motion_.setRotationRateGamma(p.rotation_rate_gamma); | |
| 83 | |
| 84 if (p.can_provide_interval) | |
| 85 last_motion_.setInterval(p.interval); | |
| 86 | |
| 87 client_->didDetectDeviceMotion(last_motion_); | |
| 88 } | |
| OLD | NEW |