This source file includes following definitions.
- m_timer
- fireDeviceEvent
- dispatchDeviceEvent
- startUpdating
- stopUpdating
- pageVisibilityChanged
#include "config.h"
#include "core/frame/DeviceSensorEventController.h"
#include "core/dom/Document.h"
#include "core/frame/DOMWindow.h"
#include "core/page/Page.h"
namespace WebCore {
DeviceSensorEventController::DeviceSensorEventController(Document& document)
: PageLifecycleObserver(document.page())
, m_hasEventListener(false)
, m_document(document)
, m_isActive(false)
, m_needsCheckingNullEvents(true)
, m_timer(this, &DeviceSensorEventController::fireDeviceEvent)
{
}
DeviceSensorEventController::~DeviceSensorEventController()
{
}
void DeviceSensorEventController::fireDeviceEvent(Timer<DeviceSensorEventController>* timer)
{
ASSERT_UNUSED(timer, timer == &m_timer);
ASSERT(hasLastData());
m_timer.stop();
dispatchDeviceEvent(getLastEvent());
}
void DeviceSensorEventController::dispatchDeviceEvent(PassRefPtrWillBeRawPtr<Event> prpEvent)
{
if (!m_document.domWindow() || m_document.activeDOMObjectsAreSuspended() || m_document.activeDOMObjectsAreStopped())
return;
RefPtrWillBeRawPtr<Event> event = prpEvent;
m_document.domWindow()->dispatchEvent(event);
if (m_needsCheckingNullEvents) {
if (isNullEvent(event.get()))
stopUpdating();
else
m_needsCheckingNullEvents = false;
}
}
void DeviceSensorEventController::startUpdating()
{
if (m_isActive)
return;
if (hasLastData() && !m_timer.isActive()) {
m_timer.startOneShot(0, FROM_HERE);
}
registerWithDispatcher();
m_isActive = true;
}
void DeviceSensorEventController::stopUpdating()
{
if (!m_isActive)
return;
if (m_timer.isActive())
m_timer.stop();
unregisterWithDispatcher();
m_isActive = false;
}
void DeviceSensorEventController::pageVisibilityChanged()
{
if (!m_hasEventListener)
return;
if (page()->visibilityState() == PageVisibilityStateVisible)
startUpdating();
else
stopUpdating();
}
}