int RenderTextControl::textBlockLogicalWidth() const { Element* innerText = innerTextElement(); ASSERT(innerText); LayoutUnit unitWidth = logicalWidth() - borderAndPaddingLogicalWidth(); if (innerText->renderer()) unitWidth -= innerText->renderBox()->paddingStart() + innerText->renderBox()->paddingEnd(); return unitWidth; }
int RenderTextControl::textBlockWidth() const { Element* innerText = innerTextElement(); ASSERT(innerText); LayoutUnit unitWidth = width() - borderAndPaddingWidth(); if (innerText->renderer()) unitWidth -= innerText->renderBox()->paddingLeft() + innerText->renderBox()->paddingRight(); return unitWidth; }
void RenderTextControl::hitInnerTextElement(HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset) { TextControlInnerTextElement* innerText = innerTextElement(); if (!innerText->renderer()) return; LayoutPoint adjustedLocation = accumulatedOffset + location(); LayoutPoint localPoint = pointInContainer - toLayoutSize(adjustedLocation + innerText->renderBox()->location()) + scrolledContentOffset(); result.setInnerNode(innerText); result.setInnerNonSharedNode(innerText); result.setLocalPoint(localPoint); }
int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const { Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); if (enclosingTextFormControl(indexPosition) != this) return 0; ExceptionCode ec = 0; RefPtr<Range> range = Range::create(indexPosition.document()); range->setStart(innerTextElement(), 0, ec); ASSERT(!ec); range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainerNode(), ec); ASSERT(!ec); return TextIterator::rangeLength(range.get()); }
void HTMLTextAreaElement::updatePlaceholderText() { ExceptionCode ec = 0; String placeholderText = strippedPlaceholder(); if (placeholderText.isEmpty()) { if (m_placeholder) { shadow()->oldestShadowRoot()->removeChild(m_placeholder.get(), ec); ASSERT(!ec); m_placeholder.clear(); } return; } if (!m_placeholder) { m_placeholder = HTMLDivElement::create(document()); m_placeholder->setShadowPseudoId("-webkit-input-placeholder"); shadow()->oldestShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling(), ec); ASSERT(!ec); } m_placeholder->setInnerText(placeholderText, ec); ASSERT(!ec); fixPlaceholderRenderer(m_placeholder.get(), innerTextElement()); }
void HTMLTextFormControlElement::setInnerTextValue(const String& value) { if (!isTextFormControl()) return; bool textIsChanged = value != innerTextValue(); if (textIsChanged || !innerTextElement()->hasChildNodes()) { if (textIsChanged && document() && renderer() && AXObjectCache::accessibilityEnabled()) document()->axObjectCache()->postNotification(this, AXObjectCache::AXValueChanged, false); ExceptionCode ec = 0; innerTextElement()->setInnerText(value, ec); ASSERT(!ec); if (value.endsWith('\n') || value.endsWith('\r')) { innerTextElement()->appendChild(HTMLBRElement::create(document()), ec); ASSERT(!ec); } } setFormControlValueMatchesRenderer(true); }
void HTMLTextAreaElement::updatePlaceholderText() { ExceptionCode ec = 0; String placeholderText = strippedPlaceholder(); if (placeholderText.isEmpty()) { if (m_placeholder) { userAgentShadowRoot()->removeChild(m_placeholder, ec); ASSERT(!ec); m_placeholder = 0; } return; } if (!m_placeholder) { RefPtr<HTMLDivElement> placeholder = HTMLDivElement::create(document()); m_placeholder = placeholder.get(); m_placeholder->setPseudo(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral)); userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->nextSibling(), ec); ASSERT(!ec); } m_placeholder->setInnerText(placeholderText, ec); ASSERT(!ec); fixPlaceholderRenderer(m_placeholder, innerTextElement()); }
void RenderTextControl::computeLogicalHeight() { HTMLElement* innerText = innerTextElement(); ASSERT(innerText); RenderBox* innerTextBox = innerText->renderBox(); LayoutUnit nonContentHeight = innerTextBox->borderAndPaddingHeight() + innerTextBox->marginHeight(); setHeight(computeControlHeight(innerTextBox->lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight) + borderAndPaddingHeight()); // We are able to have a horizontal scrollbar if the overflow style is scroll, or if its auto and there's no word wrap. if (style()->overflowX() == OSCROLL || (style()->overflowX() == OAUTO && innerText->renderer()->style()->wordWrap() == NormalWordWrap)) setHeight(height() + scrollbarThickness()); RenderBlock::computeLogicalHeight(); }
String HTMLTextFormControlElement::innerTextValue() const { HTMLElement* innerText = innerTextElement(); if (!innerText || !isTextFormControl()) return emptyString(); StringBuilder result; for (Node* node = innerText; node; node = NodeTraversal::next(node, innerText)) { if (node->hasTagName(brTag)) result.append(newlineCharacter); else if (node->isTextNode()) result.append(toText(node)->data()); } return finishText(result); }
void RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const { HTMLElement* innerText = innerTextElement(); ASSERT(innerText); if (RenderBox* innerTextBox = innerText->renderBox()) { LayoutUnit nonContentHeight = innerTextBox->borderAndPaddingHeight() + innerTextBox->marginHeight(); logicalHeight = computeControlHeight(innerTextBox->lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight) + borderAndPaddingHeight(); // We are able to have a horizontal scrollbar if the overflow style is scroll, or if its auto and there's no word wrap. if (style()->overflowX() == OSCROLL || (style()->overflowX() == OAUTO && innerText->renderer()->style()->overflowWrap() == NormalOverflowWrap)) logicalHeight += scrollbarThickness(); } RenderBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues); }
String HTMLTextFormControlElement::innerTextValue() const { ASSERT(!hasAuthorShadowRoot()); HTMLElement* innerText = innerTextElement(); if (!innerText || !isTextFormControl()) return emptyString(); StringBuilder result; for (Node* node = innerText; node; node = NodeTraversal::next(*node, innerText)) { if (isHTMLBRElement(*node)) result.append(newlineCharacter); else if (node->isTextNode()) result.append(toText(node)->data()); } return finishText(result); }
void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) { RenderBlockFlow::styleDidChange(diff, oldStyle); TextControlInnerTextElement* innerText = innerTextElement(); if (!innerText) return; RenderTextControlInnerBlock* innerTextRenderer = innerText->renderer(); if (innerTextRenderer) { // We may have set the width and the height in the old style in layout(). // Reset them now to avoid getting a spurious layout hint. innerTextRenderer->style().setHeight(Length()); innerTextRenderer->style().setWidth(Length()); innerTextRenderer->setStyle(createInnerTextStyle(&style())); } textFormControlElement().updatePlaceholderVisibility(); }
String HTMLTextFormControlElement::valueWithHardLineBreaks() const { // FIXME: It's not acceptable to ignore the HardWrap setting when there is no renderer. // While we have no evidence this has ever been a practical problem, it would be best to fix it some day. if (!isTextFormControl()) return value(); TextControlInnerTextElement* innerText = innerTextElement(); if (!innerText) return value(); RenderTextControlInnerBlock* renderer = innerText->renderer(); if (!renderer) return value(); Node* breakNode; unsigned breakOffset; RootInlineBox* line = renderer->firstRootBox(); if (!line) return value(); getNextSoftBreak(line, breakNode, breakOffset); StringBuilder result; for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(*node, innerText)) { if (is<HTMLBRElement>(*node)) result.append(newlineCharacter); else if (is<Text>(*node)) { String data = downcast<Text>(*node).data(); unsigned length = data.length(); unsigned position = 0; while (breakNode == node && breakOffset <= length) { if (breakOffset > position) { result.append(data, position, breakOffset - position); position = breakOffset; result.append(newlineCharacter); } getNextSoftBreak(line, breakNode, breakOffset); } result.append(data, position, length - position); } while (breakNode == node) getNextSoftBreak(line, breakNode, breakOffset); } stripTrailingNewline(result); return result.toString(); }
void HTMLTextAreaElement::updatePlaceholderText() { HTMLElement* placeholder = placeholderElement(); String placeholderText = strippedPlaceholder(); if (placeholderText.isEmpty()) { if (placeholder) userAgentShadowRoot()->removeChild(placeholder); return; } if (!placeholder) { RefPtr<HTMLDivElement> newElement = HTMLDivElement::create(document()); placeholder = newElement.get(); placeholder->setPart(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral)); placeholder->setAttribute(idAttr, ShadowElementNames::placeholder()); userAgentShadowRoot()->insertBefore(placeholder, innerTextElement()->nextSibling()); } placeholder->setTextContent(placeholderText, ASSERT_NO_EXCEPTION); }
PassRefPtr<Range> HTMLTextFormControlElement::selection() const { #if defined(S_CLEAR_SELECTION_ONAUTOFOCUS) if (!renderer() || !isTextFormControl()) #else if (!renderer() || !isTextFormControl() || !hasCachedSelection()) #endif return 0; int start = m_cachedSelectionStart; int end = m_cachedSelectionEnd; ASSERT(start <= end); HTMLElement* innerText = innerTextElement(); if (!innerText) return 0; if (!innerText->firstChild()) return Range::create(document(), innerText, 0, innerText, 0); int offset = 0; Node* startNode = 0; Node* endNode = 0; for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(*node, innerText)) { ASSERT(!node->firstChild()); ASSERT(node->isTextNode() || node->hasTagName(brTag)); int length = node->isTextNode() ? lastOffsetInNode(node) : 1; if (offset <= start && start <= offset + length) setContainerAndOffsetForRange(node, start - offset, startNode, start); if (offset <= end && end <= offset + length) { setContainerAndOffsetForRange(node, end - offset, endNode, end); break; } offset += length; } if (!startNode || !endNode) return 0; return Range::create(document(), startNode, start, endNode, end); }
void HTMLTextAreaElement::updatePlaceholderText() { String placeholderText = strippedPlaceholder(); if (placeholderText.isEmpty()) { if (m_placeholder) { userAgentShadowRoot()->removeChild(*m_placeholder, ASSERT_NO_EXCEPTION); m_placeholder = nullptr; } return; } if (!m_placeholder) { RefPtr<HTMLDivElement> placeholder = HTMLDivElement::create(document()); m_placeholder = placeholder.get(); m_placeholder->setPseudo(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral)); m_placeholder->setInlineStyleProperty(CSSPropertyDisplay, isPlaceholderVisible() ? CSSValueBlock : CSSValueNone, true); userAgentShadowRoot()->insertBefore(*m_placeholder, innerTextElement()->nextSibling()); } m_placeholder->setInnerText(placeholderText, ASSERT_NO_EXCEPTION); }
String HTMLTextFormControlElement::valueWithHardLineBreaks() const { // FIXME: It's not acceptable to ignore the HardWrap setting when there is no renderer. // While we have no evidence this has ever been a practical problem, it would be best to fix it some day. HTMLElement* innerText = innerTextElement(); if (!innerText || !isTextFormControl()) return value(); RenderBlock* renderer = toRenderBlock(innerText->renderer()); if (!renderer) return value(); Node* breakNode; unsigned breakOffset; RootInlineBox* line = renderer->firstRootBox(); if (!line) return value(); getNextSoftBreak(line, breakNode, breakOffset); StringBuilder result; for (Node* node = innerText->firstChild(); node; node = node->traverseNextNode(innerText)) { if (node->hasTagName(brTag)) result.append(newlineCharacter); else if (node->isTextNode()) { String data = toText(node)->data(); unsigned length = data.length(); unsigned position = 0; while (breakNode == node && breakOffset <= length) { if (breakOffset > position) { result.append(data.characters() + position, breakOffset - position); position = breakOffset; result.append(newlineCharacter); } getNextSoftBreak(line, breakNode, breakOffset); } result.append(data.characters() + position, length - position); } while (breakNode == node) getNextSoftBreak(line, breakNode, breakOffset); } return finishText(result); }
PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const { if (!renderer() || !isTextFormControl()) return nullptr; int start = m_cachedSelectionStart; int end = m_cachedSelectionEnd; ASSERT(start <= end); HTMLElement* innerText = innerTextElement(); if (!innerText) return nullptr; if (!innerText->firstChild()) return Range::create(document(), innerText, 0, innerText, 0); int offset = 0; Node* startNode = 0; Node* endNode = 0; for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(*node, innerText)) { ASSERT(!node->firstChild()); ASSERT(node->isTextNode() || isHTMLBRElement(*node)); int length = node->isTextNode() ? lastOffsetInNode(node) : 1; if (offset <= start && start <= offset + length) setContainerAndOffsetForRange(node, start - offset, startNode, start); if (offset <= end && end <= offset + length) { setContainerAndOffsetForRange(node, end - offset, endNode, end); break; } offset += length; } if (!startNode || !endNode) return nullptr; return Range::create(document(), startNode, start, endNode, end); }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction) { document().updateLayoutIgnorePendingStylesheets(); if (!renderer() || !renderer()->isTextControl()) return; end = std::max(end, 0); start = std::min(std::max(start, 0), end); if (!hasVisibleTextArea(*renderer(), innerTextElement())) { cacheSelection(start, end, direction); return; } VisiblePosition startPosition = visiblePositionForIndex(start); VisiblePosition endPosition; if (start == end) endPosition = startPosition; else endPosition = visiblePositionForIndex(end); #if !PLATFORM(IOS) // startPosition and endPosition can be null position for example when // "-webkit-user-select: none" style attribute is specified. if (startPosition.isNotNull() && endPosition.isNotNull()) { ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == this); } #endif VisibleSelection newSelection; if (direction == SelectionHasBackwardDirection) newSelection = VisibleSelection(endPosition, startPosition); else newSelection = VisibleSelection(startPosition, endPosition); newSelection.setIsDirectional(direction != SelectionHasNoDirection); if (Frame* frame = document().frame()) frame->selection().setSelection(newSelection); }
unsigned HTMLTextFormControlElement::indexForPosition(const Position& passedPosition) const { TextControlInnerTextElement* innerText = innerTextElement(); if (!innerText || !innerText->contains(passedPosition.anchorNode()) || passedPosition.isNull()) return 0; if (positionBeforeNode(innerText) == passedPosition) return 0; unsigned index = 0; Node* startNode = passedPosition.computeNodeBeforePosition(); if (!startNode) startNode = passedPosition.containerNode(); ASSERT(startNode); ASSERT(innerText->contains(startNode)); for (Node* node = startNode; node; node = NodeTraversal::previous(*node, innerText)) { if (is<Text>(*node)) { unsigned length = downcast<Text>(*node).length(); if (node == passedPosition.containerNode()) index += std::min<unsigned>(length, passedPosition.offsetInContainerNode()); else index += length; } else if (is<HTMLBRElement>(*node)) ++index; } unsigned length = innerTextValue().length(); index = std::min(index, length); // FIXME: We shouldn't have to call innerTextValue() just to ignore the last LF. See finishText. #ifndef ASSERT_DISABLED VisiblePosition visiblePosition = passedPosition; unsigned indexComputedByVisiblePosition = 0; if (visiblePosition.isNotNull()) indexComputedByVisiblePosition = WebCore::indexForVisiblePosition(innerText, visiblePosition, false /* forSelectionPreservation */); ASSERT(index == indexComputedByVisiblePosition); #endif return index; }
void RenderTextControl::computePreferredLogicalWidths() { ASSERT(preferredLogicalWidthsDirty()); m_minPreferredLogicalWidth = 0; m_maxPreferredLogicalWidth = 0; if (style()->width().isFixed() && style()->width().value() >= 0) m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style()->width().value()); else { // Use average character width. Matches IE. AtomicString family = style()->font().family().family(); m_maxPreferredLogicalWidth = preferredContentWidth(getAvgCharWidth(family)); if (RenderBox* innerTextRenderBox = innerTextElement()->renderBox()) m_maxPreferredLogicalWidth += innerTextRenderBox->paddingLeft() + innerTextRenderBox->paddingRight(); if (!style()->width().isPercent()) m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth; } if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) { m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value())); m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value())); } if (style()->maxWidth().isFixed()) { m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value())); m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value())); } LayoutUnit toAdd = borderAndPaddingWidth(); m_minPreferredLogicalWidth += toAdd; m_maxPreferredLogicalWidth += toAdd; setPreferredLogicalWidthsDirty(false); }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction) { if (!isTextFormControl()) return; end = std::max(end, 0); start = std::min(std::max(start, 0), end); TextControlInnerTextElement* innerText = innerTextElement(); bool hasFocus = document().focusedElement() == this; if (!hasFocus && innerText) { // FIXME: Removing this synchronous layout requires fixing <https://webkit.org/b/128797> document().updateLayoutIgnorePendingStylesheets(); if (RenderElement* rendererTextControl = renderer()) { if (rendererTextControl->style().visibility() == HIDDEN || !innerText->renderBox()->height()) { cacheSelection(start, end, direction); return; } } } Position startPosition = positionForIndex(innerText, start); Position endPosition; if (start == end) endPosition = startPosition; else { if (direction == SelectionHasBackwardDirection) { endPosition = startPosition; startPosition = positionForIndex(innerText, end); } else endPosition = positionForIndex(innerText, end); } if (Frame* frame = document().frame()) frame->selection().moveWithoutValidationTo(startPosition, endPosition, direction != SelectionHasNoDirection, !hasFocus); }
bool RenderTextControl::canScroll() const { Element* innerText = innerTextElement(); return innerText && innerText->renderer() && innerText->renderer()->hasOverflowClip(); }
void RenderTextControl::updateFromElement() { Element* innerText = innerTextElement(); if (innerText) updateUserModifyProperty(node(), innerText->renderer()->style()); }
int RenderTextControl::textBlockWidth() const { Element* innerText = innerTextElement(); ASSERT(innerText); return width() - borderAndPaddingWidth() - innerText->renderBox()->paddingLeft() - innerText->renderBox()->paddingRight(); }
void HTMLTextFormControlElement::forwardEvent(Event* event) { if (event->type() == eventNames().blurEvent || event->type() == eventNames().focusEvent) return; innerTextElement()->defaultEventHandler(event); }
void HTMLTextFormControlElement::updateInnerTextElementEditability() { if (TextControlInnerTextElement* innerText = innerTextElement()) innerText->setAttribute(contenteditableAttr, isDisabledOrReadOnly() ? "false" : "plaintext-only"); }
void HTMLTextFormControlElement::forwardEvent(Event* event) { if (event->type() == EventTypeNames::blur || event->type() == EventTypeNames::focus) return; innerTextElement()->defaultEventHandler(event); }
String HTMLTextFormControlElement::innerTextValue() const { TextControlInnerTextElement* innerText = innerTextElement(); return innerText ? innerTextValueFrom(*innerText) : emptyString(); }
void HTMLTextAreaElement::attach() { HTMLTextFormControlElement::attach(); fixPlaceholderRenderer(m_placeholder, innerTextElement()); }