Bug 1222098 - Devicemotion event timestamp should return values from Android sensor API and not Gecko. r:smaug

This commit is contained in:
James Willcox
2016-04-04 12:22:59 -05:00
parent 126e430fe1
commit c954a908ff
7 changed files with 41 additions and 4 deletions

View File

@@ -34,6 +34,22 @@ DeviceMotionEvent::InitDeviceMotionEvent(
const DeviceAccelerationInit& aAccelIncludingGravity, const DeviceAccelerationInit& aAccelIncludingGravity,
const DeviceRotationRateInit& aRotationRate, const DeviceRotationRateInit& aRotationRate,
Nullable<double> aInterval) Nullable<double> aInterval)
{
InitDeviceMotionEvent(aType, aCanBubble, aCancelable, aAcceleration,
aAccelIncludingGravity, aRotationRate, aInterval,
Nullable<uint64_t>());
}
void
DeviceMotionEvent::InitDeviceMotionEvent(
const nsAString& aType,
bool aCanBubble,
bool aCancelable,
const DeviceAccelerationInit& aAcceleration,
const DeviceAccelerationInit& aAccelIncludingGravity,
const DeviceRotationRateInit& aRotationRate,
Nullable<double> aInterval,
Nullable<uint64_t> aTimeStamp)
{ {
Event::InitEvent(aType, aCanBubble, aCancelable); Event::InitEvent(aType, aCanBubble, aCancelable);
@@ -50,6 +66,9 @@ DeviceMotionEvent::InitDeviceMotionEvent(
aRotationRate.mBeta, aRotationRate.mBeta,
aRotationRate.mGamma); aRotationRate.mGamma);
mInterval = aInterval; mInterval = aInterval;
if (!aTimeStamp.IsNull()) {
mEvent->mTime = aTimeStamp.Value();
}
} }
already_AddRefed<DeviceMotionEvent> already_AddRefed<DeviceMotionEvent>
@@ -141,7 +160,7 @@ using namespace mozilla::dom;
already_AddRefed<DeviceMotionEvent> already_AddRefed<DeviceMotionEvent>
NS_NewDOMDeviceMotionEvent(EventTarget* aOwner, NS_NewDOMDeviceMotionEvent(EventTarget* aOwner,
nsPresContext* aPresContext, nsPresContext* aPresContext,
WidgetEvent* aEvent) WidgetEvent* aEvent)
{ {
RefPtr<DeviceMotionEvent> it = RefPtr<DeviceMotionEvent> it =
new DeviceMotionEvent(aOwner, aPresContext, aEvent); new DeviceMotionEvent(aOwner, aPresContext, aEvent);

View File

@@ -130,6 +130,16 @@ public:
const DeviceRotationRateInit& aRotationRate, const DeviceRotationRateInit& aRotationRate,
Nullable<double> aInterval); Nullable<double> aInterval);
void InitDeviceMotionEvent(
const nsAString& aType,
bool aCanBubble,
bool aCancelable,
const DeviceAccelerationInit& aAcceleration,
const DeviceAccelerationInit& aAccelerationIncludingGravity,
const DeviceRotationRateInit& aRotationRate,
Nullable<double> aInterval,
Nullable<uint64_t> aTimeStamp);
static already_AddRefed<DeviceMotionEvent> static already_AddRefed<DeviceMotionEvent>
Constructor(const GlobalObject& aGlobal, Constructor(const GlobalObject& aGlobal,
const nsAString& aType, const nsAString& aType,

View File

@@ -332,6 +332,7 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData)
double y = len > 1 ? values[1] : 0.0; double y = len > 1 ? values[1] : 0.0;
double z = len > 2 ? values[2] : 0.0; double z = len > 2 ? values[2] : 0.0;
double w = len > 3 ? values[3] : 0.0; double w = len > 3 ? values[3] : 0.0;
PRTime timestamp = aSensorData.timestamp();
nsCOMArray<nsIDOMWindow> windowListeners; nsCOMArray<nsIDOMWindow> windowListeners;
for (uint32_t i = 0; i < mWindowListeners[type]->Length(); i++) { 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 || if (type == nsIDeviceSensorData::TYPE_ACCELERATION ||
type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION || type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION ||
type == nsIDeviceSensorData::TYPE_GYROSCOPE) { 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) { } else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) {
FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute); FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute);
} else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) { } else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) {
@@ -488,6 +489,7 @@ void
nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc, nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc,
EventTarget* target, EventTarget* target,
uint32_t type, uint32_t type,
PRTime timestamp,
double x, double x,
double y, double y,
double z) double z)
@@ -553,7 +555,8 @@ nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc,
*mLastAcceleration, *mLastAcceleration,
*mLastAccelerationIncludingGravity, *mLastAccelerationIncludingGravity,
*mLastRotationRate, *mLastRotationRate,
Nullable<double>(DEFAULT_SENSOR_POLL)); Nullable<double>(DEFAULT_SENSOR_POLL),
Nullable<uint64_t>(timestamp));
event->SetTrusted(true); event->SetTrusted(true);

View File

@@ -63,6 +63,7 @@ private:
void FireDOMMotionEvent(class nsIDOMDocument *domDoc, void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
mozilla::dom::EventTarget* target, mozilla::dom::EventTarget* target,
uint32_t type, uint32_t type,
PRTime timestamp,
double x, double x,
double y, double y,
double z); double z);

View File

@@ -451,6 +451,9 @@ public class GeckoEvent {
} }
break; break;
} }
// SensorEvent timestamp is in nanoseconds, Gecko expects microseconds.
event.mTime = s.timestamp / 1000;
return event; return event;
} }

View File

@@ -376,6 +376,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
mW = jenv->GetDoubleField(jobj, jWField); mW = jenv->GetDoubleField(jobj, jWField);
mFlags = jenv->GetIntField(jobj, jFlagsField); mFlags = jenv->GetIntField(jobj, jFlagsField);
mMetaState = jenv->GetIntField(jobj, jMetaStateField); mMetaState = jenv->GetIntField(jobj, jMetaStateField);
mTime = jenv->GetLongField(jobj, jTimeField);
break; break;
case LOCATION_EVENT: { case LOCATION_EVENT: {

View File

@@ -575,7 +575,7 @@ nsAppShell::LegacyGeckoEvent::Run()
} }
const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState(); 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); hal::NotifySensorChange(sdata);
} }
break; break;