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..465b98c7f5f66e633693a02f86dd281f60d2e68f 100644 |
| --- a/Source/core/dom/Node.cpp |
| +++ b/Source/core/dom/Node.cpp |
| @@ -382,6 +382,26 @@ void Node::clearRareData() |
| } |
| #endif |
| +PassRefPtrWillBeRawPtr<Node> Node::mutationMethodMacro(const HeapVector<NodeOrString>& nodes) |
| +{ |
| + RefPtrWillBeRawPtr<Node> node; |
| + if (nodes.size() == 1) { |
|
philipj_slow
2015/06/09 12:48:32
If the bindings guarantees that nodes.size()!=0 he
Paritosh Kumar
2015/06/12 15:55:37
Updated as per new specs.
|
| + if (nodes[0].isNode()) |
| + 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 = mutationMethodMacro(nodes); |
| + this->insertBefore(nodeToPrepend, this->firstChild(), exceptionState); |
| +} |
| + |
| +void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + RefPtrWillBeRawPtr<Node> nodeToAppend = mutationMethodMacro(nodes); |
| + this->appendChild(nodeToAppend, exceptionState); |
| +} |
| + |
| +void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = mutationMethodMacro(nodes); |
| + parent->insertBefore(nodeToInsert, this, exceptionState); |
| +} |
| + |
| +void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = mutationMethodMacro(nodes); |
| + parent->insertBefore(nodeToInsert, this->nextSibling(), exceptionState); |
| +} |
| + |
| +void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtrWillBeRawPtr<Node> nodeToReplaceWith = mutationMethodMacro(nodes); |
| + parent->replaceChild(nodeToReplaceWith, this, exceptionState); |
| +} |
| + |
| void Node::remove(ExceptionState& exceptionState) |
| { |
| if (ContainerNode* parent = parentNode()) |