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

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: fix webruntimefeatures 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/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 {
23 }
24
25 DeviceLightDispatcher::~DeviceLightDispatcher()
26 {
27 }
28
29
30 void DeviceLightDispatcher::addDeviceLightController(DeviceLightController* cont roller)
31 {
32 addController(controller);
33 }
34
35 void DeviceLightDispatcher::removeDeviceLightController(DeviceLightController* c ontroller)
36 {
37 removeController(controller);
38 }
39
40 void DeviceLightDispatcher::startListening()
41 {
42 blink::Platform::current()->setDeviceLightListener(this);
43 }
44
45 void DeviceLightDispatcher::stopListening()
46 {
47 blink::Platform::current()->setDeviceLightListener(0);
48 }
49
50 void DeviceLightDispatcher::didChangeDeviceLight(const double value)
51 {
52 m_lastDeviceLightData = value;
53
54 {
55 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
56 // Don't fire controllers removed or added during event dispatch.
57 size_t size = m_controllers.size();
58 for (size_t i = 0; i < size; ++i) {
59 if (m_controllers[i])
60 static_cast<DeviceLightController*>(m_controllers[i])->didChange DeviceLight(m_lastDeviceLightData);
61 }
62 }
63
64 if (m_needsPurge)
65 purgeControllers();
66 }
67
68 double DeviceLightDispatcher::latestDeviceLightData() const
69 {
70 return m_lastDeviceLightData;
71 }
72
73 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698