From 6e7f3aff6ac8ada695db09a4bae8d5bb2ff4e1c4 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 7 Jan 2020 15:41:07 +0000 Subject: [PATCH] Bug 1607124 - Query system colors in child processes directly. r=geckoview-reviewers,snorp Using LookAndFeelInt to query system colors is awkward, it's normally used for eIntID_XX values. Differential Revision: https://phabricator.services.mozilla.com/D58744 --HG-- extra : moz-landing-system : lando --- widget/android/AndroidBridge.cpp | 29 -------- widget/android/AndroidBridge.h | 2 - widget/android/nsLookAndFeel.cpp | 112 ++++++++----------------------- widget/android/nsLookAndFeel.h | 3 - 4 files changed, 28 insertions(+), 118 deletions(-) diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index a05559120bd3..3fc0b9fdb546 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -369,35 +369,6 @@ void AndroidBridge::Vibrate(const nsTArray& aPattern) { -1 /* don't repeat */); } -void AndroidBridge::GetSystemColors(AndroidSystemColors* aColors) { - NS_ASSERTION(aColors != nullptr, - "AndroidBridge::GetSystemColors: aColors is null!"); - if (!aColors) return; - - auto arr = GeckoAppShell::GetSystemColors(); - if (!arr) return; - - JNIEnv* const env = arr.Env(); - uint32_t len = static_cast(env->GetArrayLength(arr.Get())); - jint* elements = env->GetIntArrayElements(arr.Get(), 0); - - uint32_t colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor); - if (len < colorsCount) colorsCount = len; - - // Convert Android colors to nscolor by switching R and B in the ARGB 32 bit - // value - nscolor* colors = (nscolor*)aColors; - - for (uint32_t i = 0; i < colorsCount; i++) { - uint32_t androidColor = static_cast(elements[i]); - uint8_t r = (androidColor & 0x00ff0000) >> 16; - uint8_t b = (androidColor & 0x000000ff); - colors[i] = (androidColor & 0xff00ff00) | (b << 16) | r; - } - - env->ReleaseIntArrayElements(arr.Get(), elements, 0); -} - void AndroidBridge::GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t* const aBuf) { diff --git a/widget/android/AndroidBridge.h b/widget/android/AndroidBridge.h index 0a1437f8a44c..9c63845a4a83 100644 --- a/widget/android/AndroidBridge.h +++ b/widget/android/AndroidBridge.h @@ -119,8 +119,6 @@ class AndroidBridge final { void Vibrate(const nsTArray& aPattern); - void GetSystemColors(AndroidSystemColors* aColors); - void GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t* const aBuf); diff --git a/widget/android/nsLookAndFeel.cpp b/widget/android/nsLookAndFeel.cpp index 9393b2a62887..0e4c19349eaa 100644 --- a/widget/android/nsLookAndFeel.cpp +++ b/widget/android/nsLookAndFeel.cpp @@ -36,9 +36,34 @@ nsLookAndFeel::~nsLookAndFeel() {} #define RED_COLOR NS_RGB(0xff, 0x00, 0x00) nsresult nsLookAndFeel::GetSystemColors() { - if (!AndroidBridge::Bridge()) return NS_ERROR_FAILURE; + if (!jni::IsAvailable()) { + return NS_ERROR_FAILURE; + } - AndroidBridge::Bridge()->GetSystemColors(&mSystemColors); + auto arr = java::GeckoAppShell::GetSystemColors(); + if (!arr) { + return NS_ERROR_FAILURE; + } + + JNIEnv* const env = arr.Env(); + uint32_t len = static_cast(env->GetArrayLength(arr.Get())); + jint* elements = env->GetIntArrayElements(arr.Get(), 0); + + uint32_t colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor); + if (len < colorsCount) colorsCount = len; + + // Convert Android colors to nscolor by switching R and B in the ARGB 32 bit + // value + nscolor* colors = (nscolor*)&mSystemColors; + + for (uint32_t i = 0; i < colorsCount; i++) { + uint32_t androidColor = static_cast(elements[i]); + uint8_t r = (androidColor & 0x00ff0000) >> 16; + uint8_t b = (androidColor & 0x000000ff); + colors[i] = (androidColor & 0xff00ff00) | (b << 16) | r; + } + + env->ReleaseIntArrayElements(arr.Get(), elements, 0); return NS_OK; } @@ -472,11 +497,7 @@ char16_t nsLookAndFeel::GetPasswordCharacterImpl() { void nsLookAndFeel::EnsureInitSystemColors() { if (!mInitializedSystemColors) { - if (XRE_IsParentProcess()) { - nsresult rv = GetSystemColors(); - mInitializedSystemColors = NS_SUCCEEDED(rv); - } - // Child process will set system color cache from ContentParent. + mInitializedSystemColors = NS_SUCCEEDED(GetSystemColors()); } } @@ -492,80 +513,3 @@ void nsLookAndFeel::EnsureInitShowPassword() { } } -nsTArray nsLookAndFeel::GetIntCacheImpl() { - MOZ_ASSERT(XRE_IsParentProcess()); - EnsureInitSystemColors(); - MOZ_ASSERT(mInitializedSystemColors); - - nsTArray lookAndFeelCache = - nsXPLookAndFeel::GetIntCacheImpl(); - lookAndFeelCache.SetCapacity(sizeof(AndroidSystemColors) / sizeof(nscolor)); - - LookAndFeelInt laf; - laf.id = int32_t(ColorID::WindowForeground); - laf.colorValue = mSystemColors.textColorPrimary; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::WidgetBackground); - laf.colorValue = mSystemColors.colorBackground; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::WidgetForeground); - laf.colorValue = mSystemColors.colorForeground; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::WidgetSelectBackground); - laf.colorValue = mSystemColors.textColorHighlight; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::WidgetSelectForeground); - laf.colorValue = mSystemColors.textColorPrimaryInverse; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::Inactivecaptiontext); - laf.colorValue = mSystemColors.textColorTertiary; - lookAndFeelCache.AppendElement(laf); - - laf.id = int32_t(ColorID::Windowtext); - laf.colorValue = mSystemColors.textColorPrimary; - lookAndFeelCache.AppendElement(laf); - - // XXX The following colors are unused. - // - textColorTertiaryInverse - // - panelColorForeground - // - panelColorBackground - - return lookAndFeelCache; -} - -void nsLookAndFeel::SetIntCacheImpl( - const nsTArray& aLookAndFeelCache) { - for (auto entry : aLookAndFeelCache) { - switch (ColorID(entry.id)) { - case ColorID::WindowForeground: - mSystemColors.textColorPrimary = entry.colorValue; - break; - case ColorID::WidgetBackground: - mSystemColors.colorBackground = entry.colorValue; - break; - case ColorID::WidgetForeground: - mSystemColors.colorForeground = entry.colorValue; - break; - case ColorID::WidgetSelectBackground: - mSystemColors.textColorHighlight = entry.colorValue; - break; - case ColorID::WidgetSelectForeground: - mSystemColors.textColorPrimaryInverse = entry.colorValue; - break; - case ColorID::Inactivecaptiontext: - mSystemColors.textColorTertiary = entry.colorValue; - break; - case ColorID::Windowtext: - mSystemColors.textColorPrimary = entry.colorValue; - break; - default: - MOZ_ASSERT(false); - } - } - mInitializedSystemColors = true; -} diff --git a/widget/android/nsLookAndFeel.h b/widget/android/nsLookAndFeel.h index 4015f3d9beac..a1974ca524c3 100644 --- a/widget/android/nsLookAndFeel.h +++ b/widget/android/nsLookAndFeel.h @@ -23,9 +23,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel { virtual bool GetEchoPasswordImpl() override; virtual uint32_t GetPasswordMaskDelayImpl() override; virtual char16_t GetPasswordCharacterImpl() override; - virtual nsTArray GetIntCacheImpl() override; - virtual void SetIntCacheImpl( - const nsTArray& aLookAndFeelIntCache) override; protected: static bool mInitializedSystemColors;