DeviceMotionController.cpp [plain text]
#include "config.h"
#include "DeviceMotionController.h"
#include "DeviceMotionClient.h"
#include "DeviceMotionData.h"
#include "DeviceMotionEvent.h"
#include "Page.h"
namespace WebCore {
DeviceMotionController::DeviceMotionController(DeviceMotionClient* client)
: DeviceController(client)
{
ASSERT(m_client);
deviceMotionClient()->setController(this);
}
PassOwnPtr<DeviceMotionController> DeviceMotionController::create(DeviceMotionClient* client)
{
return adoptPtr(new DeviceMotionController(client));
}
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();
}
PassRefPtr<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;
}
void provideDeviceMotionTo(Page* page, DeviceMotionClient* client)
{
DeviceMotionController::provideTo(page, DeviceMotionController::supplementName(), DeviceMotionController::create(client));
}
}