| 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_params.h" | 7 #include "chrome/common/render_messages_params.h" |
| 8 #include "chrome/renderer/render_view.h" | |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" |
| 11 | 10 |
| 12 DeviceOrientationDispatcher::DeviceOrientationDispatcher( | 11 DeviceOrientationDispatcher::DeviceOrientationDispatcher() |
| 13 RenderView* render_view) | 12 : controller_(NULL), started_(false) { |
| 14 : render_view_(render_view), | |
| 15 controller_(NULL), | |
| 16 started_(false) { | |
| 17 } | 13 } |
| 18 | 14 |
| 19 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { | 15 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { |
| 20 if (started_) | 16 if (started_) |
| 21 stopUpdating(); | 17 stopUpdating(); |
| 22 } | 18 } |
| 23 | 19 |
| 24 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { | 20 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 25 bool handled = true; | 21 bool handled = true; |
| 26 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) | 22 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) |
| 27 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, | 23 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, |
| 28 OnDeviceOrientationUpdated) | 24 OnDeviceOrientationUpdated) |
| 29 IPC_MESSAGE_UNHANDLED(handled = false) | 25 IPC_MESSAGE_UNHANDLED(handled = false) |
| 30 IPC_END_MESSAGE_MAP() | 26 IPC_END_MESSAGE_MAP() |
| 31 return handled; | 27 return handled; |
| 32 } | 28 } |
| 33 | 29 |
| 34 void DeviceOrientationDispatcher::setController( | 30 void DeviceOrientationDispatcher::setController( |
| 35 WebKit::WebDeviceOrientationController* controller) { | 31 WebKit::WebDeviceOrientationController* controller) { |
| 36 controller_.reset(controller); | 32 controller_.reset(controller); |
| 37 } | 33 } |
| 38 | 34 |
| 39 void DeviceOrientationDispatcher::startUpdating() { | 35 void DeviceOrientationDispatcher::startUpdating() { |
| 40 render_view_->Send(new ViewHostMsg_DeviceOrientation_StartUpdating( | 36 Send(new ViewHostMsg_DeviceOrientation_StartUpdating(routing_id())); |
| 41 render_view_->routing_id())); | |
| 42 started_ = true; | 37 started_ = true; |
| 43 } | 38 } |
| 44 | 39 |
| 45 void DeviceOrientationDispatcher::stopUpdating() { | 40 void DeviceOrientationDispatcher::stopUpdating() { |
| 46 render_view_->Send(new ViewHostMsg_DeviceOrientation_StopUpdating( | 41 Send(new ViewHostMsg_DeviceOrientation_StopUpdating(routing_id())); |
| 47 render_view_->routing_id())); | |
| 48 started_ = false; | 42 started_ = false; |
| 49 } | 43 } |
| 50 | 44 |
| 51 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() | 45 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() |
| 52 const { | 46 const { |
| 53 if (!last_orientation_.get()) | 47 if (!last_orientation_.get()) |
| 54 return WebKit::WebDeviceOrientation::nullOrientation(); | 48 return WebKit::WebDeviceOrientation::nullOrientation(); |
| 55 | 49 |
| 56 return *last_orientation_; | 50 return *last_orientation_; |
| 57 } | 51 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 | 78 |
| 85 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, | 79 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, |
| 86 p.alpha, | 80 p.alpha, |
| 87 p.can_provide_beta, | 81 p.can_provide_beta, |
| 88 p.beta, | 82 p.beta, |
| 89 p.can_provide_gamma, | 83 p.can_provide_gamma, |
| 90 p.gamma)); | 84 p.gamma)); |
| 91 | 85 |
| 92 controller_->didChangeDeviceOrientation(*last_orientation_); | 86 controller_->didChangeDeviceOrientation(*last_orientation_); |
| 93 } | 87 } |
| OLD | NEW |