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

Unified Diff: content/renderer/screen_orientation_dispatcher.cc

Issue 150153004: [WIP] Add Chromium-side support for the Screen Orientation API (Closed) Base URL: https://git.chromium.org/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
Index: content/renderer/screen_orientation_dispatcher.cc
diff --git a/content/renderer/screen_orientation_dispatcher.cc b/content/renderer/screen_orientation_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5b7cd4c52d4c5bf4e24512416df1a85530bb15d5
--- /dev/null
+++ b/content/renderer/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_dispatcher.h"
+
+#include "content/common/view_messages.h"
+#include "content/renderer/render_thread_impl.h"
+#include "content/renderer/render_view_impl.h"
+#include "ipc/ipc_channel.h"
+#include "ipc/ipc_message_utils.h"
+#include "third_party/WebKit/public/web/WebScreenOrientationController.h"
+
+namespace content {
+
+ScreenOrientationDispatcher::ScreenOrientationDispatcher(
+ RenderViewImpl* render_view)
+ : RenderViewObserver(render_view),
+ controller_(NULL) {
+}
+
+void ScreenOrientationDispatcher::OrientationChangeEvent(int orientation) {
+ if (!controller_)
+ return;
+
+ blink::WebScreenOrientation web_orientation;
+ switch(orientation) {
+ case 90:
+ web_orientation = blink::WebScreenOrientationLandscapePrimary;
+ break;
+ case 180:
+ web_orientation = blink::WebScreenOrientationPortraitSecondary;
+ break;
+ case 270:
+ case -90:
+ web_orientation = blink::WebScreenOrientationLandscapeSecondary;
+ break;
+ case 0:
+ default:
+ web_orientation = blink::WebScreenOrientationPortraitPrimary;
+ }
+
+ controller_->orientationChanged(web_orientation);
kenneth.r.christiansen 2014/02/06 15:03:12 are you making sure this is sent as the same time
ostap 2014/02/06 21:23:28 At least it is hooked at the same RenderViewImpl::
+}
+
+bool ScreenOrientationDispatcher::lockOrientation(
+ blink::WebScreenOrientations lock) {
+ bool result = false;
+
+ IPC::Message* msg = new ViewHostMsg_LockScreenOrientation(lock, &result);
+ if (!RenderThread::Get()->Send(msg))
+ return false;
+
+ return result;
+}
+
+void ScreenOrientationDispatcher::unlockOrientation() {
+ IPC::Message* msg = new ViewHostMsg_UnlockScreenOrientation();
+ RenderThread::Get()->Send(msg);
+}
+
+void ScreenOrientationDispatcher::setController(
+ blink::WebScreenOrientationController* controller) {
+ controller_ = controller;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698