From fafc24dc784c2985ebbd7a918b9f42352af85838 Mon Sep 17 00:00:00 2001 From: broly Date: Thu, 8 Aug 2024 19:17:55 -0600 Subject: [PATCH] clean some shit up, fix 10.8 by putting back sharp corners. (release) - remove some vibrancy code that i thought i needed when i knew less. @EMILIO-O-O (https://www.youtube.com/watch?v=K43NKA3f98k) - there is a problem with 10.8, maybe 10.9. this is the conundrum. rounded corners via: mRootCALayer.masksToBounds = YES in nsChildView.mm results in a bunch of things shownig that should not be. i.e. you get some weird boxes when you mouseover and also it 'whites' out the preferences popup or even preview hovers. if i disable it, you get sharp corners but everything else works. so for now, all you get is sharp corners. oh and, i did notice that the firefox screenshotter does crash in 10.8 after you click download, but it downloads. so that's weird ass shit. i'll look into it fuck you, cry about it. i'm doing this for free and it's like the entire this is just a checkpoint commit. i don't want a gnarly one getting lost because i may find something else. who knows. whatever at least i found the issue. also find it weird that milestone commits (i.e. 130.0a1) were included in releases with a lesser number (129.0). no answer in the channel of course. e.g. https://hg.mozilla.org/mozilla-unified/rev/96acf0534436cec34e18f7078e206873339a31d5 (@EMILIO-O-O-O) paid mozilla team is either choked, scared, or just speechless (except @mstange ofc, my dogg). --- widget/cocoa/MacThemeGeometryType.h | 15 +------ widget/cocoa/SDKDeclarations.h | 6 ++- widget/cocoa/VibrancyManager.h | 2 - widget/cocoa/VibrancyManager.mm | 22 +-------- widget/cocoa/nsChildView.mm | 47 +------------------- widget/cocoa/nsCocoaWindow.mm | 69 ++++++++++++++++------------- widget/cocoa/nsLookAndFeel.mm | 2 - 7 files changed, 49 insertions(+), 114 deletions(-) diff --git a/widget/cocoa/MacThemeGeometryType.h b/widget/cocoa/MacThemeGeometryType.h index 0996a1b2ca22a..d2c8d594bb0f7 100644 --- a/widget/cocoa/MacThemeGeometryType.h +++ b/widget/cocoa/MacThemeGeometryType.h @@ -7,21 +7,8 @@ enum MacThemeGeometryType { eThemeGeometryTypeTitlebar = 1, - eThemeGeometryTypeToolbar, - eThemeGeometryTypeToolbox, eThemeGeometryTypeWindowButtons, - eThemeGeometryTypeFullscreenButton, - eThemeGeometryTypeMenu, - eThemeGeometryTypeHighlightedMenuItem, - eThemeGeometryTypeVibrancyLight, - eThemeGeometryTypeVibrancyDark, - eThemeGeometryTypeVibrantTitlebarLight, - eThemeGeometryTypeVibrantTitlebarDark, - eThemeGeometryTypeTooltip, - eThemeGeometryTypeSheet, - eThemeGeometryTypeSourceList, - eThemeGeometryTypeSourceListSelection, - eThemeGeometryTypeActiveSourceListSelection + eThemeGeometryTypeFullscreenButton }; #endif diff --git a/widget/cocoa/SDKDeclarations.h b/widget/cocoa/SDKDeclarations.h index 5d641f03778b0..e3d8423075b31 100644 --- a/widget/cocoa/SDKDeclarations.h +++ b/widget/cocoa/SDKDeclarations.h @@ -58,7 +58,7 @@ enum : OSType { #endif -#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_15 +#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14 const NSAppearanceName NSAppearanceNameDarkAqua = @"NSAppearanceNameDarkAqua"; @@ -81,6 +81,10 @@ const NSAppearanceName NSAppearanceNameDarkAqua = @"NSAppearanceNameDarkAqua"; @property(class, strong, readonly) NSColor* linkColor NS_AVAILABLE_MAC(10_10); @end +enum { + NSVisualEffectMaterialToolTip NS_ENUM_AVAILABLE_MAC(10_14) = 17, +}; + #endif diff --git a/widget/cocoa/VibrancyManager.h b/widget/cocoa/VibrancyManager.h index 90992bdce4296..839674ca2ce12 100644 --- a/widget/cocoa/VibrancyManager.h +++ b/widget/cocoa/VibrancyManager.h @@ -19,8 +19,6 @@ class ViewRegion; enum class VibrancyType { // Add new values here, or update MaxEnumValue below if you add them after. - TOOLTIP, - MENU, Titlebar, }; diff --git a/widget/cocoa/VibrancyManager.mm b/widget/cocoa/VibrancyManager.mm index 5a2cad4ff4782..da42a972f9aa3 100644 --- a/widget/cocoa/VibrancyManager.mm +++ b/widget/cocoa/VibrancyManager.mm @@ -37,14 +37,7 @@ @interface MOZVibrantLeafView : MOZVibrantView static NSVisualEffectState VisualEffectStateForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - case VibrancyType::MENU: - // Tooltip and menu windows are never "key", so we need to tell the - // vibrancy effect to look active regardless of window state. - return NSVisualEffectStateActive; - default: - return NSVisualEffectStateFollowsWindowActiveState; - case VibrancyType::Titlebar: + case VibrancyType::Titlebar: break; } return NSVisualEffectStateFollowsWindowActiveState; @@ -53,14 +46,6 @@ static NSVisualEffectState VisualEffectStateForVibrancyType( static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - if (@available(macOS 10.14, *)) { - return (NSVisualEffectMaterial)NSVisualEffectMaterialToolTip; - } else { - return NSVisualEffectMaterialMenu; - } - case VibrancyType::MENU: - return NSVisualEffectMaterialMenu; case VibrancyType::Titlebar: return NSVisualEffectMaterialTitlebar; } @@ -69,13 +54,10 @@ static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType( static NSVisualEffectBlendingMode VisualEffectBlendingModeForVibrancyType( VibrancyType aType) { switch (aType) { - case VibrancyType::TOOLTIP: - case VibrancyType::MENU: - return NSVisualEffectBlendingModeBehindWindow; case VibrancyType::Titlebar: return StaticPrefs::widget_macos_titlebar_blend_mode_behind_window() ? NSVisualEffectBlendingModeBehindWindow - : NSVisualEffectBlendingModeWithinWindow; + : NSVisualEffectBlendingModeWithinWindow; } } diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index e8d21596393c7..95240f415a3b4 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1705,33 +1705,6 @@ static void blinkRgn(RgnHandle rgn) { RefPtr nsChildView::GetNativeLayerRoot() { return mNativeLayerRoot; } -static int32_t FindTitlebarBottom(const nsTArray& aThemeGeometries, - int32_t aWindowWidth) { - int32_t titlebarBottom = 0; - for (auto& g : aThemeGeometries) { - 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()); - } - } - return titlebarBottom; -} - -static int32_t FindUnifiedToolbarBottom(const nsTArray& aThemeGeometries, - int32_t aWindowWidth, int32_t aTitlebarBottom) { - int32_t unifiedToolbarBottom = aTitlebarBottom; - for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) { - const nsIWidget::ThemeGeometry& g = aThemeGeometries[i]; - if ((g.mType == eThemeGeometryTypeToolbar) && g.mRect.X() <= 0 && - g.mRect.XMost() >= aWindowWidth && g.mRect.Y() <= aTitlebarBottom) { - unifiedToolbarBottom = std::max(unifiedToolbarBottom, g.mRect.YMost()); - } - } - return unifiedToolbarBottom; -} - static LayoutDeviceIntRect FindFirstRectOfType( const nsTArray& aThemeGeometries, nsITheme::ThemeGeometryType aThemeGeometryType) { @@ -1757,23 +1730,7 @@ static LayoutDeviceIntRect FindFirstRectOfType( } - // Update unified toolbar height and sheet attachment position. - int32_t windowWidth = mBounds.width; - int32_t titlebarBottom = FindTitlebarBottom(aThemeGeometries, windowWidth); - int32_t unifiedToolbarBottom = - FindUnifiedToolbarBottom(aThemeGeometries, windowWidth, titlebarBottom); - int32_t toolboxBottom = - FindFirstRectOfType(aThemeGeometries, eThemeGeometryTypeToolbox).YMost(); - ToolbarWindow* win = (ToolbarWindow*)[mView window]; - int32_t titlebarHeight = CocoaPointsToDevPixels([win titlebarHeight]); - int32_t devUnifiedHeight = titlebarHeight + unifiedToolbarBottom; - [win setUnifiedToolbarHeight:DevPixelsToCocoaPoints(devUnifiedHeight)]; - - int32_t sheetPositionDevPx = std::max(toolboxBottom, unifiedToolbarBottom); - NSPoint sheetPositionView = {0, DevPixelsToCocoaPoints(sheetPositionDevPx)}; - NSPoint sheetPositionWindow = [mView convertPoint:sheetPositionView toView:nil]; - [win setSheetAttachmentPosition:sheetPositionWindow.y]; // Update titlebar control offsets. LayoutDeviceIntRect windowButtonRect = @@ -2235,11 +2192,11 @@ - (id)initWithFrame:(NSRect)inFrame geckoChild:(nsChildView*)inChild { mRootCALayer.bounds = NSZeroRect; mRootCALayer.anchorPoint = NSZeroPoint; mRootCALayer.contentsGravity = kCAGravityTopLeft; + [mPixelHostingView.layer addSublayer:mRootCALayer]; if(!nsCocoaFeatures::OnMavericksOrLater()) { mRootCALayer.cornerRadius = 4.0f; - mRootCALayer.masksToBounds = YES; + //mRootCALayer.masksToBounds = YES; } - [mPixelHostingView.layer addSublayer:mRootCALayer]; mLastPressureStage = 0; } diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 38a2feb89aa19..815e756693daa 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -2374,7 +2374,7 @@ static nsSizeMode GetWindowSizeMode(NSWindow* aWindow, bool aFullScreen) { return; } //10.7 complains if we don't have this check. - if(@available(macOS 10.8, *)) { + if(@available(macOS 10.9, *)) { NSAppearance* appearance = aScheme ? NSAppearanceForColorScheme(*aScheme) : nil; if (mWindow.appearance != appearance) { @@ -3286,9 +3286,8 @@ - (id)initWithContentRect:(NSRect)aContentRect } static NSImage* GetMenuMaskImage() { - CGFloat radius = 4.0f; - NSEdgeInsets insets = {5, 5, 5, 5}; - NSSize maskSize = {12, 12}; + CGFloat radius = 6.0f; + NSSize maskSize = {radius * 3.0f, radius * 3.0f}; NSImage* maskImage = [NSImage imageWithSize:maskSize flipped:YES drawingHandler:^BOOL(NSRect dstRect) { @@ -3300,41 +3299,51 @@ - (id)initWithContentRect:(NSRect)aContentRect [path fill]; return YES; }]; - [maskImage setCapInsets:insets]; + maskImage.capInsets = NSEdgeInsetsMake(radius, radius, radius, radius); return maskImage; } -- (void)swapOutChildViewWrapper:(NSView*)aNewWrapper { - [aNewWrapper setFrame:[[self contentView] frame]]; + +// Add an effect view wrapper if needed so that the OS draws the appropriate +// vibrancy effect and window border. +- (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle { + NSView* wrapper = [&]() -> NSView* { + if (aStyle == WindowShadow::Menu || aStyle == WindowShadow::Tooltip) { + const bool isMenu = aStyle == WindowShadow::Menu; + auto* effectView = + [[NSVisualEffectView alloc] initWithFrame:self.contentView.frame]; + + // Tooltip and menu windows are never "key", so we need to tell the + // vibrancy effect to look active regardless of window state. + effectView.state = NSVisualEffectStateActive; + effectView.blendingMode = NSVisualEffectBlendingModeBehindWindow; + if (isMenu) { + // Turn on rounded corner masking. + effectView.maskImage = GetMenuMaskImage(); + effectView.material = NSVisualEffectMaterialMenu; + } else { + if(@available(macOS 10.14, *)) { + effectView.material = NSVisualEffectMaterialToolTip; + } + } + return effectView; + } + return [[NSView alloc] initWithFrame:self.contentView.frame]; + }(); + + wrapper.wantsLayer = YES; + // Swap out our content view by the new view. Setting .contentView releases + // the old view. NSView* childView = [self.mainChildView retain]; [childView removeFromSuperview]; - [aNewWrapper addSubview:childView]; + [wrapper addSubview:childView]; [childView release]; - [super setContentView:aNewWrapper]; + super.contentView = wrapper; + [wrapper release]; } -- (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle { - if (aStyle == WindowShadow::Menu || aStyle == WindowShadow::Tooltip) { - // Add an effect view wrapper so that the OS draws the appropriate - // vibrancy effect and window border. - BOOL isMenu = aStyle == WindowShadow::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 { - // Remove the existing wrapper. - NSView* wrapper = [[NSView alloc] initWithFrame:NSZeroRect]; - [wrapper setWantsLayer:YES]; - [self swapOutChildViewWrapper:wrapper]; - [wrapper release]; - } -} + - (NSTouchBar*)makeTouchBar { mTouchBar = [[nsTouchBar alloc] init]; if (mTouchBar) { diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index 69be5edf54e8e..a733acebe19ee 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -345,9 +345,7 @@ static nscolor ProcessSelectionBackground(nscolor aColor, ColorScheme aScheme) { color = GetColorFromNSColor(NSColor.secondarySelectedControlColor); break; case ColorID::MozColheadertext: - DISPATCH_FALLTHROUGH; case ColorID::MozColheaderhovertext: - DISPATCH_FALLTHROUGH; case ColorID::MozColheaderactivetext: color = GetColorFromNSColor(NSColor.headerTextColor); break;