diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 414aff11b1ba..09444dae4cc6 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -290,16 +290,9 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, MutationBitForEventType(aType)); } } else if (aTypeAtom == nsGkAtoms::ondeviceorientation) { - nsPIDOMWindow* window = GetInnerWindowForTarget(); - if (window) - window->EnableDeviceSensor(SENSOR_ORIENTATION); + EnableDevice(NS_DEVICE_ORIENTATION); } else if (aTypeAtom == nsGkAtoms::ondevicemotion) { - nsPIDOMWindow* window = GetInnerWindowForTarget(); - if (window) { - window->EnableDeviceSensor(SENSOR_ACCELERATION); - window->EnableDeviceSensor(SENSOR_LINEAR_ACCELERATION); - window->EnableDeviceSensor(SENSOR_GYROSCOPE); - } + EnableDevice(NS_DEVICE_MOTION); } else if ((aType >= NS_MOZTOUCH_DOWN && aType <= NS_MOZTOUCH_UP) || (aTypeAtom == nsGkAtoms::ontouchstart || aTypeAtom == nsGkAtoms::ontouchend || @@ -341,12 +334,40 @@ nsEventListenerManager::IsDeviceType(PRUint32 aType) } void -nsEventListenerManager::DisableDevice(PRUint32 aType) +nsEventListenerManager::EnableDevice(PRUint32 aType) { - nsPIDOMWindow* window = GetInnerWindowForTarget(); + nsCOMPtr window = do_QueryInterface(mTarget); if (!window) { return; } + + NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window"); + + switch (aType) { + case NS_DEVICE_ORIENTATION: + window->EnableDeviceSensor(SENSOR_ORIENTATION); + break; + case NS_DEVICE_MOTION: + window->EnableDeviceSensor(SENSOR_ACCELERATION); + window->EnableDeviceSensor(SENSOR_LINEAR_ACCELERATION); + window->EnableDeviceSensor(SENSOR_GYROSCOPE); + break; + default: + NS_WARNING("Enabling an unknown device sensor."); + break; + } +} + +void +nsEventListenerManager::DisableDevice(PRUint32 aType) +{ + nsCOMPtr window = do_QueryInterface(mTarget); + if (!window) { + return; + } + + NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window"); + switch (aType) { case NS_DEVICE_ORIENTATION: window->DisableDeviceSensor(SENSOR_ORIENTATION); diff --git a/content/events/src/nsEventListenerManager.h b/content/events/src/nsEventListenerManager.h index 06005df9d6c9..c1e522307765 100644 --- a/content/events/src/nsEventListenerManager.h +++ b/content/events/src/nsEventListenerManager.h @@ -284,6 +284,7 @@ protected: nsListenerStruct **aListenerStruct); bool IsDeviceType(PRUint32 aType); + void EnableDevice(PRUint32 aType); void DisableDevice(PRUint32 aType); public: