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

Unified Diff: Source/modules/device_orientation/DeviceOrientationDispatcher.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/DeviceOrientationDispatcher.cpp
diff --git a/Source/modules/device_orientation/DeviceOrientationDispatcher.cpp b/Source/modules/device_orientation/DeviceOrientationDispatcher.cpp
index b6989e95340be9c2898e92299d30ee579cfe7a56..24fd9bf3d31e6a99f5b8bd966a2f9189a0b01812 100644
--- a/Source/modules/device_orientation/DeviceOrientationDispatcher.cpp
+++ b/Source/modules/device_orientation/DeviceOrientationDispatcher.cpp
@@ -34,6 +34,7 @@
#include "modules/device_orientation/DeviceOrientationData.h"
#include "modules/device_orientation/NewDeviceOrientationController.h"
#include "public/platform/Platform.h"
+#include "wtf/TemporaryChange.h"
namespace WebCore {
@@ -69,20 +70,24 @@ void DeviceOrientationDispatcher::startListening()
void DeviceOrientationDispatcher::stopListening()
{
WebKit::Platform::current()->setDeviceOrientationListener(0);
+ m_lastDeviceOrientationData.clear();
}
void DeviceOrientationDispatcher::didChangeDeviceOrientation(const WebKit::WebDeviceOrientationData& motion)
{
m_lastDeviceOrientationData = DeviceOrientationData::create(motion);
- bool needsPurge = false;
- for (size_t i = 0; i < m_controllers.size(); ++i) {
- if (m_controllers[i])
- static_cast<NewDeviceOrientationController*>(m_controllers[i])->didChangeDeviceOrientation(m_lastDeviceOrientationData.get());
- else
- needsPurge = true;
+
+ {
+ TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
+ // Don't fire controllers removed or added during event dispatch.
+ size_t size = m_controllers.size();
+ for (size_t i = 0; i < size; ++i) {
+ if (m_controllers[i])
+ static_cast<NewDeviceOrientationController*>(m_controllers[i])->didChangeDeviceOrientation(m_lastDeviceOrientationData.get());
+ }
}
- if (needsPurge)
+ if (m_needsPurge)
purgeControllers();
}

Powered by Google App Engine
This is Rietveld 408576698