Commit eedd09df authored by Boris Chiou's avatar Boris Chiou
Browse files

Bug 1528960 - Query MacOS system dark mode only on the main browser process or...

Bug 1528960 - Query MacOS system dark mode only on the main browser process or it's the initial query on the child process. r=hiro

Based on the implementation and issues on prefers-reduced-motion, it
seems we have the same issue on the dark mode.

In child processes on MacOSX we don't spin native event loop at all.
Without native event loops, the global preference returned from
`SystemWantsDarkTheme()` doesn't return up-to-date value when the system
setting changed for some reasons.
To workaround this we call `SystemWantsDarkTheme()` only on the parent
process which spins native event loop or when it's the initial query on
the child process. And we give the up-to-date value to the child process
via an IPC call just like other cached values do.

Differential Revision:

extra : moz-landing-system : lando
parent 836121f5
......@@ -48,6 +48,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
int32_t mPrefersReducedMotion;
bool mPrefersReducedMotionCached;
int32_t mSystemUsesDarkTheme;
bool mSystemUsesDarkThemeCached;
nscolor mColorTextSelectBackground;
nscolor mColorTextSelectBackgroundDisabled;
nscolor mColorHighlight;
......@@ -43,6 +43,8 @@ nsLookAndFeel::nsLookAndFeel()
......@@ -112,6 +114,7 @@ void nsLookAndFeel::RefreshImpl() {
mUseOverlayScrollbarsCached = false;
mAllowOverlayScrollbarsOverlapCached = false;
mPrefersReducedMotionCached = false;
mSystemUsesDarkThemeCached = false;
// Fetch colors next time they are requested.
......@@ -564,7 +567,11 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
aResult = 1;
case eIntID_SystemUsesDarkTheme:
aResult = SystemWantsDarkTheme();
if (!mSystemUsesDarkThemeCached) {
mSystemUsesDarkTheme = SystemWantsDarkTheme();
mSystemUsesDarkThemeCached = true;
aResult = mSystemUsesDarkTheme;
case eIntID_PrefersReducedMotion:
// Without native event loops,
......@@ -622,10 +629,10 @@ bool nsLookAndFeel::AllowOverlayScrollbarsOverlap() { return (UseOverlayScrollba
bool nsLookAndFeel::SystemWantsDarkTheme() {
// This returns true if the macOS system appearance is set to dark mode on
// 10.14+, false otherwise.
if (nsCocoaFeatures::OnMojaveOrLater()) {
return !![[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
if (!nsCocoaFeatures::OnMojaveOrLater()) {
return false;
return false;
return !![[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
......@@ -670,6 +677,11 @@ nsTArray<LookAndFeelInt> nsLookAndFeel::GetIntCacheImpl() {
prefersReducedMotion.value = GetInt(eIntID_PrefersReducedMotion);
LookAndFeelInt systemUsesDarkTheme; = eIntID_SystemUsesDarkTheme;
systemUsesDarkTheme.value = GetInt(eIntID_SystemUsesDarkTheme);
return lookAndFeelIntCache;
......@@ -684,6 +696,10 @@ void nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeel
mAllowOverlayScrollbarsOverlap = entry.value;
mAllowOverlayScrollbarsOverlapCached = true;
case eIntID_SystemUsesDarkTheme:
mSystemUsesDarkTheme = entry.value;
mSystemUsesDarkThemeCached = true;
case eIntID_PrefersReducedMotion:
mPrefersReducedMotion = entry.value;
mPrefersReducedMotionCached = true;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment