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

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

Issue 143823004: Implement DeviceLight (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: nits Created 6 years, 7 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/DeviceLightDispatcher.h"
7
8 #include "core/frame/DeviceSensorEventDispatcher.h"
9 #include "modules/device_light/DeviceLightController.h"
10 #include "public/platform/Platform.h"
11 #include "wtf/TemporaryChange.h"
12
13 namespace WebCore {
14
15 DeviceLightDispatcher& DeviceLightDispatcher::instance()
16 {
17 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ());
18 return deviceLightDispatcher;
19 }
20
21 DeviceLightDispatcher::DeviceLightDispatcher()
22 : m_lastDeviceLightData(-1)
23 {
24 }
25
26 DeviceLightDispatcher::~DeviceLightDispatcher()
27 {
28 }
29
30
31 void DeviceLightDispatcher::addDeviceLightController(DeviceLightController* cont roller)
32 {
33 addController(controller);
34 }
35
36 void DeviceLightDispatcher::removeDeviceLightController(DeviceLightController* c ontroller)
37 {
38 removeController(controller);
39 }
40
41 void DeviceLightDispatcher::startListening()
42 {
43 blink::Platform::current()->setDeviceLightListener(this);
44 }
45
46 void DeviceLightDispatcher::stopListening()
47 {
48 blink::Platform::current()->setDeviceLightListener(0);
49 m_lastDeviceLightData = -1;
50 }
51
52 void DeviceLightDispatcher::didChangeDeviceLight(double value)
53 {
54 m_lastDeviceLightData = value;
55
56 {
57 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
58 // Don't fire controllers removed or added during event dispatch.
59 size_t size = m_controllers.size();
60 for (size_t i = 0; i < size; ++i) {
61 if (m_controllers[i])
62 static_cast<DeviceLightController*>(m_controllers[i])->didChange DeviceLight(m_lastDeviceLightData);
63 }
64 }
65
66 if (m_needsPurge)
67 purgeControllers();
68 }
69
70 double DeviceLightDispatcher::latestDeviceLightData() const
71 {
72 return m_lastDeviceLightData;
73 }
74
75 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/device_light/DeviceLightDispatcher.h ('k') | Source/modules/device_light/DeviceLightEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698