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

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: Rebase after r172920 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() : m_lastDeviceLightData(-1)
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 m_lastDeviceLightData = -1;
49 }
50
51 void DeviceLightDispatcher::didChangeDeviceLight(const double value)
52 {
53 m_lastDeviceLightData = value;
54
55 {
56 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
57 // Don't fire controllers removed or added during event dispatch.
58 size_t size = m_controllers.size();
59 for (size_t i = 0; i < size; ++i) {
60 if (m_controllers[i])
61 static_cast<DeviceLightController*>(m_controllers[i])->didChange DeviceLight(m_lastDeviceLightData);
62 }
63 }
64
65 if (m_needsPurge)
66 purgeControllers();
67 }
68
69 double DeviceLightDispatcher::latestDeviceLightData() const
70 {
71 return m_lastDeviceLightData;
72 }
73
74 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698