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)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;
- (NSArray*)titlebarControls;

View File

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