Ejemplo n.º 1
0
void EventDispatcher::dispatchSimulatedClick(Node* node, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions)
{
    if (isDisabledFormControl(node))
        return;

    if (!gNodesDispatchingSimulatedClicks)
        gNodesDispatchingSimulatedClicks = new HashSet<Node*>;
    else if (gNodesDispatchingSimulatedClicks->contains(node))
        return;

    gNodesDispatchingSimulatedClicks->add(node);

    if (mouseEventOptions == SendMouseOverUpDownEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseoverEvent, node->document()->defaultView(), underlyingEvent)).dispatch();

    if (mouseEventOptions != SendNoEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mousedownEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    node->setActive(true, visualOptions == ShowPressedLook);
    if (mouseEventOptions != SendNoEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseupEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    node->setActive(false);

    // always send click
    EventDispatcher(node, SimulatedMouseEvent::create(eventNames().clickEvent, node->document()->defaultView(), underlyingEvent)).dispatch();

    gNodesDispatchingSimulatedClicks->remove(node);
}
void EventDispatcher::dispatchSimulatedClick(Node& node, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickCreationScope creationScope)
{
    // This persistent vector doesn't cause leaks, because added Nodes are removed
    // before dispatchSimulatedClick() returns. This vector is here just to prevent
    // the code from running into an infinite recursion of dispatchSimulatedClick().
    DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapHashSet<RawPtrWillBeMember<Node>>>, nodesDispatchingSimulatedClicks, (adoptPtrWillBeNoop(new WillBeHeapHashSet<RawPtrWillBeMember<Node>>())));

    if (isDisabledFormControl(&node))
        return;

    if (nodesDispatchingSimulatedClicks->contains(&node))
        return;

    nodesDispatchingSimulatedClicks->add(&node);

    if (mouseEventOptions == SendMouseOverUpDownEvents)
        EventDispatcher(node, MouseEvent::create(EventTypeNames::mouseover, node.document().domWindow(), underlyingEvent, creationScope)).dispatch();

    if (mouseEventOptions != SendNoEvents) {
        EventDispatcher(node, MouseEvent::create(EventTypeNames::mousedown, node.document().domWindow(), underlyingEvent, creationScope)).dispatch();
        node.setActive(true);
        EventDispatcher(node, MouseEvent::create(EventTypeNames::mouseup, node.document().domWindow(), underlyingEvent, creationScope)).dispatch();
    }
    // Some elements (e.g. the color picker) may set active state to true before
    // calling this method and expect the state to be reset during the call.
    node.setActive(false);

    // always send click
    EventDispatcher(node, MouseEvent::create(EventTypeNames::click, node.document().domWindow(), underlyingEvent, creationScope)).dispatch();

    nodesDispatchingSimulatedClicks->remove(&node);
}
Ejemplo n.º 3
0
void EventDispatcher::dispatchSimulatedClick(Node* node, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions)
{
    if (isDisabledFormControl(node))
        return;

    if (!gNodesDispatchingSimulatedClicks)
        gNodesDispatchingSimulatedClicks = new HashSet<Node*>;
    else if (gNodesDispatchingSimulatedClicks->contains(node))
        return;

    gNodesDispatchingSimulatedClicks->add(node);

    if (mouseEventOptions == SendMouseOverUpDownEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(EventTypeNames::mouseover, node->document().domWindow(), underlyingEvent)).dispatch();

    if (mouseEventOptions != SendNoEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(EventTypeNames::mousedown, node->document().domWindow(), underlyingEvent)).dispatch();
    node->setActive(true);
    if (mouseEventOptions != SendNoEvents)
        EventDispatcher(node, SimulatedMouseEvent::create(EventTypeNames::mouseup, node->document().domWindow(), underlyingEvent)).dispatch();
    node->setActive(false);

    // always send click
    EventDispatcher(node, SimulatedMouseEvent::create(EventTypeNames::click, node->document().domWindow(), underlyingEvent)).dispatch();

    gNodesDispatchingSimulatedClicks->remove(node);
}
Ejemplo n.º 4
0
bool HTMLPlugInElement::willRespondToMouseClickEvents()
{
    if (isDisabledFormControl())
        return false;
    RenderObject* r = renderer();
    return r && (r->isEmbeddedObject() || r->isWidget());
}
Ejemplo n.º 5
0
bool GestureEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
{
    if (isDisabledFormControl(dispatcher->node()))
        return true;

    dispatcher->dispatch();
    ASSERT(!event()->defaultPrevented());
    return event()->defaultHandled() || event()->defaultPrevented();
}
Ejemplo n.º 6
0
DispatchEventResult MouseEventDispatchMediator::dispatchEvent(
    EventDispatcher& dispatcher) const {
  MouseEvent& mouseEvent = event();
  mouseEvent.eventPath().adjustForRelatedTarget(dispatcher.node(),
                                                mouseEvent.relatedTarget());

  if (!mouseEvent.isTrusted())
    return dispatcher.dispatch();

  if (isDisabledFormControl(&dispatcher.node()))
    return DispatchEventResult::CanceledBeforeDispatch;

  if (mouseEvent.type().isEmpty())
    return DispatchEventResult::NotCanceled;  // Shouldn't happen.

  DCHECK(!mouseEvent.target() ||
         mouseEvent.target() != mouseEvent.relatedTarget());

  EventTarget* relatedTarget = mouseEvent.relatedTarget();

  DispatchEventResult dispatchResult = dispatcher.dispatch();

  if (mouseEvent.type() != EventTypeNames::click || mouseEvent.detail() != 2)
    return dispatchResult;

  // Special case: If it's a double click event, we also send the dblclick
  // event. This is not part of the DOM specs, but is used for compatibility
  // with the ondblclick="" attribute. This is treated as a separate event in
  // other DOM-compliant browsers like Firefox, and so we do the same.
  MouseEvent* doubleClickEvent = MouseEvent::create();
  doubleClickEvent->initMouseEventInternal(
      EventTypeNames::dblclick, mouseEvent.bubbles(), mouseEvent.cancelable(),
      mouseEvent.view(), mouseEvent.detail(), mouseEvent.screenX(),
      mouseEvent.screenY(), mouseEvent.clientX(), mouseEvent.clientY(),
      mouseEvent.modifiers(), mouseEvent.button(), relatedTarget,
      mouseEvent.sourceCapabilities(), mouseEvent.buttons());
  doubleClickEvent->setComposed(mouseEvent.composed());

  // Inherit the trusted status from the original event.
  doubleClickEvent->setTrusted(mouseEvent.isTrusted());
  if (mouseEvent.defaultHandled())
    doubleClickEvent->setDefaultHandled();
  DispatchEventResult doubleClickDispatchResult =
      EventDispatcher::dispatchEvent(
          dispatcher.node(),
          MouseEventDispatchMediator::create(doubleClickEvent));
  if (doubleClickDispatchResult != DispatchEventResult::NotCanceled)
    return doubleClickDispatchResult;
  return dispatchResult;
}
Ejemplo n.º 7
0
DispatchEventResult PointerEventDispatchMediator::dispatchEvent(
    EventDispatcher& dispatcher) const {
  if (isDisabledFormControl(&dispatcher.node()))
    return DispatchEventResult::CanceledBeforeDispatch;

  if (event().type().isEmpty())
    return DispatchEventResult::NotCanceled;  // Shouldn't happen.

  DCHECK(!event().target() || event().target() != event().relatedTarget());

  event().eventPath().adjustForRelatedTarget(dispatcher.node(),
                                             event().relatedTarget());

  return dispatcher.dispatch();
}
Ejemplo n.º 8
0
void HTMLButtonElement::defaultEventHandler(Event* event)
{
    if (event->type() == eventNames().DOMActivateEvent && !isDisabledFormControl()) {
        if (form() && m_type == SUBMIT) {
            m_isActivatedSubmit = true;
            form()->prepareForSubmission(event);
            event->setDefaultHandled();
            m_isActivatedSubmit = false; // Do this in case submission was canceled.
        }
        if (form() && m_type == RESET) {
            form()->reset();
            event->setDefaultHandled();
        }
    }

    if (is<KeyboardEvent>(*event)) {
        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
        if (keyboardEvent.type() == eventNames().keydownEvent && keyboardEvent.keyIdentifier() == "U+0020") {
            setActive(true, true);
            // No setDefaultHandled() - IE dispatches a keypress in this case.
            return;
        }
        if (keyboardEvent.type() == eventNames().keypressEvent) {
            switch (keyboardEvent.charCode()) {
                case '\r':
                    dispatchSimulatedClick(&keyboardEvent);
                    keyboardEvent.setDefaultHandled();
                    return;
                case ' ':
                    // Prevent scrolling down the page.
                    keyboardEvent.setDefaultHandled();
                    return;
            }
        }
        if (keyboardEvent.type() == eventNames().keyupEvent && keyboardEvent.keyIdentifier() == "U+0020") {
            if (active())
                dispatchSimulatedClick(&keyboardEvent);
            keyboardEvent.setDefaultHandled();
            return;
        }
    }

    HTMLFormControlElement::defaultEventHandler(event);
}
Ejemplo n.º 9
0
void HTMLButtonElement::defaultEventHandler(Event* event)
{
    if (event->type() == EventTypeNames::DOMActivate && !isDisabledFormControl()) {
        if (form() && m_type == SUBMIT) {
            m_isActivatedSubmit = true;
            form()->prepareForSubmission(event);
            event->setDefaultHandled();
            m_isActivatedSubmit = false; // Do this in case submission was canceled.
        }
        if (form() && m_type == RESET) {
            form()->reset();
            event->setDefaultHandled();
        }
    }

    if (event->isKeyboardEvent()) {
        if (event->type() == EventTypeNames::keydown && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
            setActive(true);
            // No setDefaultHandled() - IE dispatches a keypress in this case.
            return;
        }
        if (event->type() == EventTypeNames::keypress) {
            switch (toKeyboardEvent(event)->charCode()) {
                case '\r':
                    dispatchSimulatedClick(event);
                    event->setDefaultHandled();
                    return;
                case ' ':
                    // Prevent scrolling down the page.
                    event->setDefaultHandled();
                    return;
            }
        }
        if (event->type() == EventTypeNames::keyup && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
            if (active())
                dispatchSimulatedClick(event);
            event->setDefaultHandled();
            return;
        }
    }

    HTMLFormControlElement::defaultEventHandler(event);
}
Ejemplo n.º 10
0
bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) const
{
    MouseEvent& mouseEvent = event();
    if (!mouseEvent.isTrusted()) {
        mouseEvent.eventPath().adjustForRelatedTarget(dispatcher.node(), mouseEvent.relatedTarget());
        return dispatcher.dispatch();
    }

    if (isDisabledFormControl(&dispatcher.node()))
        return false;

    if (mouseEvent.type().isEmpty())
        return true; // Shouldn't happen.

    ASSERT(!mouseEvent.target() || mouseEvent.target() != mouseEvent.relatedTarget());

    EventTarget* relatedTarget = mouseEvent.relatedTarget();
    mouseEvent.eventPath().adjustForRelatedTarget(dispatcher.node(), relatedTarget);

    dispatcher.dispatch();
    bool swallowEvent = mouseEvent.defaultHandled() || mouseEvent.defaultPrevented();

    if (mouseEvent.type() != EventTypeNames::click || mouseEvent.detail() != 2)
        return !swallowEvent;

    // Special case: If it's a double click event, we also send the dblclick event. This is not part
    // of the DOM specs, but is used for compatibility with the ondblclick="" attribute. This is treated
    // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
    RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
    doubleClickEvent->initMouseEventInternal(EventTypeNames::dblclick, mouseEvent.bubbles(), mouseEvent.cancelable(), mouseEvent.view(),
        mouseEvent.detail(), mouseEvent.screenX(), mouseEvent.screenY(), mouseEvent.clientX(), mouseEvent.clientY(),
        mouseEvent.modifiers(), mouseEvent.button(), relatedTarget, mouseEvent.sourceCapabilities(), mouseEvent.buttons());

    // Inherit the trusted status from the original event.
    doubleClickEvent->setTrusted(mouseEvent.isTrusted());
    if (mouseEvent.defaultHandled())
        doubleClickEvent->setDefaultHandled();
    EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator::create(doubleClickEvent));
    if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented())
        return false;
    return !swallowEvent;
}
Ejemplo n.º 11
0
bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
{
    if (isSyntheticMouseEvent()) {
        event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
        return dispatcher->dispatch();
    }

    if (isDisabledFormControl(dispatcher->node()))
        return false;

    if (event()->type().isEmpty())
        return true; // Shouldn't happen.

    ASSERT(!event()->target() || event()->target() != event()->relatedTarget());

    EventTarget* relatedTarget = event()->relatedTarget();
    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), relatedTarget);

    dispatcher->dispatch();
    bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented();

    if (event()->type() != EventTypeNames::click || event()->detail() != 2)
        return !swallowEvent;

    // Special case: If it's a double click event, we also send the dblclick event. This is not part
    // of the DOM specs, but is used for compatibility with the ondblclick="" attribute. This is treated
    // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
    RefPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
    doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles(), event()->cancelable(), event()->view(),
                                     event()->detail(), event()->screenX(), event()->screenY(), event()->clientX(), event()->clientY(),
                                     event()->ctrlKey(), event()->altKey(), event()->shiftKey(), event()->metaKey(),
                                     event()->button(), relatedTarget);
    if (event()->defaultHandled())
        doubleClickEvent->setDefaultHandled();
    EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediator::create(doubleClickEvent));
    if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented())
        return false;
    return !swallowEvent;
}
Ejemplo n.º 12
0
bool SliderThumbElement::shouldAcceptTouchEvents()
{
    return renderer() && !isDisabledFormControl();
}
Ejemplo n.º 13
0
bool HTMLButtonElement::isSuccessfulSubmitButton() const
{
    // HTML spec says that buttons must have names to be considered successful.
    // However, other browsers do not impose this constraint.
    return m_type == SUBMIT && !isDisabledFormControl();
}
Ejemplo n.º 14
0
bool HTMLButtonElement::willRespondToMouseClickEvents()
{
    return !isDisabledFormControl();
}
bool HTMLFieldSetElement::supportsFocus() const
{
    return HTMLElement::supportsFocus() && !isDisabledFormControl();
}
Ejemplo n.º 16
0
bool HTMLButtonElement::willRespondToMouseClickEvents()
{
    if (!isDisabledFormControl() && form() && (m_type == SUBMIT || m_type == RESET))
        return true;
    return HTMLFormControlElement::willRespondToMouseClickEvents();
}