This source file includes following definitions.
- instance
- addDeviceMotionController
- removeDeviceMotionController
- startListening
- stopListening
- didChangeDeviceMotion
- latestDeviceMotionData
#include "config.h"
#include "modules/device_orientation/DeviceMotionDispatcher.h"
#include "modules/device_orientation/DeviceMotionController.h"
#include "modules/device_orientation/DeviceMotionData.h"
#include "public/platform/Platform.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
DeviceMotionDispatcher& DeviceMotionDispatcher::instance()
{
DEFINE_STATIC_LOCAL(DeviceMotionDispatcher, deviceMotionDispatcher, ());
return deviceMotionDispatcher;
}
DeviceMotionDispatcher::DeviceMotionDispatcher()
{
}
DeviceMotionDispatcher::~DeviceMotionDispatcher()
{
}
void DeviceMotionDispatcher::addDeviceMotionController(DeviceMotionController* controller)
{
addController(controller);
}
void DeviceMotionDispatcher::removeDeviceMotionController(DeviceMotionController* controller)
{
removeController(controller);
}
void DeviceMotionDispatcher::startListening()
{
blink::Platform::current()->setDeviceMotionListener(this);
}
void DeviceMotionDispatcher::stopListening()
{
blink::Platform::current()->setDeviceMotionListener(0);
m_lastDeviceMotionData.clear();
}
void DeviceMotionDispatcher::didChangeDeviceMotion(const blink::WebDeviceMotionData& motion)
{
m_lastDeviceMotionData = DeviceMotionData::create(motion);
{
TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
size_t size = m_controllers.size();
for (size_t i = 0; i < size; ++i) {
if (m_controllers[i])
static_cast<DeviceMotionController*>(m_controllers[i])->didChangeDeviceMotion(m_lastDeviceMotionData.get());
}
}
if (m_needsPurge)
purgeControllers();
}
DeviceMotionData* DeviceMotionDispatcher::latestDeviceMotionData()
{
return m_lastDeviceMotionData.get();
}
}