Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dialog fails to show after modal close #22889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 8 additions & 18 deletions shell/browser/native_window_mac.mm
Expand Up @@ -598,28 +598,18 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

void NativeWindowMac::Close() {
// When this is a sheet showing, performClose won't work.
if (is_modal() && parent() && IsVisible()) {
NSWindow* window = parent()->GetNativeWindow().GetNativeNSWindow();
if (NSWindow* sheetParent = [window sheetParent]) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(base::RetainBlock(^{
[sheetParent endSheet:window];
})));
}

// Manually emit close event (not triggered from close fn)
NotifyWindowCloseButtonClicked();
CloseImmediately();
return;
}

if (!IsClosable()) {
WindowList::WindowCloseCancelled(this);
return;
}

[window_ performClose:nil];

// Closing a sheet doesn't trigger windowShouldClose,
// so we need to manually call it ourselves here.
if (is_modal() && parent() && IsVisible()) {
NotifyWindowCloseButtonClicked();
}
}

void NativeWindowMac::CloseImmediately() {
Expand Down Expand Up @@ -656,9 +646,9 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

void NativeWindowMac::Show() {
if (is_modal() && parent()) {
NSWindow* window = parent()->GetNativeWindow().GetNativeNSWindow();
if ([window_ sheetParent] == nil)
[parent()->GetNativeWindow().GetNativeNSWindow()
beginSheet:window_
[window beginSheet:window_
completionHandler:^(NSModalResponse){
}];
return;
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/ui/cocoa/electron_ns_window.mm
Expand Up @@ -185,6 +185,10 @@ - (void)performClose:(id)sender {
return;
}
[self close];
} else if (shell_->is_modal() && shell_->parent() && shell_->IsVisible()) {
// We don't want to actually call [window close] here since
// we've already called endSheet on the modal sheet.
return;
} else {
[super performClose:sender];
}
Expand Down
13 changes: 13 additions & 0 deletions shell/browser/ui/cocoa/electron_ns_window_delegate.mm
Expand Up @@ -270,6 +270,19 @@ - (void)windowDidExitFullScreen:(NSNotification*)notification {
- (void)windowWillClose:(NSNotification*)notification {
shell_->NotifyWindowClosed();

// Something called -[NSWindow close] on a sheet rather than calling
// -[NSWindow endSheet:] on its parent. If the modal session is not ended
// then the parent will never be able to show another sheet. But calling
// -endSheet: here will block the thread with an animation, so post a task.
if (shell_->is_modal() && shell_->parent() && shell_->IsVisible()) {
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
NSWindow* sheetParent = [window sheetParent];
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(base::RetainBlock(^{
[sheetParent endSheet:window];
})));
}

// Clears the delegate when window is going to be closed, since EL Capitan it
// is possible that the methods of delegate would get called after the window
// has been closed.
Expand Down