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 |
| 55 last_motion_.reset(); |
| 56 if (p.can_provide_acceleration_x || p.can_provide_acceleration_y || |
| 57 p.can_provide_acceleration_z) |
| 58 last_motion_.initializeAcceleration(p.can_provide_acceleration_x, |
| 59 p.acceleration_x, |
| 60 p.can_provide_acceleration_y, |
| 61 p.acceleration_y, |
| 62 p.can_provide_acceleration_z, |
| 63 p.acceleration_z); |
| 64 |
| 65 if (p.can_provide_acceleration_including_gravity_x || |
| 66 p.can_provide_acceleration_including_gravity_y || |
| 67 p.can_provide_acceleration_including_gravity_z) |
| 68 last_motion_.initializeAccelerationIncludingGravity( |
| 69 p.can_provide_acceleration_including_gravity_x, |
| 70 p.acceleration_including_gravity_x, |
| 71 p.can_provide_acceleration_including_gravity_y, |
| 72 p.acceleration_including_gravity_y, |
| 73 p.can_provide_acceleration_including_gravity_z, |
| 74 p.acceleration_including_gravity_z); |
| 75 |
| 76 if (p.can_provide_rotation_rate_alpha || p.can_provide_rotation_rate_beta || |
| 77 p.can_provide_rotation_rate_gamma) |
| 78 last_motion_.initializeRotationRate(p.can_provide_rotation_rate_alpha, |
| 79 p.rotation_rate_alpha, |
| 80 p.can_provide_rotation_rate_beta, |
| 81 p.rotation_rate_beta, |
| 82 p.can_provide_rotation_rate_gamma, |
| 83 p.rotation_rate_gamma); |
| 84 if (p.can_provide_interval) |
| 85 last_motion_.initializeInterval(p.interval); |
| 86 |
| 87 client_->didDetectDeviceMotion(last_motion_); |
| 88 } |
OLD | NEW |