diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/modules/device_light/DeviceLightController.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/modules/device_light/DeviceLightController.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chromium/third_party/WebKit/Source/modules/device_light/DeviceLightController.cpp b/chromium/third_party/WebKit/Source/modules/device_light/DeviceLightController.cpp new file mode 100644 index 00000000000..3768be38631 --- /dev/null +++ b/chromium/third_party/WebKit/Source/modules/device_light/DeviceLightController.cpp @@ -0,0 +1,74 @@ +// 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 "core/dom/Document.h" +#include "core/frame/LocalDOMWindow.h" +#include "core/page/Page.h" +#include "modules/device_light/DeviceLightDispatcher.h" +#include "modules/device_light/DeviceLightEvent.h" +#include "platform/RuntimeEnabledFeatures.h" + +namespace WebCore { + +DeviceLightController::DeviceLightController(Document& document) + : DeviceSingleWindowEventController(document) +{ +} + +DeviceLightController::~DeviceLightController() +{ + stopUpdating(); +} + +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(), adoptPtrWillBeNoop(controller)); + } + return *controller; +} + +bool DeviceLightController::hasLastData() +{ + return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0; +} + +void DeviceLightController::registerWithDispatcher() +{ + DeviceLightDispatcher::instance().addController(this); +} + +void DeviceLightController::unregisterWithDispatcher() +{ + DeviceLightDispatcher::instance().removeController(this); +} + +PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const +{ + return DeviceLightEvent::create(EventTypeNames::devicelight, + DeviceLightDispatcher::instance().latestDeviceLightData()); +} + +bool DeviceLightController::isNullEvent(Event* event) const +{ + DeviceLightEvent* lightEvent = toDeviceLightEvent(event); + return lightEvent->value() == std::numeric_limits<double>::infinity(); +} + +const AtomicString& DeviceLightController::eventTypeName() const +{ + return EventTypeNames::devicelight; +} + +} // namespace WebCore |