Bug 77992 part 1.0 - Add timeStamp to WidgetEvent; r=smaug

This patch adds a timeStamp member to WidgetEvent alongside the existing 'time'
member. In the future we would like to remove 'time' and just keep timeStamp but
that depends on it being web-compatible. For now we introduce both members
side-by-side. Later we will add a pref to determine which one to return. If no
compatibility issues arise we will remove 'time' altogether.
This commit is contained in:
Brian Birtles 2014-06-06 14:29:49 +09:00
parent 0e83486db9
commit dba77091dc
10 changed files with 68 additions and 22 deletions

View File

@ -2181,6 +2181,7 @@ EventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
event.refPoint = aEvent->refPoint;
event.widget = aEvent->widget;
event.time = aEvent->time;
event.timeStamp = aEvent->timeStamp;
event.modifiers = aEvent->modifiers;
event.buttons = aEvent->buttons;
event.isHorizontal = (aDeltaDirection == DELTA_DIRECTION_X);
@ -2220,6 +2221,7 @@ EventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
event.refPoint = aEvent->refPoint;
event.widget = aEvent->widget;
event.time = aEvent->time;
event.timeStamp = aEvent->timeStamp;
event.modifiers = aEvent->modifiers;
event.buttons = aEvent->buttons;
event.isHorizontal = (aDeltaDirection == DELTA_DIRECTION_X);
@ -4357,6 +4359,7 @@ EventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
event.modifiers = aEvent->modifiers;
event.buttons = aEvent->buttons;
event.time = aEvent->time;
event.timeStamp = aEvent->timeStamp;
event.mFlags.mNoContentDispatch = notDispatchToContents;
event.button = aEvent->button;
event.inputSource = aEvent->inputSource;

View File

@ -51,7 +51,7 @@ GestureEventListener::GestureEventListener(AsyncPanZoomController* aAsyncPanZoom
mState(GESTURE_NONE),
mSpanChange(0.0f),
mPreviousSpan(0.0f),
mLastTouchInput(MultiTouchInput::MULTITOUCH_START, 0, 0)
mLastTouchInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0)
{
}
@ -228,6 +228,7 @@ nsEventStatus GestureEventListener::HandleInputTouchMove()
SetState(GESTURE_PINCH);
PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_START,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
GetCurrentFocus(mLastTouchInput),
currentSpan,
currentSpan,
@ -252,6 +253,7 @@ nsEventStatus GestureEventListener::HandleInputTouchMove()
PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_SCALE,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
GetCurrentFocus(mLastTouchInput),
currentSpan,
mPreviousSpan,
@ -290,6 +292,7 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd()
CancelMaxTapTimeoutTask();
TapGestureInput tapEvent(TapGestureInput::TAPGESTURE_UP,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
mLastTouchInput.mTouches[0].mScreenPoint,
mLastTouchInput.modifiers);
nsEventStatus tapupStatus = mAsyncPanZoomController->HandleGestureEvent(tapEvent);
@ -308,6 +311,7 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd()
SetState(GESTURE_NONE);
TapGestureInput tapEvent(TapGestureInput::TAPGESTURE_DOUBLE,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
mLastTouchInput.mTouches[0].mScreenPoint,
mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(tapEvent);
@ -324,6 +328,7 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd()
SetState(GESTURE_NONE);
TapGestureInput tapEvent(TapGestureInput::TAPGESTURE_LONG_UP,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
mLastTouchInput.mTouches[0].mScreenPoint,
mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(tapEvent);
@ -341,6 +346,7 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd()
SetState(GESTURE_NONE);
PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_END,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
ScreenPoint(),
1.0f,
1.0f,
@ -380,6 +386,7 @@ void GestureEventListener::HandleInputTimeoutLongTap()
SetState(GESTURE_LONG_TOUCH_DOWN);
TapGestureInput tapEvent(TapGestureInput::TAPGESTURE_LONG,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
mLastTouchInput.mTouches[0].mScreenPoint,
mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(tapEvent);
@ -412,6 +419,7 @@ void GestureEventListener::TriggerSingleTapConfirmedEvent()
{
TapGestureInput tapEvent(TapGestureInput::TAPGESTURE_CONFIRMED,
mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp,
mLastTouchInput.mTouches[0].mScreenPoint,
mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(tapEvent);

View File

@ -204,7 +204,8 @@ void ApzcPan(AsyncPanZoomController* apzc,
touchStartStatus = nsEventStatus_eConsumeNoDefault;
}
mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_START, aTime, 0);
mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_START, aTime, TimeStamp(), 0);
aTime += TIME_BETWEEN_TOUCH_EVENT;
// Make sure the move is large enough to not be handled as a tap
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchStartY+OVERCOME_TOUCH_TOLERANCE), ScreenSize(0, 0), 0, 0));
@ -227,19 +228,22 @@ void ApzcPan(AsyncPanZoomController* apzc,
touchMoveStatus = nsEventStatus_eConsumeNoDefault;
}
mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, 0);
mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
aTime += TIME_BETWEEN_TOUCH_EVENT;
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchStartY), ScreenSize(0, 0), 0, 0));
status = apzc->ReceiveInputEvent(mti);
EXPECT_EQ(touchMoveStatus, status);
mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, 0);
mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
aTime += TIME_BETWEEN_TOUCH_EVENT;
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchEndY), ScreenSize(0, 0), 0, 0));
status = apzc->ReceiveInputEvent(mti);
EXPECT_EQ(touchMoveStatus, status);
mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_END, aTime, 0);
mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_END, aTime, TimeStamp(), 0);
aTime += TIME_BETWEEN_TOUCH_EVENT;
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchEndY), ScreenSize(0, 0), 0, 0));
status = apzc->ReceiveInputEvent(mti);
@ -319,6 +323,7 @@ static void ApzcPinchWithPinchInput(AsyncPanZoomController* aApzc,
actualStatus = aApzc->HandleGestureEvent(PinchGestureInput(PinchGestureInput::PINCHGESTURE_START,
0,
TimeStamp(),
ScreenPoint(aFocusX, aFocusY),
10.0,
10.0,
@ -326,6 +331,7 @@ static void ApzcPinchWithPinchInput(AsyncPanZoomController* aApzc,
EXPECT_EQ(actualStatus, expectedStatus);
actualStatus = aApzc->HandleGestureEvent(PinchGestureInput(PinchGestureInput::PINCHGESTURE_SCALE,
0,
TimeStamp(),
ScreenPoint(aFocusX, aFocusY),
10.0 * aScale,
10.0,
@ -333,6 +339,7 @@ static void ApzcPinchWithPinchInput(AsyncPanZoomController* aApzc,
EXPECT_EQ(actualStatus, expectedStatus);
aApzc->HandleGestureEvent(PinchGestureInput(PinchGestureInput::PINCHGESTURE_END,
0,
TimeStamp(),
ScreenPoint(aFocusX, aFocusY),
// note: negative values here tell APZC
// not to turn the pinch into a pan
@ -358,7 +365,8 @@ static void ApzcPinchWithTouchMoveInput(AsyncPanZoomController* aApzc,
: nsEventStatus_eIgnore;
nsEventStatus actualStatus;
MultiTouchInput mtiStart = MultiTouchInput(MultiTouchInput::MULTITOUCH_START, 0, 0);
MultiTouchInput mtiStart =
MultiTouchInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0);
mtiStart.mTouches.AppendElement(SingleTouchData(inputId, ScreenIntPoint(aFocusX, aFocusY), ScreenSize(0, 0), 0, 0));
mtiStart.mTouches.AppendElement(SingleTouchData(inputId + 1, ScreenIntPoint(aFocusX, aFocusY), ScreenSize(0, 0), 0, 0));
aApzc->ReceiveInputEvent(mtiStart);
@ -367,19 +375,22 @@ static void ApzcPinchWithTouchMoveInput(AsyncPanZoomController* aApzc,
aApzc->SetAllowedTouchBehavior(*aAllowedTouchBehaviors);
}
MultiTouchInput mtiMove1 = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, 0);
MultiTouchInput mtiMove1 =
MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
mtiMove1.mTouches.AppendElement(SingleTouchData(inputId, ScreenIntPoint(aFocusX - pinchLength, aFocusY), ScreenSize(0, 0), 0, 0));
mtiMove1.mTouches.AppendElement(SingleTouchData(inputId + 1, ScreenIntPoint(aFocusX + pinchLength, aFocusY), ScreenSize(0, 0), 0, 0));
actualStatus = aApzc->ReceiveInputEvent(mtiMove1);
EXPECT_EQ(actualStatus, expectedStatus);
MultiTouchInput mtiMove2 = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, 0);
MultiTouchInput mtiMove2 =
MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
mtiMove2.mTouches.AppendElement(SingleTouchData(inputId, ScreenIntPoint(aFocusX - pinchLengthScaled, aFocusY), ScreenSize(0, 0), 0, 0));
mtiMove2.mTouches.AppendElement(SingleTouchData(inputId + 1, ScreenIntPoint(aFocusX + pinchLengthScaled, aFocusY), ScreenSize(0, 0), 0, 0));
actualStatus = aApzc->ReceiveInputEvent(mtiMove2);
EXPECT_EQ(actualStatus, expectedStatus);
MultiTouchInput mtiEnd = MultiTouchInput(MultiTouchInput::MULTITOUCH_END, 0, 0);
MultiTouchInput mtiEnd =
MultiTouchInput(MultiTouchInput::MULTITOUCH_END, 0, TimeStamp(), 0);
mtiEnd.mTouches.AppendElement(SingleTouchData(inputId, ScreenIntPoint(aFocusX - pinchLengthScaled, aFocusY), ScreenSize(0, 0), 0, 0));
mtiEnd.mTouches.AppendElement(SingleTouchData(inputId + 1, ScreenIntPoint(aFocusX + pinchLengthScaled, aFocusY), ScreenSize(0, 0), 0, 0));
aApzc->ReceiveInputEvent(mtiEnd);
@ -473,14 +484,16 @@ void DoPinchTest(bool aUseGestureRecognizer, bool aShouldTriggerPinch,
static nsEventStatus
ApzcDown(AsyncPanZoomController* apzc, int aX, int aY, int& aTime) {
MultiTouchInput mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_START, aTime, 0);
MultiTouchInput mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_START, aTime, TimeStamp(), 0);
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(aX, aY), ScreenSize(0, 0), 0, 0));
return apzc->ReceiveInputEvent(mti);
}
static nsEventStatus
ApzcUp(AsyncPanZoomController* apzc, int aX, int aY, int& aTime) {
MultiTouchInput mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_END, aTime, 0);
MultiTouchInput mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_END, aTime, TimeStamp(), 0);
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(aX, aY), ScreenSize(0, 0), 0, 0));
return apzc->ReceiveInputEvent(mti);
}
@ -1011,7 +1024,8 @@ DoLongPressPreventDefaultTest(bool aShouldUseTouchAction, uint32_t aBehavior) {
time += 1000;
MultiTouchInput mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, time, 0);
MultiTouchInput mti =
MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, time, TimeStamp(), 0);
mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(touchX, touchEndY), ScreenSize(0, 0), 0, 0));
status = apzc->ReceiveInputEvent(mti);
EXPECT_EQ(nsEventStatus_eIgnore, status);

View File

@ -6605,6 +6605,7 @@ DispatchPointerFromMouseOrTouch(PresShell* aShell,
event.tiltX = touch->tiltX;
event.tiltY = touch->tiltY;
event.time = touchEvent->time;
event.timeStamp = touchEvent->timeStamp;
event.mFlags = touchEvent->mFlags;
event.button = WidgetMouseEvent::eLeftButton;
event.buttons = WidgetMouseEvent::eLeftButtonFlag;

View File

@ -9,6 +9,7 @@
#include <stdint.h>
#include "mozilla/dom/EventTarget.h"
#include "mozilla/TimeStamp.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsISupportsImpl.h"
@ -623,7 +624,7 @@ protected:
WidgetEvent(bool aIsTrusted, uint32_t aMessage,
nsEventStructType aStructType) :
eventStructType(aStructType), message(aMessage), refPoint(0, 0),
lastRefPoint(0, 0), time(0), userType(0)
lastRefPoint(0, 0), time(0), timeStamp(TimeStamp::Now()), userType(0)
{
MOZ_COUNT_CTOR(WidgetEvent);
mFlags.Clear();
@ -640,7 +641,7 @@ protected:
public:
WidgetEvent(bool aIsTrusted, uint32_t aMessage) :
eventStructType(NS_EVENT), message(aMessage), refPoint(0, 0),
lastRefPoint(0, 0), time(0), userType(0)
lastRefPoint(0, 0), time(0), timeStamp(TimeStamp::Now()), userType(0)
{
MOZ_COUNT_CTOR(WidgetEvent);
mFlags.Clear();
@ -682,6 +683,9 @@ public:
// Elapsed time, in milliseconds, from a platform-specific zero time
// to the time the message was created
uint64_t time;
// Timestamp when the message was created. Set in parallel to 'time' until we
// determine if it is safe to drop 'time' (see bug 77992).
mozilla::TimeStamp timeStamp;
// See BaseEventFlags definition for the detail.
BaseEventFlags mFlags;
@ -705,6 +709,7 @@ public:
refPoint = aEvent.refPoint;
// lastRefPoint doesn't need to be copied.
time = aEvent.time;
timeStamp = aEvent.timeStamp;
// mFlags should be copied manually if it's necessary.
userType = aEvent.userType;
// typeString should be copied manually if it's necessary.

View File

@ -11,6 +11,7 @@
#include "nsTArray.h"
#include "Units.h"
#include "mozilla/EventForwards.h"
#include "mozilla/TimeStamp.h"
namespace mozilla {
@ -48,6 +49,9 @@ public:
// is platform-specific but it in the case of B2G and Fennec it is since
// startup.
uint32_t mTime;
// Set in parallel to mTime until we determine it is safe to drop
// platform-specific event times (see bug 77992).
TimeStamp mTimeStamp;
Modifiers modifiers;
@ -60,9 +64,11 @@ public:
}
protected:
InputData(InputType aInputType, uint32_t aTime, Modifiers aModifiers)
InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
Modifiers aModifiers)
: mInputType(aInputType),
mTime(aTime),
mTimeStamp(aTimeStamp),
modifiers(aModifiers)
{
@ -151,8 +157,9 @@ public:
MULTITOUCH_CANCEL
};
MultiTouchInput(MultiTouchType aType, uint32_t aTime, Modifiers aModifiers)
: InputData(MULTITOUCH_INPUT, aTime, aModifiers),
MultiTouchInput(MultiTouchType aType, uint32_t aTime, TimeStamp aTimeStamp,
Modifiers aModifiers)
: InputData(MULTITOUCH_INPUT, aTime, aTimeStamp, aModifiers),
mType(aType)
{
@ -194,11 +201,12 @@ public:
PinchGestureInput(PinchGestureType aType,
uint32_t aTime,
TimeStamp aTimeStamp,
const ScreenPoint& aFocusPoint,
float aCurrentSpan,
float aPreviousSpan,
Modifiers aModifiers)
: InputData(PINCHGESTURE_INPUT, aTime, aModifiers),
: InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers),
mType(aType),
mFocusPoint(aFocusPoint),
mCurrentSpan(aCurrentSpan),
@ -248,9 +256,10 @@ public:
TapGestureInput(TapGestureType aType,
uint32_t aTime,
TimeStamp aTimeStamp,
const ScreenIntPoint& aPoint,
Modifiers aModifiers)
: InputData(TAPGESTURE_INPUT, aTime, aModifiers),
: InputData(TAPGESTURE_INPUT, aTime, aTimeStamp, aModifiers),
mType(aType),
mPoint(aPoint)
{

View File

@ -167,6 +167,7 @@ public:
{
modifiers = aOther.modifiers;
time = aOther.time;
timeStamp = aOther.timeStamp;
touches.AppendElements(aOther.touches);
mFlags.mCancelable = message != NS_TOUCH_CANCEL;
MOZ_COUNT_CTOR(WidgetTouchEvent);

View File

@ -9,6 +9,7 @@
#include "nsIDOMKeyEvent.h"
#include "nsIWidget.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/TouchEvents.h"
using namespace mozilla;
@ -754,7 +755,7 @@ AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget)
}
}
MultiTouchInput event(type, Time(), 0);
MultiTouchInput event(type, Time(), TimeStamp(), 0);
event.modifiers = DOMModifiers();
if (type < 0) {

View File

@ -49,6 +49,7 @@ struct ParamTraits<mozilla::WidgetEvent>
WriteParam(aMsg, aParam.message);
WriteParam(aMsg, aParam.refPoint);
WriteParam(aMsg, aParam.time);
WriteParam(aMsg, aParam.timeStamp);
WriteParam(aMsg, aParam.mFlags);
}
@ -59,6 +60,7 @@ struct ParamTraits<mozilla::WidgetEvent>
ReadParam(aMsg, aIter, &aResult->message) &&
ReadParam(aMsg, aIter, &aResult->refPoint) &&
ReadParam(aMsg, aIter, &aResult->time) &&
ReadParam(aMsg, aIter, &aResult->timeStamp) &&
ReadParam(aMsg, aIter, &aResult->mFlags);
aResult->eventStructType = static_cast<nsEventStructType>(eventStructType);
return ret;

View File

@ -16,7 +16,8 @@ namespace mozilla {
using namespace dom;
MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
: InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.modifiers)
: InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.timeStamp,
aTouchEvent.modifiers)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(),
"Can only copy from WidgetTouchEvent on main thread");
@ -74,7 +75,8 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
// SingleTouchData. It also sends garbage for the identifier, radius, force
// and rotation angle.
MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent)
: InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.modifiers)
: InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.timeStamp,
aMouseEvent.modifiers)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(),
"Can only copy from WidgetMouseEvent on main thread");