Chromium Code Reviews| Index: Source/modules/devicelight/DeviceLightController.cpp |
| diff --git a/Source/modules/devicelight/DeviceLightController.cpp b/Source/modules/devicelight/DeviceLightController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bcb78d31ce9b6529d2c9aaa70211dc5bd6217d45 |
| --- /dev/null |
| +++ b/Source/modules/devicelight/DeviceLightController.cpp |
| @@ -0,0 +1,121 @@ |
| +/* |
| + * Copyright (C) 2014 Intel Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions |
| + * are met: |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above copyright |
| + * notice, this list of conditions and the following disclaimer in the |
| + * documentation and/or other materials provided with the distribution. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
|
abarth-chromium
2014/03/04 18:59:32
Please use the copyright noticed listed in:
http:
riju_
2014/03/05 15:47:27
Done.
|
| + |
| +#include "config.h" |
| +#include "modules/devicelight/DeviceLightController.h" |
| + |
| +#include "RuntimeEnabledFeatures.h" |
| +#include "core/dom/Document.h" |
| +#include "core/events/ThreadLocalEventNames.h" |
| +#include "core/page/Page.h" |
| +#include "modules/device_orientation/DeviceSensorEventController.h" |
| +#include "modules/devicelight/DeviceLightDispatcher.h" |
| +#include "modules/devicelight/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 |