void RenderTextControlMultiLine::updateFromElement() { createSubtreeIfNeeded(0); RenderTextControl::updateFromElement(); HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(node()); if (m_placeholderVisible) setInnerTextValue(textArea->getAttribute(HTMLNames::placeholderAttr)); else setInnerTextValue(textArea->value()); }
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); }
void RenderTextControlMultiLine::updateFromElement() { createSubtreeIfNeeded(0); RenderTextControl::updateFromElement(); setInnerTextValue(static_cast<HTMLTextAreaElement*>(node())->value()); }
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); }
void HTMLTextAreaElement::childrenChanged(const ChildChange& change) { HTMLElement::childrenChanged(change); setLastChangeWasNotUserEdit(); if (m_isDirty) setInnerTextValue(value()); else setNonDirtyValue(defaultValue()); }
void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState& exceptionState) { if (start > end) { exceptionState.throwDOMException(IndexSizeError, "The provided start value (" + String::number(start) + ") is larger than the provided end value (" + String::number(end) + ")."); return; } if (hasAuthorShadowRoot()) return; String text = innerTextValue(); unsigned textLength = text.length(); unsigned replacementLength = replacement.length(); unsigned newSelectionStart = selectionStart(); unsigned newSelectionEnd = selectionEnd(); start = std::min(start, textLength); end = std::min(end, textLength); if (start < end) text.replace(start, end - start, replacement); else text.insert(replacement, start); setInnerTextValue(text); // FIXME: What should happen to the value (as in value()) if there's no renderer? if (!renderer()) return; subtreeHasChanged(); if (equalIgnoringCase(selectionMode, "select")) { newSelectionStart = start; newSelectionEnd = start + replacementLength; } else if (equalIgnoringCase(selectionMode, "start")) newSelectionStart = newSelectionEnd = start; else if (equalIgnoringCase(selectionMode, "end")) newSelectionStart = newSelectionEnd = start + replacementLength; else { // Default is "preserve". long delta = replacementLength - (end - start); if (newSelectionStart > end) newSelectionStart += delta; else if (newSelectionStart > start) newSelectionStart = start; if (newSelectionEnd > end) newSelectionEnd += delta; else if (newSelectionEnd > start) newSelectionEnd = start + replacementLength; } setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection); }
void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode& ec) { if (start > end) { ec = INDEX_SIZE_ERR; return; } String text = innerTextValue(); unsigned textLength = text.length(); unsigned replacementLength = replacement.length(); unsigned newSelectionStart = selectionStart(); unsigned newSelectionEnd = selectionEnd(); start = std::min(start, textLength); end = std::min(end, textLength); if (start < end) text.replace(start, end - start, replacement); else text.insert(replacement, start); setInnerTextValue(text); // FIXME: What should happen to the value (as in value()) if there's no renderer? if (!renderer()) return; subtreeHasChanged(); if (equalIgnoringCase(selectionMode, "select")) { newSelectionStart = start; newSelectionEnd = start + replacementLength; } else if (equalIgnoringCase(selectionMode, "start")) newSelectionStart = newSelectionEnd = start; else if (equalIgnoringCase(selectionMode, "end")) newSelectionStart = newSelectionEnd = start + replacementLength; else { // Default is "preserve". long delta = replacementLength - (end - start); if (newSelectionStart > end) newSelectionStart += delta; else if (newSelectionStart > start) newSelectionStart = start; if (newSelectionEnd > end) newSelectionEnd += delta; else if (newSelectionEnd > start) newSelectionEnd = start + replacementLength; } setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection); }