Issue #2022 Follow-Up - Add autorelease to our manual NSView to prevent potential leaks. Also move titlebar overrides from BaseWindow to ToolbarWindow... This caused problems in Waterfox Classic on Ventura, while this didn't seem to be necessary in UXP... There is no need for those overrides in BaseWindow, so why risk potential problems. https://bugzilla.mozilla.org/show_bug.cgi?id=1576387 d7f5814dc0

This commit is contained in:
Brian Smith 2022-11-27 13:57:13 -06:00 committed by roytam1
commit e10eeed772

View file

@ -2905,7 +2905,7 @@ static NSMutableSet *gSwizzledFrameViewClasses = nil;
[super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag];
// MacOS 13 Ventura, doesn't seem to create the contentView... so create it ourselves
if(![super contentView]) {
[super setContentView:[[NSView alloc] initWithFrame:aContentRect]];
[super setContentView:[[[NSView alloc] initWithFrame:aContentRect] autorelease]];
}
mState = nil;
mActiveTitlebarColor = nil;
@ -3213,64 +3213,6 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
}
}
// Override methods that translate between content rect and frame rect.
- (NSRect)contentRectForFrameRect:(NSRect)aRect
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super contentRectForFrameRect:aRect];
}
- (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
if ([super respondsToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
return [super contentRectForFrameRect:aRect styleMask:aMask];
} else {
return [NSWindow contentRectForFrameRect:aRect styleMask:aMask];
}
}
- (NSRect)frameRectForContentRect:(NSRect)aRect
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super frameRectForContentRect:aRect];
}
- (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
if ([super respondsToSelector:@selector(frameRectForContentRect:styleMask:)]) {
return [super frameRectForContentRect:aRect styleMask:aMask];
} else {
return [NSWindow frameRectForContentRect:aRect styleMask:aMask];
}
}
- (void)setContentView:(NSView*)aView
{
[super setContentView:aView];
// Now move the contentView to the bottommost layer so that it's guaranteed
// to be under the window buttons.
NSView* frameView = [aView superview];
[aView removeFromSuperview];
if ([frameView respondsToSelector:@selector(_addKnownSubview:positioned:relativeTo:)]) {
// 10.10 prints a warning when we call addSubview on the frame view, so we
// silence the warning by calling a private method instead.
[frameView _addKnownSubview:aView positioned:NSWindowBelow relativeTo:nil];
} else {
[frameView addSubview:aView positioned:NSWindowBelow relativeTo:nil];
}
}
- (NSArray*)titlebarControls
{
// Return all subviews of the frameView which are not the content view.
@ -3504,6 +3446,64 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return NSMaxY(frameRect) - NSMaxY(originalContentRect);
}
// Override methods that translate between content rect and frame rect.
- (NSRect)contentRectForFrameRect:(NSRect)aRect
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super contentRectForFrameRect:aRect];
}
- (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
if ([super respondsToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
return [super contentRectForFrameRect:aRect styleMask:aMask];
} else {
return [NSWindow contentRectForFrameRect:aRect styleMask:aMask];
}
}
- (NSRect)frameRectForContentRect:(NSRect)aRect
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super frameRectForContentRect:aRect];
}
- (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
if ([super respondsToSelector:@selector(frameRectForContentRect:styleMask:)]) {
return [super frameRectForContentRect:aRect styleMask:aMask];
} else {
return [NSWindow frameRectForContentRect:aRect styleMask:aMask];
}
}
- (void)setContentView:(NSView*)aView
{
[super setContentView:aView];
// Now move the contentView to the bottommost layer so that it's guaranteed
// to be under the window buttons.
NSView* frameView = [aView superview];
[aView removeFromSuperview];
if ([frameView respondsToSelector:@selector(_addKnownSubview:positioned:relativeTo:)]) {
// 10.10 prints a warning when we call addSubview on the frame view, so we
// silence the warning by calling a private method instead.
[frameView _addKnownSubview:aView positioned:NSWindowBelow relativeTo:nil];
} else {
[frameView addSubview:aView positioned:NSWindowBelow relativeTo:nil];
}
}
// Stores the complete height of titlebar + toolbar.
- (void)setUnifiedToolbarHeight:(CGFloat)aHeight
{