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: https://phabricator.services.mozilla.com/D21303

--HG--
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()
mAllowOverlayScrollbarsOverlapCached(false),
mPrefersReducedMotion(-1),
mPrefersReducedMotionCached(false),
mSystemUsesDarkTheme(-1),
mSystemUsesDarkThemeCached(false),
mColorTextSelectBackground(0),
mColorTextSelectBackgroundDisabled(0),
mColorHighlight(0),
......@@ -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;
break;
case eIntID_SystemUsesDarkTheme:
aResult = SystemWantsDarkTheme();
if (!mSystemUsesDarkThemeCached) {
mSystemUsesDarkTheme = SystemWantsDarkTheme();
mSystemUsesDarkThemeCached = true;
}
aResult = mSystemUsesDarkTheme;
break;
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);
lookAndFeelIntCache.AppendElement(prefersReducedMotion);
LookAndFeelInt systemUsesDarkTheme;
systemUsesDarkTheme.id = eIntID_SystemUsesDarkTheme;
systemUsesDarkTheme.value = GetInt(eIntID_SystemUsesDarkTheme);
lookAndFeelIntCache.AppendElement(systemUsesDarkTheme);
return lookAndFeelIntCache;
}
......@@ -684,6 +696,10 @@ void nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeel
mAllowOverlayScrollbarsOverlap = entry.value;
mAllowOverlayScrollbarsOverlapCached = true;
break;
case eIntID_SystemUsesDarkTheme:
mSystemUsesDarkTheme = entry.value;
mSystemUsesDarkThemeCached = true;
break;
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