Chromium Code Reviews| Index: sky/engine/core/dom/Node.cpp |
| diff --git a/sky/engine/core/dom/Node.cpp b/sky/engine/core/dom/Node.cpp |
| index 6ff1d2c4ee935c46e4b4327b91585d8c90026f4b..fa6330ce55dbbe01f610cd41665748ebd53becda 100644 |
| --- a/sky/engine/core/dom/Node.cpp |
| +++ b/sky/engine/core/dom/Node.cpp |
| @@ -379,6 +379,61 @@ PassRefPtr<Node> Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& ex |
| return nullptr; |
| } |
| +Element* Node::previousElementSibling() |
| +{ |
| + return ElementTraversal::previousSibling(*this); |
| +} |
| + |
| +Element* Node::nextElementSibling() |
| +{ |
| + return ElementTraversal::nextSibling(*this); |
| +} |
| + |
| +void Node::newInsertBefore(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| +{ |
| + RefPtr<Node> protect(this); |
| + for (auto& node : nodes) { |
| + ContainerNode* parent = parentNode(); |
| + if (!parent) |
| + return; |
| + parent->insertBefore(node.release(), this, es); |
| + if (es.had_exception()) |
| + return; |
| + } |
| +} |
| + |
| +void Node::newInsertAfter(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| +{ |
| + RefPtr<Node> protect(this); |
| + ScriptForbiddenScope scope; |
| + Node* refNode = this; |
| + for (auto& node : nodes) { |
| + ContainerNode* parent = refNode->parentNode(); |
|
esprehn
2015/02/14 01:50:08
You don't need to keep checking parent node like t
|
| + if (!parent) |
| + return; |
| + Node* nextRefNode = node.get() |
| + parent->insertBefore(node.release(), refNode, es); |
| + if (es.had_exception()) |
| + return; |
| + refNode = nextRefNode; |
| + } |
| +} |
| + |
| +void Node::replaceWith(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| +{ |
| + if (RefPtr<Node> next = m_next) { |
| + remove(es); |
| + if (es.had_exception()) |
| + return; |
| + next->newInsertBefore(nodes, es); |
| + } else if (RefPtr<ContainerNode> parent = parentNode()) { |
| + remove(es); |
| + if (es.had_exception()) |
| + return; |
| + parent->append(nodes, es); |
| + } |
|
esprehn
2015/02/14 01:50:08
RefPtr<Node> parent = this->parent();
RefPtr<Node>
esprehn
2015/02/14 01:51:06
Sorry that's parent->insertBefore(this, next);
abarth-chromium
2015/02/14 02:30:53
We're trying to insert |nodes|, not |this|. Also,
esprehn
2015/02/14 02:37:43
Why not a loop then?
RefPtr<Node> parent = this->
|
| +} |
| + |
| void Node::remove(ExceptionState& exceptionState) |
| { |
| if (ContainerNode* parent = parentNode()) |
| @@ -862,7 +917,7 @@ Document* Node::ownerDocument() const |
| return doc == this ? 0 : doc; |
| } |
| -ContainerNode* Node::ownerScope() const |
| +ContainerNode* Node::owner() const |
| { |
| if (inDocument()) |
| return &treeScope().rootNode(); |