diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 557458adbe6f..54db507a49a9 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -84,6 +84,7 @@ import android.graphics.RectF; import android.graphics.SurfaceTexture; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.hardware.display.DisplayManager; import android.hardware.Sensor; import android.hardware.SensorEventListener; import android.hardware.SensorManager; @@ -110,6 +111,7 @@ import android.util.Base64; import android.util.DisplayMetrics; import android.util.Log; import android.view.ContextThemeWrapper; +import android.view.Display; import android.view.HapticFeedbackConstants; import android.view.Surface; import android.view.SurfaceView; @@ -2740,4 +2742,10 @@ public class GeckoAppShell } return 0; } + + @WrapForJNI + static Rect getScreenSize() { + Display disp = getGeckoInterface().getActivity().getWindowManager().getDefaultDisplay(); + return new Rect(0, 0, disp.getWidth(), disp.getHeight()); + } } diff --git a/widget/android/GeneratedJNIWrappers.cpp b/widget/android/GeneratedJNIWrappers.cpp index 21a967de8341..5b5c9aa444bf 100644 --- a/widget/android/GeneratedJNIWrappers.cpp +++ b/widget/android/GeneratedJNIWrappers.cpp @@ -393,6 +393,14 @@ auto GeckoAppShell::GetScreenOrientationWrapper() -> int16_t return mozilla::jni::Method::Call(nullptr, nullptr); } +constexpr char GeckoAppShell::GetScreenSize_t::name[]; +constexpr char GeckoAppShell::GetScreenSize_t::signature[]; + +auto GeckoAppShell::GetScreenSize() -> mozilla::jni::Object::LocalRef +{ + return mozilla::jni::Method::Call(nullptr, nullptr); +} + constexpr char GeckoAppShell::GetShowPasswordSetting_t::name[]; constexpr char GeckoAppShell::GetShowPasswordSetting_t::signature[]; diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index 2a0b340cd0cc..33517d8542bb 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -944,6 +944,23 @@ public: static auto GetScreenOrientationWrapper() -> int16_t; +public: + struct GetScreenSize_t { + typedef GeckoAppShell Owner; + typedef mozilla::jni::Object::LocalRef ReturnType; + typedef mozilla::jni::Object::Param SetterType; + typedef mozilla::jni::Args<> Args; + static constexpr char name[] = "getScreenSize"; + static constexpr char signature[] = + "()Landroid/graphics/Rect;"; + static const bool isStatic = true; + static const bool isMultithreaded = false; + static const mozilla::jni::ExceptionMode exceptionMode = + mozilla::jni::ExceptionMode::ABORT; + }; + + static auto GetScreenSize() -> mozilla::jni::Object::LocalRef; + public: struct GetShowPasswordSetting_t { typedef GeckoAppShell Owner; diff --git a/widget/android/bindings/AndroidRect-classes.txt b/widget/android/bindings/AndroidRect-classes.txt new file mode 100644 index 000000000000..cbacca81e1a4 --- /dev/null +++ b/widget/android/bindings/AndroidRect-classes.txt @@ -0,0 +1,2 @@ +android.graphics.Rect +android.graphics.RectF diff --git a/widget/android/bindings/Makefile.in b/widget/android/bindings/Makefile.in index c42ce48862d1..644c2e19688a 100644 --- a/widget/android/bindings/Makefile.in +++ b/widget/android/bindings/Makefile.in @@ -24,6 +24,7 @@ sdk_processor := \ # We'd like these to be defined in a future GENERATED_EXPORTS list. bindings_exports_FILES := \ + AndroidRect.h \ Bundle.h \ MediaCodec.h \ SurfaceTexture.h \ diff --git a/widget/android/bindings/moz.build b/widget/android/bindings/moz.build index 622e4f6394a6..a70bf79ac61a 100644 --- a/widget/android/bindings/moz.build +++ b/widget/android/bindings/moz.build @@ -7,9 +7,10 @@ # List of stems to generate .cpp and .h files for. To add a stem, add it to # this list and ensure that $(stem)-classes.txt exists in this directory. generated = [ + 'AndroidRect', 'Bundle', 'MediaCodec', - 'SurfaceTexture', + 'SurfaceTexture' ] SOURCES += ['!%s.cpp' % stem for stem in generated] diff --git a/widget/android/nsScreenManagerAndroid.cpp b/widget/android/nsScreenManagerAndroid.cpp index f7d0f67fd407..9a8b3651fe79 100644 --- a/widget/android/nsScreenManagerAndroid.cpp +++ b/widget/android/nsScreenManagerAndroid.cpp @@ -8,6 +8,9 @@ #include "nsScreenManagerAndroid.h" #include "nsWindow.h" #include "AndroidBridge.h" +#include "GeneratedJNIWrappers.h" +#include "AndroidRect.h" +#include using namespace mozilla; @@ -29,13 +32,11 @@ nsScreenAndroid::GetId(uint32_t *outId) NS_IMETHODIMP nsScreenAndroid::GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) { - gfx::IntSize sz = nsWindow::GetAndroidScreenBounds(); - - *outLeft = 0; - *outTop = 0; - - *outWidth = sz.width; - *outHeight = sz.height; + widget::sdk::Rect::LocalRef rect = widget::GeckoAppShell::GetScreenSize(); + rect->Left(outLeft); + rect->Top(outTop); + rect->Width(outWidth); + rect->Height(outHeight); return NS_OK; }