diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index c15874715c..47c65dc620 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -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 {