Properly clean up NSEvent monitor
This commit is contained in:
parent
d492ff45d5
commit
e96e674201
2 changed files with 19 additions and 15 deletions
|
@ -110,6 +110,7 @@ class NativeWindowMac : public NativeWindow {
|
|||
|
||||
base::scoped_nsobject<AtomNSWindow> window_;
|
||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||
base::scoped_nsobject<id> event_monitor_;
|
||||
|
||||
// The view that will fill the whole frameless window.
|
||||
base::scoped_nsobject<FullSizeContentView> content_view_;
|
||||
|
|
|
@ -491,7 +491,9 @@ NativeWindowMac::NativeWindowMac(
|
|||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
|
||||
BOOL __block down = NO;
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask handler:^NSEvent * _Nullable(NSEvent * event) {
|
||||
event_monitor_.reset([[NSEvent
|
||||
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
|
||||
handler:^NSEvent * _Nullable(NSEvent * event) {
|
||||
if (![window_ isKeyWindow])
|
||||
return event;
|
||||
|
||||
|
@ -499,20 +501,21 @@ NativeWindowMac::NativeWindowMac(
|
|||
return event;
|
||||
|
||||
if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) {
|
||||
this->NotifyWindowScrollTouchDown();
|
||||
this->NotifyWindowScrollTouchBegin();
|
||||
down = YES;
|
||||
}
|
||||
if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) {
|
||||
this->NotifyWindowScrollTouchUp();
|
||||
this->NotifyWindowScrollTouchEnd();
|
||||
down = NO;
|
||||
}
|
||||
return event;
|
||||
}];
|
||||
}] retain]);
|
||||
|
||||
InstallView();
|
||||
}
|
||||
|
||||
NativeWindowMac::~NativeWindowMac() {
|
||||
[NSEvent removeMonitor: event_monitor_.get()];
|
||||
Observe(nullptr);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue