| 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..eabbc71b4ed928390aa702b9c7db0d5cfa67d101
|
| --- /dev/null
|
| +++ b/Source/modules/device_light/DeviceLightController.cpp
|
| @@ -0,0 +1,100 @@
|
| +// 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/events/ThreadLocalEventNames.h"
|
| +#include "core/frame/DeviceSensorEventController.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();
|
| +}
|
| +
|
| +PassRefPtr<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();
|
| +}
|
| +
|
| +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
|
|
|