OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/device_orientation_dispatcher.h" | 5 #include "chrome/renderer/device_orientation_dispatcher.h" |
6 | 6 |
| 7 #include "chrome/common/render_messages.h" |
7 #include "chrome/common/render_messages_params.h" | 8 #include "chrome/common/render_messages_params.h" |
8 #include "chrome/renderer/render_view.h" | |
9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" |
11 | 11 |
12 DeviceOrientationDispatcher::DeviceOrientationDispatcher( | 12 DeviceOrientationDispatcher::DeviceOrientationDispatcher( |
13 RenderView* render_view) | 13 RenderView* render_view) |
14 : render_view_(render_view), | 14 : RenderViewObserver(render_view), |
15 controller_(NULL), | 15 controller_(NULL), |
16 started_(false) { | 16 started_(false) { |
17 } | 17 } |
18 | 18 |
19 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { | 19 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { |
20 if (started_) | 20 if (started_) |
21 stopUpdating(); | 21 stopUpdating(); |
22 } | 22 } |
23 | 23 |
24 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { | 24 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { |
25 bool handled = true; | 25 bool handled = true; |
26 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) | 26 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) |
27 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, | 27 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, |
28 OnDeviceOrientationUpdated) | 28 OnDeviceOrientationUpdated) |
29 IPC_MESSAGE_UNHANDLED(handled = false) | 29 IPC_MESSAGE_UNHANDLED(handled = false) |
30 IPC_END_MESSAGE_MAP() | 30 IPC_END_MESSAGE_MAP() |
31 return handled; | 31 return handled; |
32 } | 32 } |
33 | 33 |
34 void DeviceOrientationDispatcher::setController( | 34 void DeviceOrientationDispatcher::setController( |
35 WebKit::WebDeviceOrientationController* controller) { | 35 WebKit::WebDeviceOrientationController* controller) { |
36 controller_.reset(controller); | 36 controller_.reset(controller); |
37 } | 37 } |
38 | 38 |
39 void DeviceOrientationDispatcher::startUpdating() { | 39 void DeviceOrientationDispatcher::startUpdating() { |
40 render_view_->Send(new ViewHostMsg_DeviceOrientation_StartUpdating( | 40 Send(new ViewHostMsg_DeviceOrientation_StartUpdating(routing_id())); |
41 render_view_->routing_id())); | |
42 started_ = true; | 41 started_ = true; |
43 } | 42 } |
44 | 43 |
45 void DeviceOrientationDispatcher::stopUpdating() { | 44 void DeviceOrientationDispatcher::stopUpdating() { |
46 render_view_->Send(new ViewHostMsg_DeviceOrientation_StopUpdating( | 45 Send(new ViewHostMsg_DeviceOrientation_StopUpdating(routing_id())); |
47 render_view_->routing_id())); | |
48 started_ = false; | 46 started_ = false; |
49 } | 47 } |
50 | 48 |
51 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() | 49 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() |
52 const { | 50 const { |
53 if (!last_orientation_.get()) | 51 if (!last_orientation_.get()) |
54 return WebKit::WebDeviceOrientation::nullOrientation(); | 52 return WebKit::WebDeviceOrientation::nullOrientation(); |
55 | 53 |
56 return *last_orientation_; | 54 return *last_orientation_; |
57 } | 55 } |
(...skipping 26 matching lines...) Expand all Loading... |
84 | 82 |
85 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, | 83 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, |
86 p.alpha, | 84 p.alpha, |
87 p.can_provide_beta, | 85 p.can_provide_beta, |
88 p.beta, | 86 p.beta, |
89 p.can_provide_gamma, | 87 p.can_provide_gamma, |
90 p.gamma)); | 88 p.gamma)); |
91 | 89 |
92 controller_->didChangeDeviceOrientation(*last_orientation_); | 90 controller_->didChangeDeviceOrientation(*last_orientation_); |
93 } | 91 } |
OLD | NEW |