Chromium Code Reviews| Index: content/renderer/device_motion_dispatcher.cc | 
| diff --git a/content/renderer/device_motion_dispatcher.cc b/content/renderer/device_motion_dispatcher.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..372aeddd5dcffdafa1327eda0ba423054b0234bb | 
| --- /dev/null | 
| +++ b/content/renderer/device_motion_dispatcher.cc | 
| @@ -0,0 +1,88 @@ | 
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "content/renderer/device_motion_dispatcher.h" | 
| + | 
| +#include "content/common/device_motion_messages.h" | 
| +#include "content/renderer/render_view_impl.h" | 
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionData.h" | 
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionDetectorClient.h" | 
| + | 
| +DeviceMotionDispatcher::DeviceMotionDispatcher( | 
| + RenderViewImpl* render_view) | 
| + : content::RenderViewObserver(render_view), | 
| + client_(NULL), | 
| + started_(false) { | 
| +} | 
| + | 
| +DeviceMotionDispatcher::~DeviceMotionDispatcher() { | 
| + if (started_) | 
| + stopUpdating(); | 
| +} | 
| + | 
| +bool DeviceMotionDispatcher::OnMessageReceived(const IPC::Message& msg) { | 
| + bool handled = true; | 
| + IPC_BEGIN_MESSAGE_MAP(DeviceMotionDispatcher, msg) | 
| + IPC_MESSAGE_HANDLER(DeviceMotionMsg_Updated, | 
| + 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.
 
 | 
| + IPC_MESSAGE_UNHANDLED(handled = false) | 
| + IPC_END_MESSAGE_MAP() | 
| + return handled; | 
| +} | 
| + | 
| +void DeviceMotionDispatcher::startUpdating( | 
| + WebKit::WebDeviceMotionDetectorClient* client) { | 
| + client_.reset(client); | 
| + Send(new DeviceMotionHostMsg_StartUpdating(routing_id())); | 
| + started_ = true; | 
| +} | 
| + | 
| +void DeviceMotionDispatcher::stopUpdating() { | 
| + Send(new DeviceMotionHostMsg_StopUpdating(routing_id())); | 
| + started_ = false; | 
| +} | 
| + | 
| +WebKit::WebDeviceMotionData DeviceMotionDispatcher::lastMotion() | 
| + const { | 
| + 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.
 
 | 
| +} | 
| + | 
| +void DeviceMotionDispatcher::OnDeviceMotionUpdated( | 
| + const DeviceMotionMsg_Updated_Params& p) { | 
| + if (client_ == NULL) | 
| + return; | 
| + | 
| + last_motion_.setNull(false); | 
| + if (p.can_provide_acceleration_x) | 
| + last_motion_.setAccelerationX(p.acceleration_x); | 
| + if (p.can_provide_acceleration_y) | 
| + last_motion_.setAccelerationY(p.acceleration_y); | 
| + if (p.can_provide_acceleration_z) | 
| + last_motion_.setAccelerationZ(p.acceleration_z); | 
| + | 
| + if (p.can_provide_acceleration_including_gravity_x) { | 
| + last_motion_.setAccelerationIncludingGravityX( | 
| + p.acceleration_including_gravity_x); | 
| + } | 
| + if (p.can_provide_acceleration_including_gravity_y) { | 
| + last_motion_.setAccelerationIncludingGravityY( | 
| + p.acceleration_including_gravity_y); | 
| + } | 
| + if (p.can_provide_acceleration_including_gravity_z) { | 
| + last_motion_.setAccelerationIncludingGravityZ( | 
| + p.acceleration_including_gravity_z); | 
| + } | 
| + | 
| + if (p.can_provide_rotation_rate_alpha) | 
| + last_motion_.setRotationRateAlpha(p.rotation_rate_alpha); | 
| + if (p.can_provide_rotation_rate_beta) | 
| + last_motion_.setRotationRateBeta(p.rotation_rate_beta); | 
| + if (p.can_provide_rotation_rate_gamma) | 
| + last_motion_.setRotationRateGamma(p.rotation_rate_gamma); | 
| + | 
| + if (p.can_provide_interval) | 
| + last_motion_.setInterval(p.interval); | 
| + | 
| + client_->didDetectDeviceMotion(last_motion_); | 
| +} |