OSX: Capture 3-finger swipe events in NativeWindow

This commit is contained in:
James Wheare 2016-03-18 15:20:04 +00:00
parent 67db92d500
commit 03319a5426
7 changed files with 76 additions and 0 deletions

View file

@ -243,6 +243,22 @@ void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end");
}
void Window::OnWindowSwipeUp() {
Emit("swipe-up");
}
void Window::OnWindowSwipeRight() {
Emit("swipe-right");
}
void Window::OnWindowSwipeDown() {
Emit("swipe-down");
}
void Window::OnWindowSwipeLeft() {
Emit("swipe-left");
}
void Window::OnWindowEnterHtmlFullScreen() {
Emit("enter-html-full-screen");
}

View file

@ -69,6 +69,10 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override;
void OnWindowSwipeUp() override;
void OnWindowSwipeRight() override;
void OnWindowSwipeDown() override;
void OnWindowSwipeLeft() override;
void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override;

View file

@ -480,6 +480,26 @@ void NativeWindow::NotifyWindowScrollTouchEnd() {
OnWindowScrollTouchEnd());
}
void NativeWindow::NotifyWindowSwipeUp() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipeUp());
}
void NativeWindow::NotifyWindowSwipeRight() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipeRight());
}
void NativeWindow::NotifyWindowSwipeDown() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipeDown());
}
void NativeWindow::NotifyWindowSwipeLeft() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipeLeft());
}
void NativeWindow::NotifyWindowLeaveFullScreen() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowLeaveFullScreen());

View file

@ -221,6 +221,10 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMoved();
void NotifyWindowScrollTouchBegin();
void NotifyWindowScrollTouchEnd();
void NotifyWindowSwipeUp();
void NotifyWindowSwipeRight();
void NotifyWindowSwipeDown();
void NotifyWindowSwipeLeft();
void NotifyWindowEnterFullScreen();
void NotifyWindowLeaveFullScreen();
void NotifyWindowEnterHtmlFullScreen();

View file

@ -267,6 +267,18 @@ bool ScopedDisableResize::disable_resize_ = false;
// NSWindow overrides.
- (void)swipeWithEvent:(NSEvent *)event {
if (event.deltaY == 1.0) {
shell_->NotifyWindowSwipeUp();
} else if (event.deltaX == -1.0) {
shell_->NotifyWindowSwipeRight();
} else if (event.deltaY == -1.0) {
shell_->NotifyWindowSwipeDown();
} else if (event.deltaX == 1.0) {
shell_->NotifyWindowSwipeLeft();
}
}
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
// Resizing is disabled.
if (ScopedDisableResize::IsResizeDisabled())

View file

@ -58,6 +58,10 @@ class NativeWindowObserver {
virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowSwipeUp() {}
virtual void OnWindowSwipeRight() {}
virtual void OnWindowSwipeDown() {}
virtual void OnWindowSwipeLeft() {}
virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {}

View file

@ -322,6 +322,22 @@ Emitted when scroll wheel event phase has begun.
Emitted when scroll wheel event phase has ended.
### Event: 'swipe-up' _OS X_
Emitted on 3-finger swipe up.
### Event: 'swipe-right' _OS X_
Emitted on 3-finger swipe right.
### Event: 'swipe-down' _OS X_
Emitted on 3-finger swipe down.
### Event: 'swipe-left' _OS X_
Emitted on 3-finger swipe left.
## Methods
The `BrowserWindow` object has the following methods: