Bug 1261894 - Update InitDeviceMotionEvent to handle high-res timestamps. r=smaug
authorDylan Roeh <droeh@mozilla.com>
Tue, 28 Feb 2017 16:50:15 -0600
changeset 374340 7b406378bfe5fb840c633fe63262e30c8cfc60e3
parent 374339 36730ac6b59ff964fcc0fdfdc9425aad6349272c
child 374341 232a19e40a52117301918832dbd35a00b2e440ae
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1261894
milestone54.0a1
Bug 1261894 - Update InitDeviceMotionEvent to handle high-res timestamps. r=smaug
dom/events/DeviceMotionEvent.cpp
--- a/dom/events/DeviceMotionEvent.cpp
+++ b/dom/events/DeviceMotionEvent.cpp
@@ -65,16 +65,21 @@ DeviceMotionEvent::InitDeviceMotionEvent
                            aAccelIncludingGravity.mZ);
 
   mRotationRate = new DeviceRotationRate(this, aRotationRate.mAlpha,
                                          aRotationRate.mBeta,
                                          aRotationRate.mGamma);
   mInterval = aInterval;
   if (!aTimeStamp.IsNull()) {
     mEvent->mTime = aTimeStamp.Value();
+
+    static mozilla::TimeStamp sInitialNow = mozilla::TimeStamp::Now();
+    static uint64_t sInitialEventTime = aTimeStamp.Value();
+    mEvent->mTimeStamp = sInitialNow + mozilla::TimeDuration::FromMicroseconds(
+      aTimeStamp.Value() - sInitialEventTime);
   }
 }
 
 already_AddRefed<DeviceMotionEvent>
 DeviceMotionEvent::Constructor(const GlobalObject& aGlobal,
                                const nsAString& aType,
                                const DeviceMotionEventInit& aEventInitDict,
                                ErrorResult& aRv)