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

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

Issue 240993003: Fix the issue with adding/removing event listeners for Device Motion/Orientation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: similarity=80 Created 6 years, 8 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/DeviceMotionController.cpp
diff --git a/Source/modules/device_orientation/DeviceMotionController.cpp b/Source/modules/device_orientation/DeviceMotionController.cpp
index 3a5e5b96406dc51dcf3e47f969d6694db9d4927f..b23ba8899882a79c44e4ec727463e5a407263285 100644
--- a/Source/modules/device_orientation/DeviceMotionController.cpp
+++ b/Source/modules/device_orientation/DeviceMotionController.cpp
@@ -29,6 +29,7 @@
#include "RuntimeEnabledFeatures.h"
#include "core/dom/Document.h"
+#include "core/frame/DOMWindow.h"
#include "core/page/Page.h"
#include "modules/device_orientation/DeviceMotionData.h"
#include "modules/device_orientation/DeviceMotionDispatcher.h"
@@ -93,18 +94,25 @@ bool DeviceMotionController::isNullEvent(Event* event)
return !motionEvent->deviceMotionData()->canProvideEventData();
}
-void DeviceMotionController::didAddEventListener(DOMWindow*, const AtomicString& eventType)
+void DeviceMotionController::didAddEventListener(DOMWindow* window, const AtomicString& eventType)
{
- if (eventType == EventTypeNames::devicemotion && RuntimeEnabledFeatures::deviceMotionEnabled()) {
+ if (eventType == EventTypeNames::devicemotion
+ && RuntimeEnabledFeatures::deviceMotionEnabled()
+ && window->hasEventListeners(EventTypeNames::devicemotion)) {
Inactive 2014/04/17 14:38:20 How can this new condition ever be false?
Inactive 2014/04/17 14:43:17 Unless I am mistaken, when didAddEventListener() i
timvolodine 2014/04/17 15:34:13 I think you are right. Also it cannot hurt to call
+
if (page() && page()->visibilityState() == PageVisibilityStateVisible)
startUpdating();
+
m_hasEventListener = true;
}
}
-void DeviceMotionController::didRemoveEventListener(DOMWindow*, const AtomicString& eventType)
+void DeviceMotionController::didRemoveEventListener(DOMWindow* window, const AtomicString& eventType)
{
- if (eventType == EventTypeNames::devicemotion) {
+ if (eventType == EventTypeNames::devicemotion
+ && RuntimeEnabledFeatures::deviceMotionEnabled()
+ && !window->hasEventListeners(EventTypeNames::devicemotion)) {
Inactive 2014/04/17 14:38:20 Right, much better than my "counter" idea :)
Peter Beverloo 2014/04/17 14:48:17 nit: you could early return here.
timvolodine 2014/04/17 15:34:13 Done.
timvolodine 2014/04/17 15:34:13 ;)
+
stopUpdating();
m_hasEventListener = false;
}

Powered by Google App Engine
This is Rietveld 408576698