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 "modules/EventModules.h"
10 #include "modules/device_light/DeviceLightDispatcher.h"
11 #include "modules/device_light/DeviceLightEvent.h"
12 #include "platform/RuntimeEnabledFeatures.h"
16 DeviceLightController::DeviceLightController(Document& document)
17 : DeviceSingleWindowEventController(document)
21 DeviceLightController::~DeviceLightController()
28 const char* DeviceLightController::supplementName()
30 return "DeviceLightController";
33 DeviceLightController& DeviceLightController::from(Document& document)
35 DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
37 controller = new DeviceLightController(document);
38 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
43 bool DeviceLightController::hasLastData()
45 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
48 void DeviceLightController::registerWithDispatcher()
50 DeviceLightDispatcher::instance().addController(this);
53 void DeviceLightController::unregisterWithDispatcher()
55 DeviceLightDispatcher::instance().removeController(this);
58 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
60 return DeviceLightEvent::create(EventTypeNames::devicelight,
61 DeviceLightDispatcher::instance().latestDeviceLightData());
64 bool DeviceLightController::isNullEvent(Event* event) const
66 DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
67 return lightEvent->value() == std::numeric_limits<double>::infinity();
70 const AtomicString& DeviceLightController::eventTypeName() const
72 return EventTypeNames::devicelight;
75 void DeviceLightController::trace(Visitor* visitor)
77 DeviceSingleWindowEventController::trace(visitor);
78 DocumentSupplement::trace(visitor);