Chromium Code Reviews| Index: Source/core/dom/Node.cpp |
| diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp |
| index 56fb995d78a7033954fdda8b5b547b0d8d05500c..8566ae4aad92281a04838fc2b0bb239308358ad9 100644 |
| --- a/Source/core/dom/Node.cpp |
| +++ b/Source/core/dom/Node.cpp |
| @@ -382,6 +382,26 @@ void Node::clearRareData() |
| } |
| #endif |
| +PassRefPtrWillBeRawPtr<Node> Node::convertNodesIntoNode(const HeapVector<NodeOrString>& nodes) |
| +{ |
| + RefPtrWillBeRawPtr<Node> node = nullptr; |
| + if (nodes.size() == 1) { |
| + if (nodes[0].isNode()) |
|
philipj_slow
2015/06/12 16:12:33
This text->node conversion is a separate step in t
Paritosh Kumar
2015/06/15 08:55:23
Yes.
|
| + node = nodes[0].getAsNode(); |
| + else |
| + node = Text::create(document(), nodes[0].getAsString()); |
| + } else { |
| + node = DocumentFragment::create(document()); |
| + for (const NodeOrString& nodeOrString : nodes) { |
| + if (nodeOrString.isNode()) |
| + node->appendChild(nodeOrString.getAsNode(), ASSERT_NO_EXCEPTION); |
| + else |
| + node->appendChild(Text::create(document(), nodeOrString.getAsString()), ASSERT_NO_EXCEPTION); |
| + } |
| + } |
| + return node.release(); |
| +} |
| + |
| Node* Node::toNode() |
| { |
| return this; |
| @@ -501,6 +521,45 @@ PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC |
| return nullptr; |
| } |
| +void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + RefPtrWillBeRawPtr<Node> nodeToPrepend = convertNodesIntoNode(nodes); |
| + this->insertBefore(nodeToPrepend, this->firstChild(), exceptionState); |
| +} |
| + |
| +void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + RefPtrWillBeRawPtr<Node> nodeToAppend = convertNodesIntoNode(nodes); |
| + this->appendChild(nodeToAppend, exceptionState); |
| +} |
| + |
| +void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = convertNodesIntoNode(nodes); |
| + parent->insertBefore(nodeToInsert, this, exceptionState); |
| +} |
| + |
| +void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = convertNodesIntoNode(nodes); |
| + parent->insertBefore(nodeToInsert, this->nextSibling(), exceptionState); |
| +} |
| + |
| +void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
|
philipj_slow
2015/06/12 16:12:33
This may change: https://github.com/whatwg/dom/iss
Paritosh Kumar
2015/06/15 08:55:23
Thanks for info. I'll also watch this.
|
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToReplaceWith = convertNodesIntoNode(nodes); |
| + parent->replaceChild(nodeToReplaceWith, this, exceptionState); |
| +} |
| + |
| void Node::remove(ExceptionState& exceptionState) |
| { |
| if (ContainerNode* parent = parentNode()) |