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,28 +491,31 @@ NativeWindowMac::NativeWindowMac( | |||
|   [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | ||||
| 
 | ||||
|   BOOL __block down = NO; | ||||
|   [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask handler:^NSEvent * _Nullable(NSEvent * event) { | ||||
|     if (![window_ isKeyWindow]) | ||||
|       return event; | ||||
|   event_monitor_.reset([[NSEvent | ||||
|     addLocalMonitorForEventsMatchingMask:NSScrollWheelMask | ||||
|     handler:^NSEvent * _Nullable(NSEvent * event) { | ||||
|       if (![window_ isKeyWindow]) | ||||
|         return event; | ||||
| 
 | ||||
|     if (!web_contents) | ||||
|       return event; | ||||
|       if (!web_contents) | ||||
|         return event; | ||||
| 
 | ||||
|     if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { | ||||
|       this->NotifyWindowScrollTouchDown(); | ||||
|       down = YES; | ||||
|     } | ||||
|     if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) { | ||||
|       this->NotifyWindowScrollTouchUp(); | ||||
|       down = NO; | ||||
|     } | ||||
|     return event; | ||||
|   }]; | ||||
|       if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { | ||||
|         this->NotifyWindowScrollTouchBegin(); | ||||
|         down = YES; | ||||
|       } | ||||
|       if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) { | ||||
|         this->NotifyWindowScrollTouchEnd(); | ||||
|         down = NO; | ||||
|       } | ||||
|       return event; | ||||
|   }] retain]); | ||||
| 
 | ||||
|   InstallView(); | ||||
| } | ||||
| 
 | ||||
| NativeWindowMac::~NativeWindowMac() { | ||||
|   [NSEvent removeMonitor: event_monitor_.get()]; | ||||
|   Observe(nullptr); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ben Gotow
				Ben Gotow