| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/device_light/DeviceLightDispatcher.h" | 6 #include "modules/device_light/DeviceLightDispatcher.h" |
| 7 | 7 |
| 8 #include "core/frame/DeviceSensorEventDispatcher.h" | 8 #include "core/frame/DeviceSensorEventDispatcher.h" |
| 9 #include "modules/device_light/DeviceLightController.h" | 9 #include "modules/device_light/DeviceLightController.h" |
| 10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "wtf/TemporaryChange.h" |
| 11 | 12 |
| 12 namespace WebCore { | 13 namespace WebCore { |
| 13 | 14 |
| 14 DeviceLightDispatcher& DeviceLightDispatcher::instance() | 15 DeviceLightDispatcher& DeviceLightDispatcher::instance() |
| 15 { | 16 { |
| 16 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ()); | 17 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ()); |
| 17 return deviceLightDispatcher; | 18 return deviceLightDispatcher; |
| 18 } | 19 } |
| 19 | 20 |
| 20 DeviceLightDispatcher::DeviceLightDispatcher() | 21 DeviceLightDispatcher::DeviceLightDispatcher() |
| 21 : m_lastDeviceLightData(-1) | 22 : m_lastDeviceLightData(-1) |
| 22 { | 23 { |
| 23 } | 24 } |
| 24 | 25 |
| 25 DeviceLightDispatcher::~DeviceLightDispatcher() | 26 DeviceLightDispatcher::~DeviceLightDispatcher() |
| 26 { | 27 { |
| 27 } | 28 } |
| 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 |
| 29 void DeviceLightDispatcher::startListening() | 41 void DeviceLightDispatcher::startListening() |
| 30 { | 42 { |
| 31 blink::Platform::current()->setDeviceLightListener(this); | 43 blink::Platform::current()->setDeviceLightListener(this); |
| 32 } | 44 } |
| 33 | 45 |
| 34 void DeviceLightDispatcher::stopListening() | 46 void DeviceLightDispatcher::stopListening() |
| 35 { | 47 { |
| 36 blink::Platform::current()->setDeviceLightListener(0); | 48 blink::Platform::current()->setDeviceLightListener(0); |
| 37 m_lastDeviceLightData = -1; | 49 m_lastDeviceLightData = -1; |
| 38 } | 50 } |
| 39 | 51 |
| 40 void DeviceLightDispatcher::didChangeDeviceLight(double value) | 52 void DeviceLightDispatcher::didChangeDeviceLight(double value) |
| 41 { | 53 { |
| 42 m_lastDeviceLightData = value; | 54 m_lastDeviceLightData = value; |
| 43 notifyControllers(); | 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(); |
| 44 } | 68 } |
| 45 | 69 |
| 46 double DeviceLightDispatcher::latestDeviceLightData() const | 70 double DeviceLightDispatcher::latestDeviceLightData() const |
| 47 { | 71 { |
| 48 return m_lastDeviceLightData; | 72 return m_lastDeviceLightData; |
| 49 } | 73 } |
| 50 | 74 |
| 51 } // namespace WebCore | 75 } // namespace WebCore |
| OLD | NEW |