Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/modules/device_light/DeviceLightController.cpp

Issue 143823004: Implement DeviceLight (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Event not Oilpan-ed yet. Add a test back Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/frame/DeviceSensorEventController.h"
12 #include "core/page/Page.h"
13 #include "modules/device_light/DeviceLightDispatcher.h"
14 #include "modules/device_light/DeviceLightEvent.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();
abarth-chromium 2014/03/21 13:04:13 You still haven't fixed this bug. If someone call
riju_ 2014/04/03 17:52:53 DeviceLightController is inheriting from DeviceSen
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698