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

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

Issue 23705010: Add page visibility observer support for Device Motion (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Improve the test Created 7 years, 3 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
« no previous file with comments | « Source/modules/device_orientation/DeviceMotionController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/device_orientation/DeviceMotionController.cpp
diff --git a/Source/modules/device_orientation/DeviceMotionController.cpp b/Source/modules/device_orientation/DeviceMotionController.cpp
index e29890c5612eb2606584da9e72bb789f6e3430df..f4ed24a7f2f8d064ae2002ea1e1b20386a1eade8 100644
--- a/Source/modules/device_orientation/DeviceMotionController.cpp
+++ b/Source/modules/device_orientation/DeviceMotionController.cpp
@@ -30,6 +30,7 @@
#include "RuntimeEnabledFeatures.h"
#include "core/dom/Document.h"
#include "core/dom/EventNames.h"
+#include "core/page/Page.h"
#include "modules/device_orientation/DeviceMotionData.h"
#include "modules/device_orientation/DeviceMotionDispatcher.h"
#include "modules/device_orientation/DeviceMotionEvent.h"
@@ -39,6 +40,8 @@ namespace WebCore {
DeviceMotionController::DeviceMotionController(Document* document)
: DOMWindowLifecycleObserver(document->domWindow())
, DeviceSensorEventController(document)
+ , PageLifecycleObserver(document->page())
+ , m_hasEventListener(false)
{
}
@@ -95,19 +98,36 @@ bool DeviceMotionController::isNullEvent(Event* event)
void DeviceMotionController::didAddEventListener(DOMWindow*, const AtomicString& eventType)
{
- if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::deviceMotionEnabled())
- startUpdating();
+ if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::deviceMotionEnabled()) {
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible)
+ startUpdating();
+ m_hasEventListener = true;
+ }
}
void DeviceMotionController::didRemoveEventListener(DOMWindow*, const AtomicString& eventType)
{
- if (eventType == eventNames().devicemotionEvent)
+ if (eventType == eventNames().devicemotionEvent) {
stopUpdating();
+ m_hasEventListener = false;
+ }
}
void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*)
{
stopUpdating();
+ m_hasEventListener = false;
+}
+
+void DeviceMotionController::pageVisibilityChanged()
+{
+ if (!m_hasEventListener)
+ return;
+
+ if (page()->visibilityState() == PageVisibilityStateVisible)
+ startUpdating();
+ else
+ stopUpdating();
}
} // namespace WebCore
« no previous file with comments | « Source/modules/device_orientation/DeviceMotionController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698