From 4a90f2279e2643a36559c23868fb9d0f607fc34f Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Wed, 19 Sep 2012 17:28:16 +0100 Subject: [PATCH] Bug 787534 - Remove Portrait and Landscape special ScreenOrientation values. r=jlebar --- dom/base/ScreenOrientation.h | 10 ++++----- dom/base/nsScreen.cpp | 22 ++++++++++--------- dom/plugins/base/android/ANPWindow.cpp | 6 +++-- .../GeckoScreenOrientationListener.java | 14 +++++------- hal/android/AndroidHal.cpp | 4 ++-- .../base/GeckoScreenOrientationListener.java | 14 +++++------- widget/gonk/OrientationObserver.cpp | 10 +++++---- widget/gonk/OrientationObserver.h | 6 +++-- 8 files changed, 44 insertions(+), 42 deletions(-) diff --git a/dom/base/ScreenOrientation.h b/dom/base/ScreenOrientation.h index 394579523be..6f06400505b 100644 --- a/dom/base/ScreenOrientation.h +++ b/dom/base/ScreenOrientation.h @@ -16,12 +16,10 @@ namespace dom { typedef uint32_t ScreenOrientation; static const ScreenOrientation eScreenOrientation_None = 0; -static const ScreenOrientation eScreenOrientation_PortraitPrimary = 1; // 00000001 -static const ScreenOrientation eScreenOrientation_PortraitSecondary = 2; // 00000010 -static const ScreenOrientation eScreenOrientation_Portrait = 3; // 00000011 -static const ScreenOrientation eScreenOrientation_LandscapePrimary = 4; // 00000100 -static const ScreenOrientation eScreenOrientation_LandscapeSecondary = 8; // 00001000 -static const ScreenOrientation eScreenOrientation_Landscape = 12; // 00001100 +static const ScreenOrientation eScreenOrientation_PortraitPrimary = PR_BIT(0); +static const ScreenOrientation eScreenOrientation_PortraitSecondary = PR_BIT(1); +static const ScreenOrientation eScreenOrientation_LandscapePrimary = PR_BIT(2); +static const ScreenOrientation eScreenOrientation_LandscapeSecondary = PR_BIT(3); } // namespace dom } // namespace mozilla diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index 787cb9537ac..e8554b7bc55 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -276,9 +276,10 @@ nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration) ScreenOrientation previousOrientation = mOrientation; mOrientation = aConfiguration.orientation(); - NS_ASSERTION(mOrientation != eScreenOrientation_None && - mOrientation != eScreenOrientation_Portrait && - mOrientation != eScreenOrientation_Landscape, + NS_ASSERTION(mOrientation == eScreenOrientation_PortraitPrimary || + mOrientation == eScreenOrientation_PortraitSecondary || + mOrientation == eScreenOrientation_LandscapePrimary || + mOrientation == eScreenOrientation_LandscapeSecondary, "Invalid orientation value passed to notify method!"); if (mOrientation != previousOrientation) { @@ -306,11 +307,6 @@ NS_IMETHODIMP nsScreen::GetMozOrientation(nsAString& aOrientation) { switch (mOrientation) { - case eScreenOrientation_None: - case eScreenOrientation_Portrait: - case eScreenOrientation_Landscape: - NS_ASSERTION(false, "Shouldn't be used when getting value!"); - return NS_ERROR_FAILURE; case eScreenOrientation_PortraitPrimary: aOrientation.AssignLiteral("portrait-primary"); break; @@ -323,6 +319,10 @@ nsScreen::GetMozOrientation(nsAString& aOrientation) case eScreenOrientation_LandscapeSecondary: aOrientation.AssignLiteral("landscape-secondary"); break; + case eScreenOrientation_None: + default: + MOZ_ASSERT(false); + return NS_ERROR_FAILURE; } return NS_OK; @@ -406,13 +406,15 @@ nsScreen::MozLockOrientation(const jsval& aOrientation, JSContext* aCx, bool* aR nsString& item = orientations[i]; if (item.EqualsLiteral("portrait")) { - orientation |= eScreenOrientation_Portrait; + orientation |= eScreenOrientation_PortraitPrimary | + eScreenOrientation_PortraitSecondary; } else if (item.EqualsLiteral("portrait-primary")) { orientation |= eScreenOrientation_PortraitPrimary; } else if (item.EqualsLiteral("portrait-secondary")) { orientation |= eScreenOrientation_PortraitSecondary; } else if (item.EqualsLiteral("landscape")) { - orientation |= eScreenOrientation_Landscape; + orientation |= eScreenOrientation_LandscapePrimary | + eScreenOrientation_LandscapeSecondary; } else if (item.EqualsLiteral("landscape-primary")) { orientation |= eScreenOrientation_LandscapePrimary; } else if (item.EqualsLiteral("landscape-secondary")) { diff --git a/dom/plugins/base/android/ANPWindow.cpp b/dom/plugins/base/android/ANPWindow.cpp index cfb20301897..8fc7a90af50 100644 --- a/dom/plugins/base/android/ANPWindow.cpp +++ b/dom/plugins/base/android/ANPWindow.cpp @@ -120,10 +120,12 @@ void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation newOrientation = eScreenOrientation_PortraitPrimary; break; case kLandscape_ANPScreenOrientation: - newOrientation = eScreenOrientation_Landscape; + newOrientation = eScreenOrientation_LandscapePrimary | + eScreenOrientation_LandscapeSecondary; break; case kPortrait_ANPScreenOrientation: - newOrientation = eScreenOrientation_Portrait; + newOrientation = eScreenOrientation_PortraitPrimary | + eScreenOrientation_PortraitSecondary; break; default: newOrientation = eScreenOrientation_None; diff --git a/embedding/android/GeckoScreenOrientationListener.java b/embedding/android/GeckoScreenOrientationListener.java index 0bcbb96127f..53d52180cd5 100644 --- a/embedding/android/GeckoScreenOrientationListener.java +++ b/embedding/android/GeckoScreenOrientationListener.java @@ -29,12 +29,10 @@ public class GeckoScreenOrientationListener // Make sure that any change in dom/base/ScreenOrientation.h happens here too. static public final short eScreenOrientation_None = 0; - static public final short eScreenOrientation_PortraitPrimary = 1; - static public final short eScreenOrientation_PortraitSecondary = 2; - static public final short eScreenOrientation_Portrait = 3; - static public final short eScreenOrientation_LandscapePrimary = 4; - static public final short eScreenOrientation_LandscapeSecondary = 8; - static public final short eScreenOrientation_Landscape = 12; + static public final short eScreenOrientation_PortraitPrimary = 1; // PR_BIT(0) + static public final short eScreenOrientation_PortraitSecondary = 2; // PR_BIT(1) + static public final short eScreenOrientation_LandscapePrimary = 4; // PR_BIT(2) + static public final short eScreenOrientation_LandscapeSecondary = 8; // PR_BIT(3) private short mOrientation; private OrientationEventListenerImpl mListener = null; @@ -136,7 +134,7 @@ public class GeckoScreenOrientationListener case eScreenOrientation_PortraitSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; - case eScreenOrientation_Portrait: + case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; break; case eScreenOrientation_LandscapePrimary: @@ -145,7 +143,7 @@ public class GeckoScreenOrientationListener case eScreenOrientation_LandscapeSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; - case eScreenOrientation_Landscape: + case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; break; default: diff --git a/hal/android/AndroidHal.cpp b/hal/android/AndroidHal.cpp index 3ecfd70a9d4..a44daba3d86 100644 --- a/hal/android/AndroidHal.cpp +++ b/hal/android/AndroidHal.cpp @@ -189,10 +189,10 @@ LockScreenOrientation(const ScreenOrientation& aOrientation) // The Android backend only supports these orientations. case eScreenOrientation_PortraitPrimary: case eScreenOrientation_PortraitSecondary: - case eScreenOrientation_Portrait: + case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary: case eScreenOrientation_LandscapePrimary: case eScreenOrientation_LandscapeSecondary: - case eScreenOrientation_Landscape: + case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary: bridge->LockScreenOrientation(aOrientation); return true; default: diff --git a/mobile/android/base/GeckoScreenOrientationListener.java b/mobile/android/base/GeckoScreenOrientationListener.java index 0e0a47f7601..2187a231c93 100644 --- a/mobile/android/base/GeckoScreenOrientationListener.java +++ b/mobile/android/base/GeckoScreenOrientationListener.java @@ -31,12 +31,10 @@ public class GeckoScreenOrientationListener { // Make sure that any change in dom/base/ScreenOrientation.h happens here too. static public final short eScreenOrientation_None = 0; - static public final short eScreenOrientation_PortraitPrimary = 1; - static public final short eScreenOrientation_PortraitSecondary = 2; - static public final short eScreenOrientation_Portrait = 3; - static public final short eScreenOrientation_LandscapePrimary = 4; - static public final short eScreenOrientation_LandscapeSecondary = 8; - static public final short eScreenOrientation_Landscape = 12; + static public final short eScreenOrientation_PortraitPrimary = 1; // PR_BIT(0) + static public final short eScreenOrientation_PortraitSecondary = 2; // PR_BIT(1) + static public final short eScreenOrientation_LandscapePrimary = 4; // PR_BIT(2) + static public final short eScreenOrientation_LandscapeSecondary = 8; // PR_BIT(3) static private final short DEFAULT_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @@ -178,7 +176,7 @@ public class GeckoScreenOrientationListener { case eScreenOrientation_PortraitSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; - case eScreenOrientation_Portrait: + case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; break; case eScreenOrientation_LandscapePrimary: @@ -187,7 +185,7 @@ public class GeckoScreenOrientationListener { case eScreenOrientation_LandscapeSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; - case eScreenOrientation_Landscape: + case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary: orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; break; default: diff --git a/widget/gonk/OrientationObserver.cpp b/widget/gonk/OrientationObserver.cpp index ab808e2227e..873f0862d40 100644 --- a/widget/gonk/OrientationObserver.cpp +++ b/widget/gonk/OrientationObserver.cpp @@ -37,10 +37,10 @@ struct OrientationMapping { static OrientationMapping sOrientationMappings[] = { {nsIScreen::ROTATION_0_DEG, eScreenOrientation_PortraitPrimary}, {nsIScreen::ROTATION_180_DEG, eScreenOrientation_PortraitSecondary}, - {nsIScreen::ROTATION_0_DEG, eScreenOrientation_Portrait}, + {nsIScreen::ROTATION_0_DEG, eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary}, {nsIScreen::ROTATION_90_DEG, eScreenOrientation_LandscapePrimary}, {nsIScreen::ROTATION_270_DEG, eScreenOrientation_LandscapeSecondary}, - {nsIScreen::ROTATION_90_DEG, eScreenOrientation_Landscape} + {nsIScreen::ROTATION_90_DEG, eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary} }; const static int sDefaultLandscape = 3; @@ -290,8 +290,10 @@ OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation) // Enable/disable the observer depending on 1. multiple orientations // allowed, and 2. observer enabled. - if (aOrientation == eScreenOrientation_Landscape || - aOrientation == eScreenOrientation_Portrait) { + if (aOrientation == (eScreenOrientation_LandscapePrimary | + eScreenOrientation_LandscapeSecondary) || + aOrientation == (eScreenOrientation_PortraitPrimary | + eScreenOrientation_PortraitSecondary)) { if (!mAutoOrientationEnabled) { EnableAutoOrientation(); } diff --git a/widget/gonk/OrientationObserver.h b/widget/gonk/OrientationObserver.h index 3e43b405f13..9426c353239 100644 --- a/widget/gonk/OrientationObserver.h +++ b/widget/gonk/OrientationObserver.h @@ -62,8 +62,10 @@ private: // 200 ms, the latency which is barely perceptible by human. static const PRTime sMinUpdateInterval = 200 * PR_USEC_PER_MSEC; static const uint32_t sDefaultOrientations = - mozilla::dom::eScreenOrientation_Portrait | - mozilla::dom::eScreenOrientation_Landscape; + mozilla::dom::eScreenOrientation_PortraitPrimary | + mozilla::dom::eScreenOrientation_PortraitSecondary | + mozilla::dom::eScreenOrientation_LandscapePrimary | + mozilla::dom::eScreenOrientation_LandscapeSecondary; }; #endif