No need to use scoped_nsobject for id

This commit is contained in:
Cheng Zhao 2016-01-25 15:02:43 +08:00
parent 059d97e1aa
commit a83aee90e5
3 changed files with 23 additions and 11 deletions

View file

@ -126,7 +126,9 @@ 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_;
// Event monitor for scroll wheel event.
id wheel_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_;

View file

@ -499,32 +499,34 @@ NativeWindowMac::NativeWindowMac(
NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
BOOL __block down = NO; // Use an NSEvent monitor to listen for the wheel event.
event_monitor_.reset([[NSEvent BOOL __block began = NO;
wheel_event_monitor_ = [NSEvent
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
handler:^NSEvent * _Nullable(NSEvent * event) { handler:^(NSEvent* event) {
if ([[event window] windowNumber] != [window_ windowNumber]) if ([[event window] windowNumber] != [window_ windowNumber])
return event; return event;
if (!web_contents) if (!web_contents)
return event; return event;
if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { if (!began && (([event phase] == NSEventPhaseMayBegin) ||
([event phase] == NSEventPhaseBegan))) {
this->NotifyWindowScrollTouchBegin(); this->NotifyWindowScrollTouchBegin();
down = YES; began = YES;
} } else if (began && (([event phase] == NSEventPhaseEnded) ||
if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) { ([event phase] == NSEventPhaseCancelled))) {
this->NotifyWindowScrollTouchEnd(); this->NotifyWindowScrollTouchEnd();
down = NO; began = NO;
} }
return event; return event;
}] retain]); }];
InstallView(); InstallView();
} }
NativeWindowMac::~NativeWindowMac() { NativeWindowMac::~NativeWindowMac() {
[NSEvent removeMonitor: event_monitor_.get()]; [NSEvent removeMonitor:wheel_event_monitor_];
Observe(nullptr); Observe(nullptr);
} }

View file

@ -307,6 +307,14 @@ someWindow.on('app-command', function(e, cmd) {
}); });
``` ```
### Event: 'scroll-touch-begin' _OS X_
Emitted when scroll wheel event phase has begun.
### Event: 'scroll-touch-end' _OS X_
Emitted when scroll wheel event phase has ended.
## Methods ## Methods
The `BrowserWindow` object has the following methods: The `BrowserWindow` object has the following methods: