Chromium Code Reviews| Index: Source/modules/device_light/DeviceLightDispatcher.cpp |
| diff --git a/Source/modules/device_light/DeviceLightDispatcher.cpp b/Source/modules/device_light/DeviceLightDispatcher.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..65c9cf51a2b8e2a3e3b74db6a0c284d6652df55d |
| --- /dev/null |
| +++ b/Source/modules/device_light/DeviceLightDispatcher.cpp |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/device_light/DeviceLightDispatcher.h" |
| + |
| +#include "core/frame/DeviceSensorEventDispatcher.h" |
| +#include "modules/device_light/DeviceLightController.h" |
| +#include "public/platform/Platform.h" |
| +#include "wtf/TemporaryChange.h" |
| + |
| +namespace WebCore { |
| + |
| +DeviceLightDispatcher& DeviceLightDispatcher::instance() |
| +{ |
| + DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ()); |
| + return deviceLightDispatcher; |
| +} |
| + |
| +DeviceLightDispatcher::DeviceLightDispatcher() : m_lastDeviceLightData(-1) |
|
Inactive
2014/05/09 13:12:47
nit: Per coding style, I think ": m_lastDeviceLigh
riju_
2014/05/09 13:45:35
Done.
Tools/Scripts/check-webkit-style (or cpplin
|
| +{ |
| +} |
| + |
| +DeviceLightDispatcher::~DeviceLightDispatcher() |
| +{ |
| +} |
| + |
| + |
| +void DeviceLightDispatcher::addDeviceLightController(DeviceLightController* controller) |
| +{ |
| + addController(controller); |
| +} |
| + |
| +void DeviceLightDispatcher::removeDeviceLightController(DeviceLightController* controller) |
| +{ |
| + removeController(controller); |
| +} |
| + |
| +void DeviceLightDispatcher::startListening() |
| +{ |
| + blink::Platform::current()->setDeviceLightListener(this); |
| +} |
| + |
| +void DeviceLightDispatcher::stopListening() |
| +{ |
| + blink::Platform::current()->setDeviceLightListener(0); |
| + m_lastDeviceLightData = -1; |
| +} |
| + |
| +void DeviceLightDispatcher::didChangeDeviceLight(double value) |
| +{ |
| + m_lastDeviceLightData = value; |
| + |
| + { |
| + TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); |
| + // Don't fire controllers removed or added during event dispatch. |
| + size_t size = m_controllers.size(); |
| + for (size_t i = 0; i < size; ++i) { |
| + if (m_controllers[i]) |
| + static_cast<DeviceLightController*>(m_controllers[i])->didChangeDeviceLight(m_lastDeviceLightData); |
| + } |
| + } |
| + |
| + if (m_needsPurge) |
| + purgeControllers(); |
| +} |
| + |
| +double DeviceLightDispatcher::latestDeviceLightData() const |
| +{ |
| + return m_lastDeviceLightData; |
| +} |
| + |
| +} // namespace WebCore |