void BaseClickableWithKeyInputType::handleKeypressEvent(HTMLInputElement& element, KeyboardEvent* event)
{
    int charCode = event->charCode();
    if (charCode == '\r') {
        element.dispatchSimulatedClick(event);
        event->setDefaultHandled();
        return;
    }
    if (charCode == ' ') {
        // Prevent scrolling down the page.
        event->setDefaultHandled();
    }
}
Пример #2
0
void HTMLFormElement::submitClick(Event* event)
{
    bool submitFound = false;
    for (unsigned i = 0; i < formElements.size(); ++i) {
        if (formElements[i]->hasLocalName(inputTag)) {
            HTMLInputElement* element = static_cast<HTMLInputElement*>(formElements[i]);
            if (element->isSuccessfulSubmitButton() && element->renderer()) {
                submitFound = true;
                element->dispatchSimulatedClick(event);
                break;
            }
        }
    }
    if (!submitFound) // submit the form without a submit or image input
        prepareSubmit(event);
}
Пример #3
0
void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
{
    BaseCheckableInputType::handleKeydownEvent(event);
    if (event->defaultHandled())
        return;
    const String& key = event->keyIdentifier();
    if (key != "Up" && key != "Down" && key != "Left" && key != "Right")
        return;

    // Left and up mean "previous radio button".
    // Right and down mean "next radio button".
    // Tested in WinIE, and even for RTL, left still means previous radio button
    // (and so moves to the right). Seems strange, but we'll match it. However,
    // when using Spatial Navigation, we need to be able to navigate without
    // changing the selection.
    Document& document = element().document();
    if (isSpatialNavigationEnabled(document.frame()))
        return;
    bool forward = (key == "Down" || key == "Right");

    // We can only stay within the form's children if the form hasn't been demoted to a leaf because
    // of malformed HTML.
    Node* node = &element();
    while ((node = (forward ? NodeTraversal::next(*node) : NodeTraversal::previous(*node)))) {
        // Once we encounter a form element, we know we're through.
        if (node->hasTagName(formTag))
            break;
        // Look for more radio buttons.
        if (!node->hasTagName(inputTag))
            continue;
        HTMLInputElement* inputElement = toHTMLInputElement(node);
        if (inputElement->form() != element().form())
            break;
        if (inputElement->isRadioButton() && inputElement->name() == element().name() && inputElement->isFocusable()) {
            RefPtr<HTMLInputElement> protector(inputElement);
            document.setFocusedElement(inputElement);
            inputElement->dispatchSimulatedClick(event, SendNoEvents);
            event->setDefaultHandled();
            return;
        }
    }
}
void RadioInputType::handleKeydownEvent(KeyboardEvent* event)
{
    BaseCheckableInputType::handleKeydownEvent(event);
    if (event->defaultHandled())
        return;
    const String& key = event->keyIdentifier();
    if (key != "Up" && key != "Down" && key != "Left" && key != "Right")
        return;

    // Left and up mean "previous radio button".
    // Right and down mean "next radio button".
    // Tested in WinIE, and even for RTL, left still means previous radio button
    // (and so moves to the right). Seems strange, but we'll match it. However,
    // when using Spatial Navigation, we need to be able to navigate without
    // changing the selection.
    Document& document = element().document();
    if (isSpatialNavigationEnabled(document.frame()))
        return;
    bool forward = (key == "Down" || key == "Right");

    // We can only stay within the form's children if the form hasn't been demoted to a leaf because
    // of malformed HTML.
    HTMLInputElement* inputElement = findNextFocusableRadioButtonInGroup(toHTMLInputElement(&element()), forward);
    if (!inputElement) {
        // Traverse in reverse direction till last or first radio button
        forward = !(forward);
        HTMLInputElement* nextInputElement = findNextFocusableRadioButtonInGroup(toHTMLInputElement(&element()), forward);
        while (nextInputElement) {
            inputElement = nextInputElement;
            nextInputElement = findNextFocusableRadioButtonInGroup(nextInputElement, forward);
        }
    }
    if (inputElement) {
        RefPtrWillBeRawPtr<HTMLInputElement> protector(inputElement);
        document.setFocusedElement(inputElement);
        inputElement->dispatchSimulatedClick(event, SendNoEvents);
        event->setDefaultHandled();
        return;
    }
}
// FIXME: Could share this with BaseCheckableInputType and RangeInputType if we had a common base class.
void BaseClickableWithKeyInputType::accessKeyAction(HTMLInputElement& element, bool sendMouseEvents)
{
    element.dispatchSimulatedClick(0, sendMouseEvents ? SendMouseUpDownEvents : SendNoEvents);
}