Index: Source/core/frame/DeviceEventDispatcherBase.cpp |
diff --git a/Source/core/frame/DeviceSensorEventDispatcher.cpp b/Source/core/frame/DeviceEventDispatcherBase.cpp |
similarity index 71% |
copy from Source/core/frame/DeviceSensorEventDispatcher.cpp |
copy to Source/core/frame/DeviceEventDispatcherBase.cpp |
index a992f0aa2e5246d1cce865668bee49ce393a8975..ef64cd1a8d99c6124c32a7eeb36478f79d500dd8 100644 |
--- a/Source/core/frame/DeviceSensorEventDispatcher.cpp |
+++ b/Source/core/frame/DeviceEventDispatcherBase.cpp |
@@ -1,5 +1,5 @@ |
/* |
- * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * Copyright (C) 2014 Google Inc. All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -29,21 +29,24 @@ |
*/ |
#include "config.h" |
-#include "core/frame/DeviceSensorEventDispatcher.h" |
+#include "core/frame/DeviceEventDispatcherBase.h" |
+ |
+#include "core/frame/DeviceEventControllerBase.h" |
+#include "wtf/TemporaryChange.h" |
namespace WebCore { |
-DeviceSensorEventDispatcher::DeviceSensorEventDispatcher() |
+DeviceEventDispatcherBase::DeviceEventDispatcherBase() |
: m_needsPurge(false) |
, m_isDispatching(false) |
{ |
} |
-DeviceSensorEventDispatcher::~DeviceSensorEventDispatcher() |
+DeviceEventDispatcherBase::~DeviceEventDispatcherBase() |
{ |
} |
-void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* controller) |
+void DeviceEventDispatcherBase::addController(DeviceEventControllerBase* controller) |
{ |
bool wasEmpty = m_controllers.isEmpty(); |
if (!m_controllers.contains(controller)) |
@@ -52,13 +55,12 @@ void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* con |
startListening(); |
} |
-void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* controller) |
+void DeviceEventDispatcherBase::removeController(DeviceEventControllerBase* controller) |
{ |
// Do not actually remove the controller from the vector, instead zero them out. |
// The zeros are removed in these two cases: |
// 1. either immediately if we are not dispatching any events, |
- // 2. or after events to all controllers have dispatched |
- // (see e.g. DeviceOrientationDispatcher::didChangeDeviceOrientation). |
+ // 2. or after events to all controllers have dispatched (see notifyControllers()). |
// This is to correctly handle the re-entrancy case when a controller is destroyed |
// while the events are still being dispatched. |
size_t index = m_controllers.find(controller); |
@@ -72,7 +74,7 @@ void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* |
purgeControllers(); |
} |
-void DeviceSensorEventDispatcher::purgeControllers() |
+void DeviceEventDispatcherBase::purgeControllers() |
{ |
ASSERT(m_needsPurge); |
@@ -92,4 +94,20 @@ void DeviceSensorEventDispatcher::purgeControllers() |
stopListening(); |
} |
+void DeviceEventDispatcherBase::notifyControllers() |
+{ |
+ { |
+ TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); |
+ // Don't notify 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]) |
+ m_controllers[i]->didUpdateData(); |
+ } |
+ } |
+ |
+ if (m_needsPurge) |
+ purgeControllers(); |
+} |
+ |
} // namespace WebCore |