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

Unified Diff: content/renderer/screen_orientation/screen_orientation_dispatcher.cc

Issue 164913004: Chromium plumbing for Screen Orientation API orientationchange events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/screen_orientation/screen_orientation_dispatcher.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/screen_orientation/screen_orientation_dispatcher.cc
diff --git a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47b49699ed7f325e43e221ae7b0d2d1ee2e11a18
--- /dev/null
+++ b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
@@ -0,0 +1,67 @@
+// Copyright 2014 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/screen_orientation/screen_orientation_dispatcher.h"
+
+#include "content/common/screen_orientation_messages.h"
+#include "content/public/renderer/render_thread.h"
+#include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
+
+namespace content {
+
+ScreenOrientationDispatcher::ScreenOrientationDispatcher(
+ RenderThread* thread)
+ : listener_(NULL) {
+ thread->AddObserver(this);
+}
+
+bool ScreenOrientationDispatcher::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher, message)
+ IPC_MESSAGE_HANDLER(ScreenOrientationMsg_OrientationChange,
+ OnOrientationChange)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void ScreenOrientationDispatcher::OnOrientationChange(int orientation) {
+ if (!listener_)
+ return;
+
+ // TODO(mlamouri): we might want to have OrientationChangeEvent to pass us
+ // a WebScreenOrientation instead of an int so we can let the backend decide
+ // of the relation between angle and orientation name.
+ blink::WebScreenOrientation web_orientation;
+ switch(orientation) {
+ case 0:
+ web_orientation = blink::WebScreenOrientationPortraitPrimary;
+ break;
+ case 90:
+ web_orientation = blink::WebScreenOrientationLandscapePrimary;
+ break;
+ case 180:
+ web_orientation = blink::WebScreenOrientationPortraitSecondary;
+ break;
+ case -90:
+ web_orientation = blink::WebScreenOrientationLandscapeSecondary;
+ break;
+ default:
+ NOTREACHED();
Cris Neckar 2014/02/20 18:47:45 We prefer that you not handle failures when it com
mlamouri (slow - plz ping) 2014/02/20 19:01:12 Done.
+ web_orientation = blink::WebScreenOrientationPortraitPrimary;
+ break;
+ }
+
+ listener_->didChangeScreenOrientation(web_orientation);
+}
+
+void ScreenOrientationDispatcher::setListener(
+ blink::WebScreenOrientationListener* listener) {
+ listener_ = listener;
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/screen_orientation/screen_orientation_dispatcher.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698