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

Unified Diff: Source/core/frame/DeviceSingleWindowEventController.cpp

Issue 315573002: Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add stopUpdating in destructor of BatteryManager. Created 6 years, 6 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/core/frame/DeviceSingleWindowEventController.h ('k') | Source/modules/battery/BatteryDispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/frame/DeviceSingleWindowEventController.cpp
diff --git a/Source/core/frame/DeviceSingleWindowEventController.cpp b/Source/core/frame/DeviceSingleWindowEventController.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..91f852bbfc18333139a8a76a65954f886f0c4163
--- /dev/null
+++ b/Source/core/frame/DeviceSingleWindowEventController.cpp
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/frame/DeviceSingleWindowEventController.h"
+
+#include "core/dom/Document.h"
+#include "core/frame/DOMWindow.h"
+#include "core/page/Page.h"
+
+namespace WebCore {
+
+DeviceSingleWindowEventController::DeviceSingleWindowEventController(Document& document)
+ : DeviceEventControllerBase(document.page())
+ , DOMWindowLifecycleObserver(document.domWindow())
+ , m_needsCheckingNullEvents(true)
+ , m_document(document)
+{
+}
+
+DeviceSingleWindowEventController::~DeviceSingleWindowEventController()
+{
+}
+
+void DeviceSingleWindowEventController::didUpdateData()
+{
+ dispatchDeviceEvent(lastEvent());
+}
+
+void DeviceSingleWindowEventController::dispatchDeviceEvent(PassRefPtrWillBeRawPtr<Event> prpEvent)
+{
+ if (!m_document.domWindow() || m_document.activeDOMObjectsAreSuspended() || m_document.activeDOMObjectsAreStopped())
+ return;
+
+ RefPtrWillBeRawPtr<Event> event = prpEvent;
+ m_document.domWindow()->dispatchEvent(event);
+
+ if (m_needsCheckingNullEvents) {
+ if (isNullEvent(event.get()))
+ stopUpdating();
+ else
+ m_needsCheckingNullEvents = false;
+ }
+}
+
+void DeviceSingleWindowEventController::didAddEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType != eventTypeName())
+ return;
+
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible)
+ startUpdating();
+
+ m_hasEventListener = true;
+}
+
+void DeviceSingleWindowEventController::didRemoveEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType != eventTypeName() || window->hasEventListeners(eventTypeName()))
+ return;
+
+ stopUpdating();
+ m_hasEventListener = false;
+}
+
+void DeviceSingleWindowEventController::didRemoveAllEventListeners(DOMWindow*)
+{
+ stopUpdating();
+ m_hasEventListener = false;
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/core/frame/DeviceSingleWindowEventController.h ('k') | Source/modules/battery/BatteryDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698