Bug 1476106 - Part 3 - Refresh ScreenManager data when detecting orientation change. r?snorp draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 02 Aug 2018 22:03:59 +0200
changeset 826054 1a2080d8481e54eef227661565eafd9976370c07
parent 826053 71ce68d97c381faa74c65fd35b2e48749f59bc9a
child 826055 2a79d5c368f8ed9eed268e2a1f46ddd8748b8b27
push id118234
push usermozilla@buttercookie.de
push dateThu, 02 Aug 2018 20:54:10 +0000
reviewerssnorp
bugs1476106
milestone63.0a1
Bug 1476106 - Part 3 - Refresh ScreenManager data when detecting orientation change. r?snorp MozReview-Commit-ID: JsY6sBCcOih
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
widget/android/ScreenHelperAndroid.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1825,18 +1825,21 @@ public class GeckoAppShell
             return 2;
         } else if (pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
             // 1 finger
             return 1;
         }
         return 0;
     }
 
-    public static synchronized void resetScreenSize() {
+    public static synchronized void refreshScreenInfo() {
         sScreenSize = null;
+        if (GeckoThread.isRunning()) {
+            ScreenManagerHelper.refreshScreenInfo();
+        }
     }
 
     @WrapForJNI(calledFrom = "gecko")
     private static synchronized Rect getScreenSize() {
         if (sScreenSize == null) {
             final WindowManager wm = (WindowManager)
                     getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
             final Display disp = wm.getDefaultDisplay();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -171,17 +171,17 @@ public class GeckoScreenOrientation {
 
             if (GeckoThread.isRunning()) {
                 onOrientationChange(aScreenOrientation.value, getAngle());
             } else {
                 GeckoThread.queueNativeCall(GeckoScreenOrientation.class, "onOrientationChange",
                                             aScreenOrientation.value, getAngle());
             }
         }
-        GeckoAppShell.resetScreenSize();
+        GeckoAppShell.refreshScreenInfo();
         return true;
     }
 
     /*
      * @return The Android orientation (Configuration.orientation).
      */
     public int getAndroidOrientation() {
         return screenOrientationToAndroidOrientation(getScreenOrientation());
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
@@ -13,16 +13,22 @@ class ScreenManagerHelper {
     /**
      * The following display types use the same definition in nsIScreen.idl
      */
     final static int DISPLAY_PRIMARY  = 0; // primary screen
     final static int DISPLAY_EXTERNAL = 1; // wired displays, such as HDMI, DisplayPort, etc.
     final static int DISPLAY_VIRTUAL  = 2; // wireless displays, such as Chromecast, WiFi-Display, etc.
 
     /**
+     * Refresh the cached screen information held by Gecko.
+     */
+    @WrapForJNI(dispatchTo = "gecko")
+    public native static void refreshScreenInfo();
+
+    /**
      * Add a new nsScreen when a new display in Android is available.
      *
      * @param displayType the display type of the nsScreen would be added
      * @param width       the width of the new nsScreen
      * @param height      the height of the new nsScreen
      * @param density     the density of the new nsScreen
      *
      * @return            return the ID of the added nsScreen
--- a/widget/android/ScreenHelperAndroid.cpp
+++ b/widget/android/ScreenHelperAndroid.cpp
@@ -20,16 +20,20 @@ using namespace mozilla::widget;
 static ScreenHelperAndroid* gHelper = nullptr;
 
 class ScreenHelperAndroid::ScreenHelperSupport final
     : public ScreenManagerHelper::Natives<ScreenHelperSupport>
 {
 public:
     typedef ScreenManagerHelper::Natives<ScreenHelperSupport> Base;
 
+    static void RefreshScreenInfo() {
+      gHelper->Refresh();
+    }
+
     static int32_t AddDisplay(int32_t aDisplayType, int32_t aWidth, int32_t aHeight, float aDensity) {
         static int32_t nextId = 1;
 
         int32_t screenId = nextId++;
         NS_DispatchToMainThread(NS_NewRunnableFunction(
             "ScreenHelperAndroid::ScreenHelperSupport::AddDisplay",
             [&aDisplayType, &aWidth, &aHeight, &aDensity, &screenId] {
                 MOZ_ASSERT(NS_IsMainThread());