DeviceMotionController.cpp [plain text]
#include "config.h"
#include "DeviceMotionController.h"
#include "DeviceMotionClient.h"
#include "DeviceMotionData.h"
#include "DeviceMotionEvent.h"
#include "EventNames.h"
#include "Page.h"
namespace WebCore {
DeviceMotionController::DeviceMotionController(DeviceMotionClient& client)
: DeviceController(client)
{
deviceMotionClient().setController(this);
}
#if PLATFORM(IOS_FAMILY)
void DeviceMotionController::suspendUpdates()
{
m_client.stopUpdating();
}
void DeviceMotionController::resumeUpdates()
{
if (!m_listeners.isEmpty())
m_client.startUpdating();
}
#endif
void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData)
{
dispatchDeviceEvent(DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData));
}
DeviceMotionClient& DeviceMotionController::deviceMotionClient()
{
return static_cast<DeviceMotionClient&>(m_client);
}
bool DeviceMotionController::hasLastData()
{
return deviceMotionClient().lastMotion();
}
RefPtr<Event> DeviceMotionController::getLastEvent()
{
return DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionClient().lastMotion());
}
const char* DeviceMotionController::supplementName()
{
return "DeviceMotionController";
}
DeviceMotionController* DeviceMotionController::from(Page* page)
{
return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName()));
}
bool DeviceMotionController::isActiveAt(Page* page)
{
if (DeviceMotionController* self = DeviceMotionController::from(page))
return self->isActive();
return false;
}
}