Merge pull request #4843 from jwheare/mac-swipe-events

OSX: Expose 3-finger swipe events in browser-window
This commit is contained in:
Cheng Zhao 2016-03-31 10:37:27 +09:00
commit 0e3737423b
7 changed files with 33 additions and 0 deletions

View file

@ -248,6 +248,10 @@ void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end");
}
void Window::OnWindowSwipe(const std::string& direction) {
Emit("swipe", direction);
}
void Window::OnWindowEnterHtmlFullScreen() {
Emit("enter-html-full-screen");
}

View file

@ -69,6 +69,7 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override;
void OnWindowSwipe(const std::string& direction) override;
void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override;

View file

@ -480,6 +480,11 @@ void NativeWindow::NotifyWindowScrollTouchEnd() {
OnWindowScrollTouchEnd());
}
void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipe(direction));
}
void NativeWindow::NotifyWindowLeaveFullScreen() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowLeaveFullScreen());

View file

@ -221,6 +221,7 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMoved();
void NotifyWindowScrollTouchBegin();
void NotifyWindowScrollTouchEnd();
void NotifyWindowSwipe(const std::string& direction);
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_->NotifyWindowSwipe("up");
} else if (event.deltaX == -1.0) {
shell_->NotifyWindowSwipe("right");
} else if (event.deltaY == -1.0) {
shell_->NotifyWindowSwipe("down");
} else if (event.deltaX == 1.0) {
shell_->NotifyWindowSwipe("left");
}
}
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
// Resizing is disabled.
if (ScopedDisableResize::IsResizeDisabled())

View file

@ -58,6 +58,7 @@ class NativeWindowObserver {
virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowSwipe(const std::string& direction) {}
virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {}

View file

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