summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-05-18 02:27:15 (GMT)
committer Rupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-10 22:57:09 (GMT)
commit2c4fcd2e416c51dc95af1e9054df1dc1fa28ff25 (patch)
tree76c0d0a8f2bdd3fe9835d8971bc3fe3a788a76ea
parentefec9dd5e88f563242a645e0a1f1904f5c262093 (diff)
downloadlibdom-2c4fcd2e416c51dc95af1e9054df1dc1fa28ff25.tar.gz
libdom-2c4fcd2e416c51dc95af1e9054df1dc1fa28ff25.tar.bz2
[Map Element Rev.2(fix)] & [Script Element add]
-rw-r--r--Makefile1
-rw-r--r--include/dom/dom.h1
-rw-r--r--include/dom/html/html_script_element.h52
-rw-r--r--src/html/Makefile4
-rw-r--r--src/html/TODO2
-rw-r--r--src/html/html_document.c12
-rw-r--r--src/html/html_document_strings.h2
-rw-r--r--src/html/html_map_element.c19
-rw-r--r--src/html/html_script_element.c213
-rw-r--r--src/html/html_script_element.h45
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement01.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement02.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement02.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement03.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement03.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement04.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement04.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement05.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement05.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement06.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement06.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLScriptElement07.xml (renamed from test/testcases/tests/level1/html/HTMLScriptElement07.xml.kfail)0
17 files changed, 338 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 29917ff..a50b2db 100644
--- a/Makefile
+++ b/Makefile
@@ -122,6 +122,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_param_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_applet_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_area_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_map_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_script_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/include/dom/dom.h b/include/dom/dom.h
index 8a1b5e5..b23ede0 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -81,6 +81,7 @@
#include <dom/html/html_applet_element.h>
#include <dom/html/html_area_element.h>
#include <dom/html/html_map_element.h>
+#include <dom/html/html_script_element.h>
/* DOM Events header */
#include <dom/events/events.h>
diff --git a/include/dom/html/html_script_element.h b/include/dom/html/html_script_element.h
index 2e182d5..b7df3aa 100644
--- a/include/dom/html/html_script_element.h
+++ b/include/dom/html/html_script_element.h
@@ -3,5 +3,57 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar <rsk1coder99@gmail.com>
*/
+#ifndef dom_html_script_element_h_
+#define dom_html_script_element_h_
+#include <stdbool.h>
+#include <dom/core/exceptions.h>
+#include <dom/core/string.h>
+
+typedef struct dom_html_script_element dom_html_script_element;
+
+dom_exception dom_html_script_element_get_defer(
+ dom_html_script_element *ele, bool *defer);
+
+dom_exception dom_html_script_element_set_defer(
+ dom_html_script_element *ele, bool defer);
+
+dom_exception dom_html_script_element_get_text(
+ dom_html_script_element *element, dom_string **text);
+
+dom_exception dom_html_script_element_set_text(
+ dom_html_script_element *element, dom_string *text);
+
+dom_exception dom_html_script_element_get_html_for(
+ dom_html_script_element *element, dom_string **html_for);
+
+dom_exception dom_html_script_element_set_html_for(
+ dom_html_script_element *element, dom_string *html_for);
+
+dom_exception dom_html_script_element_get_event(
+ dom_html_script_element *element, dom_string **event);
+
+dom_exception dom_html_script_element_set_event(
+ dom_html_script_element *ele, dom_string *event);
+
+dom_exception dom_html_script_element_get_charset(
+ dom_html_script_element *ele, dom_string **charset);
+
+dom_exception dom_html_script_element_set_charset(
+ dom_html_script_element *ele, dom_string *charset);
+
+dom_exception dom_html_script_element_get_src(
+ dom_html_script_element *ele, dom_string **src);
+
+dom_exception dom_html_script_element_set_src(
+ dom_html_script_element *ele, dom_string *src);
+
+dom_exception dom_html_script_element_get_type(
+ dom_html_script_element *ele, dom_string **type);
+
+dom_exception dom_html_script_element_set_type(
+ dom_html_script_element *ele, dom_string *type);
+
+#endif
diff --git a/src/html/Makefile b/src/html/Makefile
index 240f54e..66d6ab0 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -15,10 +15,10 @@ DIR_SOURCES := \
html_font_element.c html_mod_element.c html_anchor_element.c \
html_basefont_element.c html_image_element.c html_object_element.c \
html_param_element.c html_applet_element.c html_area_element.c \
- html_map_element.c
+ html_map_element.c html_script_element.c
UNINMPLEMENTED_SOURCES := \
- html_script_element.c html_table_element.c \
+ html_table_element.c \
html_tablecaption_element.c html_tablecol_element.c html_tablesection_element.c \
html_tablerow_element.c html_tablecell_element.c html_frameset_element.c \
html_frame_element.c html_iframe_element.c
diff --git a/src/html/TODO b/src/html/TODO
index 28ff163..3888e23 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -45,7 +45,7 @@ HTMLParamElement html_param_element DONE
HTMLAppletElement html_applet_element DONE
HTMLMapElement html_map_element DONE
HTMLAreaElement html_area_element DONE
-HTMLScriptElement html_script_element MISSING
+HTMLScriptElement html_script_element DONE
HTMLTableElement html_table_element MISSING
HTMLTableCaptionElement html_tablecaption_element MISSING
HTMLTableColElement html_tablecol_element MISSING
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 08dbe23..b7bf117 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -47,6 +47,9 @@
#include "html/html_object_element.h"
#include "html/html_param_element.h"
#include "html/html_applet_element.h"
+#include "html/html_map_element.h"
+#include "html/html_area_element.h"
+#include "html/html_script_element.h"
#include "core/attr.h"
#include "core/string.h"
@@ -319,6 +322,15 @@ _dom_html_document_create_element_internal(dom_html_document *html,
} else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_APPLET])) {
exc = _dom_html_applet_element_create(html, namespace, prefix,
(dom_html_applet_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_MAP])) {
+ exc = _dom_html_map_element_create(html, namespace, prefix,
+ (dom_html_map_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_AREA])) {
+ exc = _dom_html_area_element_create(html, namespace, prefix,
+ (dom_html_area_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_SCRIPT])) {
+ exc = _dom_html_script_element_create(html, namespace, prefix,
+ (dom_html_script_element **) result);
} else {
exc = _dom_html_element_create(html, tag_name, namespace,
prefix, result);
diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h
index ad8e602..8ed3bb2 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -96,6 +96,8 @@ HTML_DOCUMENT_STRINGS_ACTION1(data)
HTML_DOCUMENT_STRINGS_ACTION1(height)
HTML_DOCUMENT_STRINGS_ACTION1(standby)
HTML_DOCUMENT_STRINGS_ACTION1(object)
+HTML_DOCUMENT_STRINGS_ACTION1(event)
+HTML_DOCUMENT_STRINGS_ACTION1(defer)
HTML_DOCUMENT_STRINGS_ACTION(tab_index,tabindex)
HTML_DOCUMENT_STRINGS_ACTION(html_for,for)
HTML_DOCUMENT_STRINGS_ACTION(date_time,datetime)
diff --git a/src/html/html_map_element.c b/src/html/html_map_element.c
index bdd4ef0..cf0fe5e 100644
--- a/src/html/html_map_element.c
+++ b/src/html/html_map_element.c
@@ -165,10 +165,13 @@ SIMPLE_GET_SET(name);
/* The callback function for _dom_html_collection_create*/
bool callback(struct dom_node_internal *node, void *ctx)
{
- if(dom_string_caseless_isequal
- (node->name,((dom_html_document *)ctx)->memoised[hds_AREA])) {
+ if(node->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(node->name,
+ ((dom_html_document *)ctx)->memoised[hds_AREA]))
+ {
return true;
}
+
return false;
}
@@ -185,12 +188,8 @@ dom_exception dom_html_map_element_get_areas(
{
dom_html_document *doc
= (dom_html_document *) ((dom_node_internal *) ele)->owner;
- dom_node_internal *root = ((dom_node_internal *) ele);
-
- while (root->parent != NULL) {
- root = root->parent;
- }
-
- return _dom_html_collection_create(doc, root,
- callback, (void *)doc, areas);
+
+ /*doc is passed as a parameter to callback to avoid repeated calculations */
+ return _dom_html_collection_create(doc, (dom_node_internal *) ele,
+ callback, (void *) doc, areas);
}
diff --git a/src/html/html_script_element.c b/src/html/html_script_element.c
index 2e182d5..f107d45 100644
--- a/src/html/html_script_element.c
+++ b/src/html/html_script_element.c
@@ -3,5 +3,218 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar<rsk1coder99@gmail.com>
*/
+#include <assert.h>
+#include <stdlib.h>
+#include <dom/html/html_script_element.h>
+
+#include "html/html_document.h"
+#include "html/html_script_element.h"
+
+#include "core/node.h"
+#include "core/attr.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_SCRIPT_ELEMENT
+ },
+ DOM_HTML_SCRIPT_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_script_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_script_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_script_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_script_element));
+ if (*ele == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up vtables */
+ node = (struct dom_node_internal *) *ele;
+ node->base.vtable = &_dom_html_element_vtable;
+ node->vtable = &_protect_vtable;
+
+ return _dom_html_script_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_script_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_script_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_script_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_script_element *ele)
+{
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_SCRIPT],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_script_element object
+ *
+ * \param ele The dom_html_script_element object
+ */
+void _dom_html_script_element_finalise(struct dom_html_script_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_script_element object
+ *
+ * \param ele The dom_html_script_element object
+ */
+void _dom_html_script_element_destroy(struct dom_html_script_element *ele)
+{
+ _dom_html_script_element_finalise(ele);
+ free(ele);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_script_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ 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_script_element_destroy(dom_node_internal *node)
+{
+ _dom_html_script_element_destroy((struct dom_html_script_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_script_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ return _dom_html_element_copy(old, copy);
+}
+
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET(attr) \
+ dom_exception dom_html_script_element_get_##attr( \
+ dom_html_script_element *element, \
+ dom_string **attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ }
+#define SIMPLE_SET(attr) \
+dom_exception dom_html_script_element_set_##attr( \
+ dom_html_script_element *element, \
+ dom_string *attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ }
+
+#define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
+
+SIMPLE_GET_SET(html_for);
+SIMPLE_GET_SET(event);
+SIMPLE_GET_SET(charset);
+SIMPLE_GET_SET(src);
+SIMPLE_GET_SET(type);
+
+/**
+ * Get the defer property
+ *
+ * \param ele The dom_html_script_element object
+ * \param defer The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_script_element_get_defer(dom_html_script_element *ele,
+ bool *defer)
+{
+ return dom_html_element_get_bool_property(&ele->base, "defer",
+ SLEN("defer"), defer);
+}
+
+/**
+ * Set the defer property
+ *
+ * \param ele The dom_html_script_element object
+ * \param defer The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_script_element_set_defer(dom_html_script_element *ele,
+ bool defer)
+{
+ return dom_html_element_set_bool_property(&ele->base, "defer",
+ SLEN("defer"), defer);
+}
+
+/**
+ * Get the text property
+ *
+ * \param ele The dom_html_script_element object
+ * \param text The returned dom_string object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_script_element_get_text(
+ dom_html_script_element *ele,
+ dom_string **text)
+{
+ return _dom_node_get_text_content((dom_node_internal *)ele, text);
+}
+
+/**
+ * Set the text property
+ *
+ * \param ele The dom_html_script_element object
+ * \param text The dom_string value to be set
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_script_element_set_text(
+ dom_html_script_element *ele,
+ dom_string *text)
+{
+ return _dom_node_set_text_content((dom_node_internal *)ele, text);
+}
diff --git a/src/html/html_script_element.h b/src/html/html_script_element.h
index 2e182d5..dcb7b72 100644
--- a/src/html/html_script_element.h
+++ b/src/html/html_script_element.h
@@ -3,5 +3,50 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar <rsk1coder99@gmail.com>
*/
+#ifndef dom_internal_html_script_element_h_
+#define dom_internal_html_script_element_h_
+
+#include <dom/html/html_script_element.h>
+#include "html/html_element.h"
+
+
+struct dom_html_script_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_script_element object */
+dom_exception _dom_html_script_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_script_element **ele);
+
+/* Initialise a dom_html_script_element object */
+dom_exception _dom_html_script_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_script_element *ele);
+
+/* Finalise a dom_html_script_element object */
+void _dom_html_script_element_finalise(struct dom_html_script_element *ele);
+
+/* Destroy a dom_html_script_element object */
+void _dom_html_script_element_destroy(struct dom_html_script_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_script_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_script_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_script_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_SCRIPT_ELEMENT_PROTECT_VTABLE \
+ _dom_html_script_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_SCRIPT_ELEMENT \
+ _dom_virtual_html_script_element_destroy, \
+ _dom_html_script_element_copy
+
+#endif
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement01.xml
index c4f28dd..c4f28dd 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement02.xml
index dd3911d..dd3911d 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement02.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement03.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement03.xml
index d23ad8a..d23ad8a 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement03.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement03.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement04.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement04.xml
index da94196..da94196 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement04.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement04.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement05.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement05.xml
index 2a3ede2..2a3ede2 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement05.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement05.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement06.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement06.xml
index 4e869fc..4e869fc 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement06.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement06.xml
diff --git a/test/testcases/tests/level1/html/HTMLScriptElement07.xml.kfail b/test/testcases/tests/level1/html/HTMLScriptElement07.xml
index d5a0145..d5a0145 100644
--- a/test/testcases/tests/level1/html/HTMLScriptElement07.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLScriptElement07.xml