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

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: added fix and test for device orientation 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..d36e1983f4f4121ac381586f821816928f26cf82 100644
--- a/Source/modules/device_orientation/DeviceMotionController.cpp
+++ b/Source/modules/device_orientation/DeviceMotionController.cpp
@@ -27,8 +27,8 @@
#include "config.h"
#include "modules/device_orientation/DeviceMotionController.h"
-#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,21 +93,24 @@ 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 (page() && page()->visibilityState() == PageVisibilityStateVisible)
- startUpdating();
- m_hasEventListener = true;
- }
+ if (eventType != EventTypeNames::devicemotion)
+ return;
+
+ 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) {
- stopUpdating();
- m_hasEventListener = false;
- }
+ if (eventType != EventTypeNames::devicemotion || window->hasEventListeners(EventTypeNames::devicemotion))
+ return;
+
+ stopUpdating();
+ m_hasEventListener = false;
}
void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*)

Powered by Google App Engine
This is Rietveld 408576698