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

Unified Diff: ui/events/cocoa/events_mac.mm

Issue 2193153002: MacViews: Send Mac scrollWheel NSEvents as ui::ET_SCROLL (ui::ScrollEvent). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20160728-MacViews-ScrollLayers
Patch Set: Support Widget MouseWheelEvent conversion Created 4 years, 3 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/events/cocoa/events_mac.mm
diff --git a/ui/events/cocoa/events_mac.mm b/ui/events/cocoa/events_mac.mm
index 48c955d7e17808db95bea6948dc4afe9d633bc02..4704424faae475c607b8867ce46393d9b7c9162b 100644
--- a/ui/events/cocoa/events_mac.mm
+++ b/ui/events/cocoa/events_mac.mm
@@ -43,7 +43,7 @@ EventType EventTypeFromNative(const base::NativeEvent& native_event) {
case NSMouseMoved:
return ET_MOUSE_MOVED;
case NSScrollWheel:
- return ET_MOUSEWHEEL;
+ return ET_SCROLL;
case NSMouseEntered:
return ET_MOUSE_ENTERED;
case NSMouseExited:
@@ -198,9 +198,48 @@ bool GetScrollOffsets(const base::NativeEvent& native_event,
float* y_offset,
float* x_offset_ordinal,
float* y_offset_ordinal,
- int* finger_count) {
- NOTIMPLEMENTED();
- return false;
+ int* finger_count,
+ EventMomentumPhase* momentum_phase) {
+ gfx::Vector2d offset = GetMouseWheelOffset(native_event);
+ *x_offset = *x_offset_ordinal = offset.x();
+ *y_offset = *y_offset_ordinal = offset.y();
+
+ // For non-scrolling events, the finger count can be determined with
+ // [[native_event touchesMatchingPhase:NSTouchPhaseTouching inView:nil] count]
+ // but it's illegal to ask that of scroll events, so say two fingers.
+ *finger_count = 2;
+
+ // If a user just rests two fingers on the touchpad without moving, AppKit
+ // uses NSEventPhaseMayBegin. Treat this the same as NSEventPhaseBegan.
+ const NSUInteger kBeginPhaseMask = NSEventPhaseBegan | NSEventPhaseMayBegin;
+ const NSUInteger kEndPhaseMask = NSEventPhaseCancelled | NSEventPhaseEnded;
+
+ // Note: although the NSEventPhase constants are bit flags, the logic here
+ // assumes AppKit will not combine them, so momentum phase should only be set
+ // once. If one of these DCHECKs fails it could mean some new hardware that
+ // needs tests in events_mac_unittest.mm.
+ DCHECK_EQ(EM_PHASE_NONE, *momentum_phase);
+
+ if ([native_event phase] & kBeginPhaseMask)
+ *momentum_phase = EM_PHASE_MAY_BEGIN;
+
+ if (([native_event phase] | [native_event momentumPhase]) & kEndPhaseMask) {
+ DCHECK_EQ(EM_PHASE_NONE, *momentum_phase);
+ *momentum_phase = EM_PHASE_END;
+ } else if ([native_event momentumPhase] != NSEventPhaseNone) {
+ DCHECK_EQ(EM_PHASE_NONE, *momentum_phase);
+ *momentum_phase = EM_PHASE_INERTIAL_UPDATE;
+ }
+
+ // If the event completely lacks phase information, there won't be further
+ // updates, so they must be treated as an end.
+ if (([native_event phase] | [native_event momentumPhase]) ==
+ NSEventPhaseNone) {
+ DCHECK_EQ(EM_PHASE_NONE, *momentum_phase);
+ *momentum_phase = EM_PHASE_END;
+ }
+
+ return true;
}
bool GetFlingData(const base::NativeEvent& native_event,

Powered by Google App Engine
This is Rietveld 408576698