mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 12:32:55 +00:00
Bug 1061372 - [2/2] Fix Gecko screen orientation to Android orientation mapping. r=snorp
--HG-- extra : rebase_source : 98040a219d8371404de0ce06d10b01fdda3bcf69
This commit is contained in:
parent
072041e7b0
commit
d76ca551ee
@ -28,8 +28,10 @@ public class GeckoScreenOrientation {
|
||||
NONE(0),
|
||||
PORTRAIT_PRIMARY(1 << 0),
|
||||
PORTRAIT_SECONDARY(1 << 1),
|
||||
PORTRAIT(PORTRAIT_PRIMARY.value | PORTRAIT_SECONDARY.value),
|
||||
LANDSCAPE_PRIMARY(1 << 2),
|
||||
LANDSCAPE_SECONDARY(1 << 3),
|
||||
LANDSCAPE(LANDSCAPE_PRIMARY.value | LANDSCAPE_SECONDARY.value),
|
||||
DEFAULT(1 << 4);
|
||||
|
||||
public final short value;
|
||||
@ -38,15 +40,15 @@ public class GeckoScreenOrientation {
|
||||
this.value = (short)value;
|
||||
}
|
||||
|
||||
public static ScreenOrientation get(short value) {
|
||||
switch (value) {
|
||||
case (1 << 0): return PORTRAIT_PRIMARY;
|
||||
case (1 << 1): return PORTRAIT_SECONDARY;
|
||||
case (1 << 2): return LANDSCAPE_PRIMARY;
|
||||
case (1 << 3): return LANDSCAPE_SECONDARY;
|
||||
case (1 << 4): return DEFAULT;
|
||||
default: return NONE;
|
||||
private final static ScreenOrientation[] sValues = ScreenOrientation.values();
|
||||
|
||||
public static ScreenOrientation get(int value) {
|
||||
for (ScreenOrientation orient: sValues) {
|
||||
if (orient.value == value) {
|
||||
return orient;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +145,14 @@ public class GeckoScreenOrientation {
|
||||
mScreenOrientation = aScreenOrientation;
|
||||
Log.d(LOGTAG, "updating to new orientation " + mScreenOrientation);
|
||||
if (mShouldNotify) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenOrientationEvent(mScreenOrientation.value));
|
||||
// Gecko expects a definite screen orientation, so we default to the
|
||||
// primary orientations.
|
||||
if (aScreenOrientation == ScreenOrientation.PORTRAIT) {
|
||||
aScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
|
||||
} else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
|
||||
aScreenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
|
||||
}
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenOrientationEvent(aScreenOrientation.value));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -164,14 +173,13 @@ public class GeckoScreenOrientation {
|
||||
}
|
||||
|
||||
/*
|
||||
* Lock screen orientation given the Android orientation.
|
||||
* Retrieve rotation via GeckoAppShell.
|
||||
* Lock screen orientation given the Gecko screen orientation.
|
||||
*
|
||||
* @param aAndroidOrientation
|
||||
* The Android orientation provided by Configuration.orientation.
|
||||
* @param aGeckoOrientation
|
||||
* The Gecko orientation provided.
|
||||
*/
|
||||
public void lock(int aAndroidOrientation) {
|
||||
lock(getScreenOrientation(aAndroidOrientation, getRotation()));
|
||||
public void lock(int aGeckoOrientation) {
|
||||
lock(ScreenOrientation.get(aGeckoOrientation));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -300,9 +308,9 @@ public class GeckoScreenOrientation {
|
||||
public static ScreenOrientation screenOrientationFromString(String aStr) {
|
||||
switch (aStr) {
|
||||
case "portrait":
|
||||
return ScreenOrientation.PORTRAIT_PRIMARY;
|
||||
return ScreenOrientation.PORTRAIT;
|
||||
case "landscape":
|
||||
return ScreenOrientation.LANDSCAPE_PRIMARY;
|
||||
return ScreenOrientation.LANDSCAPE;
|
||||
case "portrait-primary":
|
||||
return ScreenOrientation.PORTRAIT_PRIMARY;
|
||||
case "portrait-secondary":
|
||||
@ -313,7 +321,7 @@ public class GeckoScreenOrientation {
|
||||
return ScreenOrientation.LANDSCAPE_SECONDARY;
|
||||
}
|
||||
|
||||
Log.w(LOGTAG, "screenOrientationFromString: unknown orientation string");
|
||||
Log.w(LOGTAG, "screenOrientationFromString: unknown orientation string: " + aStr);
|
||||
return DEFAULT_SCREEN_ORIENTATION;
|
||||
}
|
||||
|
||||
@ -328,9 +336,11 @@ public class GeckoScreenOrientation {
|
||||
*/
|
||||
public static int screenOrientationToAndroidOrientation(ScreenOrientation aScreenOrientation) {
|
||||
switch (aScreenOrientation) {
|
||||
case PORTRAIT:
|
||||
case PORTRAIT_PRIMARY:
|
||||
case PORTRAIT_SECONDARY:
|
||||
return Configuration.ORIENTATION_PORTRAIT;
|
||||
case LANDSCAPE:
|
||||
case LANDSCAPE_PRIMARY:
|
||||
case LANDSCAPE_SECONDARY:
|
||||
return Configuration.ORIENTATION_LANDSCAPE;
|
||||
@ -354,10 +364,12 @@ public class GeckoScreenOrientation {
|
||||
*/
|
||||
public static int screenOrientationToActivityInfoOrientation(ScreenOrientation aScreenOrientation) {
|
||||
switch (aScreenOrientation) {
|
||||
case PORTRAIT:
|
||||
case PORTRAIT_PRIMARY:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
case PORTRAIT_SECONDARY:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
case LANDSCAPE:
|
||||
case LANDSCAPE_PRIMARY:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
case LANDSCAPE_SECONDARY:
|
||||
|
Loading…
x
Reference in New Issue
Block a user