Bug 1697338 - Make context menus and tooltips adapt to the system appearance, if widget.macos.respect-system-appearance is set to true. r=mac-reviewers,bradwerth

With this patch, we will no longer use the vibrant appearance names on 10.14+,
as suggested in the 10.14 release notes:

> For apps linked against the macOS 10.14 SDK, NSVisualEffectView automatically
> uses the correct vibrant NSAppearance as its appearance, based on the
> appearance of its superview. For example, if its superview uses the aqua
> appearance, NSVisualEffectView uses vibrantLight. As a result, you shouldn’t
> explicitly set the appearance of the NSVisualEffectView, either in code or in
> Interface Builder. Explicitly setting the appearance was necessary in earlier
> versions of macOS."

The above applies to us even while we still link to the 10.12 SDK, because we
now set the "requires aqua appearance" plist flag to false (since bug 1697331).

Depends on D108154

Differential Revision: https://phabricator.services.mozilla.com/D108155
This commit is contained in:
Markus Stange 2021-03-17 16:50:10 +00:00
Родитель 42b696aac7
Коммит 744801d6de
1 изменённых файлов: 24 добавлений и 2 удалений

Просмотреть файл

@ -28,6 +28,28 @@ using namespace mozilla;
@end
static NSAppearance* AppearanceForVibrancyType(VibrancyType aType) {
if (@available(macOS 10.14, *)) {
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:
@ -36,9 +58,9 @@ static NSAppearance* AppearanceForVibrancyType(VibrancyType aType) {
case VibrancyType::SOURCE_LIST:
case VibrancyType::SOURCE_LIST_SELECTION:
case VibrancyType::ACTIVE_SOURCE_LIST_SELECTION:
return [NSAppearance appearanceNamed:@"NSAppearanceNameVibrantLight"];
return [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
case VibrancyType::TITLEBAR_DARK:
return [NSAppearance appearanceNamed:@"NSAppearanceNameVibrantDark"];
return [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];
}
}