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()
26 const char* DeviceLightController::supplementName()
28 return "DeviceLightController";
31 DeviceLightController& DeviceLightController::from(Document& document)
33 DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
35 controller = new DeviceLightController(document);
36 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
41 bool DeviceLightController::hasLastData()
43 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
46 void DeviceLightController::registerWithDispatcher()
48 DeviceLightDispatcher::instance().addController(this);
51 void DeviceLightController::unregisterWithDispatcher()
53 DeviceLightDispatcher::instance().removeController(this);
56 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
58 return DeviceLightEvent::create(EventTypeNames::devicelight,
59 DeviceLightDispatcher::instance().latestDeviceLightData());
62 bool DeviceLightController::isNullEvent(Event* event) const
64 DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
65 return lightEvent->value() == std::numeric_limits<double>::infinity();
68 const AtomicString& DeviceLightController::eventTypeName() const
70 return EventTypeNames::devicelight;
73 void DeviceLightController::trace(Visitor* visitor)
75 DeviceSingleWindowEventController::trace(visitor);
76 DocumentSupplement::trace(visitor);