From 8482109dea8f0c3f506e435d2e0e0269a16ff83c Mon Sep 17 00:00:00 2001 From: James Wheare Date: Wed, 23 Mar 2016 15:20:11 +0000 Subject: [PATCH] Switch to a single OS X swipe event with a direction argument --- atom/browser/api/atom_api_window.cc | 16 ++-------------- atom/browser/api/atom_api_window.h | 5 +---- atom/browser/native_window.cc | 19 ++----------------- atom/browser/native_window.h | 5 +---- atom/browser/native_window_mac.mm | 18 +++++++++--------- atom/browser/native_window_observer.h | 5 +---- docs/api/browser-window.md | 17 +++++------------ 7 files changed, 21 insertions(+), 64 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c99f80876b8..9a57c98e626 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -243,20 +243,8 @@ 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::OnWindowSwipe(const std::string& direction) { + Emit("swipe", direction); } void Window::OnWindowEnterHtmlFullScreen() { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 33bf479b8f9..d26ff5b3674 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -69,10 +69,7 @@ class Window : public mate::TrackableObject, void OnWindowMoved() override; void OnWindowScrollTouchBegin() override; void OnWindowScrollTouchEnd() override; - void OnWindowSwipeUp() override; - void OnWindowSwipeRight() override; - void OnWindowSwipeDown() override; - void OnWindowSwipeLeft() override; + void OnWindowSwipe(const std::string& direction) override; void OnWindowEnterFullScreen() override; void OnWindowLeaveFullScreen() override; void OnWindowEnterHtmlFullScreen() override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index d95c2346642..2627c704d21 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -480,24 +480,9 @@ void NativeWindow::NotifyWindowScrollTouchEnd() { OnWindowScrollTouchEnd()); } -void NativeWindow::NotifyWindowSwipeUp() { +void NativeWindow::NotifyWindowSwipe(const std::string& direction) { 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()); + OnWindowSwipe(direction)); } void NativeWindow::NotifyWindowLeaveFullScreen() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 27bb4fa5de8..49e1e71d5df 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -221,10 +221,7 @@ class NativeWindow : public base::SupportsUserData, void NotifyWindowMoved(); void NotifyWindowScrollTouchBegin(); void NotifyWindowScrollTouchEnd(); - void NotifyWindowSwipeUp(); - void NotifyWindowSwipeRight(); - void NotifyWindowSwipeDown(); - void NotifyWindowSwipeLeft(); + void NotifyWindowSwipe(const std::string& direction); void NotifyWindowEnterFullScreen(); void NotifyWindowLeaveFullScreen(); void NotifyWindowEnterHtmlFullScreen(); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b0f2df4aaec..2044ee7d718 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -268,15 +268,15 @@ 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(); - } + 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 { diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index e88a77af41a..cfbae95bda1 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -58,10 +58,7 @@ 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 OnWindowSwipe(const std::string& direction) {} virtual void OnWindowEnterFullScreen() {} virtual void OnWindowLeaveFullScreen() {} virtual void OnWindowEnterHtmlFullScreen() {} diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 3ccbb6fe9ad..76343f967b1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -322,21 +322,14 @@ Emitted when scroll wheel event phase has begun. Emitted when scroll wheel event phase has ended. -### Event: 'swipe-up' _OS X_ +### Event: 'swipe' _OS X_ -Emitted on 3-finger swipe up. +Returns: -### Event: 'swipe-right' _OS X_ +* `event` Event +* `direction` String -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. +Emitted on 3-finger swipe. Possible directions are `up`, `right`, `down`, `left`. ## Methods