From d5e1616a454ffd1a2e9f7b2abf479f0c1aee4425 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 19 Sep 2012 14:42:05 +0100 Subject: [PATCH] Fix select elements. Requires latest libdom. --- render/html_forms.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ utils/corestrings.c | 3 +++ utils/corestrings.h | 1 + 3 files changed, 58 insertions(+) diff --git a/render/html_forms.c b/render/html_forms.c index 2165dc821..739947d3b 100644 --- a/render/html_forms.c +++ b/render/html_forms.c @@ -454,6 +454,56 @@ out: return control; } +static struct form_control * +parse_select_element(struct form *forms, dom_html_select_element *select) +{ + struct form_control *control = NULL; + dom_html_form_element *form = NULL; + dom_string *ds_name = NULL; + + char *name = NULL; + + if (dom_html_select_element_get_form(select, &form) != DOM_NO_ERR) + goto out; + + if (dom_html_select_element_get_name(select, &ds_name) != DOM_NO_ERR) + goto out; + + if (ds_name != NULL) + name = strndup(dom_string_data(ds_name), + dom_string_byte_length(ds_name)); + + control = form_new_control(select, GADGET_SELECT); + + if (control == NULL) + goto out; + + if (name != NULL) { + /* Hand the name string over */ + control->name = name; + name = NULL; + } + + dom_html_select_element_get_multiple(select, + &(control->data.select.multiple)); + + if (form != NULL && control != NULL) + form_add_control(find_form(forms, form), control); + +out: + if (form != NULL) + dom_node_unref(form); + if (ds_name != NULL) + dom_string_unref(ds_name); + + if (name != NULL) + free(name); + + + return control; +} + + static struct form_control * invent_fake_gadget(dom_node *node) { @@ -505,6 +555,10 @@ struct form_control *html_forms_get_control_for_node(struct form *forms, dom_nod corestring_lwc_textarea)) { ctl = parse_textarea_element(forms, (dom_html_text_area_element *) node); + } else if (dom_string_caseless_lwc_isequal(ds_name, + corestring_lwc_select)) { + ctl = parse_select_element(forms, + (dom_html_select_element *) node); } } diff --git a/utils/corestrings.c b/utils/corestrings.c index af87ce206..86f2c4cb4 100644 --- a/utils/corestrings.c +++ b/utils/corestrings.c @@ -85,6 +85,7 @@ lwc_string *corestring_lwc_rectangle; lwc_string *corestring_lwc_refresh; lwc_string *corestring_lwc_reset; lwc_string *corestring_lwc_right; +lwc_string *corestring_lwc_select; lwc_string *corestring_lwc_src; lwc_string *corestring_lwc_style; lwc_string *corestring_lwc_submit; @@ -224,6 +225,7 @@ void corestrings_fini(void) CSS_LWC_STRING_UNREF(refresh); CSS_LWC_STRING_UNREF(reset); CSS_LWC_STRING_UNREF(right); + CSS_LWC_STRING_UNREF(select); CSS_LWC_STRING_UNREF(src); CSS_LWC_STRING_UNREF(style); CSS_LWC_STRING_UNREF(submit); @@ -382,6 +384,7 @@ nserror corestrings_init(void) CSS_LWC_STRING_INTERN(refresh); CSS_LWC_STRING_INTERN(reset); CSS_LWC_STRING_INTERN(right); + CSS_LWC_STRING_INTERN(select); CSS_LWC_STRING_INTERN(src); CSS_LWC_STRING_INTERN(style); CSS_LWC_STRING_INTERN(submit); diff --git a/utils/corestrings.h b/utils/corestrings.h index 1bcf8aee7..a64f62f65 100644 --- a/utils/corestrings.h +++ b/utils/corestrings.h @@ -89,6 +89,7 @@ extern lwc_string *corestring_lwc_rectangle; extern lwc_string *corestring_lwc_refresh; extern lwc_string *corestring_lwc_reset; extern lwc_string *corestring_lwc_right; +extern lwc_string *corestring_lwc_select; extern lwc_string *corestring_lwc_src; extern lwc_string *corestring_lwc_style; extern lwc_string *corestring_lwc_submit;