зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1702765 - Plumb ColorScheme through nsXPLookAndFeel. r=mstange
After this patch, there are two remaining pieces to fix bug 1700294: * macOS nsLookAndFeel needs to return the right colors for light / dark appearance. * We need to return ColorScheme::Dark for the right documents in ColorSchemeForDocument. Both of those should be straight-forward. Differential Revision: https://phabricator.services.mozilla.com/D110680
This commit is contained in:
Родитель
7319f11f91
Коммит
d3f4f81c53
|
@ -34,13 +34,15 @@ namespace widget {
|
|||
struct LookAndFeelTables {
|
||||
int32_t[] ints;
|
||||
float[] floats;
|
||||
nscolor[] colors;
|
||||
LookAndFeelFont[] fonts;
|
||||
nscolor[] lightColors;
|
||||
nscolor[] darkColors;
|
||||
|
||||
uint8_t[] intMap;
|
||||
uint8_t[] floatMap;
|
||||
uint8_t[] colorMap;
|
||||
uint8_t[] fontMap;
|
||||
uint8_t[] lightColorMap;
|
||||
uint8_t[] darkColorMap;
|
||||
|
||||
uint16_t passwordChar;
|
||||
bool passwordEcho;
|
||||
|
|
|
@ -106,9 +106,14 @@ void AddToMap(nsTArray<Item>& aItems, nsTArray<UInt>& aMap, Id aId,
|
|||
|
||||
} // namespace
|
||||
|
||||
nsresult RemoteLookAndFeel::NativeGetColor(ColorID aID, nscolor& aResult) {
|
||||
nsresult RemoteLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
|
||||
nscolor& aResult) {
|
||||
const nscolor* result;
|
||||
MOZ_TRY_VAR(result, MapLookup(mTables.colors(), mTables.colorMap(), aID));
|
||||
const bool dark = aScheme == ColorScheme::Dark;
|
||||
MOZ_TRY_VAR(
|
||||
result,
|
||||
MapLookup(dark ? mTables.darkColors() : mTables.lightColors(),
|
||||
dark ? mTables.darkColorMap() : mTables.lightColorMap(), aID));
|
||||
aResult = *result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -149,6 +154,7 @@ static bool AddIDsToMap(nsXPLookAndFeel* aImpl, FullLookAndFeel* aLf,
|
|||
using FontID = LookAndFeel::FontID;
|
||||
using FloatID = LookAndFeel::FloatID;
|
||||
using ColorID = LookAndFeel::ColorID;
|
||||
using ColorScheme = LookAndFeel::ColorScheme;
|
||||
|
||||
bool anyFromOtherTheme = false;
|
||||
for (auto id : MakeEnumeratedRange(IntID::End)) {
|
||||
|
@ -168,8 +174,11 @@ static bool AddIDsToMap(nsXPLookAndFeel* aImpl, FullLookAndFeel* aLf,
|
|||
continue;
|
||||
}
|
||||
nscolor theColor;
|
||||
nsresult rv = aImpl->NativeGetColor(id, theColor);
|
||||
AddToMap(aLf->tables().colors(), aLf->tables().colorMap(), id,
|
||||
nsresult rv = aImpl->NativeGetColor(id, ColorScheme::Light, theColor);
|
||||
AddToMap(aLf->tables().lightColors(), aLf->tables().lightColorMap(), id,
|
||||
NS_SUCCEEDED(rv) ? Some(theColor) : Nothing{});
|
||||
rv = aImpl->NativeGetColor(id, ColorScheme::Dark, theColor);
|
||||
AddToMap(aLf->tables().darkColors(), aLf->tables().darkColorMap(), id,
|
||||
NS_SUCCEEDED(rv) ? Some(theColor) : Nothing{});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ class RemoteLookAndFeel final : public nsXPLookAndFeel {
|
|||
|
||||
void NativeInit() override {}
|
||||
|
||||
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetInt(IntID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ void nsLookAndFeel::RefreshImpl() {
|
|||
mSystemUsesDarkThemeCached = false;
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme,
|
||||
nscolor& aColor) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
EnsureInitSystemColors();
|
||||
|
|
|
@ -15,9 +15,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
|
||||
void NativeInit() final;
|
||||
virtual void RefreshImpl() override;
|
||||
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetInt(IntID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aName,
|
||||
gfxFontStyle& aStyle) override;
|
||||
virtual bool GetEchoPasswordImpl() override;
|
||||
|
|
|
@ -14,9 +14,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
|
||||
void NativeInit() final;
|
||||
virtual void RefreshImpl() override;
|
||||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
nsresult NativeGetInt(IntID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID, float& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ nscolor nsLookAndFeel::ProcessSelectionBackground(nscolor aColor) {
|
|||
return resultColor;
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme, nscolor& aColor) {
|
||||
EnsureInit();
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
|
|
@ -300,7 +300,8 @@ static bool IsSelectionColorBackground(LookAndFeel::ColorID aID) {
|
|||
}
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme,
|
||||
nscolor& aColor) {
|
||||
EnsureInit();
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
|
|
@ -25,7 +25,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
void RefreshImpl() override;
|
||||
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ class HeadlessLookAndFeel : public nsXPLookAndFeel {
|
|||
void NativeInit() final{};
|
||||
virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
virtual nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
virtual nsresult NativeGetColor(ColorID, ColorScheme,
|
||||
nscolor& aResult) override;
|
||||
virtual bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ HeadlessLookAndFeel::HeadlessLookAndFeel() {}
|
|||
|
||||
HeadlessLookAndFeel::~HeadlessLookAndFeel() = default;
|
||||
|
||||
nsresult HeadlessLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
nsresult HeadlessLookAndFeel::NativeGetColor(ColorID aID, ColorScheme,
|
||||
nscolor& aColor) {
|
||||
// For headless mode, we use GetStandinForNativeColor for everything we can,
|
||||
// and hardcoded values for everything else.
|
||||
|
||||
|
|
|
@ -93,7 +93,8 @@ class EnumeratedCache {
|
|||
}
|
||||
};
|
||||
|
||||
static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sColorCache;
|
||||
static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sLightColorCache;
|
||||
static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sDarkColorCache;
|
||||
static EnumeratedCache<FloatID, Maybe<float>, FloatID::End> sFloatCache;
|
||||
static EnumeratedCache<IntID, Maybe<int32_t>, IntID::End> sIntCache;
|
||||
static EnumeratedCache<FontID, widget::LookAndFeelFont, FontID::End> sFontCache;
|
||||
|
@ -680,7 +681,9 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, ColorScheme aScheme,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (const auto* cached = sColorCache.Get(aID)) {
|
||||
auto& cache =
|
||||
aScheme == ColorScheme::Light ? sLightColorCache : sDarkColorCache;
|
||||
if (const auto* cached = cache.Get(aID)) {
|
||||
if (cached->isNothing()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -689,11 +692,11 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, ColorScheme aScheme,
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(GetColorFromPref(aID, aResult))) {
|
||||
sColorCache.Insert(aID, Some(aResult));
|
||||
cache.Insert(aID, Some(aResult));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(NativeGetColor(aID, aResult))) {
|
||||
if (NS_SUCCEEDED(NativeGetColor(aID, aScheme, aResult))) {
|
||||
if (gfxPlatform::GetCMSMode() == CMSMode::All &&
|
||||
!IsSpecialColor(aID, aResult)) {
|
||||
qcms_transform* transform = gfxPlatform::GetCMSInverseRGBTransform();
|
||||
|
@ -710,11 +713,11 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, ColorScheme aScheme,
|
|||
|
||||
// NOTE: Servo holds a lock and the main thread is paused, so writing to the
|
||||
// global cache here is fine.
|
||||
sColorCache.Insert(aID, Some(aResult));
|
||||
cache.Insert(aID, Some(aResult));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sColorCache.Insert(aID, Nothing());
|
||||
cache.Insert(aID, Nothing());
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -832,7 +835,8 @@ bool nsXPLookAndFeel::GetFontValue(FontID aID, nsString& aName,
|
|||
|
||||
void nsXPLookAndFeel::RefreshImpl() {
|
||||
// Wipe out our caches.
|
||||
sColorCache.Clear();
|
||||
sLightColorCache.Clear();
|
||||
sDarkColorCache.Clear();
|
||||
sFontCache.Clear();
|
||||
sFloatCache.Clear();
|
||||
sIntCache.Clear();
|
||||
|
|
|
@ -40,7 +40,7 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
|
|||
|
||||
virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) = 0;
|
||||
virtual nsresult NativeGetFloat(FloatID aID, float& aResult) = 0;
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) = 0;
|
||||
virtual nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) = 0;
|
||||
virtual bool NativeGetFont(FontID aID, nsString& aName,
|
||||
gfxFontStyle& aStyle) = 0;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
virtual void RefreshImpl();
|
||||
nsresult NativeGetImpl(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(const ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
virtual char16_t GetPasswordCharacterImpl() {
|
||||
|
|
|
@ -40,7 +40,7 @@ void nsLookAndFeel::RefreshImpl() {
|
|||
mInitialized = false;
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(const ColorID aID, nscolor& aResult) {
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID, ColorScheme, nscolor& aResult) {
|
||||
EnsureInit();
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
|
|
@ -124,7 +124,8 @@ void nsLookAndFeel::RefreshImpl() {
|
|||
mInitialized = false;
|
||||
}
|
||||
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
|
||||
nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme,
|
||||
nscolor& aColor) {
|
||||
EnsureInit();
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
|
|
@ -52,9 +52,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
|
||||
void NativeInit() final;
|
||||
void RefreshImpl() override;
|
||||
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
|
||||
nsresult NativeGetInt(IntID, int32_t& aResult) override;
|
||||
nsresult NativeGetFloat(FloatID, float& aResult) override;
|
||||
nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) override;
|
||||
bool NativeGetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle) override;
|
||||
char16_t GetPasswordCharacterImpl() override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче