diff --git a/dom/events/DeviceMotionEvent.cpp b/dom/events/DeviceMotionEvent.cpp index b78241ef094b..7e6b882395a1 100644 --- a/dom/events/DeviceMotionEvent.cpp +++ b/dom/events/DeviceMotionEvent.cpp @@ -34,6 +34,22 @@ DeviceMotionEvent::InitDeviceMotionEvent( const DeviceAccelerationInit& aAccelIncludingGravity, const DeviceRotationRateInit& aRotationRate, Nullable aInterval) +{ + InitDeviceMotionEvent(aType, aCanBubble, aCancelable, aAcceleration, + aAccelIncludingGravity, aRotationRate, aInterval, + Nullable()); +} + +void +DeviceMotionEvent::InitDeviceMotionEvent( + const nsAString& aType, + bool aCanBubble, + bool aCancelable, + const DeviceAccelerationInit& aAcceleration, + const DeviceAccelerationInit& aAccelIncludingGravity, + const DeviceRotationRateInit& aRotationRate, + Nullable aInterval, + Nullable aTimeStamp) { Event::InitEvent(aType, aCanBubble, aCancelable); @@ -50,6 +66,9 @@ DeviceMotionEvent::InitDeviceMotionEvent( aRotationRate.mBeta, aRotationRate.mGamma); mInterval = aInterval; + if (!aTimeStamp.IsNull()) { + mEvent->mTime = aTimeStamp.Value(); + } } already_AddRefed @@ -141,7 +160,7 @@ using namespace mozilla::dom; already_AddRefed NS_NewDOMDeviceMotionEvent(EventTarget* aOwner, nsPresContext* aPresContext, - WidgetEvent* aEvent) + WidgetEvent* aEvent) { RefPtr it = new DeviceMotionEvent(aOwner, aPresContext, aEvent); diff --git a/dom/events/DeviceMotionEvent.h b/dom/events/DeviceMotionEvent.h index ca631787d865..6e6f3d9e5f54 100644 --- a/dom/events/DeviceMotionEvent.h +++ b/dom/events/DeviceMotionEvent.h @@ -130,6 +130,16 @@ public: const DeviceRotationRateInit& aRotationRate, Nullable aInterval); + void InitDeviceMotionEvent( + const nsAString& aType, + bool aCanBubble, + bool aCancelable, + const DeviceAccelerationInit& aAcceleration, + const DeviceAccelerationInit& aAccelerationIncludingGravity, + const DeviceRotationRateInit& aRotationRate, + Nullable aInterval, + Nullable aTimeStamp); + static already_AddRefed Constructor(const GlobalObject& aGlobal, const nsAString& aType, diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp index 4aed0227055c..d04239b95252 100644 --- a/dom/system/nsDeviceSensors.cpp +++ b/dom/system/nsDeviceSensors.cpp @@ -332,6 +332,7 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) double y = len > 1 ? values[1] : 0.0; double z = len > 2 ? values[2] : 0.0; double w = len > 3 ? values[3] : 0.0; + PRTime timestamp = aSensorData.timestamp(); nsCOMArray windowListeners; for (uint32_t i = 0; i < mWindowListeners[type]->Length(); i++) { @@ -351,7 +352,7 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) if (type == nsIDeviceSensorData::TYPE_ACCELERATION || type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION || type == nsIDeviceSensorData::TYPE_GYROSCOPE) { - FireDOMMotionEvent(domDoc, target, type, x, y, z); + FireDOMMotionEvent(domDoc, target, type, timestamp, x, y, z); } else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) { FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute); } else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) { @@ -488,6 +489,7 @@ void nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc, EventTarget* target, uint32_t type, + PRTime timestamp, double x, double y, double z) @@ -553,7 +555,8 @@ nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc, *mLastAcceleration, *mLastAccelerationIncludingGravity, *mLastRotationRate, - Nullable(DEFAULT_SENSOR_POLL)); + Nullable(DEFAULT_SENSOR_POLL), + Nullable(timestamp)); event->SetTrusted(true); diff --git a/dom/system/nsDeviceSensors.h b/dom/system/nsDeviceSensors.h index 6f7df48d9a3b..bed6cd69d9ef 100644 --- a/dom/system/nsDeviceSensors.h +++ b/dom/system/nsDeviceSensors.h @@ -63,6 +63,7 @@ private: void FireDOMMotionEvent(class nsIDOMDocument *domDoc, mozilla::dom::EventTarget* target, uint32_t type, + PRTime timestamp, double x, double y, double z); diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java b/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java index d140c5e1176d..26a4731928f8 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java @@ -451,6 +451,9 @@ public class GeckoEvent { } break; } + + // SensorEvent timestamp is in nanoseconds, Gecko expects microseconds. + event.mTime = s.timestamp / 1000; return event; } diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index 05c8932b01f8..6046ffa3e0c1 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -376,6 +376,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj) mW = jenv->GetDoubleField(jobj, jWField); mFlags = jenv->GetIntField(jobj, jFlagsField); mMetaState = jenv->GetIntField(jobj, jMetaStateField); + mTime = jenv->GetLongField(jobj, jTimeField); break; case LOCATION_EVENT: { diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp index 781ed3b85c3b..c1899450dbd4 100644 --- a/widget/android/nsAppShell.cpp +++ b/widget/android/nsAppShell.cpp @@ -575,7 +575,7 @@ nsAppShell::LegacyGeckoEvent::Run() } const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState(); - hal::SensorData sdata(type, PR_Now(), values, accuracy); + hal::SensorData sdata(type, curEvent->Time(), values, accuracy); hal::NotifySensorChange(sdata); } break;