1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "modules/device_light/DeviceLightController.h"
8 #include "core/dom/Document.h"
9 #include "core/frame/LocalDOMWindow.h"
10 #include "core/page/Page.h"
11 #include "modules/device_light/DeviceLightDispatcher.h"
12 #include "modules/device_light/DeviceLightEvent.h"
13 #include "platform/RuntimeEnabledFeatures.h"
17 DeviceLightController::DeviceLightController(Document& document)
18 : DeviceSingleWindowEventController(document)
22 DeviceLightController::~DeviceLightController()
27 const char* DeviceLightController::supplementName()
29 return "DeviceLightController";
32 DeviceLightController& DeviceLightController::from(Document& document)
34 DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
36 controller = new DeviceLightController(document);
37 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
42 bool DeviceLightController::hasLastData()
44 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
47 void DeviceLightController::registerWithDispatcher()
49 DeviceLightDispatcher::instance().addController(this);
52 void DeviceLightController::unregisterWithDispatcher()
54 DeviceLightDispatcher::instance().removeController(this);
57 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
59 return DeviceLightEvent::create(EventTypeNames::devicelight,
60 DeviceLightDispatcher::instance().latestDeviceLightData());
63 bool DeviceLightController::isNullEvent(Event* event) const
65 DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
66 return lightEvent->value() == std::numeric_limits<double>::infinity();
69 const AtomicString& DeviceLightController::eventTypeName() const
71 return EventTypeNames::devicelight;
74 } // namespace WebCore