Bug 1533562 - Do not move the TitlebarGradientView from a ToolbarWindow into a BorderlessWindow when hiding the window chrome. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D25516

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2019-04-22 19:27:09 +00:00
parent 537ff00f68
commit de6910917a
2 changed files with 32 additions and 11 deletions

View File

@ -78,6 +78,15 @@ typedef struct _nsCocoaWindowList {
- (BOOL)isBeingShown; - (BOOL)isBeingShown;
- (BOOL)isVisibleOrBeingShown; - (BOOL)isVisibleOrBeingShown;
// Returns an autoreleased NSArray containing the NSViews that we consider the
// "contents" of this window. All views in the returned array are subviews of
// this window's content view. However, the array may not include all of the
// content view's subviews; concretely, the ToolbarWindow implementation will
// exclude its TitlebarGradientView from the array that is returned here.
// In the vast majority of cases, the array will only have a single element:
// this window's mainChildView.
- (NSArray<NSView*>*)contentViewContents;
- (ChildView*)mainChildView; - (ChildView*)mainChildView;
- (NSArray*)titlebarControls; - (NSArray*)titlebarControls;

View File

@ -1209,10 +1209,12 @@ void nsCocoaWindow::HideWindowChrome(bool aShouldHide) {
[mWindow removeChildWindow:child]; [mWindow removeChildWindow:child];
} }
// Remove the content view. // Remove the views in the old window's content view.
NSView* contentView = [mWindow contentView]; // The NSArray is autoreleased and retains its NSViews.
[contentView retain]; NSArray<NSView*>* contentViewContents = [mWindow contentViewContents];
[contentView removeFromSuperviewWithoutNeedingDisplay]; for (NSView* view in contentViewContents) {
[view removeFromSuperviewWithoutNeedingDisplay];
}
// Save state (like window title). // Save state (like window title).
NSMutableDictionary* state = [mWindow exportState]; NSMutableDictionary* state = [mWindow exportState];
@ -1226,9 +1228,10 @@ void nsCocoaWindow::HideWindowChrome(bool aShouldHide) {
// Re-import state. // Re-import state.
[mWindow importState:state]; [mWindow importState:state];
// Reparent the content view. // Add the old content view subviews to the new window's content view.
[mWindow setContentView:contentView]; for (NSView* view in contentViewContents) {
[contentView release]; [[mWindow contentView] addSubview:view];
}
// Reparent child windows. // Reparent child windows.
enumerator = [childWindows objectEnumerator]; enumerator = [childWindows objectEnumerator];
@ -2906,6 +2909,10 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return [contentView superview] ? [contentView superview] : contentView; return [contentView superview] ? [contentView superview] : contentView;
} }
- (NSArray<NSView*>*)contentViewContents {
return [[[[self contentView] subviews] copy] autorelease];
}
- (ChildView*)mainChildView { - (ChildView*)mainChildView {
NSView* contentView = [self contentView]; NSView* contentView = [self contentView];
NSView* lastView = [[contentView subviews] lastObject]; NSView* lastView = [[contentView subviews] lastObject];
@ -3137,10 +3144,6 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return YES; return YES;
} }
- (BOOL)mouseDownCanMoveWindow {
return YES;
}
- (NSView*)hitTest:(NSPoint)aPoint { - (NSView*)hitTest:(NSPoint)aPoint {
return nil; return nil;
} }
@ -3212,6 +3215,15 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
[super dealloc]; [super dealloc];
} }
- (NSArray<NSView*>*)contentViewContents {
NSMutableArray<NSView*>* contents = [[[self contentView] subviews] mutableCopy];
if (mTitlebarGradientView) {
// Do not include the titlebar gradient view in the returned array.
[contents removeObject:mTitlebarGradientView];
}
return [contents autorelease];
}
- (void)updateTitlebarGradientViewPresence { - (void)updateTitlebarGradientViewPresence {
BOOL needTitlebarView = ![self drawsContentsIntoWindowFrame]; BOOL needTitlebarView = ![self drawsContentsIntoWindowFrame];
if (needTitlebarView && !mTitlebarGradientView) { if (needTitlebarView && !mTitlebarGradientView) {