| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "modules/device_light/DeviceLightController.h" | |
| 6 | |
| 7 #include "core/dom/Document.h" | |
| 8 #include "modules/EventModules.h" | |
| 9 #include "modules/device_light/DeviceLightDispatcher.h" | |
| 10 #include "modules/device_light/DeviceLightEvent.h" | |
| 11 #include "platform/RuntimeEnabledFeatures.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 DeviceLightController::DeviceLightController(Document& document) | |
| 16 : DeviceSingleWindowEventController(document), | |
| 17 Supplement<Document>(document) {} | |
| 18 | |
| 19 DeviceLightController::~DeviceLightController() {} | |
| 20 | |
| 21 const char* DeviceLightController::supplementName() { | |
| 22 return "DeviceLightController"; | |
| 23 } | |
| 24 | |
| 25 DeviceLightController& DeviceLightController::from(Document& document) { | |
| 26 DeviceLightController* controller = static_cast<DeviceLightController*>( | |
| 27 Supplement<Document>::from(document, supplementName())); | |
| 28 if (!controller) { | |
| 29 controller = new DeviceLightController(document); | |
| 30 Supplement<Document>::provideTo(document, supplementName(), controller); | |
| 31 } | |
| 32 return *controller; | |
| 33 } | |
| 34 | |
| 35 bool DeviceLightController::hasLastData() { | |
| 36 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0; | |
| 37 } | |
| 38 | |
| 39 void DeviceLightController::registerWithDispatcher() { | |
| 40 DeviceLightDispatcher::instance().addController(this); | |
| 41 } | |
| 42 | |
| 43 void DeviceLightController::unregisterWithDispatcher() { | |
| 44 DeviceLightDispatcher::instance().removeController(this); | |
| 45 } | |
| 46 | |
| 47 Event* DeviceLightController::lastEvent() const { | |
| 48 return DeviceLightEvent::create( | |
| 49 EventTypeNames::devicelight, | |
| 50 DeviceLightDispatcher::instance().latestDeviceLightData()); | |
| 51 } | |
| 52 | |
| 53 bool DeviceLightController::isNullEvent(Event* event) const { | |
| 54 DeviceLightEvent* lightEvent = toDeviceLightEvent(event); | |
| 55 return lightEvent->value() == std::numeric_limits<double>::infinity(); | |
| 56 } | |
| 57 | |
| 58 const AtomicString& DeviceLightController::eventTypeName() const { | |
| 59 return EventTypeNames::devicelight; | |
| 60 } | |
| 61 | |
| 62 DEFINE_TRACE(DeviceLightController) { | |
| 63 DeviceSingleWindowEventController::trace(visitor); | |
| 64 Supplement<Document>::trace(visitor); | |
| 65 } | |
| 66 | |
| 67 } // namespace blink | |
| OLD | NEW |