Chromium Code Reviews| Index: Source/modules/device_light/DeviceLightController.cpp |
| diff --git a/Source/modules/device_light/DeviceLightController.cpp b/Source/modules/device_light/DeviceLightController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ff9b334920ed010878e7afab4d060755e4ac8c1 |
| --- /dev/null |
| +++ b/Source/modules/device_light/DeviceLightController.cpp |
| @@ -0,0 +1,97 @@ |
| +// 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 "modules/device_light/DeviceLightController.h" |
| + |
| +#include "RuntimeEnabledFeatures.h" |
| +#include "core/dom/Document.h" |
| +#include "core/page/Page.h" |
| +#include "modules/device_light/DeviceLightDispatcher.h" |
| +#include "modules/device_light/DeviceLightEvent.h" |
| + |
| +namespace WebCore { |
| + |
| +DeviceLightController::DeviceLightController(Document& document) |
| + : DeviceSensorEventController(document) |
| + , DOMWindowLifecycleObserver(document.domWindow()) |
| +{ |
| +} |
| + |
| +DeviceLightController::~DeviceLightController() |
| +{ |
| + stopUpdating(); |
| +} |
| + |
| +void DeviceLightController::didChangeDeviceLight(double value) |
| +{ |
| + dispatchDeviceEvent(DeviceLightEvent::create(EventTypeNames::devicelight, value)); |
| +} |
| + |
| +const char* DeviceLightController::supplementName() |
| +{ |
| + return "DeviceLightController"; |
| +} |
| + |
| +DeviceLightController& DeviceLightController::from(Document& document) |
| +{ |
| + DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName())); |
| + if (!controller) { |
| + controller = new DeviceLightController(document); |
| + DocumentSupplement::provideTo(document, supplementName(), adoptPtr(controller)); |
| + } |
| + return *controller; |
| +} |
| + |
| +bool DeviceLightController::hasLastData() |
| +{ |
| + return DeviceLightDispatcher::instance().latestDeviceLightData(); |
|
timvolodine
2014/04/08 12:59:55
can lux sensor value be 0? in that case this would
riju_
2014/04/10 12:22:10
Yes. Lux value = 0 is valid. changing this to True
|
| +} |
| + |
| +PassRefPtrWillBeRawPtr<Event> DeviceLightController::getLastEvent() |
| +{ |
| + return DeviceLightEvent::create(EventTypeNames::devicelight, |
| + DeviceLightDispatcher::instance().latestDeviceLightData()); |
| +} |
| + |
| +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(); |
|
timvolodine
2014/04/08 12:59:55
should this be value==+Inf? (as according to spec)
riju_
2014/04/10 12:22:10
Done.
|
| +} |
| + |
| +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) { |
| + stopUpdating(); |
| + m_hasEventListener = false; |
| + } |
| +} |
| + |
| +void DeviceLightController::didRemoveAllEventListeners(DOMWindow* window) |
| +{ |
| + stopUpdating(); |
| + m_hasEventListener = false; |
| +} |
| + |
| +} // namespace WebCore |