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

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: Initialize m_lastDeviceLightData to -1 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/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 m_lastDeviceLightData = -1;
Inactive 2014/04/15 15:56:12 Please use initializer list.
riju_ 2014/04/22 13:11:29 Done.
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 }
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