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 "config.h" |
| 6 #include "modules/device_light/DeviceLightController.h" |
| 7 |
| 8 #include "RuntimeEnabledFeatures.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/events/ThreadLocalEventNames.h" |
| 11 #include "core/page/Page.h" |
| 12 #include "modules/device_light/DeviceLightDispatcher.h" |
| 13 #include "modules/device_light/DeviceLightEvent.h" |
| 14 #include "modules/device_orientation/DeviceSensorEventController.h" |
| 15 |
| 16 namespace WebCore { |
| 17 |
| 18 DeviceLightController::DeviceLightController(Document& document) |
| 19 : DeviceSensorEventController(document) |
| 20 , DOMWindowLifecycleObserver(document.domWindow()) |
| 21 { |
| 22 } |
| 23 |
| 24 DeviceLightController::~DeviceLightController() |
| 25 { |
| 26 stopUpdating(); |
| 27 } |
| 28 |
| 29 void DeviceLightController::didChangeDeviceLight(double value) |
| 30 { |
| 31 dispatchDeviceEvent(DeviceLightEvent::create(EventTypeNames::devicelight, va
lue)); |
| 32 } |
| 33 |
| 34 const char* DeviceLightController::supplementName() |
| 35 { |
| 36 return "DeviceLightController"; |
| 37 } |
| 38 |
| 39 DeviceLightController& DeviceLightController::from(Document& document) |
| 40 { |
| 41 DeviceLightController* controller = static_cast<DeviceLightController*>(Docu
mentSupplement::from(document, supplementName())); |
| 42 if (!controller) { |
| 43 controller = new DeviceLightController(document); |
| 44 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr
oller)); |
| 45 } |
| 46 return *controller; |
| 47 } |
| 48 |
| 49 bool DeviceLightController::hasLastData() |
| 50 { |
| 51 return DeviceLightDispatcher::instance().latestDeviceLightData(); |
| 52 } |
| 53 |
| 54 PassRefPtr<Event> DeviceLightController::getLastEvent() |
| 55 { |
| 56 return DeviceLightEvent::create(EventTypeNames::devicelight, |
| 57 DeviceLightDispatcher::instance().latestDeviceLightData()); |
| 58 } |
| 59 |
| 60 void DeviceLightController::registerWithDispatcher() |
| 61 { |
| 62 DeviceLightDispatcher::instance().addDeviceLightController(this); |
| 63 } |
| 64 |
| 65 void DeviceLightController::unregisterWithDispatcher() |
| 66 { |
| 67 DeviceLightDispatcher::instance().removeDeviceLightController(this); |
| 68 } |
| 69 |
| 70 bool DeviceLightController::isNullEvent(Event* event) |
| 71 { |
| 72 DeviceLightEvent* lightEvent = toDeviceLightEvent(event); |
| 73 return !lightEvent->value(); |
| 74 } |
| 75 |
| 76 void DeviceLightController::didAddEventListener(DOMWindow* window, const AtomicS
tring& eventType) |
| 77 { |
| 78 if (eventType == EventTypeNames::devicelight && RuntimeEnabledFeatures::devi
ceLightEnabled()) { |
| 79 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
| 80 startUpdating(); |
| 81 m_hasEventListener = true; |
| 82 } |
| 83 } |
| 84 |
| 85 void DeviceLightController::didRemoveEventListener(DOMWindow* window, const Atom
icString& eventType) |
| 86 { |
| 87 if (eventType == EventTypeNames::devicelight) { |
| 88 stopUpdating(); |
| 89 m_hasEventListener = false; |
| 90 } |
| 91 } |
| 92 |
| 93 void DeviceLightController::didRemoveAllEventListeners(DOMWindow* window) |
| 94 { |
| 95 stopUpdating(); |
| 96 m_hasEventListener = false; |
| 97 } |
| 98 |
| 99 |
| 100 } // namespace WebCore |
OLD | NEW |