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<AtomNSWindow> window_;
|
||||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||||
|
base::scoped_nsobject<id> event_monitor_;
|
||||||
|
|
||||||
// The view that will fill the whole frameless window.
|
// The view that will fill the whole frameless window.
|
||||||
base::scoped_nsobject<FullSizeContentView> content_view_;
|
base::scoped_nsobject<FullSizeContentView> content_view_;
|
||||||
|
|
|
@ -491,28 +491,31 @@ NativeWindowMac::NativeWindowMac(
|
||||||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
|
||||||
BOOL __block down = NO;
|
BOOL __block down = NO;
|
||||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask handler:^NSEvent * _Nullable(NSEvent * event) {
|
event_monitor_.reset([[NSEvent
|
||||||
if (![window_ isKeyWindow])
|
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
|
||||||
return event;
|
handler:^NSEvent * _Nullable(NSEvent * event) {
|
||||||
|
if (![window_ isKeyWindow])
|
||||||
|
return event;
|
||||||
|
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return event;
|
return event;
|
||||||
|
|
||||||
if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) {
|
if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) {
|
||||||
this->NotifyWindowScrollTouchDown();
|
this->NotifyWindowScrollTouchBegin();
|
||||||
down = YES;
|
down = YES;
|
||||||
}
|
}
|
||||||
if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) {
|
if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) {
|
||||||
this->NotifyWindowScrollTouchUp();
|
this->NotifyWindowScrollTouchEnd();
|
||||||
down = NO;
|
down = NO;
|
||||||
}
|
}
|
||||||
return event;
|
return event;
|
||||||
}];
|
}] retain]);
|
||||||
|
|
||||||
InstallView();
|
InstallView();
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindowMac::~NativeWindowMac() {
|
NativeWindowMac::~NativeWindowMac() {
|
||||||
|
[NSEvent removeMonitor: event_monitor_.get()];
|
||||||
Observe(nullptr);
|
Observe(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue