mac: Fix maximize/unmaximize event emitted before window is maximized

This commit is contained in:
Cheng Zhao 2016-06-22 14:06:54 +09:00
parent a5976055bf
commit 8ffd069689

View file

@ -70,6 +70,7 @@ bool ScopedDisableResize::disable_resize_ = false;
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> { @interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
@private @private
atom::NativeWindowMac* shell_; atom::NativeWindowMac* shell_;
bool is_zooming_;
} }
- (id)initWithShell:(atom::NativeWindowMac*)shell; - (id)initWithShell:(atom::NativeWindowMac*)shell;
@end @end
@ -79,6 +80,7 @@ bool ScopedDisableResize::disable_resize_ = false;
- (id)initWithShell:(atom::NativeWindowMac*)shell { - (id)initWithShell:(atom::NativeWindowMac*)shell {
if ((self = [super init])) { if ((self = [super init])) {
shell_ = shell; shell_ = shell;
is_zooming_ = false;
} }
return self; return self;
} }
@ -172,16 +174,20 @@ bool ScopedDisableResize::disable_resize_ = false;
} }
- (BOOL)windowShouldZoom:(NSWindow*)window toFrame:(NSRect)newFrame { - (BOOL)windowShouldZoom:(NSWindow*)window toFrame:(NSRect)newFrame {
// Cocoa doen't have concept of maximize/unmaximize, so wee need to emulate is_zooming_ = true;
// them by calculating size change when zooming.
if (newFrame.size.width < [window frame].size.width ||
newFrame.size.height < [window frame].size.height)
shell_->NotifyWindowUnmaximize();
else
shell_->NotifyWindowMaximize();
return YES; return YES;
} }
- (void)windowDidEndLiveResize:(NSNotification*)notification {
if (is_zooming_) {
if (shell_->IsMaximized())
shell_->NotifyWindowMaximize();
else
shell_->NotifyWindowUnmaximize();
is_zooming_ = false;
}
}
- (void)windowWillEnterFullScreen:(NSNotification*)notification { - (void)windowWillEnterFullScreen:(NSNotification*)notification {
// Hide the native toolbar before entering fullscreen, so there is no visual // Hide the native toolbar before entering fullscreen, so there is no visual
// artifacts. // artifacts.