Bug 1697331 - Add a pref called widget.macos.respect-system-appearance which defaults to false. false means "force aqua appearance". r=emilio

This patch also sets the Info.plist keys to <false/>, i.e. "we don't require aqua".

Differential Revision: https://phabricator.services.mozilla.com/D107749
This commit is contained in:
Markus Stange 2021-03-12 18:36:00 +00:00
parent c5e9e00e0a
commit 9f061ef34e
2 changed files with 52 additions and 0 deletions

View File

@ -10679,6 +10679,13 @@
value: false
mirror: always
#ifdef XP_MACOSX
- name: widget.macos.respect-system-appearance
type: RelaxedAtomicBool
value: false
mirror: always
#endif
# Whether to allow gtk dark themes in content.
- name: widget.content.allow-gtk-dark-theme
type: bool

View File

@ -15,6 +15,7 @@
#include "nsCSSColorUtils.h"
#include "mozilla/FontPropertyTypes.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#import <Cocoa/Cocoa.h>
@ -27,6 +28,14 @@
@property(readonly) BOOL accessibilityDisplayShouldReduceMotion;
@end
#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14
@interface NSApplication (NSApplicationAppearance)
@property(strong) NSAppearance* appearance NS_AVAILABLE_MAC(10_14);
@end
#endif
static void RegisterRespectSystemAppearancePrefListenerOnce();
nsLookAndFeel::nsLookAndFeel(const LookAndFeelCache* aCache)
: nsXPLookAndFeel(),
mUseOverlayScrollbars(-1),
@ -73,6 +82,7 @@ nsLookAndFeel::nsLookAndFeel(const LookAndFeelCache* aCache)
if (aCache) {
DoSetCache(*aCache);
}
RegisterRespectSystemAppearancePrefListenerOnce();
}
nsLookAndFeel::~nsLookAndFeel() {}
@ -889,3 +899,38 @@ void nsLookAndFeel::EnsureInit() {
NS_OBJC_END_TRY_IGNORE_BLOCK
}
static void RespectSystemAppearancePrefChanged(const char* aPref, void* UserInfo) {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (@available(macOS 10.14, *)) {
if (StaticPrefs::widget_macos_respect_system_appearance()) {
// nil means "no override".
NSApp.appearance = nil;
} else {
// Override with aqua.
NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
}
}
// Send a notification that ChildView reacts to. This will cause it to call ThemeChanged and
// invalidate LookAndFeel colors.
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"AppleInterfaceThemeChangedNotification"
object:nil
userInfo:nil
deliverImmediately:YES];
}
static void RegisterRespectSystemAppearancePrefListenerOnce() {
static bool sRegistered = false;
if (sRegistered || !XRE_IsParentProcess()) {
return;
}
sRegistered = true;
Preferences::RegisterCallbackAndCall(
&RespectSystemAppearancePrefChanged,
nsDependentCString(StaticPrefs::GetPrefName_widget_macos_respect_system_appearance()));
}