Bug 908058 - Add orientation keyword 'default' to express normal orientation. r=mounir, r=blassey, a=koi+
authorViral Wang <vwang@mozilla.com>
Mon, 30 Sep 2013 10:40:41 -0400
changeset 155602 5721fe0d5284a2eae80212bf23331fc866a643ca
parent 155601 a7c7fa46bd9e1093ec2d11e39cf374be218571cc
child 155603 0ce69d7707783219b3a2efccb6aa3d5be1a598b6
push id4331
push userryanvm@gmail.com
push dateMon, 30 Sep 2013 21:52:55 +0000
treeherdermozilla-aurora@23aa697cf2a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir, blassey, koi
bugs908058
milestone26.0a2
Bug 908058 - Add orientation keyword 'default' to express normal orientation. r=mounir, r=blassey, a=koi+
dom/base/ScreenOrientation.h
dom/base/nsScreen.cpp
hal/android/AndroidHal.cpp
mobile/android/base/GeckoScreenOrientationListener.java
widget/gonk/OrientationObserver.cpp
--- a/dom/base/ScreenOrientation.h
+++ b/dom/base/ScreenOrientation.h
@@ -12,13 +12,16 @@ namespace dom {
 // * mobile/android/base/GeckoScreenOrientationListener.java
 typedef uint32_t ScreenOrientation;
 
 static const ScreenOrientation eScreenOrientation_None               = 0;
 static const ScreenOrientation eScreenOrientation_PortraitPrimary    = 1u << 0;
 static const ScreenOrientation eScreenOrientation_PortraitSecondary  = 1u << 1;
 static const ScreenOrientation eScreenOrientation_LandscapePrimary   = 1u << 2;
 static const ScreenOrientation eScreenOrientation_LandscapeSecondary = 1u << 3;
+//eScreenOrientation_Default will use the natural orientation for the deivce,
+//it could be PortraitPrimary or LandscapePrimary depends on display resolution
+static const ScreenOrientation eScreenOrientation_Default            = 1u << 4;
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ScreenOrientation_h
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -325,16 +325,18 @@ nsScreen::MozLockOrientation(const Seque
       orientation |= eScreenOrientation_PortraitSecondary;
     } else if (item.EqualsLiteral("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 (item.EqualsLiteral("default")) {
+      orientation |= eScreenOrientation_Default;
     } else {
       // If we don't recognize the token, we should just return 'false'
       // without throwing.
       return false;
     }
   }
 
   switch (GetLockOrientationPermission()) {
--- a/hal/android/AndroidHal.cpp
+++ b/hal/android/AndroidHal.cpp
@@ -188,16 +188,17 @@ LockScreenOrientation(const ScreenOrient
   switch (aOrientation) {
     // The Android backend only supports these orientations.
     case eScreenOrientation_PortraitPrimary:
     case eScreenOrientation_PortraitSecondary:
     case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
     case eScreenOrientation_LandscapePrimary:
     case eScreenOrientation_LandscapeSecondary:
     case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
+    case eScreenOrientation_Default:
       bridge->LockScreenOrientation(aOrientation);
       return true;
     default:
       return false;
   }
 }
 
 void
--- a/mobile/android/base/GeckoScreenOrientationListener.java
+++ b/mobile/android/base/GeckoScreenOrientationListener.java
@@ -32,16 +32,17 @@ public class GeckoScreenOrientationListe
     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; // 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 public final short eScreenOrientation_Default            = 16;// PR_BIT(4)
 
     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;
@@ -194,16 +195,19 @@ public class GeckoScreenOrientationListe
             orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
             break;
         case eScreenOrientation_LandscapeSecondary:
             orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
             break;
         case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
             orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
             break;
+        case eScreenOrientation_Default:
+            orientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
+            break;
         default:
             Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
             return;
         }
 	if (GeckoAppShell.getContext() instanceof Activity)
 	  ((Activity)GeckoAppShell.getContext()).setRequestedOrientation(orientation);
         updateScreenOrientation();
     }
--- a/widget/gonk/OrientationObserver.cpp
+++ b/widget/gonk/OrientationObserver.cpp
@@ -258,17 +258,24 @@ OrientationObserver::DisableAutoOrientat
 }
 
 bool
 OrientationObserver::LockScreenOrientation(ScreenOrientation aOrientation)
 {
   MOZ_ASSERT(aOrientation | (eScreenOrientation_PortraitPrimary |
                              eScreenOrientation_PortraitSecondary |
                              eScreenOrientation_LandscapePrimary |
-                             eScreenOrientation_LandscapeSecondary));
+                             eScreenOrientation_LandscapeSecondary |
+                             eScreenOrientation_Default));
+
+  if (aOrientation == eScreenOrientation_Default) {
+    aOrientation = (sOrientationOffset == sDefaultPortrait) ?
+                    eScreenOrientation_PortraitPrimary :
+                    eScreenOrientation_LandscapePrimary;
+  }
 
   // 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) {