[lasem] dom_node: implement replace and insert_before.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] dom_node: implement replace and insert_before.
- Date: Sun, 14 Nov 2010 17:14:11 +0000 (UTC)
commit 46d63833886bba5d563a5cd012b7277bfef6d9d4
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Nov 14 18:12:55 2010 +0100
dom_node: implement replace and insert_before.
src/lsmdomnode.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 49 insertions(+), 5 deletions(-)
---
diff --git a/src/lsmdomnode.c b/src/lsmdomnode.c
index 8891ab3..cc4101b 100644
--- a/src/lsmdomnode.c
+++ b/src/lsmdomnode.c
@@ -173,17 +173,60 @@ lsm_dom_node_get_owner_document (LsmDomNode* self)
LsmDomNode*
lsm_dom_node_insert_before (LsmDomNode* self, LsmDomNode* new_child, LsmDomNode* ref_child)
{
- g_warning ("Not yet implemented");
+ LsmDomNodeClass *node_class;
- return NULL;
+ g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
+ g_return_val_if_fail (LSM_IS_DOM_NODE (new_child), NULL);
+ g_return_val_if_fail (LSM_IS_DOM_NODE (ref_child), NULL);
+
+ if (ref_child->parent_node != self)
+ return NULL;
+
+ if (!LSM_DOM_NODE_GET_CLASS (self)->can_append_child (self, new_child)) {
+ lsm_debug ("dom", "[LsmDomNode::insert_before] Can't append '%s' to '%s'",
+ lsm_dom_node_get_node_name (new_child),
+ lsm_dom_node_get_node_name (self));
+ return NULL;
+ }
+
+ new_child->parent_node = self;
+ new_child->next_sibling = ref_child;
+ new_child->previous_sibling = ref_child->previous_sibling;
+
+ if (ref_child->previous_sibling == NULL)
+ self->first_child = new_child;
+ else
+ ref_child->previous_sibling->next_sibling = new_child;
+
+ node_class = LSM_DOM_NODE_GET_CLASS (self);
+
+ if (node_class->post_new_child)
+ node_class->post_new_child (self, new_child);
+
+ lsm_dom_node_changed (self);
+
+ return new_child;
}
LsmDomNode*
lsm_dom_node_replace_child (LsmDomNode* self, LsmDomNode* new_child, LsmDomNode* old_child)
{
- g_warning ("Not yet implemented");
+ LsmDomNode *next_sibling;
- return NULL;
+ g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
+ g_return_val_if_fail (LSM_IS_DOM_NODE (old_child), NULL);
+
+ if (old_child->parent_node != self)
+ return NULL;
+
+ next_sibling = old_child->next_sibling;
+
+ lsm_dom_node_remove_child (self, old_child);
+
+ if (next_sibling == NULL)
+ return lsm_dom_node_append_child (self, new_child);
+ else
+ return lsm_dom_node_insert_before (self, new_child, next_sibling);
}
LsmDomNode*
@@ -199,7 +242,8 @@ lsm_dom_node_remove_child (LsmDomNode* self, LsmDomNode* old_child)
node != NULL && node != old_child;
node = node->next_sibling);
- g_return_val_if_fail (node != NULL, NULL);
+ if (node == NULL)
+ return NULL;
node_class = LSM_DOM_NODE_GET_CLASS (self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]