Chromium Code Reviews| 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; |
| } |