fix: handle async nature of [NSWindow -toggleFullScreen] (#25470)

This commit is contained in:
Shelley Vohr 2021-04-21 16:56:25 +02:00 committed by GitHub
parent 7063b5ef2c
commit 503d24a473
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 127 additions and 17 deletions

View file

@ -223,11 +223,23 @@ bool ScopedDisableResize::disable_resize_ = false;
if (is_simple_fs || always_simple_fs) {
shell_->SetSimpleFullScreen(!is_simple_fs);
} else {
bool maximizable = shell_->IsMaximizable();
[super toggleFullScreen:sender];
if (shell_->IsVisible()) {
// Until 10.13, AppKit would obey a call to -toggleFullScreen: made inside
// windowDidEnterFullScreen & windowDidExitFullScreen. Starting in 10.13,
// it behaves as though the transition is still in progress and just emits
// "not in a fullscreen state" when trying to exit fullscreen in the same
// runloop that entered it. To handle this, invoke -toggleFullScreen:
// asynchronously.
[super performSelector:@selector(toggleFullScreen:)
withObject:nil
afterDelay:0];
} else {
[super toggleFullScreen:sender];
}
// Exiting fullscreen causes Cocoa to redraw the NSWindow, which resets
// the enabled state for NSWindowZoomButton. We need to persist it.
bool maximizable = shell_->IsMaximizable();
shell_->SetMaximizable(maximizable);
}
}

View file

@ -17,6 +17,8 @@
#include "ui/views/widget/native_widget_mac.h"
using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
using FullScreenTransitionState =
electron::NativeWindowMac::FullScreenTransitionState;
@implementation ElectronNSWindowDelegate
@ -213,23 +215,36 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
}
- (void)windowWillEnterFullScreen:(NSNotification*)notification {
shell_->SetFullScreenTransitionState(FullScreenTransitionState::ENTERING);
shell_->NotifyWindowWillEnterFullScreen();
// Setting resizable to true before entering fullscreen.
is_resizable_ = shell_->IsResizable();
shell_->SetResizable(true);
}
- (void)windowDidEnterFullScreen:(NSNotification*)notification {
shell_->SetFullScreenTransitionState(FullScreenTransitionState::NONE);
shell_->NotifyWindowEnterFullScreen();
shell_->HandlePendingFullscreenTransitions();
}
- (void)windowWillExitFullScreen:(NSNotification*)notification {
shell_->SetFullScreenTransitionState(FullScreenTransitionState::EXITING);
shell_->NotifyWindowWillLeaveFullScreen();
}
- (void)windowDidExitFullScreen:(NSNotification*)notification {
shell_->SetFullScreenTransitionState(FullScreenTransitionState::NONE);
shell_->SetResizable(is_resizable_);
shell_->NotifyWindowLeaveFullScreen();
shell_->HandlePendingFullscreenTransitions();
}
- (void)windowWillClose:(NSNotification*)notification {