Bug 1016035 - More swipe refactoring. r?kats draft
authorMarkus Stange <mstange@themasta.com>
Thu, 23 Jul 2015 15:17:28 -0400
changeset 288164 40a6723d8216f90d02cde197cc2dff1e5c2370eb
parent 288163 d13afd01221ac1edc945cef28e2cdc05987c453f
child 288165 a79912272c150b363ddab30380eaf92c6eb6cde6
push id4815
push usermstange@themasta.com
push dateThu, 27 Aug 2015 05:31:12 +0000
reviewerskats
bugs1016035
milestone43.0a1
Bug 1016035 - More swipe refactoring. r?kats
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -302,20 +302,17 @@ typedef NSInteger NSEventGestureAxis;
 - (void)scrollWheel:(NSEvent *)anEvent;
 - (void)handleAsyncScrollEvent:(CGEventRef)cgEvent ofType:(CGEventType)type;
 
 // Helper function for Lion smart magnify events
 + (BOOL)isLionSmartMagnifyEvent:(NSEvent*)anEvent;
 
 // Support for fluid swipe tracking.
 #ifdef __LP64__
-- (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent
-                     scrollOverflowX:(double)anOverflowX
-                     scrollOverflowY:(double)anOverflowY
-              viewPortIsOverscrolled:(BOOL)aViewPortIsOverscrolled;
+- (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent;
 #endif
 
 - (void)setUsingOMTCompositor:(BOOL)aUseOMTC;
 
 - (NSEvent*)lastKeyDownEvent;
 @end
 
 class ChildViewMouseTracker {
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -4299,34 +4299,17 @@ NSEvent* gLastDragMouseDownEvent = nil;
 // for deciding which is which. But once the decision is made, the OS tracks
 // the swipe until it has finished, and decides whether or not it succeeded.
 // A horizontal swipe has the same functionality as the Back and Forward
 // buttons.
 // This method is partly based on Apple sample code available at
 // developer.apple.com/library/mac/#releasenotes/Cocoa/AppKitOlderNotes.html
 // (under Fluid Swipe Tracking API).
 - (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent
-                     scrollOverflowX:(double)anOverflowX
-                     scrollOverflowY:(double)anOverflowY
-              viewPortIsOverscrolled:(BOOL)aViewPortIsOverscrolled
-{
-  // We should only track scroll events as swipe if the viewport is being
-  // overscrolled.
-  if (!aViewPortIsOverscrolled) {
-    return;
-  }
-
-  // Only initiate tracking if the user has tried to scroll past the edge of
-  // the current page (as indicated by 'anOverflowX' or 'anOverflowY' being
-  // non-zero). Gecko only sets WidgetMouseScrollEvent.scrollOverflow when it's
-  // processing NS_MOUSE_PIXEL_SCROLL events (not NS_MOUSE_SCROLL events).
-  if (anOverflowX == 0.0) {
-    return;
-  }
-
+{
   CGFloat deltaX = [anEvent scrollingDeltaX];
 
   uint32_t direction = (deltaX < 0.0)
     ? (uint32_t)nsIDOMSimpleGestureEvent::DIRECTION_RIGHT
     : (uint32_t)nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
 
   // We're ready to start the animation. Tell Gecko about it, and at the same
   // time ask it if it really wants to start an animation for this event.
@@ -4870,16 +4853,24 @@ PanGestureTypeForEvent(NSEvent* aEvent)
           return PanGestureInput::PANGESTURE_PAN;
       }
     default:
       NS_ERROR("unexpected event phase");
       return PanGestureInput::PANGESTURE_PAN;
   }
 }
 
+static bool
+IsPotentialSwipeStartEventOverscrollingViewport(const WidgetWheelEvent& aEvent)
+{
+  // We should only track scroll events as swipe if the viewport is being
+  // overscrolled.
+  return aEvent.mViewPortIsOverscrolled && aEvent.overflowDeltaX != 0.0;
+}
+
 - (void)scrollWheel:(NSEvent*)theEvent
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (gfxPrefs::AsyncPanZoomSeparateEventThread() && [self apzctm]) {
     // Disable main-thread scrolling completely when using APZ with the
     // separate event thread. This is bug 1013412.
     return;
@@ -4944,24 +4935,19 @@ PanGestureTypeForEvent(NSEvent* aEvent)
 
     widgetWheelEvent = mGeckoChild->DispatchAPZWheelInputEvent(panEvent);
 
     if (!mGeckoChild) {
       return;
     }
 
 #ifdef __LP64__
-    // overflowDeltaX and overflowDeltaY tell us when the user has tried to
-    // scroll past the edge of a page (in those cases it's non-zero).
-    if (canTriggerSwipe) {
-
-      [self maybeTrackScrollEventAsSwipe:theEvent
-                         scrollOverflowX:widgetWheelEvent.overflowDeltaX
-                         scrollOverflowY:widgetWheelEvent.overflowDeltaY
-                  viewPortIsOverscrolled:widgetWheelEvent.mViewPortIsOverscrolled];
+    if (canTriggerSwipe && IsPotentialSwipeStartEventOverscrollingViewport(widgetWheelEvent)) {
+      [self maybeTrackScrollEventAsSwipe:theEvent];
+
     }
 #endif // #ifdef __LP64__
 
   } else if (usePreciseDeltas) {
     // This is on 10.6 or old touchpads that don't have any phase information.
     ScrollWheelInput wheelEvent(eventIntervalTime, eventTimeStamp, modifiers,
                                 ScrollWheelInput::SCROLLMODE_INSTANT,
                                 ScrollWheelInput::SCROLLDELTA_PIXEL,