Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: content/renderer/device_motion_dispatcher.cc

Issue 10698046: Implements part of Device Motion in the Renderer (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Makes changes suggested by review comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/device_motion_dispatcher.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « content/renderer/device_motion_dispatcher.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698