Bug 787534 - Remove Portrait and Landscape special ScreenOrientation values. r=jlebar
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 19 Sep 2012 17:28:16 +0100
changeset 107623 6125b883672b249e580995f2bc931c965a65580e
parent 107622 bf856d54786519dd3f926a073ed011ec890594c1
child 107624 7e429f993a1ebeed705d04db1bfd284bc880fcb6
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjlebar
bugs787534
milestone18.0a1
Bug 787534 - Remove Portrait and Landscape special ScreenOrientation values. r=jlebar
dom/base/ScreenOrientation.h
dom/base/nsScreen.cpp
dom/plugins/base/android/ANPWindow.cpp
embedding/android/GeckoScreenOrientationListener.java
hal/android/AndroidHal.cpp
mobile/android/base/GeckoScreenOrientationListener.java
widget/gonk/OrientationObserver.cpp
widget/gonk/OrientationObserver.h
--- a/dom/base/ScreenOrientation.h
+++ b/dom/base/ScreenOrientation.h
@@ -11,19 +11,17 @@ namespace mozilla {
 namespace dom {
 
 // Make sure that any change here is also made in
 // * mobile/android/base/GeckoScreenOrientationListener.java
 // * embedding/android/GeckoScreenOrientationListener.java
 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
 
 #endif // mozilla_dom_ScreenOrientation_h
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -271,19 +271,20 @@ nsScreen::GetAvailRect(nsRect& aRect)
 }
 
 void
 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) {
     // TODO: use an helper method, see bug 720768.
     nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nullptr, nullptr);
     nsresult rv = event->InitEvent(NS_LITERAL_STRING("mozorientationchange"), false, false);
     if (NS_FAILED(rv)) {
       return;
@@ -301,33 +302,32 @@ nsScreen::Notify(const hal::ScreenConfig
     }
   }
 }
 
 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;
     case eScreenOrientation_PortraitSecondary:
       aOrientation.AssignLiteral("portrait-secondary");
       break;
     case eScreenOrientation_LandscapePrimary:
       aOrientation.AssignLiteral("landscape-primary");
       break;
     case eScreenOrientation_LandscapeSecondary:
       aOrientation.AssignLiteral("landscape-secondary");
       break;
+    case eScreenOrientation_None:
+    default:
+      MOZ_ASSERT(false);
+      return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsScreen::LockPermission
 nsScreen::GetLockOrientationPermission() const
 {
@@ -401,23 +401,25 @@ nsScreen::MozLockOrientation(const jsval
   }
 
   ScreenOrientation orientation = eScreenOrientation_None;
 
   for (uint32_t i=0; i<orientations.Length(); ++i) {
     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")) {
       orientation |= eScreenOrientation_LandscapeSecondary;
     } else {
       // If we don't recognize that the token, we should just return 'false'
       // without throwing.
       return NS_OK;
--- a/dom/plugins/base/android/ANPWindow.cpp
+++ b/dom/plugins/base/android/ANPWindow.cpp
@@ -115,20 +115,22 @@ void anp_window_requestFullScreenOrienta
   switch (orientation) {
     case kFixedLandscape_ANPScreenOrientation:
       newOrientation = eScreenOrientation_LandscapePrimary;
       break;
     case kFixedPortrait_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;
       break;
   }
 
   nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
   pinst->SetFullScreenOrientation(newOrientation);
--- a/embedding/android/GeckoScreenOrientationListener.java
+++ b/embedding/android/GeckoScreenOrientationListener.java
@@ -24,22 +24,20 @@ public class GeckoScreenOrientationListe
       GeckoScreenOrientationListener.getInstance().updateScreenOrientation();
     }
   }
 
   static private GeckoScreenOrientationListener sInstance = null;
 
   // 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;
 
   // Whether the listener should be listening to changes.
   private boolean mShouldBeListening = false;
   // Whether the listener should notify Gecko that a change happened.
   private boolean mShouldNotify      = false;
@@ -131,26 +129,26 @@ public class GeckoScreenOrientationListe
 
     switch (aOrientation) {
       case eScreenOrientation_PortraitPrimary:
         orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
         break;
       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:
         orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
         break;
       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:
         Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
     }
 
     GeckoApp.mAppContext.setRequestedOrientation(orientation);
     updateScreenOrientation();
--- a/hal/android/AndroidHal.cpp
+++ b/hal/android/AndroidHal.cpp
@@ -184,20 +184,20 @@ LockScreenOrientation(const ScreenOrient
   if (!bridge) {
     return false;
   }
 
   switch (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:
       return false;
   }
 }
 
 void
--- a/mobile/android/base/GeckoScreenOrientationListener.java
+++ b/mobile/android/base/GeckoScreenOrientationListener.java
@@ -26,22 +26,20 @@ public class GeckoScreenOrientationListe
             GeckoScreenOrientationListener.getInstance().updateScreenOrientation();
         }
     }
 
     static private GeckoScreenOrientationListener sInstance = null;
 
     // 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;
 
     private short mOrientation;
     private OrientationEventListenerImpl mListener = null;
 
     // Whether the listener should be listening to changes.
     private boolean mShouldBeListening = false;
@@ -173,26 +171,26 @@ public class GeckoScreenOrientationListe
 
         switch (aOrientation) {
         case eScreenOrientation_PortraitPrimary:
             orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
             break;
         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:
             orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
             break;
         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:
             Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
             return;
         }
 
         GeckoApp.mAppContext.setRequestedOrientation(orientation);
--- a/widget/gonk/OrientationObserver.cpp
+++ b/widget/gonk/OrientationObserver.cpp
@@ -32,20 +32,20 @@ namespace {
 struct OrientationMapping {
   uint32_t mScreenRotation;
   ScreenOrientation mDomOrientation;
 };
 
 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;
 const static int sDefaultPortrait = 0;
 
 static uint32_t sOrientationOffset = 0;
 
 static already_AddRefed<nsIScreen>
@@ -285,18 +285,20 @@ OrientationObserver::LockScreenOrientati
 {
   MOZ_ASSERT(aOrientation | (eScreenOrientation_PortraitPrimary |
                              eScreenOrientation_PortraitSecondary |
                              eScreenOrientation_LandscapePrimary |
                              eScreenOrientation_LandscapeSecondary));
 
   // 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();
     }
   } else if (mAutoOrientationEnabled) {
     DisableAutoOrientation();
   }
 
   mAllowedOrientations = aOrientation;
--- a/widget/gonk/OrientationObserver.h
+++ b/widget/gonk/OrientationObserver.h
@@ -57,13 +57,15 @@ public:
 private:
   bool mAutoOrientationEnabled;
   PRTime mLastUpdate;
   uint32_t mAllowedOrientations;
 
   // 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