[gxml] * figured out a way to upwards notify ancestors with tag-name node-lists on the addition and removal
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] * figured out a way to upwards notify ancestors with tag-name node-lists on the addition and removal
- Date: Fri, 29 Jul 2011 02:13:22 +0000 (UTC)
commit 9cf58a9fdd04823833a91e199e12d7bbc8c598e9
Author: Richard Schwarting <aquarichy gmail com>
Date: Thu Jul 28 15:37:02 2011 -0400
* figured out a way to upwards notify ancestors with tag-name node-lists on the addition and removal of relevant elements.
gxml/Element.vala | 49 +++++++++++++++++++++++++++----------------------
1 files changed, 27 insertions(+), 22 deletions(-)
---
diff --git a/gxml/Element.vala b/gxml/Element.vala
index 05212cb..feec04a 100644
--- a/gxml/Element.vala
+++ b/gxml/Element.vala
@@ -193,47 +193,52 @@ namespace GXml.Dom {
}
/*** XNode methods ***/
- private void check_add_tag_name (XNode child) {
- switch (child.node_type) {
- case NodeType.ELEMENT:
- on_new_descendant_with_tag_name ((Element)child);
- break;
- /* TODO: add DocumentFragment support */
- default:
- /* does not contain elements */
- break;
+ private void check_add_tag_name (Element basenode, XNode child) {
+ // TODO: make sure there aren't any other NodeTypes that could have elements as children
+ if (child.node_type == NodeType.ELEMENT || child.node_type == NodeType.DOCUMENT_FRAGMENT) {
+ // the one we're examining is an element, and might need to be added
+ if (child.node_type == NodeType.ELEMENT) {
+ basenode.on_new_descendant_with_tag_name ((Element)child);
+ }
+
+ // if we're adding an element with descendants, or a document fragment, they might contain nodes that should go into a tag name node list for an ancestor node
+ foreach (XNode grand_child in child.child_nodes) {
+ check_add_tag_name (basenode, grand_child);
+ }
}
}
- private void check_remove_tag_name (XNode child) {
- switch (child.node_type) {
- case NodeType.ELEMENT:
- on_remove_descendant_with_tag_name ((Element)child);
- break;
- /* TODO: add DocumentFragment support */
- default:
- break;
+ private void check_remove_tag_name (Element basenode, XNode child) {
+ // TODO: make sure there aren't any other NodeTypes that could have elements as children
+ if (child.node_type == NodeType.ELEMENT) {
+ // the one we're examining is an element, and might need to be removed from a tag name node list
+ basenode.on_remove_descendant_with_tag_name ((Element)child);
+
+ // if we're removing an element with descendants, it might contain nodes that should also be removed from a tag name node list for an ancestor node
+ foreach (XNode grand_child in child.child_nodes) {
+ check_remove_tag_name (basenode, grand_child);
+ }
}
}
public override XNode? insert_before (XNode new_child, XNode? ref_child) throws DomError {
XNode ret = base.insert_before (new_child, ref_child);
- check_add_tag_name (new_child);
+ check_add_tag_name (this, new_child);
return ret;
}
public override XNode? replace_child (XNode new_child, XNode old_child) throws DomError {
XNode ret = base.replace_child (new_child, old_child);
- check_add_tag_name (new_child);
- check_remove_tag_name (old_child);
+ check_remove_tag_name (this, old_child); // removal should probably precede addition, in case we're moving something around
+ check_add_tag_name (this, new_child);
return ret;
}
public override XNode? remove_child (XNode old_child) throws DomError {
XNode ret = base.remove_child (old_child);
- check_remove_tag_name (old_child);
+ check_remove_tag_name (this, old_child);
return ret;
}
public override XNode? append_child (XNode new_child) throws DomError {
XNode ret = base.append_child (new_child);
- check_add_tag_name (new_child);
+ check_add_tag_name (this, new_child);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]