diff --git a/layout/style/test/test_non_content_accessible_values.html b/layout/style/test/test_non_content_accessible_values.html index 5136e5c54bba..af943436c3a4 100644 --- a/layout/style/test/test_non_content_accessible_values.html +++ b/layout/style/test/test_non_content_accessible_values.html @@ -109,6 +109,8 @@ const NON_CONTENT_ACCESSIBLE_VALUES = { "-moz-mac-disclosure-button-open", "-moz-mac-source-list", "-moz-mac-source-list-selection", + "-moz-mac-vibrant-titlebar-dark", + "-moz-mac-vibrant-titlebar-light", "button-bevel", "caret", diff --git a/servo/components/style/values/specified/box.rs b/servo/components/style/values/specified/box.rs index 3fca5ec71c8f..a2b0804bc4ec 100644 --- a/servo/components/style/values/specified/box.rs +++ b/servo/components/style/values/specified/box.rs @@ -1915,6 +1915,10 @@ pub enum Appearance { MozMacSourceList, #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] MozMacSourceListSelection, + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozMacVibrantTitlebarDark, + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozMacVibrantTitlebarLight, /// A themed focus outline (for outline:auto). /// diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index 3700efae0f3a..352f3e0f264d 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -371,6 +371,10 @@ pub enum SystemColor { /// Inactive light hightlight MozMacSecondaryhighlight, + /// Font smoothing background colors needed by the Mac OS X theme, based on + /// -moz-appearance names. + MozMacVibrantTitlebarLight, + MozMacVibrantTitlebarDark, MozMacMenupopup, MozMacMenuitem, MozMacActiveMenuitem, diff --git a/widget/cocoa/MacThemeGeometryType.h b/widget/cocoa/MacThemeGeometryType.h index 559e21d79211..8f29a68f562b 100644 --- a/widget/cocoa/MacThemeGeometryType.h +++ b/widget/cocoa/MacThemeGeometryType.h @@ -12,6 +12,8 @@ enum MacThemeGeometryType { eThemeGeometryTypeWindowButtons, eThemeGeometryTypeMenu, eThemeGeometryTypeHighlightedMenuItem, + eThemeGeometryTypeVibrantTitlebarLight, + eThemeGeometryTypeVibrantTitlebarDark, eThemeGeometryTypeTooltip, eThemeGeometryTypeSourceList, eThemeGeometryTypeSourceListSelection, diff --git a/widget/cocoa/VibrancyManager.h b/widget/cocoa/VibrancyManager.h index b85b8b1e8022..8f7cbc5e2959 100644 --- a/widget/cocoa/VibrancyManager.h +++ b/widget/cocoa/VibrancyManager.h @@ -22,6 +22,8 @@ class nsChildView; namespace mozilla { enum class VibrancyType { + TITLEBAR_LIGHT, + TITLEBAR_DARK, TOOLTIP, MENU, HIGHLIGHTED_MENUITEM, diff --git a/widget/cocoa/VibrancyManager.mm b/widget/cocoa/VibrancyManager.mm index a193f1549048..d9eef2b35e0a 100644 --- a/widget/cocoa/VibrancyManager.mm +++ b/widget/cocoa/VibrancyManager.mm @@ -25,14 +25,29 @@ using namespace mozilla; static NSAppearance* AppearanceForVibrancyType(VibrancyType aType) { if (@available(macOS 10.14, *)) { - // Inherit the appearance from the window. If the window is using Dark Mode, the vibrancy - // will automatically be dark, too. This is available starting with macOS 10.14. - return nil; + switch (aType) { + case VibrancyType::TITLEBAR_LIGHT: + // This must always be light (regular aqua), regardless of window appearance. + return [NSAppearance appearanceNamed:NSAppearanceNameAqua]; + case VibrancyType::TITLEBAR_DARK: + // This must always be dark (dark aqua), regardless of window appearance. + return [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; + case VibrancyType::TOOLTIP: + case VibrancyType::MENU: + case VibrancyType::HIGHLIGHTED_MENUITEM: + case VibrancyType::SOURCE_LIST: + case VibrancyType::SOURCE_LIST_SELECTION: + case VibrancyType::ACTIVE_SOURCE_LIST_SELECTION: + // Inherit the appearance from the window. If the window is using Dark Mode, the vibrancy + // will automatically be dark, too. This is available starting with macOS 10.14. + return nil; + } } // For 10.13 and below, a vibrant appearance name must be used. There is no system dark mode and // no automatic adaptation to the window; all windows are light. switch (aType) { + case VibrancyType::TITLEBAR_LIGHT: case VibrancyType::TOOLTIP: case VibrancyType::MENU: case VibrancyType::HIGHLIGHTED_MENUITEM: @@ -40,6 +55,8 @@ static NSAppearance* AppearanceForVibrancyType(VibrancyType aType) { case VibrancyType::SOURCE_LIST_SELECTION: case VibrancyType::ACTIVE_SOURCE_LIST_SELECTION: return [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]; + case VibrancyType::TITLEBAR_DARK: + return [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark]; } } @@ -59,6 +76,9 @@ static NSVisualEffectState VisualEffectStateForVibrancyType(VibrancyType aType) static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType(VibrancyType aType, BOOL* aOutIsEmphasized) { switch (aType) { + case VibrancyType::TITLEBAR_LIGHT: + case VibrancyType::TITLEBAR_DARK: + return NSVisualEffectMaterialTitlebar; case VibrancyType::TOOLTIP: if (@available(macOS 10.14, *)) { return (NSVisualEffectMaterial)NSVisualEffectMaterialToolTip; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 0cd9de60c312..0ad45df7beaf 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1636,8 +1636,10 @@ static int32_t FindTitlebarBottom(const nsTArray& aThe int32_t aWindowWidth) { int32_t titlebarBottom = 0; for (auto& g : aThemeGeometries) { - if (g.mType == eThemeGeometryTypeTitlebar && g.mRect.X() <= 0 && - g.mRect.XMost() >= aWindowWidth && g.mRect.Y() <= 0) { + if ((g.mType == eThemeGeometryTypeTitlebar || + g.mType == eThemeGeometryTypeVibrantTitlebarLight || + g.mType == eThemeGeometryTypeVibrantTitlebarDark) && + g.mRect.X() <= 0 && g.mRect.XMost() >= aWindowWidth && g.mRect.Y() <= 0) { titlebarBottom = std::max(titlebarBottom, g.mRect.YMost()); } } @@ -1703,6 +1705,10 @@ void nsChildView::UpdateThemeGeometries(const nsTArray& aThemeGeo static Maybe ThemeGeometryTypeToVibrancyType( nsITheme::ThemeGeometryType aThemeGeometryType) { switch (aThemeGeometryType) { + case eThemeGeometryTypeVibrantTitlebarLight: + return Some(VibrancyType::TITLEBAR_LIGHT); + case eThemeGeometryTypeVibrantTitlebarDark: + return Some(VibrancyType::TITLEBAR_DARK); case eThemeGeometryTypeTooltip: return Some(VibrancyType::TOOLTIP); case eThemeGeometryTypeMenu: @@ -1752,6 +1758,10 @@ static void MakeRegionsNonOverlapping(Region& aFirst, Regions&... aRest) { } void nsChildView::UpdateVibrancy(const nsTArray& aThemeGeometries) { + LayoutDeviceIntRegion vibrantTitlebarLightRegion = + GatherVibrantRegion(aThemeGeometries, VibrancyType::TITLEBAR_LIGHT); + LayoutDeviceIntRegion vibrantTitlebarDarkRegion = + GatherVibrantRegion(aThemeGeometries, VibrancyType::TITLEBAR_DARK); LayoutDeviceIntRegion menuRegion = GatherVibrantRegion(aThemeGeometries, VibrancyType::MENU); LayoutDeviceIntRegion tooltipRegion = GatherVibrantRegion(aThemeGeometries, VibrancyType::TOOLTIP); @@ -1764,11 +1774,14 @@ void nsChildView::UpdateVibrancy(const nsTArray& aThemeGeometries LayoutDeviceIntRegion activeSourceListSelectionRegion = GatherVibrantRegion(aThemeGeometries, VibrancyType::ACTIVE_SOURCE_LIST_SELECTION); - MakeRegionsNonOverlapping(menuRegion, tooltipRegion, highlightedMenuItemRegion, sourceListRegion, + MakeRegionsNonOverlapping(vibrantTitlebarLightRegion, vibrantTitlebarDarkRegion, menuRegion, + tooltipRegion, highlightedMenuItemRegion, sourceListRegion, sourceListSelectionRegion, activeSourceListSelectionRegion); auto& vm = EnsureVibrancyManager(); bool changed = false; + changed |= vm.UpdateVibrantRegion(VibrancyType::TITLEBAR_LIGHT, vibrantTitlebarLightRegion); + changed |= vm.UpdateVibrantRegion(VibrancyType::TITLEBAR_DARK, vibrantTitlebarDarkRegion); changed |= vm.UpdateVibrantRegion(VibrancyType::MENU, menuRegion); changed |= vm.UpdateVibrantRegion(VibrancyType::TOOLTIP, tooltipRegion); changed |= vm.UpdateVibrantRegion(VibrancyType::HIGHLIGHTED_MENUITEM, highlightedMenuItemRegion); diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index c19000de2839..eedbcc6b808e 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -326,6 +326,20 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme, nscolor case ColorID::MozNativevisitedhyperlinktext: color = GetColorFromNSColor(NSColor.systemPurpleColor); break; + // The following colors are supposed to be used as font-smoothing background + // colors, in the chrome-only -moz-font-smoothing-background-color property. + // This property is used for text on "vibrant" -moz-appearances. + // The colors have been obtained from the system on 10.14 using the + // program at https://bugzilla.mozilla.org/attachment.cgi?id=9208594 . + // We could obtain them at runtime, but doing so may be expensive and + // requires the use of the private API + // -[NSVisualEffectView fontSmoothingBackgroundColor]. + case ColorID::MozMacVibrantTitlebarLight: + color = NS_RGB(0xe6, 0xe6, 0xe6); + break; + case ColorID::MozMacVibrantTitlebarDark: + color = NS_RGB(0x28, 0x28, 0x28); + break; case ColorID::MozMacTooltip: case ColorID::MozMacMenupopup: case ColorID::MozMacMenuitem: diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 00512c4c328e..881d7e89e18f 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -3232,6 +3232,8 @@ nsNativeThemeCocoa::WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppear case StyleAppearance::ProgressBar: case StyleAppearance::Meter: case StyleAppearance::Meterchunk: + case StyleAppearance::MozMacVibrantTitlebarLight: + case StyleAppearance::MozMacVibrantTitlebarDark: *aShouldRepaint = false; return NS_OK; default: @@ -3364,6 +3366,9 @@ bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFra case StyleAppearance::FocusOutline: return true; + case StyleAppearance::MozMacVibrantTitlebarLight: + case StyleAppearance::MozMacVibrantTitlebarDark: + return true; default: break; } @@ -3455,6 +3460,10 @@ nsITheme::ThemeGeometryType nsNativeThemeCocoa::ThemeGeometryTypeForWidget( return eThemeGeometryTypeToolbox; case StyleAppearance::MozWindowButtonBox: return eThemeGeometryTypeWindowButtons; + case StyleAppearance::MozMacVibrantTitlebarLight: + return eThemeGeometryTypeVibrantTitlebarLight; + case StyleAppearance::MozMacVibrantTitlebarDark: + return eThemeGeometryTypeVibrantTitlebarDark; case StyleAppearance::Tooltip: return eThemeGeometryTypeTooltip; case StyleAppearance::Menupopup: diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index 7ae28e88cf57..3cc2c561dbc5 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -288,6 +288,8 @@ static const char sColorPrefs[][41] = { "ui.-moz-mac-menutextselect", "ui.-moz_mac_disabledtoolbartext", "ui.-moz-mac-secondaryhighlight", + "ui.-moz-mac-vibrant-titlebar-light", + "ui.-moz-mac-vibrant-titlebar-dark", "ui.-moz-mac-menupopup", "ui.-moz-mac-menuitem", "ui.-moz-mac-active-menuitem", @@ -621,6 +623,8 @@ nscolor nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID, COLOR(MozMacMenutextselect, 0xFF, 0xFF, 0xFF) COLOR(MozMacDisabledtoolbartext, 0x3F, 0x3F, 0x3F) COLOR(MozMacSecondaryhighlight, 0xD4, 0xD4, 0xD4) + COLOR(MozMacVibrantTitlebarLight, 0xf7, 0xf7, 0xf7) + COLOR(MozMacVibrantTitlebarDark, 0x28, 0x28, 0x28) COLOR(MozMacMenupopup, 0xe6, 0xe6, 0xe6) COLOR(MozMacMenuitem, 0xe6, 0xe6, 0xe6) COLOR(MozMacActiveMenuitem, 0x0a, 0x64, 0xdc)