Bug 1702756 - Refactor nsXPLookAndFeel's caching setup to be more consistent. r=mstange

We also cache everywhere whether getting the int/float/color failed, for
example, and do the pref lookup on demand. Seems a bit nicer. We could insert
the pref values on the cache directly on Refresh(), that's another alternative,
but I don't think it matters much either way.

Differential Revision: https://phabricator.services.mozilla.com/D110675
This commit is contained in:
Emilio Cobos Álvarez 2021-04-02 16:34:35 +00:00
Родитель 9e4fe964d6
Коммит a37b56a98d
2 изменённых файлов: 169 добавлений и 260 удалений

Просмотреть файл

@ -48,20 +48,6 @@ using FloatID = mozilla::LookAndFeel::FloatID;
using ColorID = mozilla::LookAndFeel::ColorID; using ColorID = mozilla::LookAndFeel::ColorID;
using FontID = mozilla::LookAndFeel::FontID; using FontID = mozilla::LookAndFeel::FontID;
struct nsLookAndFeelIntPref {
const char* name;
IntID id;
bool isSet;
int32_t intVar;
};
struct nsLookAndFeelFloatPref {
const char* name;
FloatID id;
bool isSet;
float floatVar;
};
template <typename Index, typename Value, Index kEnd> template <typename Index, typename Value, Index kEnd>
class EnumeratedCache { class EnumeratedCache {
static constexpr uint32_t ChunkFor(Index aIndex) { static constexpr uint32_t ChunkFor(Index aIndex) {
@ -106,9 +92,9 @@ class EnumeratedCache {
} }
}; };
static EnumeratedCache<ColorID, nscolor, ColorID::End> sColorCache; static EnumeratedCache<ColorID, Maybe<nscolor>, ColorID::End> sColorCache;
static EnumeratedCache<FloatID, float, FloatID::End> sFloatCache; static EnumeratedCache<FloatID, Maybe<float>, FloatID::End> sFloatCache;
static EnumeratedCache<IntID, int32_t, IntID::End> sIntCache; static EnumeratedCache<IntID, Maybe<int32_t>, IntID::End> sIntCache;
static EnumeratedCache<FontID, widget::LookAndFeelFont, FontID::End> sFontCache; static EnumeratedCache<FontID, widget::LookAndFeelFont, FontID::End> sFontCache;
// To make one of these prefs toggleable from a reftest add a user // To make one of these prefs toggleable from a reftest add a user
@ -117,80 +103,94 @@ static EnumeratedCache<FontID, widget::LookAndFeelFont, FontID::End> sFontCache;
// //
// user_pref("ui.useAccessibilityTheme", 0); // user_pref("ui.useAccessibilityTheme", 0);
// //
static nsLookAndFeelIntPref sIntPrefs[] = { // This needs to be of the same length and in the same order as
{"ui.caretBlinkTime", IntID::CaretBlinkTime, false, 0}, // LookAndFeel::IntID values.
{"ui.caretWidth", IntID::CaretWidth, false, 0}, static const char sIntPrefs[][42] = {
{"ui.caretVisibleWithSelection", IntID::ShowCaretDuringSelection, false, 0}, "ui.caretBlinkTime",
{"ui.submenuDelay", IntID::SubmenuDelay, false, 0}, "ui.caretWidth",
{"ui.dragThresholdX", IntID::DragThresholdX, false, 0}, "ui.caretVisibleWithSelection",
{"ui.dragThresholdY", IntID::DragThresholdY, false, 0}, "ui.selectTextfieldsOnKeyFocus",
{"ui.useAccessibilityTheme", IntID::UseAccessibilityTheme, false, 0}, "ui.submenuDelay",
{"ui.menusCanOverlapOSBar", IntID::MenusCanOverlapOSBar, false, 0}, "ui.menusCanOverlapOSBar",
{"ui.useOverlayScrollbars", IntID::UseOverlayScrollbars, false, 0}, "ui.useOverlayScrollbars",
{"ui.scrollbarDisplayOnMouseMove", IntID::ScrollbarDisplayOnMouseMove, "ui.allowOverlayScrollbarsOverlap",
false, 0}, "ui.showHideScrollbars",
{"ui.scrollbarFadeBeginDelay", IntID::ScrollbarFadeBeginDelay, false, 0}, "ui.skipNavigatingDisabledMenuItem",
{"ui.scrollbarFadeDuration", IntID::ScrollbarFadeDuration, false, 0}, "ui.dragThresholdX",
{"ui.showHideScrollbars", IntID::ShowHideScrollbars, false, 0}, "ui.dragThresholdY",
{"ui.skipNavigatingDisabledMenuItem", IntID::SkipNavigatingDisabledMenuItem, "ui.useAccessibilityTheme",
false, 0}, "ui.scrollArrowStyle",
{"ui.treeOpenDelay", IntID::TreeOpenDelay, false, 0}, "ui.scrollSliderStyle",
{"ui.treeCloseDelay", IntID::TreeCloseDelay, false, 0}, "ui.scrollButtonLeftMouseButtonAction",
{"ui.treeLazyScrollDelay", IntID::TreeLazyScrollDelay, false, 0}, "ui.scrollButtonMiddleMouseButtonAction",
{"ui.treeScrollDelay", IntID::TreeScrollDelay, false, 0}, "ui.scrollButtonRightMouseButtonAction",
{"ui.treeScrollLinesMax", IntID::TreeScrollLinesMax, false, 0}, "ui.treeOpenDelay",
{"accessibility.tabfocus", IntID::TabFocusModel, false, 0}, "ui.treeCloseDelay",
{"ui.alertNotificationOrigin", IntID::AlertNotificationOrigin, false, 0}, "ui.treeLazyScrollDelay",
{"ui.scrollToClick", IntID::ScrollToClick, false, 0}, "ui.treeScrollDelay",
{"ui.IMERawInputUnderlineStyle", IntID::IMERawInputUnderlineStyle, false, "ui.treeScrollLinesMax",
0}, "accessibility.tabfocus", // Weird one...
{"ui.IMESelectedRawTextUnderlineStyle", "ui.chosenMenuItemsShouldBlink",
IntID::IMESelectedRawTextUnderlineStyle, false, 0}, "ui.windowsAccentColorInTitlebar",
{"ui.IMEConvertedTextUnderlineStyle", IntID::IMEConvertedTextUnderlineStyle, "ui.windowsDefaultTheme",
false, 0}, "ui.dwmCompositor",
{"ui.IMESelectedConvertedTextUnderlineStyle", "ui.windowsClassic",
IntID::IMESelectedConvertedTextUnderline, false, 0}, "ui.windowsGlass",
{"ui.SpellCheckerUnderlineStyle", IntID::SpellCheckerUnderlineStyle, false, "ui.macGraphiteTheme",
0}, "ui.macBigSurTheme",
{"ui.scrollbarButtonAutoRepeatBehavior", "ui.alertNotificationOrigin",
IntID::ScrollbarButtonAutoRepeatBehavior, false, 0}, "ui.scrollToClick",
{"ui.tooltipDelay", IntID::TooltipDelay, false, 0}, "ui.IMERawInputUnderlineStyle",
{"ui.contextMenuOffsetVertical", IntID::ContextMenuOffsetVertical, false, "ui.IMESelectedRawTextUnderlineStyle",
0}, "ui.IMEConvertedTextUnderlineStyle",
{"ui.contextMenuOffsetHorizontal", IntID::ContextMenuOffsetHorizontal, "ui.IMESelectedConvertedTextUnderlineStyle",
false, 0}, "ui.SpellCheckerUnderlineStyle",
{"ui.GtkCSDAvailable", IntID::GTKCSDAvailable, false, 0}, "ui.menuBarDrag",
{"ui.GtkCSDHideTitlebarByDefault", IntID::GTKCSDHideTitlebarByDefault, "ui.windowsThemeIdentifier",
false, 0}, "ui.operatingSystemVersionIdentifier",
{"ui.GtkCSDTransparentBackground", IntID::GTKCSDTransparentBackground, "ui.scrollbarButtonAutoRepeatBehavior",
false, 0}, "ui.tooltipDelay",
{"ui.GtkCSDMinimizeButton", IntID::GTKCSDMinimizeButton, false, 0}, "ui.swipeAnimationEnabled",
{"ui.GtkCSDMaximizeButton", IntID::GTKCSDMaximizeButton, false, 0}, "ui.scrollbarDisplayOnMouseMove",
{"ui.GtkCSDCloseButton", IntID::GTKCSDCloseButton, false, 0}, "ui.scrollbarFadeBeginDelay",
{"ui.systemUsesDarkTheme", IntID::SystemUsesDarkTheme, false, 0}, "ui.scrollbarFadeDuration",
{"ui.prefersReducedMotion", IntID::PrefersReducedMotion, false, 0}, "ui.contextMenuOffsetVertical",
{"ui.primaryPointerCapabilities", IntID::PrimaryPointerCapabilities, false, "ui.contextMenuOffsetHorizontal",
6 /* fine and hover-capable pointer, i.e. mouse-type */}, "ui.GtkCSDAvailable",
{"ui.allPointerCapabilities", IntID::AllPointerCapabilities, false, "ui.GtkCSDHideTitlebarByDefault",
6 /* fine and hover-capable pointer, i.e. mouse-type */}, "ui.GtkCSDTransparentBackground",
{"ui.scrollArrowStyle", IntID::ScrollArrowStyle, false, 0}, "ui.GtkCSDMinimizeButton",
"ui.GtkCSDMaximizeButton",
"ui.GtkCSDCloseButton",
"ui.GtkCSDMinimizeButtonPosition",
"ui.GtkCSDMaximizeButtonPosition",
"ui.GtkCSDCloseButtonPosition",
"ui.GtkCSDReversedPlacement",
"ui.systemUsesDarkTheme",
"ui.prefersReducedMotion",
"ui.primaryPointerCapabilities",
"ui.allPointerCapabilities",
"ui.systemVerticalScrollbarWidth",
"ui.systemHorizontalScrollbarHeight",
}; };
static nsLookAndFeelFloatPref sFloatPrefs[] = { static_assert(ArrayLength(sIntPrefs) == size_t(LookAndFeel::IntID::End),
{"ui.IMEUnderlineRelativeSize", FloatID::IMEUnderlineRelativeSize, false, "Should have a pref for each int value");
0},
{"ui.SpellCheckerUnderlineRelativeSize", // This array MUST be kept in the same order as the float id list in
FloatID::SpellCheckerUnderlineRelativeSize, false, 0}, // LookAndFeel.h
{"ui.caretAspectRatio", FloatID::CaretAspectRatio, false, 0}, static const char sFloatPrefs[][37] = {
"ui.IMEUnderlineRelativeSize",
"ui.SpellCheckerUnderlineRelativeSize",
"ui.caretAspectRatio",
"ui.textScaleFactor",
}; };
static_assert(ArrayLength(sFloatPrefs) == size_t(LookAndFeel::FloatID::End),
"Should have a pref for each float value");
// This array MUST be kept in the same order as the color list in // This array MUST be kept in the same order as the color list in
// specified/color.rs // specified/color.rs
/* XXX If you add any strings longer than
* "ui.-moz-mac-active-source-list-selection"
* to the following array then you MUST update the
* sizes of the sColorPrefs array in nsXPLookAndFeel.h
*/
static const char sColorPrefs[][41] = { static const char sColorPrefs[][41] = {
"ui.windowBackground", "ui.windowBackground",
"ui.windowForeground", "ui.windowForeground",
@ -311,6 +311,9 @@ static const char sColorPrefs[][41] = {
"ui.-moz-colheadertext", "ui.-moz-colheadertext",
"ui.-moz-colheaderhovertext"}; "ui.-moz-colheaderhovertext"};
static_assert(ArrayLength(sColorPrefs) == size_t(LookAndFeel::ColorID::End),
"Should have a pref for each color value");
bool nsXPLookAndFeel::sInitialized = false; bool nsXPLookAndFeel::sInitialized = false;
nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nullptr; nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nullptr;
@ -370,159 +373,51 @@ void nsXPLookAndFeel::Shutdown() {
} }
// static // static
static void IntPrefChanged(nsLookAndFeelIntPref* data) { static void IntPrefChanged() {
if (!data) {
return;
}
int32_t intpref;
nsresult rv = Preferences::GetInt(data->name, &intpref);
if (NS_FAILED(rv)) {
data->isSet = false;
#ifdef DEBUG_akkana
printf("====== Cleared int pref %s\n", data->name);
#endif
} else {
data->intVar = intpref;
data->isSet = true;
#ifdef DEBUG_akkana
printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
#endif
}
// Int prefs can't change our system colors or fonts. // Int prefs can't change our system colors or fonts.
LookAndFeel::NotifyChangedAllWindows( LookAndFeel::NotifyChangedAllWindows(
widget::ThemeChangeKind::MediaQueriesOnly); widget::ThemeChangeKind::MediaQueriesOnly);
} }
static void FloatPrefChanged(nsLookAndFeelFloatPref* data) { static void FloatPrefChanged() {
if (!data) {
return;
}
int32_t intpref;
nsresult rv = Preferences::GetInt(data->name, &intpref);
if (NS_FAILED(rv)) {
data->isSet = false;
#ifdef DEBUG_akkana
printf("====== Cleared float pref %s\n", data->name);
#endif
} else {
data->floatVar = (float)intpref / 100.0f;
data->isSet = true;
#ifdef DEBUG_akkana
printf("====== Changed float pref %s to %f\n", data->name);
#endif
}
// Float prefs can't change our system colors or fonts. // Float prefs can't change our system colors or fonts.
LookAndFeel::NotifyChangedAllWindows( LookAndFeel::NotifyChangedAllWindows(
widget::ThemeChangeKind::MediaQueriesOnly); widget::ThemeChangeKind::MediaQueriesOnly);
} }
// static // static
static void ColorPrefChanged(unsigned int index, const char* prefName) { static void ColorPrefChanged() {
nsAutoString colorStr;
nsresult rv = Preferences::GetString(prefName, colorStr);
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty()) {
nscolor thecolor;
if (colorStr[0] == char16_t('#')) {
if (NS_HexToRGBA(nsDependentString(colorStr, 1), nsHexColorType::NoAlpha,
&thecolor)) {
sColorCache.Insert(ColorID(index), thecolor);
}
} else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
sColorCache.Insert(ColorID(index), thecolor);
#ifdef DEBUG_akkana
printf("====== Changed color pref %s to 0x%lx\n", prefName, thecolor);
#endif
}
} else {
// Reset to the default color, by clearing the cache
// to force lookup when the color is next used
sColorCache.Remove(ColorID(index));
#ifdef DEBUG_akkana
printf("====== Cleared color pref %s\n", prefName);
#endif
}
// Color prefs affect style, because they by definition change system colors. // Color prefs affect style, because they by definition change system colors.
LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind::Style); LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind::Style);
} }
static void InitFromPref(nsLookAndFeelIntPref* aPref) {
int32_t intpref;
nsresult rv = Preferences::GetInt(aPref->name, &intpref);
if (NS_SUCCEEDED(rv)) {
aPref->isSet = true;
aPref->intVar = intpref;
}
}
static void InitFromPref(nsLookAndFeelFloatPref* aPref) {
int32_t intpref;
nsresult rv = Preferences::GetInt(aPref->name, &intpref);
if (NS_SUCCEEDED(rv)) {
aPref->isSet = true;
aPref->floatVar = (float)intpref / 100.0f;
}
}
static void InitColorFromPref(int32_t i) {
static_assert(ArrayLength(sColorPrefs) == size_t(ColorID::End),
"Should have a pref for each color value");
nsAutoString colorStr;
nsresult rv = Preferences::GetString(sColorPrefs[i], colorStr);
if (NS_FAILED(rv) || colorStr.IsEmpty()) {
return;
}
nscolor thecolor;
if (colorStr[0] == char16_t('#')) {
nsAutoString hexString;
colorStr.Right(hexString, colorStr.Length() - 1);
if (NS_HexToRGBA(hexString, nsHexColorType::NoAlpha, &thecolor)) {
sColorCache.Insert(ColorID(i), thecolor);
}
} else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
sColorCache.Insert(ColorID(i), thecolor);
}
}
// static // static
void nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure) { void nsXPLookAndFeel::OnPrefChanged(const char* aPref, void* aClosure) {
// looping in the same order as in ::Init // looping in the same order as in ::Init
nsDependentCString prefName(aPref); nsDependentCString prefName(aPref);
unsigned int i; for (const char* pref : sIntPrefs) {
for (i = 0; i < ArrayLength(sIntPrefs); ++i) { if (prefName.Equals(pref)) {
if (prefName.Equals(sIntPrefs[i].name)) { IntPrefChanged();
IntPrefChanged(&sIntPrefs[i]);
return; return;
} }
} }
for (i = 0; i < ArrayLength(sFloatPrefs); ++i) { for (const char* pref : sFloatPrefs) {
if (prefName.Equals(sFloatPrefs[i].name)) { if (prefName.Equals(pref)) {
FloatPrefChanged(&sFloatPrefs[i]); FloatPrefChanged();
return; return;
} }
} }
for (i = 0; i < ArrayLength(sColorPrefs); ++i) { for (const char* pref : sColorPrefs) {
if (prefName.Equals(sColorPrefs[i])) { if (prefName.Equals(pref)) {
ColorPrefChanged(i, sColorPrefs[i]); ColorPrefChanged();
return; return;
} }
} }
} }
//
// Read values from the user's preferences. // Read values from the user's preferences.
// This is done once at startup, but since the user's preferences // This is done once at startup, but since the user's preferences
// haven't actually been read yet at that time, we also have to // haven't actually been read yet at that time, we also have to
@ -542,19 +437,6 @@ void nsXPLookAndFeel::Init() {
// We really do just want the accessibility.tabfocus pref, not other prefs // We really do just want the accessibility.tabfocus pref, not other prefs
// that start with that string. // that start with that string.
Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus"); Preferences::RegisterCallback(OnPrefChanged, "accessibility.tabfocus");
unsigned int i;
for (i = 0; i < ArrayLength(sIntPrefs); ++i) {
InitFromPref(&sIntPrefs[i]);
}
for (i = 0; i < ArrayLength(sFloatPrefs); ++i) {
InitFromPref(&sFloatPrefs[i]);
}
for (i = 0; i < ArrayLength(sColorPrefs); ++i) {
InitColorFromPref(i);
}
} }
nsXPLookAndFeel::~nsXPLookAndFeel() { nsXPLookAndFeel::~nsXPLookAndFeel() {
@ -764,12 +646,30 @@ static nsresult SystemColorUseDebuggingColor(LookAndFeel::ColorID aID,
} }
#endif #endif
static nsresult GetColorFromPref(LookAndFeel::ColorID aID, nscolor& aResult) {
const char* prefName = sColorPrefs[size_t(aID)];
nsAutoString colorStr;
MOZ_TRY(Preferences::GetString(prefName, colorStr));
if (colorStr.IsEmpty()) {
return NS_ERROR_FAILURE;
}
if (colorStr[0] == char16_t('#')) {
if (NS_HexToRGBA(nsDependentString(colorStr, 1), nsHexColorType::NoAlpha,
&aResult)) {
return NS_OK;
}
} else if (NS_ColorNameToRGB(colorStr, &aResult)) {
return NS_OK;
}
return NS_ERROR_FAILURE;
}
// All these routines will return NS_OK if they have a value, // All these routines will return NS_OK if they have a value,
// in which case the nsLookAndFeel should use that value; // in which case the nsLookAndFeel should use that value;
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
// platform-specific nsLookAndFeel should use its own values instead. // platform-specific nsLookAndFeel should use its own values instead.
nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, nsresult nsXPLookAndFeel::GetColorValue(ColorID aID, ColorScheme aScheme,
bool aUseStandinsForNativeColors, UseStandins aUseStandins,
nscolor& aResult) { nscolor& aResult) {
if (!sInitialized) { if (!sInitialized) {
Init(); Init();
@ -781,16 +681,21 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID,
} }
#endif #endif
if (aUseStandins == UseStandins::Yes) {
if (!aUseStandinsForNativeColors) { aResult = GetStandinForNativeColor(aID);
if (const nscolor* cached = sColorCache.Get(aID)) {
aResult = *cached;
return NS_OK; return NS_OK;
} }
if (const auto* cached = sColorCache.Get(aID)) {
if (cached->isNothing()) {
return NS_ERROR_FAILURE;
}
aResult = cached->value();
return NS_OK;
} }
if (aUseStandinsForNativeColors) { if (NS_SUCCEEDED(GetColorFromPref(aID, aResult))) {
aResult = GetStandinForNativeColor(aID); sColorCache.Insert(aID, Some(aResult));
return NS_OK; return NS_OK;
} }
@ -811,11 +716,12 @@ nsresult nsXPLookAndFeel::GetColorValue(ColorID aID,
// NOTE: Servo holds a lock and the main thread is paused, so writing to the // NOTE: Servo holds a lock and the main thread is paused, so writing to the
// global cache here is fine. // global cache here is fine.
sColorCache.Insert(aID, aResult); sColorCache.Insert(aID, Some(aResult));
return NS_OK; return NS_OK;
} }
return NS_ERROR_NOT_AVAILABLE; sColorCache.Insert(aID, Nothing());
return NS_ERROR_FAILURE;
} }
nsresult nsXPLookAndFeel::GetIntValue(IntID aID, int32_t& aResult) { nsresult nsXPLookAndFeel::GetIntValue(IntID aID, int32_t& aResult) {
@ -823,21 +729,25 @@ nsresult nsXPLookAndFeel::GetIntValue(IntID aID, int32_t& aResult) {
Init(); Init();
} }
if (const int32_t* cached = sIntCache.Get(aID)) { if (const auto* cached = sIntCache.Get(aID)) {
aResult = *cached; if (cached->isNothing()) {
return NS_ERROR_FAILURE;
}
aResult = cached->value();
return NS_OK; return NS_OK;
} }
for (unsigned int i = 0; i < ArrayLength(sIntPrefs); ++i) { if (NS_SUCCEEDED(Preferences::GetInt(sIntPrefs[size_t(aID)], &aResult))) {
if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID)) { sIntCache.Insert(aID, Some(aResult));
aResult = sIntPrefs[i].intVar;
sIntCache.Insert(aID, aResult);
return NS_OK; return NS_OK;
} }
if (NS_FAILED(NativeGetInt(aID, aResult))) {
sIntCache.Insert(aID, Nothing());
return NS_ERROR_FAILURE;
} }
MOZ_TRY(NativeGetInt(aID, aResult)); sIntCache.Insert(aID, Some(aResult));
sIntCache.Insert(aID, aResult);
return NS_OK; return NS_OK;
} }
@ -846,21 +756,27 @@ nsresult nsXPLookAndFeel::GetFloatValue(FloatID aID, float& aResult) {
Init(); Init();
} }
if (const float* cached = sFloatCache.Get(aID)) { if (const auto* cached = sFloatCache.Get(aID)) {
aResult = *cached; if (cached->isNothing()) {
return NS_ERROR_FAILURE;
}
aResult = cached->value();
return NS_OK; return NS_OK;
} }
for (unsigned int i = 0; i < ArrayLength(sFloatPrefs); ++i) { int32_t pref = 0;
if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID) { if (NS_SUCCEEDED(Preferences::GetInt(sFloatPrefs[size_t(aID)], &pref))) {
aResult = sFloatPrefs[i].floatVar; aResult = float(pref) / 100.0f;
sFloatCache.Insert(aID, aResult); sFloatCache.Insert(aID, Some(aResult));
return NS_OK; return NS_OK;
} }
if (NS_FAILED(NativeGetFloat(aID, aResult))) {
sFloatCache.Insert(aID, Nothing());
return NS_ERROR_FAILURE;
} }
MOZ_TRY(NativeGetFloat(aID, aResult)); sFloatCache.Insert(aID, Some(aResult));
sFloatCache.Insert(aID, aResult);
return NS_OK; return NS_OK;
} }
@ -927,11 +843,6 @@ void nsXPLookAndFeel::RefreshImpl() {
sFloatCache.Clear(); sFloatCache.Clear();
sIntCache.Clear(); sIntCache.Clear();
// Reinit color cache from prefs.
for (uint32_t i = 0; i < uint32_t(ColorID::End); ++i) {
InitColorFromPref(i);
}
// Clear any cached FullLookAndFeel data, which is now invalid. // Clear any cached FullLookAndFeel data, which is now invalid.
if (XRE_IsParentProcess()) { if (XRE_IsParentProcess()) {
widget::RemoteLookAndFeel::ClearCachedData(); widget::RemoteLookAndFeel::ClearCachedData();
@ -1010,12 +921,11 @@ static LookAndFeel::ColorScheme ColorSchemeForDocument(const dom::Document&) {
} }
// static // static
Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, ColorScheme, Maybe<nscolor> LookAndFeel::GetColor(ColorID aId, ColorScheme aScheme,
UseStandins aUseStandins) { UseStandins aUseStandins) {
// TODO(emilio): Actually use ColorScheme.
nscolor result; nscolor result;
nsresult rv = nsLookAndFeel::GetInstance()->GetColorValue( nsresult rv = nsLookAndFeel::GetInstance()->GetColorValue(
aId, bool(aUseStandins), result); aId, aScheme, aUseStandins, result);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return Nothing(); return Nothing();
} }

Просмотреть файл

@ -31,8 +31,7 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
// //
// NS_ERROR_NOT_AVAILABLE is returned if there is neither an override pref or // NS_ERROR_NOT_AVAILABLE is returned if there is neither an override pref or
// a platform-specific value. // a platform-specific value.
nsresult GetColorValue(ColorID aID, bool aUseStandinsForNativeColors, nsresult GetColorValue(ColorID, ColorScheme, UseStandins, nscolor& aResult);
nscolor& aResult);
nsresult GetIntValue(IntID aID, int32_t& aResult); nsresult GetIntValue(IntID aID, int32_t& aResult);
nsresult GetFloatValue(FloatID aID, float& aResult); nsresult GetFloatValue(FloatID aID, float& aResult);
// Same, but returns false if there is no platform-specific value. // Same, but returns false if there is no platform-specific value.