summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-05-17 03:09:50 (GMT)
committer Rupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-10 22:57:09 (GMT)
commitf1107bdb33dd760151d1b7311b09fb099c05d8c9 (patch)
treef2f4e2e831d8e0fcc1aab2f518628542eda465a1
parent644e93ff924466c41e55bad14fb7a42c468a4f7c (diff)
downloadlibdom-f1107bdb33dd760151d1b7311b09fb099c05d8c9.tar.gz
libdom-f1107bdb33dd760151d1b7311b09fb099c05d8c9.tar.bz2
Map Element
-rw-r--r--Makefile1
-rw-r--r--include/dom/dom.h1
-rw-r--r--include/dom/html/html_map_element.h21
-rw-r--r--src/html/Makefile5
-rw-r--r--src/html/TODO16
-rw-r--r--src/html/html_map_element.c180
-rw-r--r--src/html/html_map_element.h47
-rw-r--r--src/html/html_select_element.c2
-rw-r--r--test/testcases/tests/level1/html/HTMLMapElement01.xml.kfail44
-rw-r--r--test/testcases/tests/level1/html/HTMLMapElement02.xml (renamed from test/testcases/tests/level1/html/HTMLMapElement02.xml.kfail)0
10 files changed, 262 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index 6be20eb..29917ff 100644
--- a/Makefile
+++ b/Makefile
@@ -121,6 +121,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_object_element.h
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) /$(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 69a4f77..8a1b5e5 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -80,6 +80,7 @@
#include <dom/html/html_param_element.h>
#include <dom/html/html_applet_element.h>
#include <dom/html/html_area_element.h>
+#include <dom/html/html_map_element.h>
/* DOM Events header */
#include <dom/events/events.h>
diff --git a/include/dom/html/html_map_element.h b/include/dom/html/html_map_element.h
index 2e182d5..6abdee5 100644
--- a/include/dom/html/html_map_element.h
+++ b/include/dom/html/html_map_element.h
@@ -3,5 +3,26 @@
* 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_map_element_h_
+#define dom_html_map_element_h_
+#include <stdbool.h>
+#include <dom/core/exceptions.h>
+#include <dom/core/string.h>
+
+#include <dom/html/html_collection.h>
+
+typedef struct dom_html_map_element dom_html_map_element;
+
+dom_exception dom_html_map_element_get_name(
+ dom_html_map_element *ele, dom_string **name);
+
+dom_exception dom_html_map_element_set_name(
+ dom_html_map_element *ele, dom_string *name);
+
+dom_exception dom_html_map_element_get_areas(
+ dom_html_map_element *ele, dom_html_collection **areas);
+
+#endif
diff --git a/src/html/Makefile b/src/html/Makefile
index ba76d6c..240f54e 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -14,10 +14,11 @@ DIR_SOURCES := \
html_ulist_element.c html_olist_element.c html_li_element.c \
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_param_element.c html_applet_element.c html_area_element.c \
+ html_map_element.c
UNINMPLEMENTED_SOURCES := \
- html_map_element.c html_script_element.c html_table_element.c \
+ html_script_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 c61adbd..28ff163 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -26,10 +26,10 @@ HTMLOListElement html_olist_element DONE
HTMLDListElement html_dlist_element DONE
HTMLDirectoryElement html_directory_element DONE
HTMLMenuElement html_menu_element DONE
-HTMLLIElement html_li_element MISSING
-HTMLBlockquoteElement html_blockquote_element MISSING
-HTMLDivElement html_div_element MISSING
-HTMLParagraphElement html_paragraph_element MISSING
+HTMLLIElement html_li_element DONE
+HTMLBlockquoteElement html_blockquote_element DONE
+HTMLDivElement html_div_element DONE
+HTMLParagraphElement html_paragraph_element DONE
HTMLHeadingElement html_heading_element DONE
HTMLQuoteElement html_quote_element DONE
HTMLPreElement html_pre_element DONE
@@ -41,10 +41,10 @@ HTMLModElement html_mod_element DONE
HTMLAnchorElement html_anchor_element DONE
HTMLImageElement html_image_element DONE
HTMLObjectElement html_object_element DONE
-HTMLParamElement html_param_element MISSING
-HTMLAppletElement html_applet_element MISSING
-HTMLMapElement html_map_element MISSING
-HTMLAreaElement html_area_element MISSING
+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
HTMLTableElement html_table_element MISSING
HTMLTableCaptionElement html_tablecaption_element MISSING
diff --git a/src/html/html_map_element.c b/src/html/html_map_element.c
index 2e182d5..ca08d4c 100644
--- a/src/html/html_map_element.c
+++ b/src/html/html_map_element.c
@@ -3,5 +3,185 @@
* 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_map_element.h>
+
+#include "html/html_document.h"
+#include "html/html_map_element.h"
+
+#include "html/html_collection.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_MAP_ELEMENT
+ },
+ DOM_HTML_MAP_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_map_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_map_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_map_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_map_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_map_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_map_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_map_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_map_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_map_element *ele)
+{
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_MAP],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_map_element object
+ *
+ * \param ele The dom_html_map_element object
+ */
+void _dom_html_map_element_finalise(struct dom_html_map_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_map_element object
+ *
+ * \param ele The dom_html_map_element object
+ */
+void _dom_html_map_element_destroy(struct dom_html_map_element *ele)
+{
+ _dom_html_map_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_map_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_map_element_destroy(dom_node_internal *node)
+{
+ _dom_html_map_element_destroy((struct dom_html_map_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_map_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_map_element_get_##attr( \
+ dom_html_map_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_map_element_set_##attr( \
+ dom_html_map_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(name);
+
+bool callback(
+ struct dom_node_internal *node, void *ctx)
+{
+ if(dom_string_caseless_isequal(node->name,((dom_html_document *)ctx)->memoised[hds_AREA])) {
+ return true;
+ }
+ return false;
+}
+
+dom_exception dom_html_map_element_get_areas(
+ dom_html_map_element *ele, dom_html_collection **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);
+}
diff --git a/src/html/html_map_element.h b/src/html/html_map_element.h
index 2e182d5..0230808 100644
--- a/src/html/html_map_element.h
+++ b/src/html/html_map_element.h
@@ -3,5 +3,52 @@
* 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_map_element_h_
+#define dom_internal_html_map_element_h_
+
+#include <dom/html/html_map_element.h>
+#include "html/html_element.h"
+
+
+struct dom_html_map_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_map_element object */
+dom_exception _dom_html_map_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_map_element **ele);
+
+/* Initialise a dom_html_map_element object */
+dom_exception _dom_html_map_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_map_element *ele);
+
+/* Finalise a dom_html_map_element object */
+void _dom_html_map_element_finalise(struct dom_html_map_element *ele);
+
+/* Destroy a dom_html_map_element object */
+void _dom_html_map_element_destroy(struct dom_html_map_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_map_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_map_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_map_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_MAP_ELEMENT_PROTECT_VTABLE \
+ _dom_html_map_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_MAP_ELEMENT \
+ _dom_virtual_html_map_element_destroy, \
+ _dom_html_map_element_copy
+
+#endif
+
+bool callback(struct dom_node_internal *node, void *ctx);
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index c02f0bd..1e49c75 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -174,7 +174,7 @@ dom_exception dom_html_select_element_get_selected_index(
dom_html_select_element *ele, int32_t *index)
{
dom_exception err;
- uint32_t idx, len;
+ uint32_t idx,len;
dom_node *option;
bool selected;
dom_html_options_collection *col;
diff --git a/test/testcases/tests/level1/html/HTMLMapElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLMapElement01.xml.kfail
deleted file mode 100644
index 01e2459..0000000
--- a/test/testcases/tests/level1/html/HTMLMapElement01.xml.kfail
+++ b/dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?xml-stylesheet href="test-to-html.xsl" type="text/xml"?>
-
-<!--
-
-Copyright (c) 2001 World Wide Web Consortium,
-(Massachusetts Institute of Technology, Institut National de
-Recherche en Informatique et en Automatique, Keio University). All
-Rights Reserved. This program is distributed under the W3C's Software
-Intellectual Property License. This program is distributed in the
-hope that it will be useful, but WITHOUT ANY WARRANTY; without even
-the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-PURPOSE.
-
-See W3C License http://www.w3.org/Consortium/Legal/ for more details.
-
--->
-<!DOCTYPE test SYSTEM "dom1.dtd">
-<test xmlns="http://www.w3.org/2001/DOM-Test-Suite/Level-1" name="HTMLMapElement01">
-<metadata>
-<title>HTMLMapElement01</title>
-<creator>NIST</creator>
-<description>
- The areas attribute is a list of areas defined for the image map.
-
- Retrieve the areas attribute and find the number of areas defined.
-</description>
-<contributor>Mary Brady</contributor>
-<date qualifier="created">2002-02-22</date>
-<subject resource="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-71838730"/>
-</metadata>
-<var name="nodeList" type="NodeList"/>
-<var name="areasnodeList" type="HTMLCollection"/>
-<var name="testNode" type="Node"/>
-<var name="vareas" type="int" />
-<var name="doc" type="Document"/>
-<load var="doc" href="map" willBeModified="false"/>
-<getElementsByTagName interface="Document" obj="doc" var="nodeList" tagname='"map"'/>
-<assertSize collection="nodeList" size="1" id="Asize"/>
-<item interface="NodeList" obj="nodeList" var="testNode" index="0"/>
-<areas interface="HTMLMapElement" obj="testNode" var="areasnodeList"/>
-<length interface="HTMLCollection" obj="areasnodeList" var="vareas"/>
-<assertEquals actual="vareas" expected="3" id="areasLink" ignoreCase="false"/>
-</test>
diff --git a/test/testcases/tests/level1/html/HTMLMapElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLMapElement02.xml
index fc83993..fc83993 100644
--- a/test/testcases/tests/level1/html/HTMLMapElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLMapElement02.xml