Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2139)

Unified Diff: Source/modules/device_orientation/DeviceSensorEventController.cpp

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/device_orientation/DeviceSensorEventController.cpp
diff --git a/Source/modules/device_orientation/DeviceSensorEventController.cpp b/Source/modules/device_orientation/DeviceSensorEventController.cpp
index fc5ae617122dcea135e2b236f3ea363db7443713..4b2efb308ed402c00ab611d592cc1795aa155f1a 100644
--- a/Source/modules/device_orientation/DeviceSensorEventController.cpp
+++ b/Source/modules/device_orientation/DeviceSensorEventController.cpp
@@ -35,6 +35,7 @@ namespace WebCore {
DeviceSensorEventController::DeviceSensorEventController(Document* document)
: m_document(document)
, m_isActive(false)
+ , m_needsCheckingNullEvents(true)
, m_timer(this, &DeviceSensorEventController::fireDeviceEvent)
{
}
@@ -60,6 +61,13 @@ void DeviceSensorEventController::dispatchDeviceEvent(PassRefPtr<Event> prpEvent
&& !m_document->activeDOMObjectsAreSuspended()
&& !m_document->activeDOMObjectsAreStopped())
m_document->domWindow()->dispatchEvent(event);
+
+ if (m_needsCheckingNullEvents) {
+ if (isNullEvent(event.get()))
+ stopUpdating();
+ else
+ m_needsCheckingNullEvents = false;
+ }
}
void DeviceSensorEventController::startUpdating()
@@ -67,13 +75,13 @@ void DeviceSensorEventController::startUpdating()
if (m_isActive)
return;
- registerWithDispatcher();
- m_isActive = true;
-
if (hasLastData() && !m_timer.isActive()) {
// Make sure to fire the device motion data as soon as possible.
m_timer.startOneShot(0);
}
+
+ registerWithDispatcher();
+ m_isActive = true;
}
void DeviceSensorEventController::stopUpdating()
@@ -81,6 +89,9 @@ void DeviceSensorEventController::stopUpdating()
if (!m_isActive)
return;
+ if (m_timer.isActive())
+ m_timer.stop();
+
unregisterWithDispatcher();
m_isActive = false;
}

Powered by Google App Engine
This is Rietveld 408576698