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

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: Layout test fix Created 6 years, 8 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/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();
timvolodine 2014/04/08 12:59:55 can lux sensor value be 0? in that case this would
riju_ 2014/04/10 12:22:10 Yes. Lux value = 0 is valid. changing this to True
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();
timvolodine 2014/04/08 12:59:55 should this be value==+Inf? (as according to spec)
riju_ 2014/04/10 12:22:10 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();
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
OLDNEW
« no previous file with comments | « Source/modules/device_light/DeviceLightController.h ('k') | Source/modules/device_light/DeviceLightDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698