Author: struggleyb
Date: Sat Aug 29 08:20:40 2009
New Revision: 9494
URL:
http://source.netsurf-browser.org?rev=9494&view=rev
Log:
1. Form association related methods;
2. Add dom_html_form_element.
Modified:
branches/struggleyb/libdom-html/include/dom/html/html_form_element.h
branches/struggleyb/libdom-html/src/html/html_element.c
branches/struggleyb/libdom-html/src/html/html_element.h
branches/struggleyb/libdom-html/src/html/html_form_element.c
branches/struggleyb/libdom-html/src/html/html_form_element.h
branches/struggleyb/libdom-html/src/html/html_isindex_element.c
branches/struggleyb/libdom-html/src/html/html_isindex_element.h
Modified: branches/struggleyb/libdom-html/include/dom/html/html_form_element.h
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/include...
==============================================================================
--- branches/struggleyb/libdom-html/include/dom/html/html_form_element.h (original)
+++ branches/struggleyb/libdom-html/include/dom/html/html_form_element.h Sat Aug 29
08:20:40 2009
@@ -2,6 +2,13 @@
* This file is part of libdom.
* Licensed under the MIT License,
*
http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
+ * Copyright 2009 Bo Yang <struggleyb.nku.com>
*/
+#ifndef dom_html_form_element_h_
+#define dom_html_form_element_h_
+
+typedef struct dom_html_form_element dom_html_form_element;
+
+#endif
+
Modified: branches/struggleyb/libdom-html/src/html/html_element.c
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_element.c (original)
+++ branches/struggleyb/libdom-html/src/html/html_element.c Sat Aug 29 08:20:40 2009
@@ -13,6 +13,29 @@
#include "core/attr.h"
#include "core/document.h"
#include "utils/utils.h"
+
+dom_exception _dom_html_element_initialise(struct dom_document *doc,
+ struct dom_html_element *el, struct lwc_string_s *name,
+ struct lwc_string_s *namespace, struct lwc_string_s *prefix)
+{
+ dom_exception err;
+
+ err = _dom_element_initialise(doc, &el->base, name, namespace, prefix);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ el->form = NULL;
+ return err;
+}
+
+void _dom_html_element_finalise(struct dom_document *doc,
+ struct dom_html_element *ele)
+{
+ dom_node_unref(ele->form);
+ ele->form = NULL;
+
+ _dom_element_finalise(doc, &ele->base);
+}
/*------------------------------------------------------------------------*/
/* The protected virtual functions */
@@ -150,3 +173,31 @@
return err;
}
+/**
+ * Get the form element if this element is a form control
+ *
+ * \param ele The element object
+ * \param form The form object
+ */
+void _dom_html_element_get_form(dom_html_element *ele,
+ struct dom_html_form_element **form)
+{
+ *form = ele->form;
+ dom_node_ref(*form);
+}
+
+/**
+ * Set the form element if this element is a form control
+ *
+ * \param ele The element object
+ * \param form The form object
+ */
+void _dom_html_element_associate_form(dom_html_element *ele,
+ struct dom_html_form_element *form)
+{
+ /* Unref the form if there is any */
+ dom_node_unref(form);
+ ele->form = form;
+ dom_node_ref(form);
+}
+
Modified: branches/struggleyb/libdom-html/src/html/html_element.h
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_element.h (original)
+++ branches/struggleyb/libdom-html/src/html/html_element.h Sat Aug 29 08:20:40 2009
@@ -12,6 +12,8 @@
#include "core/element.h"
+struct dom_html_form_element;
+
/**
* The dom_html_element class
*
@@ -22,11 +24,18 @@
struct dom_html_element {
struct dom_element base;
/**< The base class */
+ struct dom_html_form_element *form;
+ /**< The form element which contains this element if
+ * this element is a form control
+ */
};
-#define _dom_html_element_initialise(d, e, n, ns, p) _dom_element_initialise(d,\
- &(e)->base, n, ns, p)
-#define _dom_html_element_finalise(d, e) _dom_element_finalise(d, &(e)->base)
+dom_exception _dom_html_element_initialise(struct dom_document *doc,
+ struct dom_html_element *el, struct lwc_string_s *name,
+ struct lwc_string_s *namespace, struct lwc_string_s *prefix);
+
+void _dom_html_element_finalise(struct dom_document *doc,
+ struct dom_html_element *ele);
/* The protected virtual functions */
void _dom_virtual_html_element_destroy(dom_node_internal *node);
@@ -40,7 +49,10 @@
const char *name, unsigned long len, bool *has);
dom_exception dom_html_element_set_bool_property(dom_html_element *ele,
const char *name, unsigned long len, bool has);
-
+void _dom_html_element_get_form(dom_html_element *ele,
+ struct dom_html_form_element **form);
+void _dom_html_element_associate_form(dom_html_element *ele,
+ struct dom_html_form_element *form);
#endif
Modified: branches/struggleyb/libdom-html/src/html/html_form_element.c
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_form_element.c (original)
+++ branches/struggleyb/libdom-html/src/html/html_form_element.c Sat Aug 29 08:20:40 2009
@@ -2,6 +2,136 @@
* This file is part of libdom.
* Licensed under the MIT License,
*
http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
+ * Copyright 2009 Bo Yang <struggleyb.nku.com>
*/
+#include "html/html_form_element.h"
+
+#include "core/node.h"
+#include "core/document.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_FORM_ELEMENT
+ },
+ DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_form_element object
+ *
+ * \param doc The document object
+ * \param ele The returned element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_form_element_create(struct dom_document *doc,
+ struct dom_html_form_element **ele)
+{
+ *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element));
+ if (*ele == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up vtables */
+ struct dom_node_internal *node = (struct dom_node_internal *) *ele;
+ node->base.vtable = &_dom_element_vtable;
+ node->vtable = &_protect_vtable;
+
+ return _dom_html_form_element_initialise(doc, *ele);
+}
+
+/**
+ * Initialise a dom_html_form_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_form_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_form_element_initialise(struct dom_document *doc,
+ struct dom_html_form_element *ele)
+{
+ const char *str = "FORM";
+ lwc_string *name = NULL;
+ dom_exception err;
+
+ err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str),
+ &name);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
+ _dom_document_unref_lwcstring(doc, name);
+
+ return err;
+}
+
+/**
+ * Finalise a dom_html_form_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_form_element object
+ */
+void _dom_html_form_element_finalise(struct dom_document *doc,
+ struct dom_html_form_element *ele)
+{
+ _dom_html_element_finalise(doc, &ele->base);
+}
+
+/**
+ * Destroy a dom_html_form_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_form_element object
+ */
+void _dom_html_form_element_destroy(struct dom_document *doc,
+ struct dom_html_form_element *ele)
+{
+ _dom_html_form_element_finalise(doc, ele);
+ _dom_document_alloc(doc, ele, 0);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_form_element_parse_attribute(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed)
+{
+ UNUSED(ele);
+ UNUSED(name);
+
+ dom_string_ref(value);
+ *parsed = value;
+
+ return DOM_NO_ERR;
+}
+
+/* The virtual destroy function, see src/core/node.c for detail */
+void _dom_virtual_html_form_element_destroy(dom_node_internal *node)
+{
+ struct dom_document *doc = dom_node_get_owner(node);
+ _dom_html_form_element_destroy(doc, (struct dom_html_form_element *) node);
+}
+
+/* The virtual allocation function, see src/core/node.c for detail */
+dom_exception _dom_html_form_element_alloc(struct dom_document *doc,
+ struct dom_node_internal *n, struct dom_node_internal **ret)
+{
+ UNUSED(n);
+
+ *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element));
+ if (*ret == NULL)
+ return DOM_NO_MEM_ERR;
+
+ return DOM_NO_ERR;
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_form_element_copy(struct dom_node_internal *new,
+ struct dom_node_internal *old)
+{
+ return _dom_html_element_copy(new, old);
+}
+
Modified: branches/struggleyb/libdom-html/src/html/html_form_element.h
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_form_element.h (original)
+++ branches/struggleyb/libdom-html/src/html/html_form_element.h Sat Aug 29 08:20:40 2009
@@ -2,6 +2,54 @@
* This file is part of libdom.
* Licensed under the MIT License,
*
http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
+ * Copyright 2009 Bo Yang <struggleyb.nku.com>
*/
+#ifndef dom_internal_html_form_element_h_
+#define dom_internal_html_form_element_h_
+
+#include <dom/html/html_form_element.h>
+
+#include "html/html_element.h"
+
+struct dom_html_form_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_form_element object */
+dom_exception _dom_html_form_element_create(struct dom_document *doc,
+ struct dom_html_form_element **ele);
+
+/* Initialise a dom_html_form_element object */
+dom_exception _dom_html_form_element_initialise(struct dom_document *doc,
+ struct dom_html_form_element *ele);
+
+/* Finalise a dom_html_form_element object */
+void _dom_html_form_element_finalise(struct dom_document *doc,
+ struct dom_html_form_element *ele);
+
+/* Destroy a dom_html_form_element object */
+void _dom_html_form_element_destroy(struct dom_document *doc,
+ struct dom_html_form_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_form_element_parse_attribute(dom_element *ele,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_string **parsed);
+void _dom_virtual_html_form_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_form_element_alloc(struct dom_document *doc,
+ struct dom_node_internal *n, struct dom_node_internal **ret);
+dom_exception _dom_html_form_element_copy(struct dom_node_internal *new,
+ struct dom_node_internal *old);
+
+#define DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE \
+ _dom_html_form_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_FORM_ELEMENT \
+ _dom_virtual_html_form_element_destroy, \
+ _dom_html_form_element_alloc, \
+ _dom_html_form_element_copy
+
+#endif
+
Modified: branches/struggleyb/libdom-html/src/html/html_isindex_element.c
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_isindex_element.c (original)
+++ branches/struggleyb/libdom-html/src/html/html_isindex_element.c Sat Aug 29 08:20:40
2009
@@ -66,7 +66,7 @@
err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
_dom_document_unref_lwcstring(doc, name);
- ele->form = form;
+ ele->base.form = form;
dom_node_ref(form);
return err;
@@ -81,7 +81,6 @@
void _dom_html_isindex_element_finalise(struct dom_document *doc,
struct dom_html_isindex_element *ele)
{
- dom_node_unref(ele->form);
_dom_html_element_finalise(doc, &ele->base);
}
@@ -157,8 +156,7 @@
dom_exception dom_html_isindex_element_get_form(dom_html_isindex_element *ele,
struct dom_html_form_element **form)
{
- *form = ele->form;
- dom_node_ref(*form);
+ _dom_html_element_get_form(&ele->base, form);
return DOM_NO_ERR;
}
Modified: branches/struggleyb/libdom-html/src/html/html_isindex_element.h
URL:
http://source.netsurf-browser.org/branches/struggleyb/libdom-html/src/htm...
==============================================================================
--- branches/struggleyb/libdom-html/src/html/html_isindex_element.h (original)
+++ branches/struggleyb/libdom-html/src/html/html_isindex_element.h Sat Aug 29 08:20:40
2009
@@ -15,9 +15,6 @@
struct dom_html_isindex_element {
struct dom_html_element base;
/**< The base class */
-
- struct dom_html_form_element *form;
- /**< The form which contains this element */
};
/* Create a dom_html_isindex_element object */