mac: Add win.disable/enable/isEnabled() API

This commit is contained in:
Cheng Zhao 2016-06-17 17:38:44 +09:00
parent 214dd97165
commit 1a4b4a65c9
7 changed files with 76 additions and 0 deletions

View file

@ -279,6 +279,7 @@ bool ScopedDisableResize::disable_resize_ = false;
@property BOOL acceptsFirstMouse;
@property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow;
@property BOOL disableMouseEvents;
- (void)setShell:(atom::NativeWindowMac*)shell;
- (void)setEnableLargerThanScreen:(bool)enable;
@ -348,6 +349,29 @@ bool ScopedDisableResize::disable_resize_ = false;
return !self.disableKeyOrMainWindow;
}
- (void)sendEvent:(NSEvent*)event {
// Drop all mouse events.
if (self.disableMouseEvents) {
switch([event type]) {
case NSLeftMouseUp:
case NSLeftMouseDown:
case NSRightMouseDown:
case NSRightMouseUp:
case NSOtherMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
case NSMouseMoved:
case NSScrollWheel:
return;
default:
break;
}
}
[super sendEvent:event];
}
@end
@interface ControlRegionView : NSView
@ -496,6 +520,7 @@ NativeWindowMac::NativeWindowMac(
backing:NSBackingStoreBuffered
defer:YES]);
[window_ setShell:this];
[window_ setDisableMouseEvents:NO];
[window_ setEnableLargerThanScreen:enable_larger_than_screen()];
window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]);
@ -647,6 +672,20 @@ bool NativeWindowMac::IsVisible() {
return [window_ isVisible];
}
void NativeWindowMac::Disable() {
[window_ setDisableKeyOrMainWindow:YES];
[window_ setDisableMouseEvents:YES];
}
void NativeWindowMac::Enable() {
[window_ setDisableKeyOrMainWindow:NO];
[window_ setDisableMouseEvents:NO];
}
bool NativeWindowMac::IsEnabled() {
return ![window_ disableMouseEvents];
}
void NativeWindowMac::Maximize() {
if (IsMaximized())
return;