Chromium Code Reviews| Index: Source/core/dom/Node.cpp |
| diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp |
| index 348b452eecd06e3d5a7daeed1fac437ea13389b9..4099ca3ff36619815895f67ec9d1966f5cda133c 100644 |
| --- a/Source/core/dom/Node.cpp |
| +++ b/Source/core/dom/Node.cpp |
| @@ -381,6 +381,33 @@ void Node::clearRareData() |
| } |
| #endif |
| +PassRefPtr<Node> Node::mutationMethodMacro(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
|
philipj_slow
2015/04/29 13:16:57
If I'm not mistaken, this should be PassRefPtrWill
Paritosh Kumar
2015/06/08 12:21:24
Yes, This will be PassRefPtrWillBeRawPtr<Node> and
|
| +{ |
| + RefPtr<Node> node; |
| + if (nodes.size() == 1) { |
| + if (nodes[0].isNode()) |
| + node = nodes[0].getAsNode(); |
| + else if (nodes[0].isString()) |
| + node = Text::create(document(), nodes[0].getAsString()); |
| + else |
| + return nullptr; |
|
philipj_slow
2015/04/29 13:16:57
This case should be unreachable.
Paritosh Kumar
2015/06/08 12:21:24
Yes, Removing it.
|
| + } else { |
| + node = DocumentFragment::create(document()); |
|
philipj_slow
2015/04/29 13:16:57
This is what the spec says, but implementing it li
Paritosh Kumar
2015/06/08 12:21:24
I looked into this and found that we may use colle
|
| + for (size_t i = 0; i < nodes.size(); ++i) { |
|
philipj_slow
2015/04/29 13:16:57
Will a range-based for loop work here? for (NodeOr
Paritosh Kumar
2015/06/08 12:21:24
Yes, Done.
|
| + if (nodes[i].isNode()) |
| + node->appendChild(nodes[i].getAsNode(), exceptionState); |
| + else |
| + node->appendChild(Text::create(document(), nodes[i].getAsString()), exceptionState); |
| + if (exceptionState.hadException()) { |
| + exceptionState.throwIfNeeded(); |
|
philipj_slow
2015/04/29 13:16:57
This looks unusual, why throwIfNeeded() here? If w
Paritosh Kumar
2015/06/08 12:21:24
Done.
|
| + return nullptr; |
| + } |
| + } |
| + } |
| + return node.release(); |
| +} |
| + |
|
philipj_slow
2015/04/29 13:16:57
There's an extra blank line here.
Paritosh Kumar
2015/06/08 12:21:24
Done.
|
| + |
| Node* Node::toNode() |
| { |
| return this; |
| @@ -500,6 +527,45 @@ PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC |
| return nullptr; |
| } |
| +void Node::prepend(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + RefPtr<Node> nodeToPrepend = mutationMethodMacro(nodes, exceptionState); |
|
philipj_slow
2015/04/29 13:16:57
All of these will also need to use the Oilpan tran
Paritosh Kumar
2015/06/08 12:21:24
Done.
|
| + this->insertBefore(nodeToPrepend, this->firstChild(), exceptionState); |
|
philipj_slow
2015/04/29 13:16:57
In the spec none of these are expressed in terms o
|
| +} |
| + |
| +void Node::append(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + RefPtr<Node> nodeToAppend = mutationMethodMacro(nodes, exceptionState); |
| + this->appendChild(nodeToAppend, exceptionState); |
| +} |
| + |
| +void Node::before(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtr<Node> nodeToInsert = mutationMethodMacro(nodes, exceptionState); |
| + parent->insertBefore(nodeToInsert, this, exceptionState); |
| +} |
| + |
| +void Node::after(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtr<Node> nodeToInsert = mutationMethodMacro(nodes, exceptionState); |
| + parent->insertBefore(nodeToInsert, this->nextSibling(), exceptionState); |
| +} |
| + |
| +void Node::replaceWith(const Vector<NodeOrString>& nodes, ExceptionState& exceptionState) |
| +{ |
| + Node* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + RefPtr<Node> nodeToReplaceWith = mutationMethodMacro(nodes, exceptionState); |
| + parent->replaceChild(nodeToReplaceWith, this, exceptionState); |
| +} |
| + |
| void Node::remove(ExceptionState& exceptionState) |
| { |
| if (ContainerNode* parent = parentNode()) |