Skip to content

Commit

Permalink
clean some shit up, fix 10.8 by putting back sharp corners. (release)
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
i3roly committed Aug 9, 2024
1 parent 97056a8 commit fafc24d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 114 deletions.
15 changes: 1 addition & 14 deletions widget/cocoa/MacThemeGeometryType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion widget/cocoa/SDKDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions widget/cocoa/VibrancyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
22 changes: 2 additions & 20 deletions widget/cocoa/VibrancyManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
}

Expand Down
47 changes: 2 additions & 45 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1705,33 +1705,6 @@ static void blinkRgn(RgnHandle rgn) {
RefPtr<layers::NativeLayerRoot> nsChildView::GetNativeLayerRoot() {
return mNativeLayerRoot;
}
static int32_t FindTitlebarBottom(const nsTArray<nsIWidget::ThemeGeometry>& 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<nsIWidget::ThemeGeometry>& 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<nsIWidget::ThemeGeometry>& aThemeGeometries,
nsITheme::ThemeGeometryType aThemeGeometryType) {
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
}
Expand Down
69 changes: 39 additions & 30 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions widget/cocoa/nsLookAndFeel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fafc24d

Please sign in to comment.