gecko-dev/widget/cocoa/SwipeTracker.h
Nathan Froyd 01583602a9 Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat
The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.

CLOSED TREE makes big refactorings like this a piece of cake.

 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'

 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h

 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py

 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'

if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi

--HG--
rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 01:24:48 -04:00

97 lines
3.5 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SwipeTracker_h
#define SwipeTracker_h
#include "EventForwards.h"
#include "mozilla/layers/AxisPhysicsMSDModel.h"
#include "mozilla/RefPtr.h"
#include "mozilla/TimeStamp.h"
#include "nsRefreshDriver.h"
#include "Units.h"
class nsIPresShell;
namespace mozilla {
class PanGestureInput;
/**
* SwipeTracker turns PanGestureInput events into swipe events
* (WidgetSimpleGestureEvent) and dispatches them into Gecko.
* The swiping behavior mirrors the behavior of the Cocoa API
* -[NSEvent trackSwipeEventWithOptions:dampenAmountThresholdMin:max:usingHandler:].
* The advantage of using this class over the Cocoa API is that this class
* properly supports submitting queued up events to it, and that it hopefully
* doesn't intermittently break scrolling the way the Cocoa API does (bug 927702).
*
* The swipe direction is either left or right. It is determined before the
* SwipeTracker is created and stays fixed during the swipe.
* During the swipe, the swipe has a current "value" which is between 0 and the
* target value. The target value is either 1 (swiping left) or -1 (swiping
* right) - see SwipeSuccessTargetValue().
* A swipe can either succeed or fail. If it succeeds, the swipe animation
* animates towards the success target value; if it fails, it animates back to
* a value of 0. A swipe can only succeed if the user is swiping in an allowed
* direction. (Since both the allowed directions and the swipe direction are
* known at swipe start time, it's clear from the beginning whether a swipe is
* doomed to fail. In that case, the purpose of the SwipeTracker is to simulate
* a bounce-back animation.)
*/
class SwipeTracker final : public nsARefreshObserver {
public:
NS_INLINE_DECL_REFCOUNTING(SwipeTracker, override)
SwipeTracker(nsChildView& aWidget,
const PanGestureInput& aSwipeStartEvent,
uint32_t aAllowedDirections,
uint32_t aSwipeDirection);
void Destroy();
nsEventStatus ProcessEvent(const PanGestureInput& aEvent);
void CancelSwipe();
static WidgetSimpleGestureEvent
CreateSwipeGestureEvent(EventMessage aMsg, nsIWidget* aWidget,
const LayoutDeviceIntPoint& aPosition);
// nsARefreshObserver
void WillRefresh(mozilla::TimeStamp aTime) override;
protected:
~SwipeTracker();
bool SwipingInAllowedDirection() const { return mAllowedDirections & mSwipeDirection; }
double SwipeSuccessTargetValue() const;
double ClampToAllowedRange(double aGestureAmount) const;
bool ComputeSwipeSuccess() const;
void StartAnimating(double aTargetValue);
void SwipeFinished();
void UnregisterFromRefreshDriver();
bool SendSwipeEvent(EventMessage aMsg, uint32_t aDirection, double aDelta);
nsChildView& mWidget;
RefPtr<nsRefreshDriver> mRefreshDriver;
layers::AxisPhysicsMSDModel mAxis;
const LayoutDeviceIntPoint mEventPosition;
TimeStamp mLastEventTimeStamp;
TimeStamp mLastAnimationFrameTime;
const uint32_t mAllowedDirections;
const uint32_t mSwipeDirection;
double mGestureAmount;
double mCurrentVelocity;
bool mEventsAreControllingSwipe;
bool mEventsHaveStartedNewGesture;
bool mRegisteredWithRefreshDriver;
};
} // namespace mozilla
#endif // SwipeTracker_h