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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java

Issue 196193002: Implement ScreenOrientationProvider for Chrome Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years, 9 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/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..853f5c4818e7042517fac9ec667a6b1bb9bd8f30
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java
@@ -0,0 +1,83 @@
+// 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.
+
+package org.chromium.content.browser;
+
+import android.app.Activity;
+import android.content.pm.ActivityInfo;
+import android.util.Log;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+/**
+ * This is the implementation of the C++ counterpart ScreenOrientationProvider.
+ */
+@JNINamespace("content")
+class ScreenOrientationProvider {
+ private static final String TAG = "ScreenOrientationProvider";
+
+ // Has to be kept in sync with:
Michael van Ouwerkerk 2014/03/12 14:42:55 Ugh. There are ways to automate this. They are ugl
mlamouri (slow - plz ping) 2014/03/12 20:19:55 Done.
+ // third_party/WebKit/public/platform/WebScreenOrientation.h
+ private static final byte PORTRAIT_PRIMARY = 1 << 0;
+ private static final byte LANDSCAPE_PRIMARY = 1 << 1;
+ private static final byte PORTRAIT_SECONDARY = 1 << 2;
+ private static final byte LANDSCAPE_SECONDARY = 1 << 3;
+
+ private int getOrientationFromWebScreenOrientations(byte orientations) {
+ switch (orientations) {
+ case PORTRAIT_PRIMARY:
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ case PORTRAIT_SECONDARY:
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+ case LANDSCAPE_PRIMARY:
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ case LANDSCAPE_SECONDARY:
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+ case PORTRAIT_PRIMARY | PORTRAIT_SECONDARY:
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+ case LANDSCAPE_PRIMARY | LANDSCAPE_SECONDARY:
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
+ case PORTRAIT_PRIMARY | PORTRAIT_SECONDARY | LANDSCAPE_PRIMARY | LANDSCAPE_SECONDARY:
+ return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
+ default:
+ Log.w(TAG, "Trying to lock to unsupported orientation!");
+ return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+ }
+ }
+
+ @VisibleForTesting
+ @CalledByNative
+ static ScreenOrientationProvider create() {
+ return new ScreenOrientationProvider();
+ }
+
+ @CalledByNative
+ void lockOrientation(byte orientations) {
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
+ if (activity == null)
Michael van Ouwerkerk 2014/03/12 14:42:55 Braces please. http://source.android.com/source/co
mlamouri (slow - plz ping) 2014/03/12 20:19:55 Done.
+ return;
+
+ int orientation = getOrientationFromWebScreenOrientations(orientations);
+ if (orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
Michael van Ouwerkerk 2014/03/12 14:42:55 Braces.
mlamouri (slow - plz ping) 2014/03/12 20:19:55 Done.
+ return;
+
+ activity.setRequestedOrientation(orientation);
+ }
+
+ @CalledByNative
+ void unlockOrientation() {
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
+ if (activity == null)
Michael van Ouwerkerk 2014/03/12 14:42:55 And braces.
mlamouri (slow - plz ping) 2014/03/12 20:19:55 Done.
+ return;
+
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+ }
+
+ private ScreenOrientationProvider() {
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698