зеркало из https://github.com/mozilla/gecko-dev.git
Bug 734391 - coalesce the device motion events. r=jdm
This commit is contained in:
Родитель
10f24217b7
Коммит
49f687955e
|
@ -87,6 +87,9 @@ EXPORTS = \
|
|||
nsDeviceMotion.h \
|
||||
$(NULL)
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
|
|
@ -59,6 +59,7 @@ CPPSRCS = \
|
|||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/dom/src/geolocation \
|
||||
-I$(topsrcdir)/content/events/src
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -49,6 +49,9 @@ LIBXUL_LIBRARY = 1
|
|||
FORCE_STATIC_LIB = 1
|
||||
EXPORT_LIBRARY = 1
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CMMSRCS = \
|
||||
|
|
|
@ -44,11 +44,11 @@
|
|||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
|
||||
using mozilla::TimeStamp;
|
||||
using mozilla::TimeDuration;
|
||||
|
||||
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
@ -361,45 +361,53 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
|||
double x,
|
||||
double y,
|
||||
double z) {
|
||||
// Attempt to coalesce events
|
||||
bool fireEvent = TimeStamp::Now() > mLastDOMMotionEventTime + TimeDuration::FromMilliseconds(DEFAULT_SENSOR_POLL);
|
||||
|
||||
switch (type) {
|
||||
case nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION:
|
||||
mLastAcceleration = new nsDOMDeviceAcceleration(x, y, z);
|
||||
break;
|
||||
case nsIDeviceMotionData::TYPE_ACCELERATION:
|
||||
mLastAccelerationIncluduingGravity = new nsDOMDeviceAcceleration(x, y, z);
|
||||
break;
|
||||
case nsIDeviceMotionData::TYPE_GYROSCOPE:
|
||||
mLastRotationRate = new nsDOMDeviceRotationRate(x, y, z);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fireEvent && (!mLastAcceleration || !mLastAccelerationIncluduingGravity || !mLastRotationRate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
bool defaultActionEnabled = true;
|
||||
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceMotionEvent"), getter_AddRefs(event));
|
||||
|
||||
nsCOMPtr<nsIDOMDeviceMotionEvent> me = do_QueryInterface(event);
|
||||
|
||||
if (!me) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<nsDOMDeviceAcceleration> acceleration;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> accelerationIncluduingGravity;
|
||||
nsRefPtr<nsDOMDeviceRotationRate> rotationRate;
|
||||
|
||||
switch (type) {
|
||||
case nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION:
|
||||
acceleration = new nsDOMDeviceAcceleration(x, y, z);
|
||||
break;
|
||||
case nsIDeviceMotionData::TYPE_ACCELERATION:
|
||||
accelerationIncluduingGravity = new nsDOMDeviceAcceleration(x, y, z);
|
||||
break;
|
||||
case nsIDeviceMotionData::TYPE_GYROSCOPE:
|
||||
rotationRate = new nsDOMDeviceRotationRate(x, y, z);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
me->InitDeviceMotionEvent(NS_LITERAL_STRING("devicemotion"),
|
||||
true,
|
||||
false,
|
||||
acceleration,
|
||||
accelerationIncluduingGravity,
|
||||
rotationRate,
|
||||
mLastAcceleration,
|
||||
mLastAccelerationIncluduingGravity,
|
||||
mLastRotationRate,
|
||||
DEFAULT_SENSOR_POLL);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
if (privateEvent)
|
||||
privateEvent->SetTrusted(true);
|
||||
|
||||
bool defaultActionEnabled = true;
|
||||
target->DispatchEvent(event, &defaultActionEnabled);
|
||||
|
||||
mLastRotationRate = nsnull;
|
||||
mLastAccelerationIncluduingGravity = nsnull;
|
||||
mLastAcceleration = nsnull;
|
||||
mLastDOMMotionEventTime = TimeStamp::Now();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
#define NS_DEVICE_MOTION_CID \
|
||||
{ 0xecba5203, 0x77da, 0x465a, \
|
||||
|
@ -91,10 +95,16 @@ private:
|
|||
double x,
|
||||
double y,
|
||||
double z);
|
||||
bool mEnabled;
|
||||
|
||||
virtual void Startup() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
bool mEnabled;
|
||||
mozilla::TimeStamp mLastDOMMotionEventTime;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
|
||||
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -82,4 +82,7 @@ LOCAL_INCLUDES += $(MOZ_QT_CFLAGS) \
|
|||
endif
|
||||
endif
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -49,6 +49,9 @@ LIBXUL_LIBRARY = 1
|
|||
FORCE_STATIC_LIB = 1
|
||||
EXPORT_LIBRARY = 1
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
|
|
Загрузка…
Ссылка в новой задаче