diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 22:30:19 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 22:30:19 +0000 |
commit | 230b7efa5edf3fe5964b55ea0aa801563996d4fc (patch) | |
tree | 4ee6e0ffbbb5ca3bc5699e3adefa390279c6f357 /content/renderer/device_orientation_dispatcher.cc | |
parent | eb7d6dd92533eae8c2514735750ccd8d0e9c5875 (diff) | |
download | chromium_src-230b7efa5edf3fe5964b55ea0aa801563996d4fc.zip chromium_src-230b7efa5edf3fe5964b55ea0aa801563996d4fc.tar.gz chromium_src-230b7efa5edf3fe5964b55ea0aa801563996d4fc.tar.bz2 |
Move a bunch of html5 renderer code to content.
TBR=avi
Review URL: http://codereview.chromium.org/6703003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78449 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/device_orientation_dispatcher.cc')
-rw-r--r-- | content/renderer/device_orientation_dispatcher.cc | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/content/renderer/device_orientation_dispatcher.cc b/content/renderer/device_orientation_dispatcher.cc new file mode 100644 index 0000000..309a3e8 --- /dev/null +++ b/content/renderer/device_orientation_dispatcher.cc @@ -0,0 +1,91 @@ +// Copyright (c) 2010 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_orientation_dispatcher.h" + +#include "chrome/common/render_messages.h" +#include "chrome/common/render_messages_params.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientationController.h" + +DeviceOrientationDispatcher::DeviceOrientationDispatcher( + RenderView* render_view) + : RenderViewObserver(render_view), + controller_(NULL), + started_(false) { +} + +DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { + if (started_) + stopUpdating(); +} + +bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) + IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, + OnDeviceOrientationUpdated) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void DeviceOrientationDispatcher::setController( + WebKit::WebDeviceOrientationController* controller) { + controller_.reset(controller); +} + +void DeviceOrientationDispatcher::startUpdating() { + Send(new ViewHostMsg_DeviceOrientation_StartUpdating(routing_id())); + started_ = true; +} + +void DeviceOrientationDispatcher::stopUpdating() { + Send(new ViewHostMsg_DeviceOrientation_StopUpdating(routing_id())); + started_ = false; +} + +WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() + const { + if (!last_orientation_.get()) + return WebKit::WebDeviceOrientation::nullOrientation(); + + return *last_orientation_; +} + +namespace { +bool OrientationsEqual(const ViewMsg_DeviceOrientationUpdated_Params& a, + WebKit::WebDeviceOrientation* b) { + if (a.can_provide_alpha != b->canProvideAlpha()) + return false; + if (a.can_provide_alpha && a.alpha != b->alpha()) + return false; + if (a.can_provide_beta != b->canProvideBeta()) + return false; + if (a.can_provide_beta && a.beta != b->beta()) + return false; + if (a.can_provide_gamma != b->canProvideGamma()) + return false; + if (a.can_provide_gamma && a.gamma != b->gamma()) + return false; + + return true; +} +} // namespace + +void DeviceOrientationDispatcher::OnDeviceOrientationUpdated( + const ViewMsg_DeviceOrientationUpdated_Params& p) { + + if (last_orientation_.get() && OrientationsEqual(p, last_orientation_.get())) + return; + + last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, + p.alpha, + p.can_provide_beta, + p.beta, + p.can_provide_gamma, + p.gamma)); + + controller_->didChangeDeviceOrientation(*last_orientation_); +} |