mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
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:
parent
c5e9e00e0a
commit
9f061ef34e
@ -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
|
||||
|
@ -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()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user