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