Ejemplo n.º 1
0
void DOMWindowEventQueue::dispatchEvent(Event* event) {
  EventTarget* eventTarget = event->target();
  InspectorInstrumentation::AsyncTask asyncTask(
      eventTarget->getExecutionContext(), event);
  if (LocalDOMWindow* window = eventTarget->toLocalDOMWindow())
    window->dispatchEvent(event, nullptr);
  else
    eventTarget->dispatchEvent(event);
}
void GenericEventQueue::cancelAllEvents()
{
    m_timer.stop();

    for (const auto& pendingEvent : m_pendingEvents) {
        Event* event = pendingEvent.get();
        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
        EventTarget* target = event->target() ? event->target() : m_owner.get();
        InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(), event);
    }
    m_pendingEvents.clear();
}
bool GenericEventQueue::cancelEvent(Event* event)
{
    bool found = m_pendingEvents.contains(event);

    if (found) {
        EventTarget* target = event->target() ? event->target() : m_owner.get();
        InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(), event);
        m_pendingEvents.remove(m_pendingEvents.find(event));
        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
    }

    if (m_pendingEvents.isEmpty())
        m_timer.stop();

    return found;
}
void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
{
    ASSERT(!m_timer.isActive());
    ASSERT(!m_pendingEvents.isEmpty());

    HeapVector<Member<Event>> pendingEvents;
    m_pendingEvents.swap(pendingEvents);

    for (const auto& pendingEvent : pendingEvents) {
        Event* event = pendingEvent.get();
        EventTarget* target = event->target() ? event->target() : m_owner.get();
        CString type(event->type().ascii());
        InspectorInstrumentation::AsyncTask asyncTask(target->getExecutionContext(), event);
        TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type);
        target->dispatchEvent(pendingEvent);
        TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type);
    }
}
bool GenericEventQueue::enqueueEvent(Event* event)
{
    if (m_isClosed)
        return false;

    if (event->target() == m_owner)
        event->setTarget(nullptr);

    TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii());
    EventTarget* target = event->target() ? event->target() : m_owner.get();
    InspectorInstrumentation::asyncTaskScheduled(target->getExecutionContext(), event->type(), event);
    m_pendingEvents.append(event);

    if (!m_timer.isActive())
        m_timer.startOneShot(0, BLINK_FROM_HERE);

    return true;
}