Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 2690573002: MacViews: Handle three-finger swipe gestures for navigation. (Closed)
Patch Set: GetGestureCommand: return early in happy path. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/BUILD.gn ('k') | ui/views/view_unittest_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index b47f522dd7c759f2f1450c06c5eb9b544bfe0806..657e9b5973b59e6dba496b40d923a6ce806c7f5a 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -800,6 +800,34 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
hostedView_->GetWidget()->OnScrollEvent(&event);
}
+// Called when we get a three-finger swipe, and they're enabled in System
+// Preferences.
+- (void)swipeWithEvent:(NSEvent*)event {
+ if (!hostedView_)
+ return;
+
+ // themblsha: In my testing all three-finger swipes send only a single event
+ // with a value of +/-1 on either axis. Diagonal swipes are not handled by
+ // AppKit.
+
+ // We need to invert deltas in order to match GestureEventDetails's
+ // directions.
+ ui::GestureEventDetails swipeDetails(ui::ET_GESTURE_SWIPE, -[event deltaX],
+ -[event deltaY]);
+ swipeDetails.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHPAD);
+ swipeDetails.set_touch_points(3);
+
+ gfx::PointF location = ui::EventLocationFromNative(event);
+ // Note this uses the default unique_touch_event_id of 0 (Swipe events do not
+ // support -[NSEvent eventNumber]). This doesn't seem like a real omission
+ // because the three-finger swipes are instant and can't be tracked anyway.
+ ui::GestureEvent gestureEvent(location.x(), location.y(),
+ ui::EventFlagsFromNative(event),
+ ui::EventTimeFromNative(event), swipeDetails);
+
+ hostedView_->GetWidget()->OnGestureEvent(&gestureEvent);
+}
+
- (void)quickLookWithEvent:(NSEvent*)theEvent {
if (!hostedView_)
return;
« no previous file with comments | « ui/views/BUILD.gn ('k') | ui/views/view_unittest_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698