summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-06-03 03:39:25 (GMT)
committer Rupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-21 12:07:14 (GMT)
commit8bc4bb6abf7f33cb100adacace73997fdb4dc1aa (patch)
tree5b029ea7f2e1ed1af8968681efee566ad91d21c7
parent9282d5bb95cab38da9ada16a6972168aea44e88a (diff)
downloadlibdom-8bc4bb6abf7f33cb100adacace73997fdb4dc1aa.tar.gz
libdom-8bc4bb6abf7f33cb100adacace73997fdb4dc1aa.tar.bz2
Xselect element && disabling IsIndex Element
-rw-r--r--src/html/Makefile4
-rw-r--r--src/html/TODO2
-rw-r--r--src/html/html_select_element.c148
-rw-r--r--src/html/html_style_element.c2
-rw-r--r--test/testcases/tests/level1/html/HTMLSelectElement17.xml.kfail (renamed from test/testcases/tests/level1/html/HTMLSelectElement17.xml.int-broken)0
-rw-r--r--test/testcases/tests/level1/html/HTMLSelectElement19.xml.kfail2
-rw-r--r--test/testcases/tests/level2/html/HTMLSelectElement20.xml (renamed from test/testcases/tests/level2/html/HTMLSelectElement20.xml.kfail)0
-rw-r--r--test/testcases/tests/level2/html/files/select.html44
-rw-r--r--test/testcases/tests/level2/html/files/select.xhtml41
-rw-r--r--test/testcases/tests/level2/html/files/select.xml41
10 files changed, 243 insertions, 41 deletions
diff --git a/src/html/Makefile b/src/html/Makefile
index 8c20362..2cb85d9 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -3,7 +3,7 @@ DIR_SOURCES := \
html_document.c html_collection.c html_options_collection.c \
html_element.c html_html_element.c html_head_element.c \
html_link_element.c html_title_element.c html_meta_element.c \
- html_base_element.c html_isindex_element.c html_style_element.c \
+ html_base_element.c html_style_element.c \
html_body_element.c html_form_element.c html_select_element.c \
html_button_element.c html_input_element.c html_text_area_element.c \
html_opt_group_element.c html_option_element.c html_hr_element.c \
@@ -20,7 +20,7 @@ DIR_SOURCES := \
html_table_element.c html_tablerow_element.c
UNINMPLEMENTED_SOURCES := \
- html_frameset_element.c \
+ html_frameset_element.c html_isindex_element.c \
html_frame_element.c html_iframe_element.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/html/TODO b/src/html/TODO
index d817e68..8e004e1 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -12,7 +12,7 @@ HTMLIsIndexElement html_isindex_element MISSING
HTMLStyleElement html_style_element DONE
HTMLBodyElement html_body_element MISSING
HTMLFormElement html_form_element DONE
-HTMLSelectElement html_select_element MISSING
+HTMLSelectElement html_select_element DONE
HTMLOptGroupElement html_optgroup_element MISSING
HTMLOptionElement html_option_element MISSING
HTMLInputElement html_input_element MISSING
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index 1e49c75..7a5e84e 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -65,8 +65,8 @@ dom_exception _dom_html_select_element_initialise(struct dom_html_document *doc,
ele->form = NULL;
return _dom_html_element_initialise(doc, &ele->base,
- doc->memoised[hds_SELECT],
- namespace, prefix);
+ doc->memoised[hds_SELECT],
+ namespace, prefix);
}
/**
@@ -125,16 +125,16 @@ dom_exception _dom_html_select_element_copy(dom_node_internal *old,
/* Public APIs */
static dom_exception _dom_html_select_element_make_collection(
- dom_html_select_element *ele,
- dom_html_options_collection **col)
+ dom_html_select_element *ele,
+ dom_html_options_collection **col)
{
dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
assert(doc != NULL);
return _dom_html_options_collection_create(doc,
- (dom_node_internal *) ele,
- is_option, ele, col);
+ (dom_node_internal *) ele,
+ is_option, ele, col);
}
/**
@@ -178,7 +178,7 @@ dom_exception dom_html_select_element_get_selected_index(
dom_node *option;
bool selected;
dom_html_options_collection *col;
-
+
err = _dom_html_select_element_make_collection(ele, &col);
err = dom_html_options_collection_get_length(col, &len);
@@ -194,7 +194,7 @@ dom_exception dom_html_select_element_get_selected_index(
dom_html_options_collection_unref(col);
return err;
}
-
+
err = dom_html_option_element_get_selected(
(dom_html_option_element *) option, &selected);
@@ -204,7 +204,7 @@ dom_exception dom_html_select_element_get_selected_index(
dom_html_options_collection_unref(col);
return err;
}
-
+
if (selected) {
*index = idx;
dom_html_options_collection_unref(col);
@@ -228,11 +228,30 @@ dom_exception dom_html_select_element_get_selected_index(
dom_exception dom_html_select_element_set_selected_index(
dom_html_select_element *ele, int32_t index)
{
- UNUSED(ele);
- UNUSED(index);
+ dom_exception err;
+ dom_node *option;
+ dom_html_options_collection *col;
- /** \todo Implement */
- return DOM_NOT_SUPPORTED_ERR;
+ err = _dom_html_select_element_make_collection(ele, &col);
+
+ err = dom_html_options_collection_item(col,
+ index, &option);
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
+ return err;
+ }
+
+ err = dom_html_option_element_set_selected(
+ (dom_html_option_element *) option, true);
+
+ dom_node_unref(option);
+
+ dom_html_options_collection_unref(col);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ return DOM_NO_ERR;
}
/**
@@ -250,7 +269,7 @@ dom_exception dom_html_select_element_get_value(
dom_node *option;
bool selected;
dom_html_options_collection *col;
-
+
err = _dom_html_select_element_make_collection(ele, &col);
if (err != DOM_NO_ERR)
return err;
@@ -291,7 +310,7 @@ dom_exception dom_html_select_element_get_value(
*value = NULL;
dom_html_options_collection_unref(col);
-
+
return DOM_NO_ERR;
}
@@ -305,11 +324,54 @@ dom_exception dom_html_select_element_get_value(
dom_exception dom_html_select_element_set_value(
dom_html_select_element *ele, dom_string *value)
{
- UNUSED(ele);
- UNUSED(value);
+ dom_exception err;
+ uint32_t idx, len;
+ dom_node *option;
+ bool selected;
+ dom_html_options_collection *col;
+
+ err = _dom_html_select_element_make_collection(ele, &col);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ err = dom_html_select_element_get_length(ele, &len);
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
+ return err;
+ }
+
+ for (idx = 0; idx < len; idx++) {
+ err = dom_html_options_collection_item(col,
+ idx, &option);
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
+ return err;
+ }
+
+ err = dom_html_option_element_get_selected(
+ (dom_html_option_element *) option, &selected);
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
+ dom_node_unref(option);
+ return err;
+ }
+
+ if (selected) {
+ err = dom_html_option_element_set_value(
+ (dom_html_option_element *) option,
+ value);
+
+ dom_html_options_collection_unref(col);
+ dom_node_unref(option);
+
+ return err;
+ }
+ }
+
+ dom_html_options_collection_unref(col);
+
+ return DOM_NO_ERR;
- /** \todo Implement */
- return DOM_NOT_SUPPORTED_ERR;
}
/**
@@ -362,7 +424,7 @@ dom_exception dom_html_select_element_set_length(
* \return DOM_NO_ERR on success, appropriate error otherwise.
*/
dom_exception dom_html_select_element_get_form(
- dom_html_select_element *select, dom_html_form_element **form)
+ dom_html_select_element *select, dom_html_form_element **form)
{
*form = select->form;
@@ -536,12 +598,12 @@ dom_exception dom_html_select_element_set_tab_index(
dom_exception dom__html_select_element_add(dom_html_select_element *select,
struct dom_html_element *ele, struct dom_html_element *before)
{
- UNUSED(select);
- UNUSED(ele);
- UNUSED(before);
- /** \todo Implement */
- return DOM_NOT_SUPPORTED_ERR;
+ return _dom_node_insert_before((dom_node_internal *)select,
+ (dom_node_internal *)ele, (dom_node_internal *)before,
+ (dom_node_internal **)&ele);
+
+
}
dom_exception dom_html_select_element_remove(dom_html_select_element *ele,
@@ -549,17 +611,31 @@ dom_exception dom_html_select_element_remove(dom_html_select_element *ele,
{
dom_exception err;
uint32_t len;
+ dom_node *option;
err = dom_html_select_element_get_length(ele, &len);
if (err != DOM_NO_ERR)
return err;
/* Ensure index is in range */
- if (index < 0 || (uint32_t)index >= len)
+ if (index < 0 || index >= (int32_t)len)
return DOM_NO_ERR;
+ dom_html_options_collection *col;
- /** \todo What does remove mean? Remove option from tree and destroy it? */
- return DOM_NOT_SUPPORTED_ERR;
+ err = _dom_html_select_element_make_collection(ele, &col);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ err = dom_html_options_collection_item(col,
+ index, &option);
+
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
+ return err;
+ }
+ return _dom_node_remove_child(((dom_node_internal *)option)->parent,
+ (dom_node_internal *)option,
+ (dom_node_internal **)&option);
}
/**
@@ -577,9 +653,9 @@ dom_exception dom_html_select_element_blur(struct dom_html_select_element *ele)
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
return _dom_dispatch_generic_event((dom_document *) doc,
- (dom_event_target *) ele,
- doc->memoised[hds_blur], true,
- true, &success);
+ (dom_event_target *) ele,
+ doc->memoised[hds_blur], true,
+ true, &success);
}
/**
@@ -597,9 +673,9 @@ dom_exception dom_html_select_element_focus(struct dom_html_select_element *ele)
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
return _dom_dispatch_generic_event((dom_document *) doc,
- (dom_event_target *) ele,
- doc->memoised[hds_focus], true,
- true, &success);
+ (dom_event_target *) ele,
+ doc->memoised[hds_focus], true,
+ true, &success);
}
@@ -611,7 +687,7 @@ bool is_option(struct dom_node_internal *node, void *ctx)
{
dom_html_select_element *ele = ctx;
dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
-
+
if (dom_string_isequal(node->name, doc->memoised[hds_OPTION]))
return true;
@@ -619,7 +695,7 @@ bool is_option(struct dom_node_internal *node, void *ctx)
}
dom_exception _dom_html_select_element_set_form(
- dom_html_select_element *select, dom_html_form_element *form)
+ dom_html_select_element *select, dom_html_form_element *form)
{
select->form = form;
diff --git a/src/html/html_style_element.c b/src/html/html_style_element.c
index 3b295f1..681f0b8 100644
--- a/src/html/html_style_element.c
+++ b/src/html/html_style_element.c
@@ -35,7 +35,7 @@ dom_exception _dom_html_style_element_create(struct dom_html_document *doc,
*ele = malloc(sizeof(dom_html_style_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;
diff --git a/test/testcases/tests/level1/html/HTMLSelectElement17.xml.int-broken b/test/testcases/tests/level1/html/HTMLSelectElement17.xml.kfail
index 03549ff..03549ff 100644
--- a/test/testcases/tests/level1/html/HTMLSelectElement17.xml.int-broken
+++ b/test/testcases/tests/level1/html/HTMLSelectElement17.xml.kfail
diff --git a/test/testcases/tests/level1/html/HTMLSelectElement19.xml.kfail b/test/testcases/tests/level1/html/HTMLSelectElement19.xml.kfail
index 2d2a732..5d06fe1 100644
--- a/test/testcases/tests/level1/html/HTMLSelectElement19.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLSelectElement19.xml.kfail
@@ -33,7 +33,7 @@ Add a new option before the selected node using HTMLSelectElement.add.
<var name="selected" type="int"/>
<var name="newOpt" type="Element"/>
<var name="newOptText" type="Text"/>
-<var name="opt" type="Element"/>
+<var name="opt" type="Node"/>
<var name="optText" type="Text"/>
<var name="optValue" type="DOMString"/>
<var name="retNode" type="Node"/>
diff --git a/test/testcases/tests/level2/html/HTMLSelectElement20.xml.kfail b/test/testcases/tests/level2/html/HTMLSelectElement20.xml
index ddbe2f7..ddbe2f7 100644
--- a/test/testcases/tests/level2/html/HTMLSelectElement20.xml.kfail
+++ b/test/testcases/tests/level2/html/HTMLSelectElement20.xml
diff --git a/test/testcases/tests/level2/html/files/select.html b/test/testcases/tests/level2/html/files/select.html
new file mode 100644
index 0000000..7820624
--- a/dev/null
+++ b/test/testcases/tests/level2/html/files/select.html
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<HEAD>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
+<TITLE>NIST DOM HTML Test - SELECT</TITLE>
+</HEAD>
+<BODY onload="parent.loadComplete()">
+<FORM ID="form1" ACTION="./files/getData.pl" METHOD="post">
+<P>
+<SELECT ID="selectId" DIR="ltr" TABINDEX="7" NAME="select1" MULTIPLE="multiple" SIZE="1">
+<OPTION SELECTED="selected" value="EMP1">EMP10001</OPTION>
+<OPTION>EMP10002</OPTION>
+<OPTION>EMP10003</OPTION>
+<OPTION>EMP10004</OPTION>
+<OPTION>EMP10005</OPTION>
+</SELECT>
+</P>
+</FORM>
+<P>
+<SELECT NAME="select2">
+<OPTION>EMP20001</OPTION>
+<OPTION>EMP20002</OPTION>
+<OPTION>EMP20003</OPTION>
+<OPTION>EMP20004</OPTION>
+<OPTION>EMP20005</OPTION>
+</SELECT>
+</P>
+<P>
+<SELECT NAME="select3" DISABLED="disabled" TABINDEX="1">
+<OPTION>EMP30001</OPTION>
+<OPTION>EMP30002</OPTION>
+<OPTION>EMP30003</OPTION>
+<OPTION>EMP30004</OPTION>
+<OPTION>EMP30005</OPTION>
+</SELECT>
+</P>
+</BODY>
+</HTML>
+
+
+
+
+
+
diff --git a/test/testcases/tests/level2/html/files/select.xhtml b/test/testcases/tests/level2/html/files/select.xhtml
new file mode 100644
index 0000000..491a74c
--- a/dev/null
+++ b/test/testcases/tests/level2/html/files/select.xhtml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "xhtml1-transitional.dtd">
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+<title>NIST DOM HTML Test - SELECT</title>
+</head>
+<body onload="parent.loadComplete()">
+<form id="form1" action="./files/getData.pl" method="post">
+<p>
+<select id="selectId" dir="ltr" tabindex="7" name="select1" multiple="multiple" size="1">
+<option selected="selected" value="EMP1">EMP10001</option>
+<option>EMP10002</option>
+<option>EMP10003</option>
+<option>EMP10004</option>
+<option>EMP10005</option>
+</select>
+</p>
+</form>
+<p>
+<select name="select2">
+<option>EMP20001</option>
+<option>EMP20002</option>
+<option>EMP20003</option>
+<option>EMP20004</option>
+<option>EMP20005</option>
+</select>
+</p>
+<p>
+<select name="select3" disabled="disabled" tabindex="1">
+<option>EMP30001</option>
+<option>EMP30002</option>
+<option>EMP30003</option>
+<option>EMP30004</option>
+<option>EMP30005</option>
+</select>
+</p>
+</body>
+</html>
+
diff --git a/test/testcases/tests/level2/html/files/select.xml b/test/testcases/tests/level2/html/files/select.xml
new file mode 100644
index 0000000..491a74c
--- a/dev/null
+++ b/test/testcases/tests/level2/html/files/select.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "xhtml1-transitional.dtd">
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+<title>NIST DOM HTML Test - SELECT</title>
+</head>
+<body onload="parent.loadComplete()">
+<form id="form1" action="./files/getData.pl" method="post">
+<p>
+<select id="selectId" dir="ltr" tabindex="7" name="select1" multiple="multiple" size="1">
+<option selected="selected" value="EMP1">EMP10001</option>
+<option>EMP10002</option>
+<option>EMP10003</option>
+<option>EMP10004</option>
+<option>EMP10005</option>
+</select>
+</p>
+</form>
+<p>
+<select name="select2">
+<option>EMP20001</option>
+<option>EMP20002</option>
+<option>EMP20003</option>
+<option>EMP20004</option>
+<option>EMP20005</option>
+</select>
+</p>
+<p>
+<select name="select3" disabled="disabled" tabindex="1">
+<option>EMP30001</option>
+<option>EMP30002</option>
+<option>EMP30003</option>
+<option>EMP30004</option>
+<option>EMP30005</option>
+</select>
+</p>
+</body>
+</html>
+