Created
February 14, 2015 02:08
-
-
Save abarth/6bf8ec62a723f7168dfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sky/engine/core/dom/ContainerNode.cpp b/sky/engine/core/dom/ContainerNode.cpp | |
index 97f3708..add9acc 100644 | |
--- a/sky/engine/core/dom/ContainerNode.cpp | |
+++ b/sky/engine/core/dom/ContainerNode.cpp | |
@@ -921,6 +921,60 @@ PassRefPtr<Node> ContainerNode::prependChild(PassRefPtr<Node> node, ExceptionSta | |
return insertBefore(node, m_firstChild, es); | |
} | |
+void ContainerNode::appendSubtree(Vector<int> commands, Vector<String> data) | |
+{ | |
+ RefPtr<ContainerNode> protect(this); | |
+ | |
+ Vector<RefPtr<Node>, 10> parents; | |
+ parents.append(this); | |
+ RefPtr<Node> currentNode; | |
+ Vector<Attribute> currentAttributes; | |
+ | |
+ auto dataIterator = data.begin(); | |
+ | |
+ int minCommand = 0; | |
+ for (int command : commands) { | |
+ if (command < minCommand) | |
+ return; | |
+ switch(command) { | |
+ case 0: | |
+ if (dataIterator == data.end()) | |
+ return; | |
+ currentNode = document().createElement(*dataIterator++); | |
+ minCommand = 1; | |
+ break; | |
+ case 1: | |
+ if (dataIterator == data.end()) | |
+ return; | |
+ String name = *dataIterator++; | |
+ if (dataIterator == data.end()) | |
+ return; | |
+ String value = *dataIterator++; | |
+ currentAttributes.append(QualifiedName(name), value); | |
+ break; | |
+ case 2: | |
+ currentNode->parserSetAttributes(currentAttributes); | |
+ minCommand = 3; | |
+ break; | |
+ case 3: | |
+ currentAttributes.resize(0); | |
+ parents.last()->parserAppendChild(currentNode); | |
+ parents.append(currentNode); | |
+ minCommand = 0; | |
+ break; | |
+ case 4: | |
+ currentAttributes.resize(0); | |
+ parents.removeLast(); | |
+ if (parents.isEmpty()) | |
+ return; | |
+ minCommand = 0; | |
+ break; | |
+ default: | |
+ return; | |
+ } | |
+ } | |
+} | |
+ | |
PassRefPtr<Node> ContainerNode::setChild(PassRefPtr<Node> node, ExceptionState& es) | |
{ | |
RefPtr<ContainerNode> protect(this); | |
diff --git a/sky/engine/core/dom/ContainerNode.h b/sky/engine/core/dom/ContainerNode.h | |
index bc9108d..fdc9ba0 100644 | |
--- a/sky/engine/core/dom/ContainerNode.h | |
+++ b/sky/engine/core/dom/ContainerNode.h | |
@@ -62,6 +62,8 @@ public: | |
void prepend(Vector<RefPtr<Node>>& nodes, ExceptionState&); | |
PassRefPtr<Node> prependChild(PassRefPtr<Node> node, ExceptionState&); | |
+ void appendSubtree(Vector<int> commands, Vector<String> data); | |
+ | |
void removeChildren(); | |
PassRefPtr<Node> setChild(PassRefPtr<Node> node, ExceptionState&); | |
void setChildren(Vector<RefPtr<Node>>& nodes, ExceptionState&); | |
diff --git a/sky/engine/core/dom/ParentNode.idl b/sky/engine/core/dom/ParentNode.idl | |
index 519ca50..d8b0573 100644 | |
--- a/sky/engine/core/dom/ParentNode.idl | |
+++ b/sky/engine/core/dom/ParentNode.idl | |
@@ -18,6 +18,8 @@ | |
[RaisesException] void prepend(sequence<Node> nodes); | |
[RaisesException] Node prependChild(Node nodes); | |
+ void appendSubtree(sequence<int> commands, sequence<DOMString> data); | |
+ | |
void removeChildren(); | |
[RaisesException] Node setChild(Node node); | |
[RaisesException] void setChildren(sequence<Node> nodes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment