Avoid strcasecmp in form control creation node name handler.

This commit is contained in:
Michael Drake 2012-07-21 17:41:17 +01:00
parent b412b93701
commit 9d3986e768
3 changed files with 24 additions and 14 deletions

View File

@ -113,6 +113,9 @@ dom_string *html_dom_string_coords;
dom_string *html_dom_string_circle;
dom_string *html_dom_string_poly;
dom_string *html_dom_string_polygon;
dom_string *html_dom_string_button;
dom_string *html_dom_string_input;
dom_string *html_dom_string_textarea;
static void html_destroy_objects(html_content *html)
@ -3140,6 +3143,9 @@ static void html_fini(void)
HTML_DOM_STRING_UNREF(circle);
HTML_DOM_STRING_UNREF(poly);
HTML_DOM_STRING_UNREF(polygon);
HTML_DOM_STRING_UNREF(button);
HTML_DOM_STRING_UNREF(input);
HTML_DOM_STRING_UNREF(textarea);
#undef HTML_DOM_STRING_UNREF
@ -3269,6 +3275,9 @@ nserror html_init(void)
HTML_DOM_STRING_INTERN(circle);
HTML_DOM_STRING_INTERN(poly);
HTML_DOM_STRING_INTERN(polygon);
HTML_DOM_STRING_INTERN(button);
HTML_DOM_STRING_INTERN(input);
HTML_DOM_STRING_INTERN(textarea);
#undef HTML_DOM_STRING_INTERN

View File

@ -416,7 +416,6 @@ struct form_control *html_forms_get_control_for_node(struct form *forms, dom_nod
struct form_control *ctl = NULL;
dom_exception err;
dom_string *ds_name = NULL;
char *node_name = NULL;
if (forms == NULL)
return NULL;
@ -432,27 +431,26 @@ struct form_control *html_forms_get_control_for_node(struct form *forms, dom_nod
/* Step two, extract the node's name so we can construct a gadget. */
err = dom_element_get_tag_name(node, &ds_name);
if (err == DOM_NO_ERR && ds_name != NULL) {
node_name = strndup(dom_string_data(ds_name),
dom_string_byte_length(ds_name));
/* Step three, attempt to work out what gadget to make */
if (dom_string_caseless_isequal(ds_name,
html_dom_string_button)) {
ctl = parse_button_element(forms,
(dom_html_button_element *) node);
} else if (dom_string_caseless_isequal(ds_name,
html_dom_string_input)) {
ctl = parse_input_element(forms,
(dom_html_input_element *) node);
}
}
/* Step three, attempt to work out what gadget to make */
if (node_name && strcasecmp(node_name, "button") == 0)
ctl = parse_button_element(forms,
(dom_html_button_element *) node);
else if (node_name && strcasecmp(node_name, "input") == 0)
ctl = parse_input_element(forms,
(dom_html_input_element *) node);
/* If all else fails, fake gadget time */
if (ctl == NULL)
ctl = invent_fake_gadget(node);
if (ds_name != NULL)
dom_string_unref(ds_name);
if (node_name != NULL)
free(node_name);
return ctl;
}

View File

@ -173,6 +173,9 @@ extern struct dom_string *html_dom_string_coords;
extern struct dom_string *html_dom_string_circle;
extern struct dom_string *html_dom_string_poly;
extern struct dom_string *html_dom_string_polygon;
extern struct dom_string *html_dom_string_button;
extern struct dom_string *html_dom_string_input;
extern struct dom_string *html_dom_string_textarea;
extern struct dom_string *html_dom_string_text_javascript;
extern struct dom_string *html_dom_string_type;
extern struct dom_string *html_dom_string_src;