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

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

Issue 2690573002: MacViews: Handle three-finger swipe gestures for navigation. (Closed)
Patch Set: Address CL isues. 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
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..b477b43db4d1e2ac9dec8a9faabf3cdcc7d62ca3 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -800,6 +800,27 @@ 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;
+
+ // We need to invert deltas in order to match GestureEventDetails's
+ // directions.
+ auto invert = [](CGFloat val) { return val * -1.; };
tapted 2017/02/15 22:25:53 The comment is good, but (unless I'm missing somet
themblsha 2017/02/16 15:27:49 You've opened my eyes yet again. Thanks :-)
+ ui::GestureEventDetails swipeDetails(
+ ui::ET_GESTURE_SWIPE, invert([event deltaX]), invert([event deltaY]));
+ swipeDetails.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHPAD);
+
+ gfx::PointF location = ui::EventLocationFromNative(event);
+ 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;

Powered by Google App Engine
This is Rietveld 408576698