void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFragment> fragment, ExceptionState& exceptionState) { ASSERT(container); RefPtr<ContainerNode> containerNode(container); ChildListMutationScope mutation(*containerNode); if (!fragment->firstChild()) { containerNode->removeChildren(); return; } // FIXME: This is wrong if containerNode->firstChild() has more than one ref! if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) { toText(containerNode->firstChild())->setData(toText(fragment->firstChild())->data()); return; } // FIXME: No need to replace the child it is a text node and its contents are already == text. if (containerNode->hasOneChild()) { containerNode->replaceChild(fragment, containerNode->firstChild(), exceptionState); return; } containerNode->removeChildren(); containerNode->appendChild(fragment, exceptionState); }
// Neighbor-anchored positions are invalid DOM positions, so they need to be // fixed up before handing them off to the Range object. Position Position::parentAnchoredEquivalent() const { if (!m_anchorNode) return Position(); // FIXME: This should only be necessary for legacy positions, but is also needed for positions before and after Tables if (m_offset <= 0 && m_anchorType != PositionIsAfterAnchor) { if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get()))) return positionInParentBeforeNode(m_anchorNode.get()); return firstPositionInOrBeforeNode(m_anchorNode.get()); } if (!m_anchorNode->offsetInCharacters() && (m_anchorType == PositionIsAfterAnchor || static_cast<unsigned>(m_offset) == m_anchorNode->childNodeCount()) && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get())) && containerNode()) { return positionInParentAfterNode(m_anchorNode.get()); } return Position(containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor); }
void replaceChildrenWithText(ContainerNode* container, const String& text, ExceptionState& exceptionState) { DCHECK(container); ContainerNode* containerNode(container); ChildListMutationScope mutation(*containerNode); // FIXME: This is wrong if containerNode->firstChild() has more than one ref! // Example: // <div>foo</div> // <script> // var oldText = div.firstChild; // console.log(oldText.data); // foo // div.innerText = "bar"; // console.log(oldText.data); // bar!?! // </script> // I believe this is an intentional benchmark cheat from years ago. // We should re-visit if we actually want this still. if (containerNode->hasOneTextChild()) { toText(containerNode->firstChild())->setData(text); return; } // NOTE: This method currently always creates a text node, even if that text // node will be empty. Text* textNode = Text::create(containerNode->document(), text); // FIXME: No need to replace the child it is a text node and its contents are // already == text. if (containerNode->hasOneChild()) { containerNode->replaceChild(textNode, containerNode->firstChild(), exceptionState); return; } containerNode->removeChildren(); containerNode->appendChild(textNode, exceptionState); }
void replaceChildrenWithFragment(ContainerNode* container, DocumentFragment* fragment, ExceptionState& exceptionState) { DCHECK(container); ContainerNode* containerNode(container); ChildListMutationScope mutation(*containerNode); if (!fragment->firstChild()) { containerNode->removeChildren(); return; } // FIXME: No need to replace the child it is a text node and its contents are // already == text. if (containerNode->hasOneChild()) { containerNode->replaceChild(fragment, containerNode->firstChild(), exceptionState); return; } containerNode->removeChildren(); containerNode->appendChild(fragment, exceptionState); }