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

Unified Diff: Source/modules/device_light/DeviceLightDispatcher.cpp

Issue 143823004: Implement DeviceLight (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Work in Adam's comments Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
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..a780b9f620671215eb856f1052fe19d894de6eca
--- /dev/null
+++ b/Source/modules/device_light/DeviceLightDispatcher.cpp
@@ -0,0 +1,73 @@
+// 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 "modules/device_light/DeviceLightController.h"
+#include "modules/device_orientation/DeviceSensorEventDispatcher.h"
+#include "public/platform/Platform.h"
+#include "wtf/TemporaryChange.h"
+
+namespace WebCore {
+
+DeviceLightDispatcher& DeviceLightDispatcher::instance()
+{
+ DEFINE_STATIC_LOCAL(DeviceLightDispatcher, deviceLightDispatcher, ());
+ return deviceLightDispatcher;
+}
+
+DeviceLightDispatcher::DeviceLightDispatcher()
+{
+}
+
+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);
+}
+
+void DeviceLightDispatcher::didChangeDeviceLight(const 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()
Inactive 2014/03/07 19:29:52 can be const
riju_ 2014/03/10 16:17:26 On Mac try bot it showed -> error: 'const' type qu
+{
+ return m_lastDeviceLightData;
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698