Bug 1871507 - Native-looking tooltips for macOS. r=desktop-theme-reviewers,emilio

Native tooltips, menus, and other opaque windows on macOS receive a border from the window server, which greatly improves their appearance with dark mode. Borderless windows, such as popups, do not receive this treatment by default. However, we have been receiving this treatment for non-native menupopups by setting an effect view wrapper as the window's content view. Extending this logic to also support tooltips allows the window server to provide the appropriate border for them as well.

macOS also provides some additional padding to native tooltips, so I have updated this as well.

Differential Revision: https://phabricator.services.mozilla.com/D197122
This commit is contained in:
Sam Johnson 2023-12-26 10:24:18 +00:00
Родитель e25e84b4e0
Коммит 9e320eb3bc
3 изменённых файлов: 29 добавлений и 13 удалений

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

@ -406,6 +406,12 @@ tooltip:not([position]) {
}
}
@media (-moz-platform: macos) {
tooltip {
padding: 2px 6px; /* Matches native metrics. */
}
}
@media (-moz-platform: windows) {
tooltip {
appearance: none;

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

@ -55,7 +55,6 @@ typedef struct _nsCocoaWindowList {
BOOL mBeingShown;
BOOL mDrawTitle;
BOOL mUseMenuStyle;
BOOL mIsAnimationSuppressed;
nsTouchBar* mTouchBar;
@ -108,7 +107,7 @@ typedef struct _nsCocoaWindowList {
- (NSRect)getAndResetNativeDirtyRect;
- (void)setUseMenuStyle:(BOOL)aValue;
- (void)setEffectViewWrapperForStyle:(mozilla::StyleWindowShadow)aStyle;
@property(nonatomic) mozilla::StyleWindowShadow shadowStyle;
- (void)releaseJSObjects;
@ -436,6 +435,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
// transition, it is the animation object.
NSAnimation* mFullscreenTransitionAnimation;
mozilla::StyleWindowShadow mShadowStyle;
BOOL mIsShadowStyleSet;
CGFloat mBackingScaleFactor;
CGFloat mAspectRatio;

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

@ -143,6 +143,7 @@ nsCocoaWindow::nsCocoaWindow()
mPopupContentView(nil),
mFullscreenTransitionAnimation(nil),
mShadowStyle(StyleWindowShadow::Default),
mIsShadowStyleSet(NO),
mBackingScaleFactor(0.0),
mAnimationType(nsIWidget::eGenericWindowAnimation),
mWindowMadeHere(false),
@ -2684,6 +2685,10 @@ bool nsCocoaWindow::HasPendingInputEvent() {
void nsCocoaWindow::SetWindowShadowStyle(StyleWindowShadow aStyle) {
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
if (mShadowStyle == aStyle && mIsShadowStyleSet) {
return;
}
mShadowStyle = aStyle;
if (!mWindow || mWindowType != WindowType::Popup) {
@ -2691,8 +2696,9 @@ void nsCocoaWindow::SetWindowShadowStyle(StyleWindowShadow aStyle) {
}
mWindow.shadowStyle = mShadowStyle;
[mWindow setUseMenuStyle:mShadowStyle == StyleWindowShadow::Menu];
[mWindow setEffectViewWrapperForStyle:mShadowStyle];
[mWindow setHasShadow:aStyle != StyleWindowShadow::None];
mIsShadowStyleSet = YES;
NS_OBJC_END_TRY_IGNORE_BLOCK;
}
@ -3577,7 +3583,6 @@ static NSMutableSet* gSwizzledFrameViewClasses = nil;
mDirtyRect = NSZeroRect;
mBeingShown = NO;
mDrawTitle = NO;
mUseMenuStyle = NO;
mTouchBar = nil;
mIsAnimationSuppressed = NO;
[self updateTrackingArea];
@ -3614,22 +3619,27 @@ static NSImage* GetMenuMaskImage() {
[super setContentView:aNewWrapper];
}
- (void)setUseMenuStyle:(BOOL)aValue {
if (aValue && !mUseMenuStyle) {
// Turn on rounded corner masking.
NSView* effectView =
VibrancyManager::CreateEffectView(VibrancyType::MENU, YES);
[effectView setMaskImage:GetMenuMaskImage()];
- (void)setEffectViewWrapperForStyle:(StyleWindowShadow)aStyle {
if (aStyle == StyleWindowShadow::Menu ||
aStyle == StyleWindowShadow::Tooltip) {
// Add an effect view wrapper so that the OS draws the appropriate
// vibrancy effect and window border.
BOOL isMenu = aStyle == StyleWindowShadow::Menu;
NSView* effectView = VibrancyManager::CreateEffectView(
isMenu ? VibrancyType::MENU : VibrancyType::TOOLTIP, YES);
if (isMenu) {
// Turn on rounded corner masking.
[effectView setMaskImage:GetMenuMaskImage()];
}
[self swapOutChildViewWrapper:effectView];
[effectView release];
} else if (mUseMenuStyle && !aValue) {
// Turn off rounded corner masking.
} else {
// Remove the existing wrapper.
NSView* wrapper = [[NSView alloc] initWithFrame:NSZeroRect];
[wrapper setWantsLayer:YES];
[self swapOutChildViewWrapper:wrapper];
[wrapper release];
}
mUseMenuStyle = aValue;
}
- (NSTouchBar*)makeTouchBar {