Ejemplo n.º 1
0
void InputElement::aboutToUnload(InputElementData& data, Document* document)
{
    if (!data.inputElement()->isTextField() || !data.element()->focused() || !document->frame())
        return;

    document->frame()->textFieldDidEndEditing(data.element());
}
Ejemplo n.º 2
0
void InputElement::parseSizeAttribute(InputElementData& data, MappedAttribute* attribute)
{
    data.setSize(attribute->isNull() ? InputElement::s_defaultSize : attribute->value().toInt());

    if (RenderObject* renderer = data.element()->renderer())
        renderer->setNeedsLayoutAndPrefWidthsRecalc();
}
Ejemplo n.º 3
0
void InputElement::updateSelectionRange(InputElementData& data, int start, int end)
{
    if (!data.inputElement()->isTextField())
        return;

    if (RenderTextControl* renderer = toRenderTextControl(data.element()->renderer()))
        renderer->setSelectionRange(start, end);
}
Ejemplo n.º 4
0
void InputElement::notifyFormStateChanged(InputElementData& data, Document* document)
{
    Frame* frame = document->frame();
    if (!frame)
        return;

    if (Page* page = frame->page())
        page->chrome()->client()->formStateDidChange(data.element());
}
Ejemplo n.º 5
0
void InputElement::updatePlaceholderVisibility(InputElementData& data, Document* document, bool placeholderValueChanged)
{
    ASSERT(data.inputElement()->isTextField());

    bool oldPlaceholderShouldBeVisible = data.placeholderShouldBeVisible();
    Element* element = data.element();

    data.setPlaceholderShouldBeVisible(data.inputElement()->value().isEmpty() 
                                       && document->focusedNode() != element
                                       && !data.inputElement()->placeholder().isEmpty());

    if ((oldPlaceholderShouldBeVisible != data.placeholderShouldBeVisible() || placeholderValueChanged) && element->renderer())
        static_cast<RenderTextControlSingleLine*>(element->renderer())->updatePlaceholderVisibility();
}
Ejemplo n.º 6
0
void InputElement::parseMaxLengthAttribute(InputElementData& data, MappedAttribute* attribute)
{
    int maxLength = attribute->isNull() ? InputElement::s_maximumLength : attribute->value().toInt();
    if (maxLength <= 0 || maxLength > InputElement::s_maximumLength)
        maxLength = InputElement::s_maximumLength;

    int oldMaxLength = data.maxLength();
    data.setMaxLength(maxLength);

    if (oldMaxLength != maxLength)
        updateValueIfNeeded(data);

    data.element()->setNeedsStyleRecalc();
}
Ejemplo n.º 7
0
void InputElement::dispatchBlurEvent(InputElementData& data, Document* document)
{
    if (!data.inputElement()->isTextField())
        return;

    Frame* frame = document->frame();
    if (!frame)
        return;

    updatePlaceholderVisibility(data, document);

    if (data.inputElement()->isPasswordField())
        document->setUseSecureKeyboardEntryWhenActive(false);

    frame->textFieldDidEndEditing(data.element());
}
Ejemplo n.º 8
0
void InputElement::setValueFromRenderer(InputElementData& data, Document* document, const String& value)
{
    // Renderer and our event handler are responsible for constraining values.
    ASSERT(value == data.inputElement()->constrainValue(value) || data.inputElement()->constrainValue(value).isEmpty());

    if (data.inputElement()->isTextField())
        updatePlaceholderVisibility(data, document);

    // Workaround for bug where trailing \n is included in the result of textContent.
    // The assert macro above may also be simplified to:  value == constrainValue(value)
    // http://bugs.webkit.org/show_bug.cgi?id=9661
    if (value == "\n")
        data.setValue("");
    else
        data.setValue(value);

    Element* element = data.element();
    element->setFormControlValueMatchesRenderer(true);

    // Fire the "input" DOM event
    element->dispatchEvent(eventNames().inputEvent, true, false);
    notifyFormStateChanged(data, document);
}