зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
c0e1f5a876
Коммит
6e7f3aff6a
|
@ -369,35 +369,6 @@ void AndroidBridge::Vibrate(const nsTArray<uint32_t>& 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<uint32_t>(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<uint32_t>(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) {
|
||||
|
|
|
@ -119,8 +119,6 @@ class AndroidBridge final {
|
|||
|
||||
void Vibrate(const nsTArray<uint32_t>& aPattern);
|
||||
|
||||
void GetSystemColors(AndroidSystemColors* aColors);
|
||||
|
||||
void GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize,
|
||||
uint8_t* const aBuf);
|
||||
|
||||
|
|
|
@ -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<uint32_t>(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<uint32_t>(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<LookAndFeelInt> nsLookAndFeel::GetIntCacheImpl() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
EnsureInitSystemColors();
|
||||
MOZ_ASSERT(mInitializedSystemColors);
|
||||
|
||||
nsTArray<LookAndFeelInt> 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<LookAndFeelInt>& 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;
|
||||
}
|
||||
|
|
|
@ -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<LookAndFeelInt> GetIntCacheImpl() override;
|
||||
virtual void SetIntCacheImpl(
|
||||
const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
|
||||
|
||||
protected:
|
||||
static bool mInitializedSystemColors;
|
||||
|
|
Загрузка…
Ссылка в новой задаче