r7755 struggleyb - in /branches/struggleyb/libdom-remain/src/core: node.c node.h

netsurf at semichrome.net netsurf at semichrome.net
Thu Jun 11 15:21:16 BST 2009


Author: struggleyb
Date: Thu Jun 11 09:21:15 2009
New Revision: 7755

URL: http://source.netsurf-browser.org?rev=7755&view=rev
Log:
Complete _dom_node_redocument and _dom_node_copy. 

Modified:
    branches/struggleyb/libdom-remain/src/core/node.c
    branches/struggleyb/libdom-remain/src/core/node.h

Modified: branches/struggleyb/libdom-remain/src/core/node.c
URL: http://source.netsurf-browser.org/branches/struggleyb/libdom-remain/src/core/node.c?rev=7755&r1=7754&r2=7755&view=diff
==============================================================================
--- branches/struggleyb/libdom-remain/src/core/node.c (original)
+++ branches/struggleyb/libdom-remain/src/core/node.c Thu Jun 11 09:21:15 2009
@@ -1772,7 +1772,44 @@
 dom_exception _dom_node_redocument(struct dom_document *doc, 
 		struct dom_node_internal *n)
 {
-	// TODO
+	dom_document *olddoc;
+	lwc_context *oldctx, *ctx;
+	lwc_string *str;
+	dom_exception err;
+	lwc_err lerr;
+
+	olddoc = n->owner;
+	assert(olddoc != NULL);
+
+	oldctx = dom_document_get_intern_context(olddoc);
+	ctx = dom_document_get_intern_context(doc);
+
+	assert(oldctx != NULL);
+	assert(ctx != NULL);
+
+	if (oldctx != ctx) {
+		err = _redocument_lwcstring(oldctx, ctx, &n->name);
+		if (err != DOM_NO_ERR)
+			return err;
+
+		err = _redocument_lwcstring(oldctx, ctx, &n->namespace);
+		if (err != DOM_NO_ERR)
+			return err;
+
+		err = _redocument_lwcstring(oldctx, ctx, &n->prefix);
+		if (err != DOM_NO_ERR)
+			return err;
+
+	}
+
+	/* Redocument dom_string */
+	err = _redocument_domstring(olddoc, doc, &n->value);
+	if (err != DOM_NO_ERR)
+		return err;
+
+	n->owner = doc;
+
+	return DOM_NO_ERR;
 }
 
 /* 
@@ -1780,7 +1817,39 @@
  */
 dom_exception _dom_node_copy(dom_node_internal *new, dom_node_internal *old)
 {
-	// TODO
+	dom_node *node = (dom_node *) new;
+	lwc_context *ctx;
+
+	new->vtable = (dom_node *) old->vtable;
+
+	assert(old->owner != NULL);
+	ctx = dom_document_get_intern_context(old->owner);
+	assert(ctx != NULL);
+
+	lwc_context_string_ref(ctx, old->name);
+	new->name = old->name;
+
+	dom_string_ref(old->value);
+	new->value = old->value;
+
+	new->type = old->type;
+	new->paretnt = NULL;
+	new->first_child = NULL;
+	new->last_child = NULL;
+	new->previous = NULL;
+	new->next = NULL;
+	new->owner = old->owner;
+
+	lwc_context_string_ref(ctx, old->namespace);
+	new->namespace = old->namespace;
+
+	lwc_context_string_ref(ctx, old->prefix);
+	new->prefix = old->prefix;
+
+	new->user_data = NULL;
+	new->refcnt = 1;
+
+	return DOM_NO_ERR;
 }
 
 /*                                                                            */
@@ -2019,3 +2088,41 @@
 	old->previous = old->next = old->parent = NULL;
 }
 
+dom_exception _redocument_lwcstring(lwc_context *old, lwc_context *new, 
+		lwc_string **string)
+{
+	lwc_string *str;
+	dom_exception err;
+	lwc_error lerr;
+
+	lerr = lwc_context_intern(new, lwc_string_data(*string),
+			lwc_string_length(*string), &str);
+	if (lerr != lwc_error_ok)
+		return lwc_error_to_exception(lerr);
+
+	lwc_context_string_unref(oldctx, *string);
+	*string = str;
+
+	return DOM_NO_ERR;
+}
+
+dom_exception _redocument_domstring(dom_document *old, dom_document* new,
+		dom_string **string)
+{
+	dom_exception err;
+	dom_string *str;
+
+	err = dom_document_create_string(new, "", 0, &str);
+	if (err != DOM_NO_ERR)
+		return err;
+	
+	err = dom_string_dup(*string, &str);
+	if (err != DOM_NO_ERR)
+		return err;
+	
+	dom_string_unref(*string);
+	*string = str;
+
+	return DOM_NO_ERR;
+}
+

Modified: branches/struggleyb/libdom-remain/src/core/node.h
URL: http://source.netsurf-browser.org/branches/struggleyb/libdom-remain/src/core/node.h?rev=7755&r1=7754&r2=7755&view=diff
==============================================================================
--- branches/struggleyb/libdom-remain/src/core/node.h (original)
+++ branches/struggleyb/libdom-remain/src/core/node.h Thu Jun 11 09:21:15 2009
@@ -206,8 +206,10 @@
 
 /* Follwoing comes the protected vtable */
 void _dom_node_destroy(struct dom_node_internal *node);
-dom_exception _dom_node_copy(struct dom_node_internal *n, 
+dom_exception _dom_node_alloc(struct dom_node_internal *n, 
 		struct dom_node_internal **ret);
+dom_exception _dom_node_copy(struct dom_node_internal *new, 
+		struct dom_node_internal *old);
 dom_exception _dom_node_redocument(struct dom_document *doc, 
 		struct dom_node_internal *n);
 
@@ -253,4 +255,10 @@
 }
 #define dom_node_copy(s,r) dom_node_copy((dom_node_internal *) (new), \
 		(dom_node_internal *) (old))
+
+/* Following are some helper functions */
+dom_exception _redocument_lwcstring(lwc_context *old, lwc_context *new, 
+		lwc_string **string);
+dom_exception _redocument_domstring(dom_document *old, dom_document* new,
+		dom_string **string);
 #endif




More information about the netsurf-commits mailing list