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
Родитель 2f1e35dda6
Коммит 0391aa89f2
7 изменённых файлов: 41 добавлений и 4 удалений

Просмотреть файл

@ -34,6 +34,22 @@ DeviceMotionEvent::InitDeviceMotionEvent(
const DeviceAccelerationInit& aAccelIncludingGravity,
const DeviceRotationRateInit& aRotationRate,
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);
@ -50,6 +66,9 @@ DeviceMotionEvent::InitDeviceMotionEvent(
aRotationRate.mBeta,
aRotationRate.mGamma);
mInterval = aInterval;
if (!aTimeStamp.IsNull()) {
mEvent->mTime = aTimeStamp.Value();
}
}
already_AddRefed<DeviceMotionEvent>
@ -141,7 +160,7 @@ using namespace mozilla::dom;
already_AddRefed<DeviceMotionEvent>
NS_NewDOMDeviceMotionEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetEvent* aEvent)
WidgetEvent* aEvent)
{
RefPtr<DeviceMotionEvent> it =
new DeviceMotionEvent(aOwner, aPresContext, aEvent);

Просмотреть файл

@ -130,6 +130,16 @@ public:
const DeviceRotationRateInit& aRotationRate,
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>
Constructor(const GlobalObject& aGlobal,
const nsAString& aType,

Просмотреть файл

@ -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<nsIDOMWindow> 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<double>(DEFAULT_SENSOR_POLL));
Nullable<double>(DEFAULT_SENSOR_POLL),
Nullable<uint64_t>(timestamp));
event->SetTrusted(true);

Просмотреть файл

@ -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);

Просмотреть файл

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

Просмотреть файл

@ -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: {

Просмотреть файл

@ -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;