summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsLookAndFeel.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/nsLookAndFeel.mm')
-rw-r--r--widget/cocoa/nsLookAndFeel.mm103
1 files changed, 58 insertions, 45 deletions
diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm
index 5675198ff2..779984be0c 100644
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -32,22 +32,44 @@ using namespace mozilla;
+ (void)startObserving;
@end
-nsLookAndFeel::nsLookAndFeel() = default;
+nsLookAndFeel::nsLookAndFeel() {
+ [MOZLookAndFeelDynamicChangeObserver startObserving];
+}
nsLookAndFeel::~nsLookAndFeel() = default;
-void nsLookAndFeel::NativeInit() {
+void nsLookAndFeel::EnsureInit() {
+ if (mInitialized) {
+ return;
+ }
+
NS_OBJC_BEGIN_TRY_ABORT_BLOCK
- [MOZLookAndFeelDynamicChangeObserver startObserving];
+ mInitialized = true;
+ NSWindow* window =
+ [[NSWindow alloc] initWithContentRect:NSZeroRect
+ styleMask:NSWindowStyleMaskTitled
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ auto release = MakeScopeExit([&] { [window release]; });
+
+ mRtl = window.windowTitlebarLayoutDirection ==
+ NSUserInterfaceLayoutDirectionRightToLeft;
+ mTitlebarHeight = std::ceil(window.frame.size.height);
+
RecordTelemetry();
NS_OBJC_END_TRY_ABORT_BLOCK
}
+void nsLookAndFeel::RefreshImpl() {
+ mInitialized = false;
+ nsXPLookAndFeel::RefreshImpl();
+}
+
static nscolor GetColorFromNSColor(NSColor* aColor) {
NSColor* deviceColor =
- [aColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
+ [aColor colorUsingColorSpace:NSColorSpace.deviceRGBColorSpace];
return NS_RGBA((unsigned int)(deviceColor.redComponent * 255.0),
(unsigned int)(deviceColor.greenComponent * 255.0),
(unsigned int)(deviceColor.blueComponent * 255.0),
@@ -77,8 +99,7 @@ static nscolor GetColorFromNSColorWithCustomAlpha(NSColor* aColor,
// whereas white text on dark blue (which what you get if you mix
// partially-transparent light blue with the black textbox background) has much
// better contrast.
-nscolor nsLookAndFeel::ProcessSelectionBackground(nscolor aColor,
- ColorScheme aScheme) {
+static nscolor ProcessSelectionBackground(nscolor aColor, ColorScheme aScheme) {
if (aScheme == ColorScheme::Dark) {
// When we use a dark selection color, we do not change alpha because we do
// not use dark selection in content. The dark system color is appropriate
@@ -136,6 +157,14 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
case ColorID::MozMenuhover:
case ColorID::Selecteditem:
color = GetColorFromNSColor(NSColor.selectedContentBackgroundColor);
+ if (aID == ColorID::MozMenuhover &&
+ !LookAndFeel::GetInt(IntID::PrefersReducedTransparency)) {
+ // Wash the color a little bit with semi-transparent white to match a
+ // bit closer the native NSVisualEffectSelection on menus.
+ color = NS_ComposeColors(
+ color,
+ NS_RGBA(255, 255, 255, aScheme == ColorScheme::Light ? 51 : 25));
+ }
break;
case ColorID::Accentcolortext:
case ColorID::MozMenuhovertext:
@@ -197,6 +226,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
: NS_RGB(0xFF, 0xFF, 0xFF);
break;
case ColorID::Windowtext:
+ case ColorID::MozDialogtext:
color = GetColorFromNSColor(NSColor.windowFrameTextColor);
break;
case ColorID::Appworkspace:
@@ -254,13 +284,14 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
case ColorID::Windowframe:
color = GetColorFromNSColor(NSColor.windowFrameColor);
break;
- case ColorID::Window: {
- color = GetColorFromNSColor(NSColor.windowBackgroundColor);
+ case ColorID::MozDialog:
+ case ColorID::Window:
+ color = GetColorFromNSColor(aScheme == ColorScheme::Light
+ ? NSColor.windowBackgroundColor
+ : NSColor.underPageBackgroundColor);
break;
- }
case ColorID::Field:
case ColorID::MozCombobox:
- case ColorID::MozDialog:
color = GetColorFromNSColor(NSColor.controlBackgroundColor);
break;
case ColorID::Fieldtext:
@@ -269,7 +300,6 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
case ColorID::MozButtonhovertext:
case ColorID::Menutext:
case ColorID::Infotext:
- case ColorID::MozDialogtext:
case ColorID::MozCellhighlighttext:
case ColorID::MozColheadertext:
case ColorID::MozColheaderhovertext:
@@ -323,6 +353,7 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
case ColorID::SpellCheckerUnderline:
case ColorID::Activeborder:
case ColorID::Inactiveborder:
+ case ColorID::MozAutofillBackground:
aColor = GetStandinForNativeColor(aID, aScheme);
return NS_OK;
default:
@@ -336,6 +367,16 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme,
NS_OBJC_END_TRY_ABORT_BLOCK
}
+static bool SystemWantsDarkTheme() {
+ // This returns true if the macOS system appearance is set to dark mode,
+ // false otherwise.
+ NSAppearanceName aquaOrDarkAqua =
+ [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[
+ NSAppearanceNameAqua, NSAppearanceNameDarkAqua
+ ]];
+ return [aquaOrDarkAqua isEqualToString:NSAppearanceNameDarkAqua];
+}
+
nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
@@ -355,9 +396,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
case IntID::CaretWidth:
aResult = 1;
break;
- case IntID::ShowCaretDuringSelection:
- aResult = 0;
- break;
case IntID::SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by EventStateManager::sTextfieldSelectModel
@@ -412,7 +450,12 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
aResult = nsCocoaFeatures::OnBigSurOrLater();
break;
case IntID::MacRTL:
- aResult = IsSystemOrientationRTL();
+ EnsureInit();
+ aResult = mRtl;
+ break;
+ case IntID::MacTitlebarHeight:
+ EnsureInit();
+ aResult = mTitlebarHeight;
break;
case IntID::AlertNotificationOrigin:
aResult = NS_ALERT_TOP;
@@ -469,14 +512,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
aResult = NSWorkspace.sharedWorkspace
.accessibilityDisplayShouldIncreaseContrast;
break;
- case IntID::VideoDynamicRange: {
- // If the platform says it supports HDR, then we claim to support
- // video-dynamic-range.
- gfxPlatform* platform = gfxPlatform::GetPlatform();
- MOZ_ASSERT(platform);
- aResult = platform->SupportsHDR();
- break;
- }
case IntID::PanelAnimations:
aResult = 1;
break;
@@ -519,28 +554,6 @@ nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
}
-bool nsLookAndFeel::SystemWantsDarkTheme() {
- // This returns true if the macOS system appearance is set to dark mode, false
- // otherwise.
- NSAppearanceName aquaOrDarkAqua =
- [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[
- NSAppearanceNameAqua, NSAppearanceNameDarkAqua
- ]];
- return [aquaOrDarkAqua isEqualToString:NSAppearanceNameDarkAqua];
-}
-
-/*static*/
-bool nsLookAndFeel::IsSystemOrientationRTL() {
- NSWindow* window =
- [[NSWindow alloc] initWithContentRect:NSZeroRect
- styleMask:NSWindowStyleMaskBorderless
- backing:NSBackingStoreBuffered
- defer:NO];
- auto direction = window.windowTitlebarLayoutDirection;
- [window release];
- return direction == NSUserInterfaceLayoutDirectionRightToLeft;
-}
-
bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;