void RenderTreeUpdater::updateRenderTree(ContainerNode& root) { ASSERT(root.renderer()); ASSERT(m_parentStack.isEmpty()); m_parentStack.append(Parent(root)); auto descendants = composedTreeDescendants(root); auto it = descendants.begin(); auto end = descendants.end(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=156172 it.dropAssertions(); while (it != end) { popParentsToDepth(it.depth()); auto& node = *it; if (auto* renderer = node.renderer()) renderTreePosition().invalidateNextSibling(*renderer); if (is<Text>(node)) { auto& text = downcast<Text>(node); if (parent().styleChange == Style::Detach || m_styleUpdate->textUpdate(text) || m_invalidatedWhitespaceOnlyTextSiblings.contains(&text)) updateTextRenderer(text); it.traverseNextSkippingChildren(); continue; } auto& element = downcast<Element>(node); auto* elementUpdate = m_styleUpdate->elementUpdate(element); if (!elementUpdate) { it.traverseNextSkippingChildren(); continue; } updateElementRenderer(element, *elementUpdate); bool mayHaveRenderedDescendants = element.renderer() || (element.hasDisplayContents() && shouldCreateRenderer(element, renderTreePosition().parent())); if (!mayHaveRenderedDescendants) { it.traverseNextSkippingChildren(); continue; } pushParent(element, elementUpdate ? elementUpdate->change : Style::NoChange); it.traverseNext(); } popParentsToDepth(0); m_invalidatedWhitespaceOnlyTextSiblings.clear(); }
PassRefPtr<Node> Text::mergeNextSiblingNodesIfPossible() { RefPtr<Node> protect(this); // Remove empty text nodes. if (!length()) { // Care must be taken to get the next node before removing the current node. RefPtr<Node> nextNode(NodeTraversal::nextPostOrder(*this)); remove(IGNORE_EXCEPTION); return nextNode.release(); } // Merge text nodes. while (Node* nextSibling = this->nextSibling()) { if (nextSibling->nodeType() != TEXT_NODE) break; RefPtr<Text> nextText = toText(nextSibling); // Remove empty text nodes. if (!nextText->length()) { nextText->remove(IGNORE_EXCEPTION); continue; } // Both non-empty text nodes. Merge them. unsigned offset = length(); String nextTextData = nextText->data(); String oldTextData = data(); setDataWithoutUpdate(data() + nextTextData); updateTextRenderer(oldTextData.length(), 0); // Empty nextText for layout update. nextText->setDataWithoutUpdate(emptyString()); nextText->updateTextRenderer(0, nextTextData.length()); document().didMergeTextNodes(nextText.get(), offset); // Restore nextText for mutation event. nextText->setDataWithoutUpdate(nextTextData); nextText->updateTextRenderer(0, 0); document().incDOMTreeVersion(); didModifyData(oldTextData); nextText->remove(IGNORE_EXCEPTION); } return NodeTraversal::nextPostOrder(*this); }