OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2014 Intel Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * * Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * * Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
abarth-chromium
2014/03/04 18:59:32
Please use the copyright noticed listed in:
http:
riju_
2014/03/05 15:47:27
Done.
| |
25 | |
26 #include "config.h" | |
27 #include "modules/devicelight/DeviceLightController.h" | |
28 | |
29 #include "RuntimeEnabledFeatures.h" | |
30 #include "core/dom/Document.h" | |
31 #include "core/events/ThreadLocalEventNames.h" | |
32 #include "core/page/Page.h" | |
33 #include "modules/device_orientation/DeviceSensorEventController.h" | |
34 #include "modules/devicelight/DeviceLightDispatcher.h" | |
35 #include "modules/devicelight/DeviceLightEvent.h" | |
36 | |
37 namespace WebCore { | |
38 | |
39 DeviceLightController::DeviceLightController(Document& document) | |
40 : DeviceSensorEventController(document) | |
41 , DOMWindowLifecycleObserver(document.domWindow()) | |
42 { | |
43 } | |
44 | |
45 DeviceLightController::~DeviceLightController() | |
46 { | |
47 stopUpdating(); | |
48 } | |
49 | |
50 void DeviceLightController::didChangeDeviceLight(double value) | |
51 { | |
52 dispatchDeviceEvent(DeviceLightEvent::create(EventTypeNames::devicelight, va lue)); | |
53 } | |
54 | |
55 const char* DeviceLightController::supplementName() | |
56 { | |
57 return "DeviceLightController"; | |
58 } | |
59 | |
60 DeviceLightController& DeviceLightController::from(Document& document) | |
61 { | |
62 DeviceLightController* controller = static_cast<DeviceLightController*>(Docu mentSupplement::from(document, supplementName())); | |
63 if (!controller) { | |
64 controller = new DeviceLightController(document); | |
65 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller)); | |
66 } | |
67 return *controller; | |
68 } | |
69 | |
70 bool DeviceLightController::hasLastData() | |
71 { | |
72 return DeviceLightDispatcher::instance().latestDeviceLightData(); | |
73 } | |
74 | |
75 PassRefPtr<Event> DeviceLightController::getLastEvent() | |
76 { | |
77 return DeviceLightEvent::create(EventTypeNames::devicelight, | |
78 DeviceLightDispatcher::instance().latestDeviceLightData()); | |
79 } | |
80 | |
81 void DeviceLightController::registerWithDispatcher() | |
82 { | |
83 DeviceLightDispatcher::instance().addDeviceLightController(this); | |
84 } | |
85 | |
86 void DeviceLightController::unregisterWithDispatcher() | |
87 { | |
88 DeviceLightDispatcher::instance().removeDeviceLightController(this); | |
89 } | |
90 | |
91 bool DeviceLightController::isNullEvent(Event* event) | |
92 { | |
93 DeviceLightEvent* lightEvent = toDeviceLightEvent(event); | |
94 return !lightEvent->value(); | |
95 } | |
96 | |
97 void DeviceLightController::didAddEventListener(DOMWindow* window, const AtomicS tring& eventType) | |
98 { | |
99 if (eventType == EventTypeNames::devicelight && RuntimeEnabledFeatures::devi ceLightEnabled()) { | |
100 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | |
101 startUpdating(); | |
102 m_hasEventListener = true; | |
103 } | |
104 } | |
105 | |
106 void DeviceLightController::didRemoveEventListener(DOMWindow* window, const Atom icString& eventType) | |
107 { | |
108 if (eventType == EventTypeNames::devicelight) { | |
109 stopUpdating(); | |
110 m_hasEventListener = false; | |
111 } | |
112 } | |
113 | |
114 void DeviceLightController::didRemoveAllEventListeners(DOMWindow* window) | |
115 { | |
116 stopUpdating(); | |
117 m_hasEventListener = false; | |
118 } | |
119 | |
120 | |
121 } // namespace WebCore | |
OLD | NEW |