Example #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);
}
Example #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;
  }
}
Example #3
0
void HTMLTextAreaElement::childrenChanged(const ChildrenChange& change) {
  HTMLElement::childrenChanged(change);
  setLastChangeWasNotUserEdit();
  if (m_isDirty)
    setInnerEditorValue(value());
  else
    setNonDirtyValue(defaultValue());
}
Example #4
0
void HTMLTextAreaElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
    setLastChangeWasNotUserEdit();
    if (!m_isDirty)
        setNonDirtyValue(defaultValue());
    setInnerTextValue(value());
    HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
}