Bug 787534 - Update the Gonk backend to take into account the new screen lock orientations values. r=mwu
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 18 Sep 2012 19:39:59 +0100
changeset 107495 7e429f993a1ebeed705d04db1bfd284bc880fcb6
parent 107494 6125b883672b249e580995f2bc931c965a65580e
child 107496 8e7d9794e8356c46525ee639cb83257211ee1897
push id15072
push usermlamouri@mozilla.com
push dateWed, 19 Sep 2012 17:30:28 +0000
treeherdermozilla-inbound@7e429f993a1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs787534
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 787534 - Update the Gonk backend to take into account the new screen lock orientations values. r=mwu
widget/gonk/OrientationObserver.cpp
--- a/widget/gonk/OrientationObserver.cpp
+++ b/widget/gonk/OrientationObserver.cpp
@@ -32,23 +32,21 @@ 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_PortraitPrimary | eScreenOrientation_PortraitSecondary},
   {nsIScreen::ROTATION_90_DEG,  eScreenOrientation_LandscapePrimary},
   {nsIScreen::ROTATION_270_DEG, eScreenOrientation_LandscapeSecondary},
-  {nsIScreen::ROTATION_90_DEG,  eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary}
 };
 
-const static int sDefaultLandscape = 3;
+const static int sDefaultLandscape = 2;
 const static int sDefaultPortrait = 0;
 
 static uint32_t sOrientationOffset = 0;
 
 static already_AddRefed<nsIScreen>
 GetPrimaryScreen()
 {
   nsCOMPtr<nsIScreenManager> screenMgr =
@@ -104,17 +102,17 @@ DetectDefaultOrientation()
  *        dom::eScreenOrientation_PortraitPrimary.
  * @param aResult output nsIScreen rotation e.g. nsIScreen::ROTATION_0_DEG.
  * @return NS_OK on success. NS_ILLEGAL_VALUE on failure.
  */
 static nsresult
 ConvertToScreenRotation(ScreenOrientation aOrientation, uint32_t *aResult)
 {
   for (int i = 0; i < ArrayLength(sOrientationMappings); i++) {
-    if (aOrientation == sOrientationMappings[i].mDomOrientation) {
+    if (aOrientation & sOrientationMappings[i].mDomOrientation) {
       // Shift the mappings in sOrientationMappings so devices with default
       // landscape orientation map landscape-primary to 0 degree and so forth.
       int adjusted = (i + sOrientationOffset) %
                      ArrayLength(sOrientationMappings);
       *aResult = sOrientationMappings[adjusted].mScreenRotation;
       return NS_OK;
     }
   }
@@ -283,22 +281,22 @@ OrientationObserver::DisableAutoOrientat
 bool
 OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation)
 {
   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_LandscapePrimary |
-                       eScreenOrientation_LandscapeSecondary) ||
-      aOrientation == (eScreenOrientation_PortraitPrimary |
-                       eScreenOrientation_PortraitSecondary)) {
+  // If there are multiple orientations allowed, we should enable the
+  // auto-rotation.
+  if (aOrientation != eScreenOrientation_LandscapePrimary &&
+      aOrientation != eScreenOrientation_LandscapeSecondary &&
+      aOrientation != eScreenOrientation_PortraitPrimary &&
+      aOrientation != eScreenOrientation_PortraitSecondary) {
     if (!mAutoOrientationEnabled) {
       EnableAutoOrientation();
     }
   } else if (mAutoOrientationEnabled) {
     DisableAutoOrientation();
   }
 
   mAllowedOrientations = aOrientation;