Esempio n. 1
0
void HTMLTextAreaElement::subtreeHasChanged() {
#if DCHECK_IS_ON()
  // The innerEditor should have either Text nodes or a placeholder break
  // element. If we see other nodes, it's a bug in editing code and we should
  // fix it.
  Element* innerEditor = innerEditorElement();
  for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) {
    if (node.isTextNode())
      continue;
    DCHECK(isHTMLBRElement(node));
    DCHECK_EQ(&node, innerEditor->lastChild());
  }
#endif
  addPlaceholderBreakElementIfNecessary();
  setChangedSinceLastFormControlChangeEvent(true);
  m_valueIsUpToDate = false;
  setNeedsValidityCheck();
  setAutofilled(false);
  updatePlaceholderVisibility();

  if (!isFocused())
    return;

  // When typing in a textarea, childrenChanged is not called, so we need to
  // force the directionality check.
  calculateAndAdjustDirectionality();

  DCHECK(document().isActive());
  document().frameHost()->chromeClient().didChangeValueInTextField(*this);
}
Esempio n. 2
0
void HTMLTextFormControlElement::setInnerEditorValue(const String& value)
{
    ASSERT(!openShadowRoot());
    if (!isTextFormControl() || openShadowRoot())
        return;

    bool textIsChanged = value != innerEditorValue();
    HTMLElement* innerEditor = innerEditorElement();
    if (!textIsChanged && innerEditor->hasChildren())
        return;

    // If the last child is a trailing <br> that's appended below, remove it
    // first so as to enable setInnerText() fast path of updating a text node.
    if (isHTMLBRElement(innerEditor->lastChild()))
        innerEditor->removeChild(innerEditor->lastChild(), ASSERT_NO_EXCEPTION);

    // We don't use setTextContent.  It triggers unnecessary paint.
    if (value.isEmpty())
        innerEditor->removeChildren();
    else
        replaceChildrenWithText(innerEditor, value, ASSERT_NO_EXCEPTION);

    // Add <br> so that we can put the caret at the next line of the last
    // newline.
    addPlaceholderBreakElementIfNecessary();

    if (textIsChanged && layoutObject()) {
        if (AXObjectCache* cache = document().existingAXObjectCache())
            cache->handleTextFormControlChanged(this);
    }
}