зеркало из https://github.com/electron/electron.git
Merge pull request #4181 from bengotow/scroll-touch-events
Extend NativeWindow to track touch-based scroll events on OS X
This commit is contained in:
Коммит
059d97e1aa
|
@ -227,6 +227,14 @@ void Window::OnWindowLeaveFullScreen() {
|
|||
Emit("leave-full-screen");
|
||||
}
|
||||
|
||||
void Window::OnWindowScrollTouchBegin() {
|
||||
Emit("scroll-touch-begin");
|
||||
}
|
||||
|
||||
void Window::OnWindowScrollTouchEnd() {
|
||||
Emit("scroll-touch-end");
|
||||
}
|
||||
|
||||
void Window::OnWindowEnterHtmlFullScreen() {
|
||||
Emit("enter-html-full-screen");
|
||||
}
|
||||
|
|
|
@ -65,6 +65,8 @@ class Window : public mate::TrackableObject<Window>,
|
|||
void OnWindowResize() override;
|
||||
void OnWindowMove() override;
|
||||
void OnWindowMoved() override;
|
||||
void OnWindowScrollTouchBegin() override;
|
||||
void OnWindowScrollTouchEnd() override;
|
||||
void OnWindowEnterFullScreen() override;
|
||||
void OnWindowLeaveFullScreen() override;
|
||||
void OnWindowEnterHtmlFullScreen() override;
|
||||
|
|
|
@ -450,6 +450,16 @@ void NativeWindow::NotifyWindowEnterFullScreen() {
|
|||
OnWindowEnterFullScreen());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowScrollTouchBegin() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowScrollTouchBegin());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowScrollTouchEnd() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowScrollTouchEnd());
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowLeaveFullScreen() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||
OnWindowLeaveFullScreen());
|
||||
|
|
|
@ -217,6 +217,8 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void NotifyWindowMove();
|
||||
void NotifyWindowResize();
|
||||
void NotifyWindowMoved();
|
||||
void NotifyWindowScrollTouchBegin();
|
||||
void NotifyWindowScrollTouchEnd();
|
||||
void NotifyWindowEnterFullScreen();
|
||||
void NotifyWindowLeaveFullScreen();
|
||||
void NotifyWindowEnterHtmlFullScreen();
|
||||
|
|
|
@ -126,6 +126,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_;
|
||||
|
|
|
@ -499,10 +499,32 @@ NativeWindowMac::NativeWindowMac(
|
|||
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
||||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
|
||||
BOOL __block down = NO;
|
||||
event_monitor_.reset([[NSEvent
|
||||
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
|
||||
handler:^NSEvent * _Nullable(NSEvent * event) {
|
||||
if ([[event window] windowNumber] != [window_ windowNumber])
|
||||
return event;
|
||||
|
||||
if (!web_contents)
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ class NativeWindowObserver {
|
|||
virtual void OnWindowResize() {}
|
||||
virtual void OnWindowMove() {}
|
||||
virtual void OnWindowMoved() {}
|
||||
virtual void OnWindowScrollTouchBegin() {}
|
||||
virtual void OnWindowScrollTouchEnd() {}
|
||||
virtual void OnWindowEnterFullScreen() {}
|
||||
virtual void OnWindowLeaveFullScreen() {}
|
||||
virtual void OnWindowEnterHtmlFullScreen() {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче