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..5dbb22b24756493c29a6191fa4cbccf96ce88e48 100644 |
| --- a/Source/core/dom/Node.cpp |
| +++ b/Source/core/dom/Node.cpp |
| @@ -382,6 +382,43 @@ void Node::clearRareData() |
| } |
| #endif |
| +PassRefPtrWillBeRawPtr<Node> Node::nodeOrStringToNode(const NodeOrString& nodeOrString) |
| +{ |
| + if (nodeOrString.isNode()) |
| + return nodeOrString.getAsNode(); |
| + return Text::create(document(), nodeOrString.getAsString()); |
| +} |
| + |
| +Node* Node::viablePreviosOrNextSibling(const HeapVector<NodeOrString>& nodes, bool next) |
|
philipj_slow
2015/06/25 13:13:23
The bool argument isn't great. I applied your patc
Paritosh Kumar
2015/06/26 13:14:05
Yes, It looks great. Thanks.
|
| +{ |
| + Node* node = next ? this->nextSibling() : this->previousSibling(); |
| + bool notFound; |
| + while (node) { |
| + notFound = true; |
| + for (NodeOrString nodeOrString : nodes) { |
| + if (nodeOrStringToNode(nodeOrString)->isSameNode(node)) { |
|
philipj_slow
2015/06/25 13:13:23
It's a waste to convert string to nodes here, inst
Paritosh Kumar
2015/06/26 13:14:06
Done.
|
| + notFound = false; |
| + break; |
| + } |
| + } |
| + if (notFound) |
| + return node; |
| + node = next ? node->nextSibling() : node->previousSibling(); |
| + } |
| + return nullptr; |
| +} |
| + |
| +PassRefPtrWillBeRawPtr<Node> Node::convertNodesIntoNode(const HeapVector<NodeOrString>& nodes) |
| +{ |
| + if (nodes.size() == 1) |
| + return nodeOrStringToNode(nodes[0]); |
| + |
| + RefPtrWillBeRawPtr<Node> node = DocumentFragment::create(document()); |
| + for (const NodeOrString& nodeOrString : nodes) |
| + node->appendChild(nodeOrStringToNode(nodeOrString), ASSERT_NO_EXCEPTION); |
| + return node.release(); |
| +} |
| + |
| Node* Node::toNode() |
| { |
| return this; |
| @@ -501,6 +538,54 @@ 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; |
| + Node* viablePreviousSibling = viablePreviosOrNextSibling(nodes, false /* Previous */); |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = convertNodesIntoNode(nodes); |
| + if (!viablePreviousSibling) |
| + parent->insertBefore(nodeToInsert, parent->firstChild(), exceptionState); |
| + else |
| + parent->insertBefore(nodeToInsert, viablePreviousSibling, exceptionState); |
| +} |
| + |
| +void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + Node* viableNextSibling = viablePreviosOrNextSibling(nodes, true /* Next */); |
| + RefPtrWillBeRawPtr<Node> nodeToInsert = convertNodesIntoNode(nodes); |
| + parent->insertBefore(nodeToInsert, viableNextSibling, exceptionState); |
| +} |
| + |
| +void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + Node* viableNextSibling = viablePreviosOrNextSibling(nodes, true /* Next */); |
|
philipj_slow
2015/06/25 13:13:23
Here viableNextSibling and nodeToReplaceWith can b
Paritosh Kumar
2015/06/26 13:14:06
Done.
|
| + RefPtrWillBeRawPtr<Node> nodeToReplaceWith = convertNodesIntoNode(nodes); |
| + if (parent == parentNode()) |
| + parent->replaceChild(nodeToReplaceWith, this, exceptionState); |
| + else |
| + parent->insertBefore(nodeToReplaceWith, viableNextSibling, exceptionState); |
| +} |
| + |
| void Node::remove(ExceptionState& exceptionState) |
| { |
| if (ContainerNode* parent = parentNode()) |