Bug 1256562 part.2 All event dispatchers under widget/cocoa should initialize WidgetEventTime::mTimeStamp with nsCocoaUtils::GetEventTimeStamp() r?smaug
MozReview-Commit-ID: 3sXtO76JScf
--- a/widget/cocoa/SwipeTracker.h
+++ b/widget/cocoa/SwipeTracker.h
@@ -49,37 +49,39 @@ public:
SwipeTracker(nsChildView& aWidget,
const PanGestureInput& aSwipeStartEvent,
uint32_t aAllowedDirections,
uint32_t aSwipeDirection);
void Destroy();
nsEventStatus ProcessEvent(const PanGestureInput& aEvent);
- void CancelSwipe();
+ void CancelSwipe(const TimeStamp& aTimeStamp);
static WidgetSimpleGestureEvent
CreateSwipeGestureEvent(EventMessage aMsg, nsIWidget* aWidget,
- const LayoutDeviceIntPoint& aPosition);
+ const LayoutDeviceIntPoint& aPosition,
+ const TimeStamp& aTimeStamp);
// 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 SwipeFinished(const TimeStamp& aTimeStamp);
void UnregisterFromRefreshDriver();
- bool SendSwipeEvent(EventMessage aMsg, uint32_t aDirection, double aDelta);
+ bool SendSwipeEvent(EventMessage aMsg, uint32_t aDirection, double aDelta,
+ const TimeStamp& aTimeStamp);
nsChildView& mWidget;
RefPtr<nsRefreshDriver> mRefreshDriver;
layers::AxisPhysicsMSDModel mAxis;
const LayoutDeviceIntPoint mEventPosition;
TimeStamp mLastEventTimeStamp;
TimeStamp mLastAnimationFrameTime;
const uint32_t mAllowedDirections;
--- a/widget/cocoa/SwipeTracker.mm
+++ b/widget/cocoa/SwipeTracker.mm
@@ -46,17 +46,17 @@ SwipeTracker::SwipeTracker(nsChildView&
, mAllowedDirections(aAllowedDirections)
, mSwipeDirection(aSwipeDirection)
, mGestureAmount(0.0)
, mCurrentVelocity(0.0)
, mEventsAreControllingSwipe(true)
, mEventsHaveStartedNewGesture(false)
, mRegisteredWithRefreshDriver(false)
{
- SendSwipeEvent(eSwipeGestureStart, 0, 0.0);
+ SendSwipeEvent(eSwipeGestureStart, 0, 0.0, aSwipeStartEvent.mTimeStamp);
ProcessEvent(aSwipeStartEvent);
}
void
SwipeTracker::Destroy()
{
UnregisterFromRefreshDriver();
}
@@ -111,28 +111,30 @@ SwipeTracker::ProcessEvent(const PanGest
return mEventsHaveStartedNewGesture ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault;
}
double delta = -aEvent.mPanDisplacement.x / mWidget.BackingScaleFactor() / kWholePagePixelSize;
if (!SwipingInAllowedDirection()) {
delta /= kRubberBandResistanceFactor;
}
mGestureAmount = ClampToAllowedRange(mGestureAmount + delta);
- SendSwipeEvent(eSwipeGestureUpdate, 0, mGestureAmount);
+ SendSwipeEvent(eSwipeGestureUpdate, 0, mGestureAmount, aEvent.mTimeStamp);
if (aEvent.mType != PanGestureInput::PANGESTURE_END) {
double elapsedSeconds = std::max(0.008, (aEvent.mTimeStamp - mLastEventTimeStamp).ToSeconds());
mCurrentVelocity = delta / elapsedSeconds;
mLastEventTimeStamp = aEvent.mTimeStamp;
} else {
mEventsAreControllingSwipe = false;
bool didSwipeSucceed = SwipingInAllowedDirection() && ComputeSwipeSuccess();
double targetValue = 0.0;
if (didSwipeSucceed) {
- SendSwipeEvent(eSwipeGesture, mSwipeDirection, 0.0);
+ // Let's use same timestamp as previous event because this is caused by
+ // the preceding event.
+ SendSwipeEvent(eSwipeGesture, mSwipeDirection, 0.0, aEvent.mTimeStamp);
targetValue = SwipeSuccessTargetValue();
}
StartAnimating(targetValue);
}
return nsEventStatus_eConsumeNoDefault;
}
@@ -159,62 +161,68 @@ void
SwipeTracker::WillRefresh(mozilla::TimeStamp aTime)
{
TimeStamp now = TimeStamp::Now();
mAxis.Simulate(now - mLastAnimationFrameTime);
mLastAnimationFrameTime = now;
bool isFinished = mAxis.IsFinished(1.0 / kWholePagePixelSize);
mGestureAmount = (isFinished ? mAxis.GetDestination() : mAxis.GetPosition());
- SendSwipeEvent(eSwipeGestureUpdate, 0, mGestureAmount);
+ SendSwipeEvent(eSwipeGestureUpdate, 0, mGestureAmount, now);
if (isFinished) {
UnregisterFromRefreshDriver();
- SwipeFinished();
+ SwipeFinished(now);
}
}
void
-SwipeTracker::CancelSwipe()
+SwipeTracker::CancelSwipe(const TimeStamp& aTimeStamp)
{
- SendSwipeEvent(eSwipeGestureEnd, 0, 0.0);
+ SendSwipeEvent(eSwipeGestureEnd, 0, 0.0, aTimeStamp);
}
-void SwipeTracker::SwipeFinished()
+void SwipeTracker::SwipeFinished(const TimeStamp& aTimeStamp)
{
- SendSwipeEvent(eSwipeGestureEnd, 0, 0.0);
+ SendSwipeEvent(eSwipeGestureEnd, 0, 0.0, aTimeStamp);
mWidget.SwipeFinished();
}
void
SwipeTracker::UnregisterFromRefreshDriver()
{
if (mRegisteredWithRefreshDriver) {
MOZ_ASSERT(mRefreshDriver, "How were we able to register, then?");
mRefreshDriver->RemoveRefreshObserver(this, Flush_Style);
}
mRegisteredWithRefreshDriver = false;
}
/* static */ WidgetSimpleGestureEvent
SwipeTracker::CreateSwipeGestureEvent(EventMessage aMsg, nsIWidget* aWidget,
- const LayoutDeviceIntPoint& aPosition)
+ const LayoutDeviceIntPoint& aPosition,
+ const TimeStamp& aTimeStamp)
{
+ // XXX Why isn't this initialized with nsCocoaUtils::InitInputEvent()?
WidgetSimpleGestureEvent geckoEvent(true, aMsg, aWidget);
geckoEvent.mModifiers = 0;
- geckoEvent.mTimeStamp = TimeStamp::Now();
+ // XXX How about geckoEvent.mTime?
+ geckoEvent.mTimeStamp = aTimeStamp;
geckoEvent.mRefPoint = aPosition;
geckoEvent.buttons = 0;
return geckoEvent;
}
bool
-SwipeTracker::SendSwipeEvent(EventMessage aMsg, uint32_t aDirection, double aDelta)
+SwipeTracker::SendSwipeEvent(EventMessage aMsg,
+ uint32_t aDirection,
+ double aDelta,
+ const TimeStamp& aTimeStamp)
{
WidgetSimpleGestureEvent geckoEvent =
- CreateSwipeGestureEvent(aMsg, &mWidget, mEventPosition);
+ CreateSwipeGestureEvent(aMsg, &mWidget, mEventPosition, aTimeStamp);
geckoEvent.mDirection = aDirection;
geckoEvent.mDelta = aDelta;
geckoEvent.mAllowedDirections = mAllowedDirections;
return mWidget.DispatchWindowEvent(geckoEvent);
}
} // namespace mozilla
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2639,34 +2639,35 @@ nsChildView::SendMayStartSwipe(const moz
// 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.
// This event also reports back the directions that we can swipe in.
LayoutDeviceIntPoint position =
RoundedToInt(aSwipeStartEvent.mPanStartPoint * ScreenToLayoutDeviceScale(1));
WidgetSimpleGestureEvent geckoEvent =
SwipeTracker::CreateSwipeGestureEvent(eSwipeGestureMayStart, this,
- position);
+ position,
+ aSwipeStartEvent.mTimeStamp);
geckoEvent.mDirection = direction;
geckoEvent.mDelta = 0.0;
geckoEvent.mAllowedDirections = 0;
bool shouldStartSwipe = DispatchWindowEvent(geckoEvent); // event cancelled == swipe should start
SwipeInfo result = { shouldStartSwipe, geckoEvent.mAllowedDirections };
return result;
}
void
nsChildView::TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
uint32_t aAllowedDirections)
{
// If a swipe is currently being tracked kill it -- it's been interrupted
// by another gesture event.
if (mSwipeTracker) {
- mSwipeTracker->CancelSwipe();
+ mSwipeTracker->CancelSwipe(aSwipeStartEvent.mTimeStamp);
mSwipeTracker->Destroy();
mSwipeTracker = nullptr;
}
uint32_t direction = (aSwipeStartEvent.mPanDisplacement.x > 0.0)
? (uint32_t)nsIDOMSimpleGestureEvent::DIRECTION_RIGHT
: (uint32_t)nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
@@ -3537,24 +3538,26 @@ NSEvent* gLastDragMouseDownEvent = nil;
return YES;
}
- (BOOL)isOpaque
{
return [[self window] isOpaque];
}
+// XXX Is this really used?
- (void)sendFocusEvent:(EventMessage)eventMessage
{
if (!mGeckoChild)
return;
nsEventStatus status = nsEventStatus_eIgnore;
WidgetGUIEvent focusGuiEvent(true, eventMessage, mGeckoChild);
focusGuiEvent.mTime = PR_IntervalNow();
+ focusGuiEvent.mTimeStamp = nsCocoaUtils::GetEventTimeStamp(0);
mGeckoChild->DispatchEvent(&focusGuiEvent, status);
}
// We accept key and mouse events, so don't keep passing them up the chain. Allow
// this to be a 'focused' widget for event dispatch.
- (BOOL)acceptsFirstResponder
{
return YES;
--- a/widget/cocoa/nsCocoaUtils.mm
+++ b/widget/cocoa/nsCocoaUtils.mm
@@ -608,16 +608,17 @@ nsCocoaUtils::InitNPCocoaEvent(NPCocoaEv
void
nsCocoaUtils::InitInputEvent(WidgetInputEvent& aInputEvent,
NSEvent* aNativeEvent)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
aInputEvent.mModifiers = ModifiersForEvent(aNativeEvent);
aInputEvent.mTime = PR_IntervalNow();
+ aInputEvent.mTimeStamp = GetEventTimeStamp([aNativeEvent timestamp]);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// static
Modifiers
nsCocoaUtils::ModifiersForEvent(NSEvent* aNativeEvent)
{