Exemplo n.º 1
0
void HTMLTextAreaElement::setValueCommon(const String& newValue)
{
    m_wasModifiedByUser = false;
    // Code elsewhere normalizes line endings added by the user via the keyboard or pasting.
    // We normalize line endings coming from JavaScript here.
    String normalizedValue = newValue.isNull() ? "" : newValue;
    normalizedValue.replace("\r\n", "\n");
    normalizedValue.replace('\r', '\n');

    // Return early because we don't want to move the caret or trigger other side effects
    // when the value isn't changing. This matches Firefox behavior, at least.
    if (normalizedValue == value())
        return;

    m_value = normalizedValue;
    setInnerTextValue(m_value);
    setLastChangeWasNotUserEdit();
    updatePlaceholderVisibility(false);
    setNeedsStyleRecalc();
    setFormControlValueMatchesRenderer(true);

    // Set the caret to the end of the text value.
    if (document()->focusedNode() == this) {
        unsigned endOfString = m_value.length();
        setSelectionRange(endOfString, endOfString);
    }

    notifyFormStateChanged();
    setTextAsOfLastFormControlChangeEvent(normalizedValue);
}
Exemplo n.º 2
0
void HTMLTextAreaElement::setValueCommon(const String& newValue,
                                         TextFieldEventBehavior eventBehavior,
                                         SetValueCommonOption setValueOption) {
  // Code elsewhere normalizes line endings added by the user via the keyboard
  // or pasting.  We normalize line endings coming from JavaScript here.
  String normalizedValue = newValue.isNull() ? "" : newValue;
  normalizedValue.replace("\r\n", "\n");
  normalizedValue.replace('\r', '\n');

  // Return early because we don't want to trigger other side effects
  // when the value isn't changing.
  // FIXME: Simple early return doesn't match the Firefox ever.
  // Remove these lines.
  if (normalizedValue == value()) {
    if (setValueOption == SetSeletion) {
      setNeedsValidityCheck();
      if (isFinishedParsingChildren()) {
        // Set the caret to the end of the text value except for initialize.
        unsigned endOfString = m_value.length();
        setSelectionRange(endOfString, endOfString);
      }
    }
    return;
  }

  m_value = normalizedValue;
  setInnerEditorValue(m_value);
  if (eventBehavior == DispatchNoEvent)
    setLastChangeWasNotUserEdit();
  updatePlaceholderVisibility();
  setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(
                                              StyleChangeReason::ControlValue));
  m_suggestedValue = String();
  setNeedsValidityCheck();
  if (isFinishedParsingChildren()) {
    // Set the caret to the end of the text value except for initialize.
    unsigned endOfString = m_value.length();
    setSelectionRange(endOfString, endOfString);
  }

  notifyFormStateChanged();
  switch (eventBehavior) {
    case DispatchChangeEvent:
      dispatchFormControlChangeEvent();
      break;

    case DispatchInputAndChangeEvent:
      dispatchFormControlInputEvent();
      dispatchFormControlChangeEvent();
      break;

    case DispatchNoEvent:
      // We need to update textAsOfLastFormControlChangeEvent for |value| IDL
      // setter without focus because input-assist features use setValue("...",
      // DispatchChangeEvent) without setting focus.
      if (!isFocused())
        setTextAsOfLastFormControlChangeEvent(normalizedValue);
      break;
  }
}
void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
{
    if (m_textAsOfLastFormControlChangeEvent != value()) {
        HTMLElement::dispatchChangeEvent();
        setTextAsOfLastFormControlChangeEvent(value());
    }
    setChangedSinceLastFormControlChangeEvent(false);
}
void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
{
    if (!equalIgnoringNullity(m_textAsOfLastFormControlChangeEvent, value())) {
        dispatchChangeEvent();
        setTextAsOfLastFormControlChangeEvent(value());
    }
    setChangedSinceLastFormControlChangeEvent(false);
}
void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
{
    String newValue = value();
    if (shouldDispatchFormControlChangeEvent(m_textAsOfLastFormControlChangeEvent, newValue)) {
        setTextAsOfLastFormControlChangeEvent(newValue);
        dispatchChangeEvent();
    }
    setChangedSinceLastFormControlChangeEvent(false);
}