1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[tags] select

This commit is contained in:
Witold Filipczyk 2021-06-19 14:45:38 +02:00
parent 29e6d7971c
commit e3852637ff

View File

@ -3216,10 +3216,6 @@ do_tags_html_select(struct source_renderer *renderer, void *node, unsigned char
int preselect = -1; int preselect = -1;
int group = 0; int group = 0;
int i, max_width; int i, max_width;
dom_exception exc;
dom_html_options_collection *options_collection = NULL;
dom_string *id_value = NULL;
dom_string *name_value = NULL;
html_focusable(html_context, a); html_focusable(html_context, a);
init_menu(&lnk_menu); init_menu(&lnk_menu);
@ -3289,55 +3285,52 @@ abort:
goto end_parse; goto end_parse;
} }
#endif #endif
exc = dom_html_select_element_get_options((dom_html_select_element *)node, &options_collection); xmlpp::Element *select = node;
if (DOM_NO_ERR == exc && options_collection) { xmlpp::Node::NodeList *options = select->get_children();
if (options) {
int len = 0, i; int len = 0, i;
exc = dom_html_options_collection_get_length(options_collection, &len); len = options->size();
order = 0; order = 0;
for (i = 0; i < len; ++i) { auto it = options->begin();
void *option_node = NULL; auto end = options->end();
for (i = 0; i < len, it != end; ++i, ++it) {
xmlpp::Element *option_node = dynamic_cast<xmlpp::Element *>(*it);
exc = dom_html_options_collection_item(options_collection, i, &option_node); if (option_node) {
if (DOM_NO_ERR == exc && option_node) { std::string tag = option_node->get_name();
dom_html_element_type tag = 0;
exc = dom_html_element_get_tag_type((dom_html_element *)option_node, &tag); if ("option" == tag) {
if (DOM_HTML_ELEMENT_TYPE_OPTION == tag) {
bool disabled = false;
bool selected = false;
dom_string *value_value = NULL;
dom_string *label_value = NULL;
dom_string *text_value = NULL;
unsigned char *value = NULL; unsigned char *value = NULL;
unsigned char *label = NULL; unsigned char *label = NULL;
add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);
exc = dom_html_option_element_get_disabled((dom_html_option_element *)option_node, &disabled); std::string disabled = option_node->get_attribute_value("disabled");
if (disabled) { if (disabled == "disabled" || disabled == "true" || disabled == "1") {
continue; continue;
} }
exc = dom_html_option_element_get_selected((dom_html_option_element *)option_node, &selected); std::string selected_value = option_node->get_attribute_value("selected");
bool selected = (selected_value == "selected" || selected_value == "true" || selected_value == "1");
if (-1 == preselect && selected) { if (-1 == preselect && selected) {
preselect = order; preselect = order;
} }
exc = dom_html_option_element_get_value((dom_html_option_element *)option_node, &value_value); std::string value_value = option_node->get_attribute_value("value");
if (DOM_NO_ERR == exc && value_value) { if (value_value) {
value = memacpy(dom_string_data(value_value), dom_string_byte_length(value_value)); value = memacpy(value_value.c_str(), value_value.size());
dom_string_unref(value_value);
if (!mem_align_alloc(&values, i, i + 1, 0xFF)) { if (!mem_align_alloc(&values, i, i + 1, 0xFF)) {
goto abort; goto abort;
} }
values[order++] = value; values[order++] = value;
} }
exc = dom_html_option_element_get_label((dom_html_option_element *)option_node, &label_value);
if (DOM_NO_ERR == exc && label_value) { std::string label_value = option_node->get_attribute_value("label");
label = memacpy(dom_string_data(label_value), dom_string_byte_length(label_value)); if (label_value) {
label = memacpy(label_value.c_str(), label_value.size());
//fprintf(stderr, "label=%s\n", label); //fprintf(stderr, "label=%s\n", label);
dom_string_unref(label_value);
} }
if (label) { if (label) {
new_menu_item(&lnk_menu, label, order - 1, 0); new_menu_item(&lnk_menu, label, order - 1, 0);
@ -3347,10 +3340,23 @@ abort:
init_string(&orig_lbl); init_string(&orig_lbl);
nnmi = !!label; nnmi = !!label;
} }
exc = dom_html_option_element_get_text((dom_html_option_element *)option_node, &text_value);
if (DOM_NO_ERR == exc && text_value) { auto child_options = option_node->get_children();
add_bytes_to_string(&lbl, dom_string_data(text_value), dom_string_byte_length(text_value)); auto it2 = child_options->begin();
add_bytes_to_string(&orig_lbl, dom_string_data(text_value), dom_string_byte_length(text_value)); auto end2 = child_options->end();
std::string text_value;
for (;it2 != end2; ++it2) {
xmlpp::TextNode *text_node = dynamic_cast<xmlpp::TextNode>(*it2);
if (text_node) {
text_value = text_mode->get_content();
break;
}
}
if (text_value) {
add_bytes_to_string(&lbl, text_value.c_str(), text_value.size());
add_bytes_to_string(&orig_lbl, text_value.c_str(), text_value.size());
dom_string_unref(text_value); dom_string_unref(text_value);
} }
@ -3382,17 +3388,15 @@ abort:
// goto see; // goto see;
// } // }
} else if (DOM_HTML_ELEMENT_TYPE_OPTGROUP == tag) { } else if ("optgroup" == tag) {
dom_string *label_value = NULL;
unsigned char *label = NULL; unsigned char *label = NULL;
add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);
if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0; if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0;
exc = dom_html_opt_group_element_get_label((dom_html_opt_group_element *)option_node, &label_value); std::string label_value = option_node->get_attribute_value("label");
if (DOM_NO_ERR == exc && label_value) { if (label_value) {
label = memacpy(dom_string_data(label_value), dom_string_byte_length(label_value)); label = memacpy(label_value.c_str(), label_value.size());
dom_string_unref(label_value);
} }
if (!label) { if (!label) {
label = stracpy(""); label = stracpy("");
@ -3407,7 +3411,6 @@ abort:
if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0; if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0;
} }
} }
dom_html_options_collection_unref(options_collection);
} }
add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);
@ -3446,16 +3449,14 @@ abort:
goto abort; goto abort;
} }
exc = dom_html_element_get_id((dom_html_element *)node, &id_value); std::string id_value = select->get_attribute_value("id");
if (DOM_NO_ERR == exc && id_value) { if (id_value) {
fc->id = memacpy(dom_string_data(id_value), dom_string_byte_length(id_value)); fc->id = memacpy(id_value.c_str(), id_value.size());
dom_string_unref(id_value);
} }
exc = dom_html_select_element_get_name((dom_html_select_element *)node, &name_value); std::string name_value = select->get_attribute_value("name");
if (DOM_NO_ERR == exc && name_value) { if (name_value) {
fc->name = memacpy(dom_string_data(name_value), dom_string_byte_length(name_value)); fc->name = memacpy(name_value.c_str(), name_value.size());
dom_string_unref(name_value);
} }
// fc->id = get_attr_val(attr, "id", html_context->doc_cp); // fc->id = get_attr_val(attr, "id", html_context->doc_cp);
@ -3512,11 +3513,12 @@ tags_html_select(struct source_renderer *renderer, void *node, unsigned char *a,
unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{ {
bool multiple = false; bool multiple = false;
xmlpp::Element *select = node;
std::string multiple = select->get_attribute_value("multiple");
dom_exception exc = dom_html_select_element_get_multiple((dom_html_select_element *)node, &multiple);
renderer->html_context->skip_select = 1; renderer->html_context->skip_select = 1;
if (DOM_NO_ERR == exc && multiple) { if (multiple) {
do_tags_html_select_multiple(renderer, node, a, xxx3, xxx4, xxx5); do_tags_html_select_multiple(renderer, node, a, xxx3, xxx4, xxx5);
} else { } else {
do_tags_html_select(renderer, node, a, xxx3, xxx4, xxx5); do_tags_html_select(renderer, node, a, xxx3, xxx4, xxx5);