diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8dd7f2143540..ae0c96529ff7 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -614,6 +614,19 @@ Returns: Emitted on 3-finger swipe. Possible directions are `up`, `right`, `down`, `left`. +#### Event: 'rotate-gesture' _macOS_ + +Returns: + +* `event` Event +* `rotation` Float + +Emitted on trackpad rotation gesture. Continually emitted until rotation gesture is +ended. The `rotation` value on each emission is the angle in degrees rotated since +the last emission. The last emitted event upon a rotation gesture will always be of +value `0`. Counter-clockwise rotation values are positive, while clockwise ones are +negative. + #### Event: 'sheet-begin' _macOS_ Emitted when the window opens a sheet. diff --git a/shell/browser/api/atom_api_top_level_window.cc b/shell/browser/api/atom_api_top_level_window.cc index 9aeab0821aec..d73326f2ad03 100644 --- a/shell/browser/api/atom_api_top_level_window.cc +++ b/shell/browser/api/atom_api_top_level_window.cc @@ -246,6 +246,10 @@ void TopLevelWindow::OnWindowSwipe(const std::string& direction) { Emit("swipe", direction); } +void TopLevelWindow::OnWindowRotateGesture(float rotation) { + Emit("rotate-gesture", rotation); +} + void TopLevelWindow::OnWindowSheetBegin() { Emit("sheet-begin"); } diff --git a/shell/browser/api/atom_api_top_level_window.h b/shell/browser/api/atom_api_top_level_window.h index c2bae0d9c19a..84b1f10c9348 100644 --- a/shell/browser/api/atom_api_top_level_window.h +++ b/shell/browser/api/atom_api_top_level_window.h @@ -73,6 +73,7 @@ class TopLevelWindow : public mate::TrackableObject, void OnWindowScrollTouchBegin() override; void OnWindowScrollTouchEnd() override; void OnWindowSwipe(const std::string& direction) override; + void OnWindowRotateGesture(float rotation) override; void OnWindowSheetBegin() override; void OnWindowSheetEnd() override; void OnWindowEnterFullScreen() override; diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index af4cbb94c553..6e63b55cba52 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -513,6 +513,11 @@ void NativeWindow::NotifyWindowSwipe(const std::string& direction) { observer.OnWindowSwipe(direction); } +void NativeWindow::NotifyWindowRotateGesture(float rotation) { + for (NativeWindowObserver& observer : observers_) + observer.OnWindowRotateGesture(rotation); +} + void NativeWindow::NotifyWindowSheetBegin() { for (NativeWindowObserver& observer : observers_) observer.OnWindowSheetBegin(); diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index cc85d6538cc9..80d70452b0e5 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -256,6 +256,7 @@ class NativeWindow : public base::SupportsUserData, void NotifyWindowScrollTouchBegin(); void NotifyWindowScrollTouchEnd(); void NotifyWindowSwipe(const std::string& direction); + void NotifyWindowRotateGesture(float rotation); void NotifyWindowSheetBegin(); void NotifyWindowSheetEnd(); void NotifyWindowEnterFullScreen(); diff --git a/shell/browser/native_window_observer.h b/shell/browser/native_window_observer.h index 03f07d36a4d2..6310344ba426 100644 --- a/shell/browser/native_window_observer.h +++ b/shell/browser/native_window_observer.h @@ -78,6 +78,7 @@ class NativeWindowObserver : public base::CheckedObserver { virtual void OnWindowScrollTouchBegin() {} virtual void OnWindowScrollTouchEnd() {} virtual void OnWindowSwipe(const std::string& direction) {} + virtual void OnWindowRotateGesture(float rotation) {} virtual void OnWindowSheetBegin() {} virtual void OnWindowSheetEnd() {} virtual void OnWindowEnterFullScreen() {} diff --git a/shell/browser/ui/cocoa/atom_ns_window.mm b/shell/browser/ui/cocoa/atom_ns_window.mm index 86040fe448c2..0b9a367bd682 100644 --- a/shell/browser/ui/cocoa/atom_ns_window.mm +++ b/shell/browser/ui/cocoa/atom_ns_window.mm @@ -72,6 +72,10 @@ bool ScopedDisableResize::disable_resize_ = false; } } +- (void)rotateWithEvent:(NSEvent*)event { + shell_->NotifyWindowRotateGesture(event.rotation); +} + - (NSRect)contentRectForFrameRect:(NSRect)frameRect { if (shell_->has_frame()) return [super contentRectForFrameRect:frameRect];