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

Unified Diff: Source/modules/device_light/DeviceLightController.cpp

Issue 315023006: Revert of Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
Index: Source/modules/device_light/DeviceLightController.cpp
diff --git a/Source/modules/device_light/DeviceLightController.cpp b/Source/modules/device_light/DeviceLightController.cpp
index ea6b76ea8a502ff1b6c67e353a56b9617fc75ebe..36e09cedfe518ea105e169d6c7817ec3389a9775 100644
--- a/Source/modules/device_light/DeviceLightController.cpp
+++ b/Source/modules/device_light/DeviceLightController.cpp
@@ -15,13 +15,20 @@
namespace WebCore {
DeviceLightController::DeviceLightController(Document& document)
- : DeviceSingleWindowEventController(document)
+ : DeviceSensorEventController(document.page())
+ , DOMWindowLifecycleObserver(document.domWindow())
+ , m_document(document)
{
}
DeviceLightController::~DeviceLightController()
{
stopUpdating();
+}
+
+void DeviceLightController::didChangeDeviceLight(double value)
+{
+ dispatchDeviceEvent(DeviceLightEvent::create(EventTypeNames::devicelight, value));
}
const char* DeviceLightController::supplementName()
@@ -44,31 +51,55 @@
return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
}
-void DeviceLightController::registerWithDispatcher()
-{
- DeviceLightDispatcher::instance().addController(this);
-}
-
-void DeviceLightController::unregisterWithDispatcher()
-{
- DeviceLightDispatcher::instance().removeController(this);
-}
-
-PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
+PassRefPtrWillBeRawPtr<Event> DeviceLightController::getLastEvent()
{
return DeviceLightEvent::create(EventTypeNames::devicelight,
DeviceLightDispatcher::instance().latestDeviceLightData());
}
-bool DeviceLightController::isNullEvent(Event* event) const
+void DeviceLightController::registerWithDispatcher()
+{
+ DeviceLightDispatcher::instance().addDeviceLightController(this);
+}
+
+void DeviceLightController::unregisterWithDispatcher()
+{
+ DeviceLightDispatcher::instance().removeDeviceLightController(this);
+}
+
+bool DeviceLightController::isNullEvent(Event* event)
{
DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
return lightEvent->value() == std::numeric_limits<double>::infinity();
}
-const AtomicString& DeviceLightController::eventTypeName() const
+Document* DeviceLightController::document()
{
- return EventTypeNames::devicelight;
+ return &m_document;
+}
+
+void DeviceLightController::didAddEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType == EventTypeNames::devicelight && RuntimeEnabledFeatures::deviceLightEnabled()) {
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible)
+ startUpdating();
+ m_hasEventListener = true;
+ }
+}
+
+void DeviceLightController::didRemoveEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType != EventTypeNames::devicelight || window->hasEventListeners(EventTypeNames::devicelight))
+ return;
+
+ stopUpdating();
+ m_hasEventListener = false;
+}
+
+void DeviceLightController::didRemoveAllEventListeners(DOMWindow* window)
+{
+ stopUpdating();
+ m_hasEventListener = false;
}
} // namespace WebCore
« no previous file with comments | « Source/modules/device_light/DeviceLightController.h ('k') | Source/modules/device_light/DeviceLightDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698