diff --git a/ext/dom/lexbor/lexbor/core/array.c b/ext/dom/lexbor/lexbor/core/array.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/array.h b/ext/dom/lexbor/lexbor/core/array.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/array_obj.c b/ext/dom/lexbor/lexbor/core/array_obj.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/array_obj.h b/ext/dom/lexbor/lexbor/core/array_obj.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/avl.c b/ext/dom/lexbor/lexbor/core/avl.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/avl.h b/ext/dom/lexbor/lexbor/core/avl.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/bst.c b/ext/dom/lexbor/lexbor/core/bst.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/bst.h b/ext/dom/lexbor/lexbor/core/bst.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/bst_map.c b/ext/dom/lexbor/lexbor/core/bst_map.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/bst_map.h b/ext/dom/lexbor/lexbor/core/bst_map.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/def.h b/ext/dom/lexbor/lexbor/core/def.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/diyfp.c b/ext/dom/lexbor/lexbor/core/diyfp.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/diyfp.h b/ext/dom/lexbor/lexbor/core/diyfp.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/dobject.c b/ext/dom/lexbor/lexbor/core/dobject.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/dobject.h b/ext/dom/lexbor/lexbor/core/dobject.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/dtoa.c b/ext/dom/lexbor/lexbor/core/dtoa.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/dtoa.h b/ext/dom/lexbor/lexbor/core/dtoa.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/fs.h b/ext/dom/lexbor/lexbor/core/fs.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/in.c b/ext/dom/lexbor/lexbor/core/in.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/in.h b/ext/dom/lexbor/lexbor/core/in.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/lexbor.h b/ext/dom/lexbor/lexbor/core/lexbor.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/mem.c b/ext/dom/lexbor/lexbor/core/mem.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/mem.h b/ext/dom/lexbor/lexbor/core/mem.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/mraw.c b/ext/dom/lexbor/lexbor/core/mraw.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/mraw.h b/ext/dom/lexbor/lexbor/core/mraw.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/plog.c b/ext/dom/lexbor/lexbor/core/plog.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/plog.h b/ext/dom/lexbor/lexbor/core/plog.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/sbst.h b/ext/dom/lexbor/lexbor/core/sbst.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/shs.c b/ext/dom/lexbor/lexbor/core/shs.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/shs.h b/ext/dom/lexbor/lexbor/core/shs.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/str.c b/ext/dom/lexbor/lexbor/core/str.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/str.h b/ext/dom/lexbor/lexbor/core/str.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/str_res.h b/ext/dom/lexbor/lexbor/core/str_res.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/strtod.c b/ext/dom/lexbor/lexbor/core/strtod.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/strtod.h b/ext/dom/lexbor/lexbor/core/strtod.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/types.h b/ext/dom/lexbor/lexbor/core/types.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/utils.c b/ext/dom/lexbor/lexbor/core/utils.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/core/utils.h b/ext/dom/lexbor/lexbor/core/utils.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/css/base.h b/ext/dom/lexbor/lexbor/css/base.h index 5a8db73e6aa35..2e403dccacae9 100644 --- a/ext/dom/lexbor/lexbor/css/base.h +++ b/ext/dom/lexbor/lexbor/css/base.h @@ -18,7 +18,7 @@ extern "C" { #define LXB_CSS_VERSION_MAJOR 1 -#define LXB_CSS_VERSION_MINOR 1 +#define LXB_CSS_VERSION_MINOR 2 #define LXB_CSS_VERSION_PATCH 0 #define LXB_CSS_VERSION_STRING \ diff --git a/ext/dom/lexbor/lexbor/css/selectors/base.h b/ext/dom/lexbor/lexbor/css/selectors/base.h index 0d2eb883c4cd0..17f56df256f33 100644 --- a/ext/dom/lexbor/lexbor/css/selectors/base.h +++ b/ext/dom/lexbor/lexbor/css/selectors/base.h @@ -16,7 +16,7 @@ extern "C" { #define LXB_CSS_SELECTORS_VERSION_MAJOR 1 -#define LXB_CSS_SELECTORS_VERSION_MINOR 0 +#define LXB_CSS_SELECTORS_VERSION_MINOR 1 #define LXB_CSS_SELECTORS_VERSION_PATCH 0 #define LXB_CSS_SELECTORS_VERSION_STRING \ diff --git a/ext/dom/lexbor/lexbor/css/syntax/tokenizer.h b/ext/dom/lexbor/lexbor/css/syntax/tokenizer.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/css/syntax/tokenizer/error.h b/ext/dom/lexbor/lexbor/css/syntax/tokenizer/error.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/base.h b/ext/dom/lexbor/lexbor/dom/base.h index b11bddb1e64fd..414be6a08a4c1 100644 --- a/ext/dom/lexbor/lexbor/dom/base.h +++ b/ext/dom/lexbor/lexbor/dom/base.h @@ -16,7 +16,7 @@ extern "C" { #define LXB_DOM_VERSION_MAJOR 1 -#define LXB_DOM_VERSION_MINOR 6 +#define LXB_DOM_VERSION_MINOR 7 #define LXB_DOM_VERSION_PATCH 0 #define LXB_DOM_VERSION_STRING \ diff --git a/ext/dom/lexbor/lexbor/dom/interface.h b/ext/dom/lexbor/lexbor/dom/interface.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/cdata_section.c b/ext/dom/lexbor/lexbor/dom/interfaces/cdata_section.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/cdata_section.h b/ext/dom/lexbor/lexbor/dom/interfaces/cdata_section.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/character_data.c b/ext/dom/lexbor/lexbor/dom/interfaces/character_data.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/character_data.h b/ext/dom/lexbor/lexbor/dom/interfaces/character_data.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/comment.c b/ext/dom/lexbor/lexbor/dom/interfaces/comment.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/comment.h b/ext/dom/lexbor/lexbor/dom/interfaces/comment.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document.c b/ext/dom/lexbor/lexbor/dom/interfaces/document.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document.h b/ext/dom/lexbor/lexbor/dom/interfaces/document.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document_fragment.c b/ext/dom/lexbor/lexbor/dom/interfaces/document_fragment.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document_fragment.h b/ext/dom/lexbor/lexbor/dom/interfaces/document_fragment.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document_type.c b/ext/dom/lexbor/lexbor/dom/interfaces/document_type.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/document_type.h b/ext/dom/lexbor/lexbor/dom/interfaces/document_type.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/element.c b/ext/dom/lexbor/lexbor/dom/interfaces/element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/element.h b/ext/dom/lexbor/lexbor/dom/interfaces/element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/event_target.c b/ext/dom/lexbor/lexbor/dom/interfaces/event_target.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/event_target.h b/ext/dom/lexbor/lexbor/dom/interfaces/event_target.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/node.c b/ext/dom/lexbor/lexbor/dom/interfaces/node.c old mode 100755 new mode 100644 index 4d1bc9493c209..702d1a802c16d --- a/ext/dom/lexbor/lexbor/dom/interfaces/node.c +++ b/ext/dom/lexbor/lexbor/dom/interfaces/node.c @@ -1239,7 +1239,7 @@ lxb_dom_node_text_content_set(lxb_dom_node_t *node, } bool -lxb_dom_node_is_empty(lxb_dom_node_t *root) +lxb_dom_node_is_empty(const lxb_dom_node_t *root) { lxb_char_t chr; lexbor_str_t *str; diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/node.h b/ext/dom/lexbor/lexbor/dom/interfaces/node.h old mode 100755 new mode 100644 index ff9c9246f940a..8ac218b4cabd8 --- a/ext/dom/lexbor/lexbor/dom/interfaces/node.h +++ b/ext/dom/lexbor/lexbor/dom/interfaces/node.h @@ -166,7 +166,7 @@ lxb_dom_node_text_content_set(lxb_dom_node_t *node, const lxb_char_t *content, size_t len); LXB_API bool -lxb_dom_node_is_empty(lxb_dom_node_t *root); +lxb_dom_node_is_empty(const lxb_dom_node_t *root); /* diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/processing_instruction.c b/ext/dom/lexbor/lexbor/dom/interfaces/processing_instruction.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/processing_instruction.h b/ext/dom/lexbor/lexbor/dom/interfaces/processing_instruction.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/shadow_root.c b/ext/dom/lexbor/lexbor/dom/interfaces/shadow_root.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/shadow_root.h b/ext/dom/lexbor/lexbor/dom/interfaces/shadow_root.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/text.c b/ext/dom/lexbor/lexbor/dom/interfaces/text.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/dom/interfaces/text.h b/ext/dom/lexbor/lexbor/dom/interfaces/text.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/base.h b/ext/dom/lexbor/lexbor/html/base.h old mode 100755 new mode 100644 index 66bac9b3c2ad3..2423857ae3327 --- a/ext/dom/lexbor/lexbor/html/base.h +++ b/ext/dom/lexbor/lexbor/html/base.h @@ -15,7 +15,7 @@ extern "C" { #define LXB_HTML_VERSION_MAJOR 2 -#define LXB_HTML_VERSION_MINOR 3 +#define LXB_HTML_VERSION_MINOR 5 #define LXB_HTML_VERSION_PATCH 0 #define LXB_HTML_VERSION_STRING LEXBOR_STRINGIZE(LXB_HTML_VERSION_MAJOR) "." \ diff --git a/ext/dom/lexbor/lexbor/html/interface.c b/ext/dom/lexbor/lexbor/html/interface.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interface.h b/ext/dom/lexbor/lexbor/html/interface.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/anchor_element.c b/ext/dom/lexbor/lexbor/html/interfaces/anchor_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/anchor_element.h b/ext/dom/lexbor/lexbor/html/interfaces/anchor_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/area_element.c b/ext/dom/lexbor/lexbor/html/interfaces/area_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/area_element.h b/ext/dom/lexbor/lexbor/html/interfaces/area_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/audio_element.c b/ext/dom/lexbor/lexbor/html/interfaces/audio_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/audio_element.h b/ext/dom/lexbor/lexbor/html/interfaces/audio_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/base_element.c b/ext/dom/lexbor/lexbor/html/interfaces/base_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/base_element.h b/ext/dom/lexbor/lexbor/html/interfaces/base_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/body_element.c b/ext/dom/lexbor/lexbor/html/interfaces/body_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/body_element.h b/ext/dom/lexbor/lexbor/html/interfaces/body_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/br_element.c b/ext/dom/lexbor/lexbor/html/interfaces/br_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/br_element.h b/ext/dom/lexbor/lexbor/html/interfaces/br_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/button_element.c b/ext/dom/lexbor/lexbor/html/interfaces/button_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/button_element.h b/ext/dom/lexbor/lexbor/html/interfaces/button_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/canvas_element.c b/ext/dom/lexbor/lexbor/html/interfaces/canvas_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/canvas_element.h b/ext/dom/lexbor/lexbor/html/interfaces/canvas_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/d_list_element.c b/ext/dom/lexbor/lexbor/html/interfaces/d_list_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/d_list_element.h b/ext/dom/lexbor/lexbor/html/interfaces/d_list_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/data_element.c b/ext/dom/lexbor/lexbor/html/interfaces/data_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/data_element.h b/ext/dom/lexbor/lexbor/html/interfaces/data_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/data_list_element.c b/ext/dom/lexbor/lexbor/html/interfaces/data_list_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/data_list_element.h b/ext/dom/lexbor/lexbor/html/interfaces/data_list_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/details_element.c b/ext/dom/lexbor/lexbor/html/interfaces/details_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/details_element.h b/ext/dom/lexbor/lexbor/html/interfaces/details_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/dialog_element.c b/ext/dom/lexbor/lexbor/html/interfaces/dialog_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/dialog_element.h b/ext/dom/lexbor/lexbor/html/interfaces/dialog_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/directory_element.c b/ext/dom/lexbor/lexbor/html/interfaces/directory_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/directory_element.h b/ext/dom/lexbor/lexbor/html/interfaces/directory_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/div_element.c b/ext/dom/lexbor/lexbor/html/interfaces/div_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/div_element.h b/ext/dom/lexbor/lexbor/html/interfaces/div_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/document.c b/ext/dom/lexbor/lexbor/html/interfaces/document.c old mode 100755 new mode 100644 index b4de5b8514a83..06a9456265afc --- a/ext/dom/lexbor/lexbor/html/interfaces/document.c +++ b/ext/dom/lexbor/lexbor/html/interfaces/document.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Alexander Borisov + * Copyright (C) 2018-2024 Alexander Borisov * * Author: Alexander Borisov */ @@ -631,6 +631,12 @@ lxb_html_document_style_remove_by_rule_cb(lxb_dom_node_t *node, lxb_css_rule_style_t *style = ctx; lxb_html_document_remove_ctx_t context; + /* FIXME: we don't have support for anything other than HTML. */ + + if (node->ns != LXB_NS_HTML) { + return LXB_STATUS_OK; + } + el = lxb_html_interface_element(node); if (el->style == NULL) { @@ -654,6 +660,10 @@ lxb_html_document_style_remove_avl_cb(lexbor_avl_t *avl, lxb_html_document_remove_ctx_t *context = ctx; lxb_html_style_node_t *style = (lxb_html_style_node_t *) node; + if (context->list == NULL) { + return LXB_STATUS_OK; + } + lxb_html_element_style_remove_by_list(context->doc, root, style, context->list); return LXB_STATUS_OK; @@ -666,8 +676,10 @@ lxb_html_document_style_attach_by_element(lxb_html_document_t *document, { lxb_html_document_css_t *css = &document->css; - return lxb_selectors_find_reverse(css->selectors, lxb_dom_interface_node(element), - style->selector, lxb_html_document_style_cb, style); + return lxb_selectors_match_node(css->selectors, + lxb_dom_interface_node(element), + style->selector, + lxb_html_document_style_cb, style); } static lxb_status_t @@ -682,6 +694,12 @@ lxb_html_document_style_cb(lxb_dom_node_t *node, return LXB_STATUS_OK; } + /* Valid behavior when there are no declarations in the style. */ + + if (style->declarations == NULL) { + return LXB_STATUS_OK; + } + return lxb_html_element_style_list_append(lxb_html_interface_element(node), style->declarations, spec); } @@ -811,13 +829,15 @@ lxb_html_document_parse_fragment_chunk_begin(lxb_html_document_t *document, lxb_dom_element_t *element) { lxb_status_t status; - lxb_html_parser_t *parser = document->dom_document.parser; + lxb_html_parser_t *parser; status = lxb_html_document_parser_prepare(document); if (status != LXB_STATUS_OK) { return status; } + parser = document->dom_document.parser; + return lxb_html_parse_fragment_chunk_begin(parser, document, element->node.local_name, element->node.ns); diff --git a/ext/dom/lexbor/lexbor/html/interfaces/document.h b/ext/dom/lexbor/lexbor/html/interfaces/document.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/element.c b/ext/dom/lexbor/lexbor/html/interfaces/element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/element.h b/ext/dom/lexbor/lexbor/html/interfaces/element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/embed_element.c b/ext/dom/lexbor/lexbor/html/interfaces/embed_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/embed_element.h b/ext/dom/lexbor/lexbor/html/interfaces/embed_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/field_set_element.c b/ext/dom/lexbor/lexbor/html/interfaces/field_set_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/field_set_element.h b/ext/dom/lexbor/lexbor/html/interfaces/field_set_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/font_element.c b/ext/dom/lexbor/lexbor/html/interfaces/font_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/font_element.h b/ext/dom/lexbor/lexbor/html/interfaces/font_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/form_element.c b/ext/dom/lexbor/lexbor/html/interfaces/form_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/form_element.h b/ext/dom/lexbor/lexbor/html/interfaces/form_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/frame_element.c b/ext/dom/lexbor/lexbor/html/interfaces/frame_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/frame_element.h b/ext/dom/lexbor/lexbor/html/interfaces/frame_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/frame_set_element.c b/ext/dom/lexbor/lexbor/html/interfaces/frame_set_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/frame_set_element.h b/ext/dom/lexbor/lexbor/html/interfaces/frame_set_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/head_element.c b/ext/dom/lexbor/lexbor/html/interfaces/head_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/head_element.h b/ext/dom/lexbor/lexbor/html/interfaces/head_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/heading_element.c b/ext/dom/lexbor/lexbor/html/interfaces/heading_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/heading_element.h b/ext/dom/lexbor/lexbor/html/interfaces/heading_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/hr_element.c b/ext/dom/lexbor/lexbor/html/interfaces/hr_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/hr_element.h b/ext/dom/lexbor/lexbor/html/interfaces/hr_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/html_element.c b/ext/dom/lexbor/lexbor/html/interfaces/html_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/html_element.h b/ext/dom/lexbor/lexbor/html/interfaces/html_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/iframe_element.c b/ext/dom/lexbor/lexbor/html/interfaces/iframe_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/iframe_element.h b/ext/dom/lexbor/lexbor/html/interfaces/iframe_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/image_element.c b/ext/dom/lexbor/lexbor/html/interfaces/image_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/image_element.h b/ext/dom/lexbor/lexbor/html/interfaces/image_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/input_element.c b/ext/dom/lexbor/lexbor/html/interfaces/input_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/input_element.h b/ext/dom/lexbor/lexbor/html/interfaces/input_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/label_element.c b/ext/dom/lexbor/lexbor/html/interfaces/label_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/label_element.h b/ext/dom/lexbor/lexbor/html/interfaces/label_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/legend_element.c b/ext/dom/lexbor/lexbor/html/interfaces/legend_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/legend_element.h b/ext/dom/lexbor/lexbor/html/interfaces/legend_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/li_element.c b/ext/dom/lexbor/lexbor/html/interfaces/li_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/li_element.h b/ext/dom/lexbor/lexbor/html/interfaces/li_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/link_element.c b/ext/dom/lexbor/lexbor/html/interfaces/link_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/link_element.h b/ext/dom/lexbor/lexbor/html/interfaces/link_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/map_element.c b/ext/dom/lexbor/lexbor/html/interfaces/map_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/map_element.h b/ext/dom/lexbor/lexbor/html/interfaces/map_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/marquee_element.c b/ext/dom/lexbor/lexbor/html/interfaces/marquee_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/marquee_element.h b/ext/dom/lexbor/lexbor/html/interfaces/marquee_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/media_element.c b/ext/dom/lexbor/lexbor/html/interfaces/media_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/media_element.h b/ext/dom/lexbor/lexbor/html/interfaces/media_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/menu_element.c b/ext/dom/lexbor/lexbor/html/interfaces/menu_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/menu_element.h b/ext/dom/lexbor/lexbor/html/interfaces/menu_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/meta_element.c b/ext/dom/lexbor/lexbor/html/interfaces/meta_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/meta_element.h b/ext/dom/lexbor/lexbor/html/interfaces/meta_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/meter_element.c b/ext/dom/lexbor/lexbor/html/interfaces/meter_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/meter_element.h b/ext/dom/lexbor/lexbor/html/interfaces/meter_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/mod_element.c b/ext/dom/lexbor/lexbor/html/interfaces/mod_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/mod_element.h b/ext/dom/lexbor/lexbor/html/interfaces/mod_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/o_list_element.c b/ext/dom/lexbor/lexbor/html/interfaces/o_list_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/o_list_element.h b/ext/dom/lexbor/lexbor/html/interfaces/o_list_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/object_element.c b/ext/dom/lexbor/lexbor/html/interfaces/object_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/object_element.h b/ext/dom/lexbor/lexbor/html/interfaces/object_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/opt_group_element.c b/ext/dom/lexbor/lexbor/html/interfaces/opt_group_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/opt_group_element.h b/ext/dom/lexbor/lexbor/html/interfaces/opt_group_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/option_element.c b/ext/dom/lexbor/lexbor/html/interfaces/option_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/option_element.h b/ext/dom/lexbor/lexbor/html/interfaces/option_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/output_element.c b/ext/dom/lexbor/lexbor/html/interfaces/output_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/output_element.h b/ext/dom/lexbor/lexbor/html/interfaces/output_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/paragraph_element.c b/ext/dom/lexbor/lexbor/html/interfaces/paragraph_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/paragraph_element.h b/ext/dom/lexbor/lexbor/html/interfaces/paragraph_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/param_element.c b/ext/dom/lexbor/lexbor/html/interfaces/param_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/param_element.h b/ext/dom/lexbor/lexbor/html/interfaces/param_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/picture_element.c b/ext/dom/lexbor/lexbor/html/interfaces/picture_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/picture_element.h b/ext/dom/lexbor/lexbor/html/interfaces/picture_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/pre_element.c b/ext/dom/lexbor/lexbor/html/interfaces/pre_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/pre_element.h b/ext/dom/lexbor/lexbor/html/interfaces/pre_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/progress_element.c b/ext/dom/lexbor/lexbor/html/interfaces/progress_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/progress_element.h b/ext/dom/lexbor/lexbor/html/interfaces/progress_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/quote_element.c b/ext/dom/lexbor/lexbor/html/interfaces/quote_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/quote_element.h b/ext/dom/lexbor/lexbor/html/interfaces/quote_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/script_element.c b/ext/dom/lexbor/lexbor/html/interfaces/script_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/script_element.h b/ext/dom/lexbor/lexbor/html/interfaces/script_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/select_element.c b/ext/dom/lexbor/lexbor/html/interfaces/select_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/select_element.h b/ext/dom/lexbor/lexbor/html/interfaces/select_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/slot_element.c b/ext/dom/lexbor/lexbor/html/interfaces/slot_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/slot_element.h b/ext/dom/lexbor/lexbor/html/interfaces/slot_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/source_element.c b/ext/dom/lexbor/lexbor/html/interfaces/source_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/source_element.h b/ext/dom/lexbor/lexbor/html/interfaces/source_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/span_element.c b/ext/dom/lexbor/lexbor/html/interfaces/span_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/span_element.h b/ext/dom/lexbor/lexbor/html/interfaces/span_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/style_element.c b/ext/dom/lexbor/lexbor/html/interfaces/style_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/style_element.h b/ext/dom/lexbor/lexbor/html/interfaces/style_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_caption_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_caption_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_caption_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_caption_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_cell_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_cell_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_cell_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_cell_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_col_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_col_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_col_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_col_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_row_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_row_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_row_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_row_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_section_element.c b/ext/dom/lexbor/lexbor/html/interfaces/table_section_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/table_section_element.h b/ext/dom/lexbor/lexbor/html/interfaces/table_section_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/template_element.c b/ext/dom/lexbor/lexbor/html/interfaces/template_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/template_element.h b/ext/dom/lexbor/lexbor/html/interfaces/template_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/text_area_element.c b/ext/dom/lexbor/lexbor/html/interfaces/text_area_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/text_area_element.h b/ext/dom/lexbor/lexbor/html/interfaces/text_area_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/time_element.c b/ext/dom/lexbor/lexbor/html/interfaces/time_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/time_element.h b/ext/dom/lexbor/lexbor/html/interfaces/time_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/title_element.c b/ext/dom/lexbor/lexbor/html/interfaces/title_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/title_element.h b/ext/dom/lexbor/lexbor/html/interfaces/title_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/track_element.c b/ext/dom/lexbor/lexbor/html/interfaces/track_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/track_element.h b/ext/dom/lexbor/lexbor/html/interfaces/track_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/u_list_element.c b/ext/dom/lexbor/lexbor/html/interfaces/u_list_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/u_list_element.h b/ext/dom/lexbor/lexbor/html/interfaces/u_list_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/unknown_element.c b/ext/dom/lexbor/lexbor/html/interfaces/unknown_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/unknown_element.h b/ext/dom/lexbor/lexbor/html/interfaces/unknown_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/video_element.c b/ext/dom/lexbor/lexbor/html/interfaces/video_element.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/video_element.h b/ext/dom/lexbor/lexbor/html/interfaces/video_element.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/window.c b/ext/dom/lexbor/lexbor/html/interfaces/window.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/interfaces/window.h b/ext/dom/lexbor/lexbor/html/interfaces/window.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/parser.c b/ext/dom/lexbor/lexbor/html/parser.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/parser.h b/ext/dom/lexbor/lexbor/html/parser.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/serialize.h b/ext/dom/lexbor/lexbor/html/serialize.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tag.h b/ext/dom/lexbor/lexbor/html/tag.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/token.c b/ext/dom/lexbor/lexbor/html/token.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/token.h b/ext/dom/lexbor/lexbor/html/token.h old mode 100755 new mode 100644 index eda8abcf5b994..0b7f4fdd04e3c --- a/ext/dom/lexbor/lexbor/html/token.h +++ b/ext/dom/lexbor/lexbor/html/token.h @@ -33,8 +33,8 @@ enum lxb_html_token_type { typedef struct { const lxb_char_t *begin; const lxb_char_t *end; - size_t line; - size_t column; + size_t line; + size_t column; const lxb_char_t *text_start; const lxb_char_t *text_end; diff --git a/ext/dom/lexbor/lexbor/html/token_attr.c b/ext/dom/lexbor/lexbor/html/token_attr.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/token_attr.h b/ext/dom/lexbor/lexbor/html/token_attr.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer.c b/ext/dom/lexbor/lexbor/html/tokenizer.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer.h b/ext/dom/lexbor/lexbor/html/tokenizer.h old mode 100755 new mode 100644 index 0be1c73408520..74bb55ef0fd78 --- a/ext/dom/lexbor/lexbor/html/tokenizer.h +++ b/ext/dom/lexbor/lexbor/html/tokenizer.h @@ -73,8 +73,8 @@ struct lxb_html_tokenizer { const lxb_char_t *end; const lxb_char_t *begin; const lxb_char_t *last; - size_t current_line; - size_t current_column; + size_t current_line; + size_t current_column; /* Entities */ const lexbor_sbst_entry_static_t *entity; diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/error.c b/ext/dom/lexbor/lexbor/html/tokenizer/error.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/error.h b/ext/dom/lexbor/lexbor/html/tokenizer/error.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state.c b/ext/dom/lexbor/lexbor/html/tokenizer/state.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state.h b/ext/dom/lexbor/lexbor/html/tokenizer/state.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_comment.c b/ext/dom/lexbor/lexbor/html/tokenizer/state_comment.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_comment.h b/ext/dom/lexbor/lexbor/html/tokenizer/state_comment.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_doctype.c b/ext/dom/lexbor/lexbor/html/tokenizer/state_doctype.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_doctype.h b/ext/dom/lexbor/lexbor/html/tokenizer/state_doctype.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_rawtext.c b/ext/dom/lexbor/lexbor/html/tokenizer/state_rawtext.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_rawtext.h b/ext/dom/lexbor/lexbor/html/tokenizer/state_rawtext.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_rcdata.c b/ext/dom/lexbor/lexbor/html/tokenizer/state_rcdata.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_rcdata.h b/ext/dom/lexbor/lexbor/html/tokenizer/state_rcdata.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_script.c b/ext/dom/lexbor/lexbor/html/tokenizer/state_script.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tokenizer/state_script.h b/ext/dom/lexbor/lexbor/html/tokenizer/state_script.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree.c b/ext/dom/lexbor/lexbor/html/tree.c old mode 100755 new mode 100644 index bdec6a5897ec3..0b345dff79879 --- a/ext/dom/lexbor/lexbor/html/tree.c +++ b/ext/dom/lexbor/lexbor/html/tree.c @@ -1582,7 +1582,7 @@ lxb_html_tree_adoption_agency_algorithm(lxb_html_tree_t *tree, /* State 14.9 */ if (last->parent != NULL) { - lxb_dom_node_remove(last); + lxb_dom_node_remove_wo_events(last); } lxb_dom_node_insert_child_wo_events(node, last); @@ -1592,7 +1592,7 @@ lxb_html_tree_adoption_agency_algorithm(lxb_html_tree_t *tree, } if (last->parent != NULL) { - lxb_dom_node_remove(last); + lxb_dom_node_remove_wo_events(last); } /* State 15 */ @@ -1630,7 +1630,7 @@ lxb_html_tree_adoption_agency_algorithm(lxb_html_tree_t *tree, while (node != NULL) { next = node->next; - lxb_dom_node_remove(node); + lxb_dom_node_remove_wo_events(node); lxb_dom_node_insert_child_wo_events(lxb_dom_interface_node(element), node); node = next; diff --git a/ext/dom/lexbor/lexbor/html/tree.h b/ext/dom/lexbor/lexbor/html/tree.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/active_formatting.c b/ext/dom/lexbor/lexbor/html/tree/active_formatting.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/active_formatting.h b/ext/dom/lexbor/lexbor/html/tree/active_formatting.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/error.c b/ext/dom/lexbor/lexbor/html/tree/error.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/error.h b/ext/dom/lexbor/lexbor/html/tree/error.h old mode 100755 new mode 100644 index 685dd400d4033..ed1859f355a67 --- a/ext/dom/lexbor/lexbor/html/tree/error.h +++ b/ext/dom/lexbor/lexbor/html/tree/error.h @@ -97,9 +97,9 @@ lxb_html_tree_error_id_t; typedef struct { lxb_html_tree_error_id_t id; - size_t line; - size_t column; - size_t length; + size_t line; + size_t column; + size_t length; } lxb_html_tree_error_t; diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode.h b/ext/dom/lexbor/lexbor/html/tree/insertion_mode.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_after_body.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_after_body.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_after_frameset.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_after_frameset.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_body.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_body.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_frameset.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_frameset.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_head.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/after_head.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/before_head.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/before_head.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/before_html.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/before_html.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/foreign_content.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/foreign_content.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_body.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_body.c old mode 100755 new mode 100644 index 2f160543cd16d..32cc40476948f --- a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_body.c +++ b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_body.c @@ -1320,8 +1320,6 @@ lxb_html_tree_insertion_mode_in_body_textarea(lxb_html_tree_t *tree, lxb_html_tokenizer_state_set(tree->tkz_ref, lxb_html_tokenizer_state_rcdata_before); - tree->original_mode = tree->mode; - tree->frameset_ok = false; tree->original_mode = tree->mode; diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_caption.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_caption.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_cell.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_cell.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_column_group.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_column_group.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_frameset.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_frameset.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_head.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_head.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_head_noscript.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_head_noscript.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_row.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_row.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_select.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_select.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_select_in_table.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_select_in_table.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table_body.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table_body.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table_text.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_table_text.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_template.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/in_template.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/initial.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/initial.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/insertion_mode/text.c b/ext/dom/lexbor/lexbor/html/tree/insertion_mode/text.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/open_elements.c b/ext/dom/lexbor/lexbor/html/tree/open_elements.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/open_elements.h b/ext/dom/lexbor/lexbor/html/tree/open_elements.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/template_insertion.c b/ext/dom/lexbor/lexbor/html/tree/template_insertion.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree/template_insertion.h b/ext/dom/lexbor/lexbor/html/tree/template_insertion.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/html/tree_res.h b/ext/dom/lexbor/lexbor/html/tree_res.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/ns/ns.c b/ext/dom/lexbor/lexbor/ns/ns.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/ns/ns.h b/ext/dom/lexbor/lexbor/ns/ns.h old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/ports/posix/lexbor/core/memory.c b/ext/dom/lexbor/lexbor/ports/posix/lexbor/core/memory.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/ports/windows_nt/lexbor/core/memory.c b/ext/dom/lexbor/lexbor/ports/windows_nt/lexbor/core/memory.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/selectors/base.h b/ext/dom/lexbor/lexbor/selectors/base.h index c3994d9adf2ed..64af0261a75c3 100644 --- a/ext/dom/lexbor/lexbor/selectors/base.h +++ b/ext/dom/lexbor/lexbor/selectors/base.h @@ -15,7 +15,7 @@ extern "C" { #define LXB_SELECTORS_VERSION_MAJOR 0 -#define LXB_SELECTORS_VERSION_MINOR 2 +#define LXB_SELECTORS_VERSION_MINOR 3 #define LXB_SELECTORS_VERSION_PATCH 0 #define LXB_SELECTORS_VERSION_STRING LEXBOR_STRINGIZE(LXB_SELECTORS_VERSION_MAJOR) "." \ diff --git a/ext/dom/lexbor/lexbor/selectors/selectors.c b/ext/dom/lexbor/lexbor/selectors/selectors.c index ec2d8f4083cef..45db265302a23 100644 --- a/ext/dom/lexbor/lexbor/selectors/selectors.c +++ b/ext/dom/lexbor/lexbor/selectors/selectors.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Alexander Borisov + * Copyright (C) 2021-2024 Alexander Borisov * * Author: Alexander Borisov */ @@ -9,88 +9,105 @@ #include +static lxb_status_t +lxb_selectors_state_tree(lxb_selectors_t *selectors, lxb_dom_node_t *root, + const lxb_css_selector_list_t *list); + +static lxb_status_t +lxb_selectors_state_run(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_list_t *list); + static lxb_selectors_entry_t * -lxb_selectors_find_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx); - -static lxb_selectors_entry_child_t * -lxb_selectors_next(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_child_t *child, - lxb_css_selector_list_t *list, - lxb_selectors_cb_f cb, void *ctx); - -static lxb_selectors_entry_child_t * -lxb_selectors_current(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_child_t *child, - lxb_css_selector_list_t *list, - lxb_selectors_cb_f cb, void *ctx); +lxb_selectors_state_find(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); static lxb_selectors_entry_t * -lxb_selectors_next_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx); +lxb_selectors_state_find_check(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_t *selector, + lxb_selectors_entry_t *entry); -static lxb_status_t -lxb_selectors_find_by(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_dom_node_t *root, lxb_dom_node_t *node, - lxb_css_selector_t *selector, lxb_selectors_cb_f cb, void *ctx); +static lxb_selectors_entry_t * +lxb_selectors_state_pseudo_class_function(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); -static lxb_status_t -lxb_selectors_find_by_reverse(lxb_selectors_t *selectors, lxb_dom_node_t *node, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx); +static lxb_dom_node_t * +lxb_selectors_next_node(lxb_selectors_nested_t *main); + +static lxb_dom_node_t * +lxb_selectors_state_has_relative(lxb_dom_node_t *node, + const lxb_css_selector_t *selector); + +static lxb_selectors_entry_t * +lxb_selectors_state_after_find_has(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); + +static lxb_selectors_entry_t * +lxb_selectors_state_after_find(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); + +static lxb_selectors_entry_t * +lxb_selectors_state_after_nth_child(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); static bool lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *node); + const lxb_css_selector_t *selector, lxb_dom_node_t *node); + +static bool +lxb_selectors_match_element(const lxb_css_selector_t *selector, + lxb_dom_node_t *node, lxb_selectors_entry_t *entry); + +static bool +lxb_selectors_match_id(const lxb_css_selector_t *selector, lxb_dom_node_t *node); static bool lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src, bool quirks); static bool -lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node); +lxb_selectors_match_attribute(const lxb_css_selector_t *selector, + lxb_dom_node_t *node, lxb_selectors_entry_t *entry); static bool -lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, - lxb_dom_node_t *node, - lxb_selectors_entry_t *entry); +lxb_selectors_pseudo_class(const lxb_css_selector_t *selector, + const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_element(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, - lxb_dom_node_t *node); +lxb_selectors_pseudo_class_function(const lxb_css_selector_t *selector, + lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_element_function(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, - lxb_dom_node_t *node); +lxb_selectors_pseudo_element(const lxb_css_selector_t *selector, + const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_disabled(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_disabled(const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_first_child(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_first_child(const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_first_of_type(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_first_of_type(const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_last_child(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_last_child(const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_last_of_type(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_last_of_type(const lxb_dom_node_t *node); static bool -lxb_selectors_pseudo_class_read_write(lxb_dom_node_t *node); +lxb_selectors_pseudo_class_read_write(const lxb_dom_node_t *node); + +static bool +lxb_selectors_anb_calc(lxb_css_selector_anb_of_t *anb, size_t index); + +static lxb_status_t +lxb_selectors_cb_ok(lxb_dom_node_t *node, + lxb_css_selector_specificity_t spec, void *ctx); static lxb_status_t -lxb_selectors_first_match(lxb_dom_node_t *node, - lxb_css_selector_specificity_t spec, void *ctx); +lxb_selectors_cb_not(lxb_dom_node_t *node, + lxb_css_selector_specificity_t spec, void *ctx); lxb_selectors_t * @@ -115,13 +132,15 @@ lxb_selectors_init(lxb_selectors_t *selectors) return status; } - selectors->chld = lexbor_dobject_create(); - status = lexbor_dobject_init(selectors->chld, - 32, sizeof(lxb_selectors_entry_child_t)); + selectors->nested = lexbor_dobject_create(); + status = lexbor_dobject_init(selectors->nested, + 64, sizeof(lxb_selectors_nested_t)); if (status != LXB_STATUS_OK) { return status; } + selectors->options = LXB_SELECTORS_OPT_DEFAULT; + return LXB_STATUS_OK; } @@ -129,7 +148,7 @@ void lxb_selectors_clean(lxb_selectors_t *selectors) { lexbor_dobject_clean(selectors->objs); - lexbor_dobject_clean(selectors->chld); + lexbor_dobject_clean(selectors->nested); } lxb_selectors_t * @@ -140,7 +159,7 @@ lxb_selectors_destroy(lxb_selectors_t *selectors, bool self_destroy) } selectors->objs = lexbor_dobject_destroy(selectors->objs, true); - selectors->chld = lexbor_dobject_destroy(selectors->chld, true); + selectors->nested = lexbor_dobject_destroy(selectors->nested, true); if (self_destroy) { return lexbor_free(selectors); @@ -149,78 +168,17 @@ lxb_selectors_destroy(lxb_selectors_t *selectors, bool self_destroy) return selectors; } - lxb_inline lxb_dom_node_t * -lxb_selectors_descendant(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *root, +lxb_selectors_descendant(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry, + const lxb_css_selector_t *selector, lxb_dom_node_t *node) -{ - do { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) - { - return node; - } - - if (node->first_child != NULL) { - node = node->first_child; - } - else { - while (node != root && node->next == NULL) { - node = node->parent; - } - - if (node == root) { - return NULL; - } - - node = node->next; - } - } - while (true); -} - -lxb_inline lxb_dom_node_t * -lxb_selectors_descendant_next(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *root, - lxb_dom_node_t *node) -{ - do { - if (node->first_child != NULL) { - node = node->first_child; - } - else { - while (node != root && node->next == NULL) { - node = node->parent; - } - - if (node == root) { - return NULL; - } - - node = node->next; - } - - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) - { - return node; - } - } - while (true); -} - -lxb_inline lxb_dom_node_t * -lxb_selectors_descendant_reverse(lxb_selectors_t *selectors, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_dom_node_t *node) { node = node->parent; while (node != NULL) { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) + if (node->type == LXB_DOM_NODE_TYPE_ELEMENT + && lxb_selectors_match(selectors, entry, selector, node)) { return node; } @@ -228,12 +186,12 @@ lxb_selectors_descendant_reverse(lxb_selectors_t *selectors, node = node->parent; } - return false; + return NULL; } lxb_inline lxb_dom_node_t * lxb_selectors_close(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *node) + const lxb_css_selector_t *selector, lxb_dom_node_t *node) { if (lxb_selectors_match(selectors, entry, selector, node)) { return node; @@ -244,39 +202,14 @@ lxb_selectors_close(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, lxb_inline lxb_dom_node_t * lxb_selectors_child(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *root, - lxb_dom_node_t *node) -{ - node = root->first_child; - - while (node != NULL) { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) - { - return node; - } - - node = node->next; - } - - return NULL; -} - -lxb_inline lxb_dom_node_t * -lxb_selectors_child_next(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *root, - lxb_dom_node_t *node) + const lxb_css_selector_t *selector, lxb_dom_node_t *root) { - node = node->next; - - while (node != NULL) { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) - { - return node; - } + root = root->parent; - node = node->next; + if (root != NULL && root->type == LXB_DOM_NODE_TYPE_ELEMENT + && lxb_selectors_match(selectors, entry, selector, root)) + { + return root; } return NULL; @@ -284,30 +217,7 @@ lxb_selectors_child_next(lxb_selectors_t *selectors, lxb_selectors_entry_t *entr lxb_inline lxb_dom_node_t * lxb_selectors_sibling(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *node) -{ - node = node->next; - - while (node != NULL) { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) { - if (lxb_selectors_match(selectors, entry, selector, node)) { - return node; - } - - return NULL; - } - - node = node->next; - } - - return NULL; -} - -lxb_inline lxb_dom_node_t * -lxb_selectors_sibling_reverse(lxb_selectors_t *selectors, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_dom_node_t *node) + const lxb_css_selector_t *selector, lxb_dom_node_t *node) { node = node->prev; @@ -328,9 +238,9 @@ lxb_selectors_sibling_reverse(lxb_selectors_t *selectors, lxb_inline lxb_dom_node_t * lxb_selectors_following(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *node) + const lxb_css_selector_t *selector, lxb_dom_node_t *node) { - node = node->next; + node = node->prev; while (node != NULL) { if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && @@ -339,298 +249,269 @@ lxb_selectors_following(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry return node; } - node = node->next; + node = node->prev; } return NULL; } -lxb_inline lxb_dom_node_t * -lxb_selectors_following_reverse(lxb_selectors_t *selectors, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_dom_node_t *node) +lxb_status_t +lxb_selectors_find(lxb_selectors_t *selectors, lxb_dom_node_t *root, + const lxb_css_selector_list_t *list, + lxb_selectors_cb_f cb, void *ctx) { - node = node->prev; - - while (node != NULL) { - if (node->type == LXB_DOM_NODE_TYPE_ELEMENT && - lxb_selectors_match(selectors, entry, selector, node)) - { - return node; - } + lxb_selectors_entry_t *entry; + lxb_selectors_nested_t nested; - node = node->prev; + entry = lexbor_dobject_calloc(selectors->objs); + if (entry == NULL) { + return LXB_STATUS_ERROR_MEMORY_ALLOCATION; } - return NULL; + entry->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; + entry->selector = list->last; + + nested.parent = NULL; + nested.entry = entry; + nested.cb = cb; + nested.ctx = ctx; + + selectors->current = &nested; + selectors->status = LXB_STATUS_OK; + + return lxb_selectors_state_tree(selectors, root, list); } -lxb_inline bool -lxb_selectors_anb_calc(lxb_css_selector_anb_of_t *anb, size_t index) +lxb_status_t +lxb_selectors_match_node(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_list_t *list, + lxb_selectors_cb_f cb, void *ctx) { - double num; + lxb_status_t status; + lxb_selectors_entry_t *entry; + lxb_selectors_nested_t nested; - if (anb->anb.a == 0) { - if (anb->anb.b >= 0 && (size_t) anb->anb.b == index) { - return true; - } + if (node->type != LXB_DOM_NODE_TYPE_ELEMENT) { + return LXB_STATUS_OK; } - else { - num = ((double) index - (double) anb->anb.b) / (double) anb->anb.a; - if (num >= 0.0f && (num - trunc(num)) == 0.0f) { - return true; - } + entry = lexbor_dobject_calloc(selectors->objs); + if (entry == NULL) { + return LXB_STATUS_ERROR_MEMORY_ALLOCATION; } - return false; -} + entry->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; + entry->selector = list->last; -lxb_status_t -lxb_selectors_find(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_css_selector_list_t *list, lxb_selectors_cb_f cb, void *ctx) -{ - lxb_selectors_entry_t *child; + nested.parent = NULL; + nested.entry = entry; + nested.cb = cb; + nested.ctx = ctx; - while (list != NULL) { - child = lxb_selectors_next_by_selector(selectors, root, NULL, - list->first, cb, ctx); - if (child == NULL) { - return LXB_STATUS_ERROR; - } + selectors->current = &nested; + selectors->status = LXB_STATUS_OK; - list = list->next; - } + status = lxb_selectors_state_run(selectors, node, list); lxb_selectors_clean(selectors); - return LXB_STATUS_OK; + return status; } lxb_status_t lxb_selectors_find_reverse(lxb_selectors_t *selectors, lxb_dom_node_t *root, lxb_css_selector_list_t *list, lxb_selectors_cb_f cb, void *ctx) +{ + return lxb_selectors_find(selectors, root, list, cb, ctx); +} + +static lxb_status_t +lxb_selectors_state_tree(lxb_selectors_t *selectors, lxb_dom_node_t *root, + const lxb_css_selector_list_t *list) { lxb_status_t status; + lxb_dom_node_t *node; - while (list != NULL) { - status = lxb_selectors_find_by_reverse(selectors, root, - list->last, cb, ctx); - if (status != LXB_STATUS_OK) { - return status; + if (selectors->options & LXB_SELECTORS_OPT_MATCH_ROOT) { + node = root; + + if (node->type == LXB_DOM_NODE_TYPE_DOCUMENT) { + node = root->first_child; } + } + else { + node = root->first_child; + } - list = list->next; + if (node == NULL) { + goto out; } - lxb_selectors_clean(selectors); + do { + if (node->type != LXB_DOM_NODE_TYPE_ELEMENT) { + goto next; + } - return LXB_STATUS_OK; -} + status = lxb_selectors_state_run(selectors, node, list); + if (status != LXB_STATUS_OK) { + if (status == LXB_STATUS_STOP) { + break; + } -static lxb_selectors_entry_t * -lxb_selectors_find_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx) -{ - lxb_status_t status; - lxb_dom_node_t *node = root, *base = root; + lxb_selectors_clean(selectors); - if (entry == NULL) { - entry = lexbor_dobject_calloc(selectors->objs); - if (entry == NULL) { - return NULL; + return status; } - entry->selector = selector; - } - - switch (selector->combinator) { - case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: - node = lxb_selectors_descendant(selectors, entry, selector, - base, node); - break; - - case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: - node = lxb_selectors_close(selectors, entry, selector, node); - break; + if (node->first_child != NULL) { + node = node->first_child; + } + else { - case LXB_CSS_SELECTOR_COMBINATOR_CHILD: - node = lxb_selectors_child(selectors, entry, selector, base, node); - break; + next: - case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: - node = lxb_selectors_sibling(selectors, entry, selector, base); - break; + while (node != root && node->next == NULL) { + node = node->parent; + } - case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: - node = lxb_selectors_following(selectors, entry, selector, node); - break; + if (node == root) { + break; + } - case LXB_CSS_SELECTOR_COMBINATOR_CELL: - default: - return NULL; + node = node->next; + } } + while (true); - status = lxb_selectors_find_by(selectors, entry, root, node, selector, - cb, ctx); - if (status != LXB_STATUS_OK) { - return NULL; - } +out: + lxb_selectors_clean(selectors); - return entry; + return LXB_STATUS_OK; } -static lxb_selectors_entry_child_t * -lxb_selectors_next(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_child_t *child, - lxb_css_selector_list_t *list, - lxb_selectors_cb_f cb, void *ctx) +static lxb_status_t +lxb_selectors_state_run(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_list_t *list) { - lxb_selectors_entry_child_t *chld_root = child; + lxb_selectors_entry_t *entry; - if (list == NULL) { - return NULL; - } + entry = selectors->current->entry; - if (child == NULL) { - child = lexbor_dobject_calloc(selectors->chld); - if (child == NULL) { - goto failed; - } + entry->node = node; + selectors->state = lxb_selectors_state_find; + selectors->first = entry; - chld_root = child; - } +again: do { - child->entry = lxb_selectors_next_by_selector(selectors, root, - child->entry, list->first, - cb, ctx); - if (child->entry == NULL) { - return NULL; - } + entry = selectors->state(selectors, entry); + } + while (entry != NULL); - if (list->next == NULL) { - return chld_root; - } + if (selectors->current->parent != NULL + && selectors->status == LXB_STATUS_OK) + { + entry = selectors->current->entry; + selectors->state = selectors->current->return_state; - if (child->next == NULL) { - child->next = lexbor_dobject_calloc(selectors->chld); - if (child->next == NULL) { - goto failed; - } - } - - child = child->next; - list = list->next; + goto again; } - while (true); - return chld_root; + return selectors->status; +} -failed: +static lxb_selectors_entry_t * +lxb_selectors_state_find(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry) +{ + lxb_dom_node_t *node; + lxb_selectors_entry_t *next; + const lxb_css_selector_t *selector; + const lxb_css_selector_anb_of_t *anb; + const lxb_css_selector_pseudo_t *pseudo; - selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + selector = entry->selector; - return NULL; -} + if (selector->type == LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION) { + pseudo = &selector->u.pseudo; -static lxb_selectors_entry_child_t * -lxb_selectors_current(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_child_t *child, - lxb_css_selector_list_t *list, - lxb_selectors_cb_f cb, void *ctx) -{ - lxb_selectors_entry_child_t *chld_root = child; + /* Optimizing. */ - if (list == NULL) { - return NULL; - } + switch (pseudo->type) { + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD: + anb = pseudo->data; - if (child == NULL) { - child = lexbor_dobject_calloc(selectors->chld); - if (child == NULL) { - goto failed; - } + if (anb->of != NULL) { + break; + } - chld_root = child; - } + goto godoit; - do { - child->entry = lxb_selectors_find_by_selector(selectors, root, - child->entry, list->first, - cb, ctx); - if (child->entry == NULL) { - return NULL; - } + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE: + goto godoit; - if (list->next == NULL) { - return chld_root; + default: + break; } - if (child->next == NULL) { - child->next = lexbor_dobject_calloc(selectors->chld); - if (child->next == NULL) { - goto failed; + if (entry->nested == NULL) { + next = lexbor_dobject_calloc(selectors->objs); + if (next == NULL) { + selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + return NULL; } - } - child = child->next; - list = list->next; - } - while (true); + next->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; - return chld_root; - -failed: - - selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + entry->nested = lexbor_dobject_calloc(selectors->nested); + if (entry->nested == NULL) { + selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + return NULL; + } - return NULL; -} + entry->nested->entry = next; + entry->nested->parent = selectors->current; + } -static lxb_selectors_entry_t * -lxb_selectors_next_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx) -{ - lxb_status_t status; - lxb_dom_node_t *node = root, *base = root; + selectors->state = lxb_selectors_state_pseudo_class_function; + selectors->current->last = entry; + selectors->current = entry->nested; - if (entry == NULL) { - entry = lexbor_dobject_calloc(selectors->objs); - if (entry == NULL) { - selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; - return NULL; - } + next = entry->nested->entry; + next->node = entry->node; - entry->selector = selector; + return next; } - switch (selector->combinator) { +godoit: + + switch (entry->combinator) { case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: - node = lxb_selectors_descendant_next(selectors, entry, selector, - base, node); + node = lxb_selectors_descendant(selectors, entry, + selector, entry->node); break; case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: - node = lxb_selectors_close(selectors, entry, selector, node); + node = lxb_selectors_close(selectors, entry, + selector, entry->node); break; case LXB_CSS_SELECTOR_COMBINATOR_CHILD: - node = lxb_selectors_child(selectors, entry, selector, base, node); + node = lxb_selectors_child(selectors, entry, + selector, entry->node); break; case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: - node = lxb_selectors_sibling(selectors, entry, selector, base); + node = lxb_selectors_sibling(selectors, entry, + selector, entry->node); break; case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: - node = lxb_selectors_following(selectors, entry, selector, node); + node = lxb_selectors_following(selectors, entry, + selector, entry->node); break; case LXB_CSS_SELECTOR_COMBINATOR_CELL: @@ -639,445 +520,626 @@ lxb_selectors_next_by_selector(lxb_selectors_t *selectors, lxb_dom_node_t *root, return NULL; } - status = lxb_selectors_find_by(selectors, entry, root, node, selector, - cb, ctx); - if (status != LXB_STATUS_OK) { - return NULL; - } - - return entry; + return lxb_selectors_state_find_check(selectors, node, selector, entry); } -static lxb_status_t -lxb_selectors_find_by(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_dom_node_t *root, lxb_dom_node_t *node, - lxb_css_selector_t *selector, lxb_selectors_cb_f cb, void *ctx) +static lxb_selectors_entry_t * +lxb_selectors_state_find_check(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_t *selector, + lxb_selectors_entry_t *entry) { - lxb_status_t status; lxb_selectors_entry_t *next; - lxb_dom_node_t *base = root; + lxb_selectors_nested_t *current; - do { - if (node == NULL) { - if (entry->prev == NULL) { - return LXB_STATUS_OK; + if (node == NULL) { + + try_next: + + if (entry->next == NULL) { + + try_next_list: + + if (selector->list->next == NULL) { + return NULL; } - do { - entry = entry->prev; - selector = entry->selector; + /* + * Try the following selectors from the selector list. + */ + + if (entry->following != NULL) { + entry->following->node = entry->node; + + if (selectors->current->parent == NULL) { + selectors->first = entry->following; + } + + return entry->following; } - while (entry->prev != NULL - && selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE); - if (selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) { - return LXB_STATUS_OK; + next = lexbor_dobject_calloc(selectors->objs); + if (next == NULL) { + selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + return NULL; } - node = entry->node; - base = (entry->prev != NULL) ? entry->prev->node : root; + next->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; + next->selector = selector->list->next->last; + next->node = entry->node; - goto next; + entry->following = next; + + if (selectors->current->parent == NULL) { + selectors->first = next; + } + + return next; } - if (selector->next == NULL) { - status = cb(node, selector->list->specificity, ctx); - if (status != LXB_STATUS_OK) { - if (status == LXB_STATUS_STOP) { - return LXB_STATUS_OK; + do { + entry = entry->next; + + while (entry->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) { + if (entry->next == NULL) { + selector = entry->selector; + goto try_next; } - return status; + entry = entry->next; } - if (selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) { - while (entry->prev != NULL - && entry->selector->combinator == LXB_CSS_SELECTOR_COMBINATOR_CLOSE) - { - entry = entry->prev; - } + switch (entry->combinator) { + case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: + node = entry->node->parent; - selector = entry->selector; - node = entry->node; - } + if (node == NULL + || node->type != LXB_DOM_NODE_TYPE_ELEMENT) + { + node = NULL; + } - base = (entry->prev != NULL) ? entry->prev->node : root; + break; - goto next; + case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: + node = entry->node->prev; + break; + + case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: + case LXB_CSS_SELECTOR_COMBINATOR_CHILD: + case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: + node = NULL; + break; + + case LXB_CSS_SELECTOR_COMBINATOR_CELL: + default: + selectors->status = LXB_STATUS_ERROR; + return NULL; + } } + while (node == NULL); - base = node; entry->node = node; - if (entry->next == NULL) { - next = lexbor_dobject_calloc(selectors->objs); - if (next == NULL) { - return LXB_STATUS_ERROR_MEMORY_ALLOCATION; - } + return entry; + } + + if (selector->prev == NULL) { + current = selectors->current; + + selectors->status = current->cb(current->entry->node, + selector->list->specificity, + current->ctx); - next->selector = selector->next; - next->prev = entry; - entry->next = next; - entry = next; + if ((selectors->options & LXB_SELECTORS_OPT_MATCH_FIRST) == 0 + && current->parent == NULL) + { + if (selectors->status == LXB_STATUS_OK) { + entry = selectors->first; + goto try_next_list; + } } - else { - entry = entry->next; + + return NULL; + } + + if (entry->prev == NULL) { + next = lexbor_dobject_calloc(selectors->objs); + if (next == NULL) { + selectors->status = LXB_STATUS_ERROR_MEMORY_ALLOCATION; + return NULL; } - selector = entry->selector; + next->combinator = selector->combinator; + next->selector = selector->prev; + next->node = node; - switch (selector->combinator) { - case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: - node = lxb_selectors_descendant_next(selectors, entry, selector, - base, node); - break; + next->next = entry; + entry->prev = next; - case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: - node = lxb_selectors_close(selectors, entry, selector, node); - break; + return next; + } - case LXB_CSS_SELECTOR_COMBINATOR_CHILD: - node = lxb_selectors_child(selectors, entry, selector, - base, node); - break; + entry->prev->node = node; - case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: - node = lxb_selectors_sibling(selectors, entry, selector, node); - break; + return entry->prev; +} - case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: - node = lxb_selectors_following(selectors, entry, - selector, node); - break; +static lxb_selectors_entry_t * +lxb_selectors_state_pseudo_class_function(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry) +{ + lxb_dom_node_t *node, *base; + lxb_selectors_nested_t *current; + const lxb_css_selector_list_t *list; + lxb_css_selector_anb_of_t *anb; + const lxb_css_selector_pseudo_t *pseudo; - case LXB_CSS_SELECTOR_COMBINATOR_CELL: - default: - return LXB_STATUS_ERROR; - } + current = selectors->current; - continue; + base = lxb_selectors_next_node(current); + if (base == NULL) { + goto not_found; + } - next: + pseudo = ¤t->parent->last->selector->u.pseudo; - switch (selector->combinator) { - case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: - node = lxb_selectors_descendant_next(selectors, entry, selector, - base, node); - break; + switch (pseudo->type) { + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_HAS: + list = (lxb_css_selector_list_t *) pseudo->data; + node = lxb_selectors_state_has_relative(base, list->first); - case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: - node = lxb_selectors_close(selectors, entry, selector, node); - break; + if (node == NULL) { + selectors->current = selectors->current->parent; + entry = selectors->current->last; - case LXB_CSS_SELECTOR_COMBINATOR_CHILD: - node = lxb_selectors_child_next(selectors, entry, selector, - base, node); - break; + selectors->state = lxb_selectors_state_find; - case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: - node = NULL; - break; + return lxb_selectors_state_find_check(selectors, NULL, + entry->selector, entry); + } - case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: - node = lxb_selectors_following(selectors, entry, - selector, node); - break; + current->root = base; - case LXB_CSS_SELECTOR_COMBINATOR_CELL: - default: - return LXB_STATUS_ERROR; - } + current->entry->selector = list->last; + current->entry->node = node; + current->return_state = lxb_selectors_state_after_find_has; + current->cb = lxb_selectors_cb_ok; + current->ctx = ¤t->found; + current->found = false; + + selectors->state = lxb_selectors_state_find; + + return entry; + + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_CURRENT: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_IS: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_WHERE: + current->entry->selector = ((lxb_css_selector_list_t *) pseudo->data)->last; + current->entry->node = base; + current->return_state = lxb_selectors_state_after_find; + current->cb = lxb_selectors_cb_ok; + current->ctx = ¤t->found; + current->found = false; + + selectors->state = lxb_selectors_state_find; + + return entry; + + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NOT: + current->entry->selector = ((lxb_css_selector_list_t *) pseudo->data)->last; + current->entry->node = base; + current->return_state = lxb_selectors_state_after_find; + current->cb = lxb_selectors_cb_not; + current->ctx = ¤t->found; + current->found = true; + + selectors->state = lxb_selectors_state_find; + + return entry; + + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD: + anb = pseudo->data; + + current->entry->selector = anb->of->last; + current->entry->node = base; + current->return_state = lxb_selectors_state_after_nth_child; + current->cb = lxb_selectors_cb_ok; + current->ctx = ¤t->found; + current->root = base; + current->index = 0; + current->found = false; + + selectors->state = lxb_selectors_state_find; + + return entry; + + /* + * This one can only happen if the user has somehow messed up the + * selector. + */ + + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_DIR: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_LANG: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_COL: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_COL: + default: + break; } - while (true); - return LXB_STATUS_OK; +not_found: + + selectors->current = selectors->current->parent; + entry = selectors->current->last; + + selectors->state = lxb_selectors_state_find; + + return lxb_selectors_state_find_check(selectors, NULL, + entry->selector, entry); } -static lxb_status_t -lxb_selectors_find_by_reverse(lxb_selectors_t *selectors, lxb_dom_node_t *node, - lxb_css_selector_t *selector, - lxb_selectors_cb_f cb, void *ctx) +static lxb_dom_node_t * +lxb_selectors_next_node(lxb_selectors_nested_t *main) { - lxb_status_t status; - lxb_dom_node_t *base = node; - lxb_selectors_entry_t *entry; - lxb_css_selector_combinator_t combinator; + lxb_dom_node_t *node = main->entry->node; - entry = lexbor_dobject_calloc(selectors->objs); - if (entry == NULL) { - return LXB_STATUS_ERROR_MEMORY_ALLOCATION; - } + switch (main->parent->last->combinator) { + case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: + case LXB_CSS_SELECTOR_COMBINATOR_CHILD: + if (node->parent == NULL + || node->parent->type != LXB_DOM_NODE_TYPE_ELEMENT) + { + return NULL; + } - entry->selector = selector; - combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE; + return node->parent; - do { - entry->node = node; - entry->id = 0; + case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: + return node; - selector = entry->selector; + case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: + case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: + node = node->prev; + break; - switch (combinator) { - case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: - node = lxb_selectors_descendant_reverse(selectors, entry, - selector, node); - break; + default: + return NULL; + } - case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: - node = lxb_selectors_close(selectors, entry, selector, node); - break; + while (node != NULL) { + if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) { + break; + } - case LXB_CSS_SELECTOR_COMBINATOR_CHILD: - node = node->parent; + node = node->prev; + } - if (node == NULL || node->type != LXB_DOM_NODE_TYPE_ELEMENT - || !lxb_selectors_match(selectors, entry, selector, node)) - { - return LXB_STATUS_OK; - } + return node; +} - break; +static lxb_dom_node_t * +lxb_selectors_state_has_relative(lxb_dom_node_t *node, + const lxb_css_selector_t *selector) +{ + lxb_dom_node_t *root = node; - case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: - node = lxb_selectors_sibling_reverse(selectors, entry, - selector, node); - break; + switch (selector->combinator) { + case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: + case LXB_CSS_SELECTOR_COMBINATOR_CHILD: + node = node->first_child; + break; - case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: - node = lxb_selectors_following_reverse(selectors, entry, - selector, node); - break; + case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: + case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: + node = node->next; + break; - case LXB_CSS_SELECTOR_COMBINATOR_CELL: - default: - return LXB_STATUS_ERROR; - } + default: + return NULL; + } - if (node == NULL) { - return LXB_STATUS_OK; + while (node != NULL) { + if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) { + break; } - if (selector->prev == NULL) { - status = cb(base, selector->list->specificity, ctx); - if (status != LXB_STATUS_OK) { - if (status == LXB_STATUS_STOP) { - return LXB_STATUS_OK; - } - - return status; - } + while (node !=root && node->next == NULL) { + node = node->parent; + } - return LXB_STATUS_OK; + if (node == root) { + return NULL; } - combinator = selector->combinator; - entry->selector = selector->prev; + node = node->next; } - while (true); - return LXB_STATUS_OK; + return node; } -static bool -lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, - lxb_css_selector_t *selector, lxb_dom_node_t *node) +static lxb_selectors_entry_t * +lxb_selectors_state_after_find_has(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry) { - bool res, ins; - const lexbor_str_t *trg, *src; - lxb_tag_id_t tag_id; - lxb_dom_attr_t *dom_attr; - lxb_dom_element_t *element; - const lxb_dom_attr_data_t *attr_data; - lxb_css_selector_attribute_t *attr; + lxb_dom_node_t *node; + lxb_selectors_entry_t *parent; + lxb_selectors_nested_t *current; - static const lexbor_str_t lxb_blank_str = { - .data = (lxb_char_t *) "", - .length = 0 - }; + if (selectors->current->found) { + node = selectors->current->root; - switch (selector->type) { - case LXB_CSS_SELECTOR_TYPE_ANY: - return true; + selectors->current = selectors->current->parent; + parent = selectors->current->last; - case LXB_CSS_SELECTOR_TYPE_ELEMENT: - if (entry->id == 0) { - tag_id = lxb_tag_id_by_name(node->owner_document->tags, - selector->name.data, selector->name.length); - if (tag_id == LXB_TAG__UNDEF) { - return false; + selectors->state = lxb_selectors_state_find; + + return lxb_selectors_state_find_check(selectors, node, + parent->selector, parent); + } + + current = selectors->current; + node = entry->node; + + switch (entry->selector->list->first->combinator) { + case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: + if (node->first_child != NULL) { + node = node->first_child; + } + else { + + next: + + while (node != current->root && node->next == NULL) { + node = node->parent; } - entry->id = tag_id; + if (node == current->root) { + goto failed; + } + + node = node->next; } - if (node->local_name == entry->id) { - return true; + if (node->type != LXB_DOM_NODE_TYPE_ELEMENT) { + goto next; } break; - case LXB_CSS_SELECTOR_TYPE_ID: - element = lxb_dom_interface_element(node); + case LXB_CSS_SELECTOR_COMBINATOR_CHILD: + case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: + node = node->next; - if (element->attr_id == NULL || element->attr_id->value == NULL) { - return false; + while (node != NULL && node->type != LXB_DOM_NODE_TYPE_ELEMENT) { + node = node->next; } - trg = element->attr_id->value; - src = &selector->name; + if (node == NULL) { + goto failed; + } + + break; - if (trg->length == src->length - && lexbor_str_data_ncasecmp(trg->data, src->data, src->length)) + case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: + goto failed; + + case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: + case LXB_CSS_SELECTOR_COMBINATOR_CELL: + default: + selectors->status = LXB_STATUS_ERROR; + return NULL; + } + + entry->node = node; + selectors->state = lxb_selectors_state_find; + + return entry; + +failed: + + selectors->current = selectors->current->parent; + parent = selectors->current->last; + + selectors->state = lxb_selectors_state_find; + + return lxb_selectors_state_find_check(selectors, NULL, + parent->selector, parent); +} + + +static lxb_selectors_entry_t * +lxb_selectors_state_after_find(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry) +{ + lxb_dom_node_t *node; + lxb_selectors_entry_t *parent; + lxb_selectors_nested_t *current; + + current = selectors->current; + + if (current->found) { + node = entry->node; + + selectors->current = current->parent; + parent = selectors->current->last; + + selectors->state = lxb_selectors_state_find; + + return lxb_selectors_state_find_check(selectors, node, + parent->selector, parent); + } + + node = entry->node; + + switch (current->parent->last->combinator) { + case LXB_CSS_SELECTOR_COMBINATOR_DESCENDANT: + if (node->parent != NULL + && node->parent->type == LXB_DOM_NODE_TYPE_ELEMENT) { - return true; + node = node->parent; + } + else { + node = NULL; } - return false; + break; - case LXB_CSS_SELECTOR_TYPE_CLASS: - element = lxb_dom_interface_element(node); + case LXB_CSS_SELECTOR_COMBINATOR_FOLLOWING: + node = node->prev; - if (element->attr_class == NULL || element->attr_class->value == NULL) { - return false; + while (node != NULL && node->type != LXB_DOM_NODE_TYPE_ELEMENT) { + node = node->prev; } - return lxb_selectors_match_class(element->attr_class->value, - &selector->name, true); + break; - case LXB_CSS_SELECTOR_TYPE_ATTRIBUTE: - element = lxb_dom_interface_element(node); - attr = &selector->u.attribute; + case LXB_CSS_SELECTOR_COMBINATOR_CHILD: + case LXB_CSS_SELECTOR_COMBINATOR_SIBLING: + case LXB_CSS_SELECTOR_COMBINATOR_CLOSE: + node = NULL; + break; - if (entry->id == 0) { - attr_data = lxb_dom_attr_data_by_local_name(node->owner_document->attrs, - selector->name.data, selector->name.length); - if (attr_data == NULL) { - return false; - } + case LXB_CSS_SELECTOR_COMBINATOR_CELL: + default: + selectors->status = LXB_STATUS_ERROR; + return NULL; + } - entry->id = attr_data->attr_id; - } + if (node == NULL) { + selectors->current = current->parent; + parent = selectors->current->last; - dom_attr = lxb_dom_element_attr_by_id(element, entry->id); - if (dom_attr == NULL) { - return false; - } + selectors->state = lxb_selectors_state_find; - trg = dom_attr->value; - src = &attr->value; + return lxb_selectors_state_find_check(selectors, node, + parent->selector, parent); + } - if (src->data == NULL) { - return true; - } + entry->node = node; + selectors->state = lxb_selectors_state_find; - if (trg == NULL) { - trg = &lxb_blank_str; - } + return entry; +} - ins = attr->modifier == LXB_CSS_SELECTOR_MODIFIER_I; +static lxb_selectors_entry_t * +lxb_selectors_state_after_nth_child(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry) +{ + bool found; + lxb_dom_node_t *node; + lxb_selectors_entry_t *parent; + lxb_selectors_nested_t *current; + const lxb_css_selector_t *selector; + const lxb_css_selector_pseudo_t *pseudo; - switch (attr->match) { - case LXB_CSS_SELECTOR_MATCH_EQUAL: /* = */ - if (trg->length == src->length) { - if (ins) { - return lexbor_str_data_ncasecmp(trg->data, src->data, - src->length); - } + current = selectors->current; + selector = current->parent->last->selector; + pseudo = &selector->u.pseudo; - return lexbor_str_data_ncmp(trg->data, src->data, - src->length); - } + node = entry->node; - return false; + if (current->found) { + current->index += 1; + } + else if (current->root == node) { + node = NULL; + goto done; + } - case LXB_CSS_SELECTOR_MATCH_INCLUDE: /* ~= */ - return lxb_selectors_match_class(trg, src, ins); + if (pseudo->type == LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD) { + node = node->prev; - case LXB_CSS_SELECTOR_MATCH_DASH: /* |= */ - if (trg->length == src->length) { - if (ins) { - return lexbor_str_data_ncasecmp(trg->data, src->data, - src->length); - } + while (node != NULL) { + if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) { + break; + } - return lexbor_str_data_ncmp(trg->data, src->data, - src->length); - } + node = node->prev; + } + } + else { + node = node->next; - if (trg->length > src->length) { - if (ins) { - res = lexbor_str_data_ncasecmp(trg->data, - src->data, src->length); - } - else { - res = lexbor_str_data_ncmp(trg->data, - src->data, src->length); - } - - if (res && trg->data[src->length] == '-') { - return true; - } - } + while (node != NULL) { + if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) { + break; + } + + node = node->next; + } + } + + if (node == NULL) { + goto done; + } + + entry->node = node; + current->found = false; + selectors->state = lxb_selectors_state_find; + + return entry; - return false; +done: - case LXB_CSS_SELECTOR_MATCH_PREFIX: /* ^= */ - if (src->length != 0 && trg->length >= src->length) { - if (ins) { - return lexbor_str_data_ncasecmp(trg->data, src->data, - src->length); - } + if (current->index > 0) { + found = lxb_selectors_anb_calc(pseudo->data, current->index); - return lexbor_str_data_ncmp(trg->data, src->data, - src->length); - } + node = (found) ? current->root : NULL; + } - return false; + selectors->state = lxb_selectors_state_find; + selectors->current = selectors->current->parent; - case LXB_CSS_SELECTOR_MATCH_SUFFIX: /* $= */ - if (src->length != 0 && trg->length >= src->length) { - size_t dif = trg->length - src->length; + parent = selectors->current->last; - if (ins) { - return lexbor_str_data_ncasecmp(trg->data + dif, - src->data, src->length); - } + return lxb_selectors_state_find_check(selectors, node, + parent->selector, parent); +} - return lexbor_str_data_ncmp(trg->data + dif, src->data, - src->length); - } +static bool +lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, + const lxb_css_selector_t *selector, lxb_dom_node_t *node) +{ + lxb_dom_element_t *element; - return false; + switch (selector->type) { + case LXB_CSS_SELECTOR_TYPE_ANY: + return true; - case LXB_CSS_SELECTOR_MATCH_SUBSTRING: /* *= */ - if (src->length == 0) { - return false; - } + case LXB_CSS_SELECTOR_TYPE_ELEMENT: + return lxb_selectors_match_element(selector, node, entry); - if (ins) { - return lexbor_str_data_ncasecmp_contain(trg->data, trg->length, - src->data, src->length); - } + case LXB_CSS_SELECTOR_TYPE_ID: + return lxb_selectors_match_id(selector, node); - return lexbor_str_data_ncmp_contain(trg->data, trg->length, - src->data, src->length); + case LXB_CSS_SELECTOR_TYPE_CLASS: + element = lxb_dom_interface_element(node); - default: - return false; + if (element->attr_class == NULL + || element->attr_class->value == NULL) + { + return false; } + return lxb_selectors_match_class(element->attr_class->value, + &selector->name, true); + + case LXB_CSS_SELECTOR_TYPE_ATTRIBUTE: + return lxb_selectors_match_attribute(selector, node, entry); + case LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS: return lxb_selectors_pseudo_class(selector, node); case LXB_CSS_SELECTOR_TYPE_PSEUDO_CLASS_FUNCTION: - return lxb_selectors_pseudo_class_function(selectors, selector, - node, entry); + return lxb_selectors_pseudo_class_function(selector, node); case LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT: - return lxb_selectors_pseudo_element(selectors, selector, node); + return lxb_selectors_pseudo_element(selector, node); case LXB_CSS_SELECTOR_TYPE_PSEUDO_ELEMENT_FUNCTION: - return lxb_selectors_pseudo_element_function(selectors, selector, node); + return false; default: break; @@ -1087,7 +1149,45 @@ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry, } static bool -lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src, +lxb_selectors_match_element(const lxb_css_selector_t *selector, + lxb_dom_node_t *node, lxb_selectors_entry_t *entry) +{ + lxb_tag_id_t tag_id; + + if (entry->id == 0) { + tag_id = lxb_tag_id_by_name(node->owner_document->tags, + selector->name.data, selector->name.length); + if (tag_id == LXB_TAG__UNDEF) { + return false; + } + + entry->id = tag_id; + } + + return node->local_name == entry->id; +} + +static bool +lxb_selectors_match_id(const lxb_css_selector_t *selector, lxb_dom_node_t *node) +{ + const lexbor_str_t *trg, *src; + lxb_dom_element_t *element; + + element = lxb_dom_interface_element(node); + + if (element->attr_id == NULL || element->attr_id->value == NULL) { + return false; + } + + trg = element->attr_id->value; + src = &selector->name; + + return trg->length == src->length + && lexbor_str_data_ncasecmp(trg->data, src->data, src->length); +} + +static bool +lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src, bool quirks) { lxb_char_t chr; @@ -1141,12 +1241,152 @@ lxb_selectors_match_class(const lexbor_str_t *target, const lexbor_str_t *src, } static bool -lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node) +lxb_selectors_match_attribute(const lxb_css_selector_t *selector, + lxb_dom_node_t *node, lxb_selectors_entry_t *entry) +{ + bool res, ins; + lxb_dom_attr_t *dom_attr; + lxb_dom_element_t *element; + const lexbor_str_t *trg, *src; + const lxb_dom_attr_data_t *attr_data; + const lxb_css_selector_attribute_t *attr; + + static const lexbor_str_t lxb_blank_str = { + .data = (lxb_char_t *) "", + .length = 0 + }; + + element = lxb_dom_interface_element(node); + attr = &selector->u.attribute; + + if (entry->id == 0) { + attr_data = lxb_dom_attr_data_by_local_name(node->owner_document->attrs, + selector->name.data, selector->name.length); + if (attr_data == NULL) { + return false; + } + + entry->id = attr_data->attr_id; + } + + dom_attr = lxb_dom_element_attr_by_id(element, entry->id); + if (dom_attr == NULL) { + return false; + } + + trg = dom_attr->value; + src = &attr->value; + + if (src->data == NULL) { + return true; + } + + if (trg == NULL) { + trg = &lxb_blank_str; + } + + ins = attr->modifier == LXB_CSS_SELECTOR_MODIFIER_I; + + switch (attr->match) { + case LXB_CSS_SELECTOR_MATCH_EQUAL: /* = */ + if (trg->length == src->length) { + if (ins) { + return lexbor_str_data_ncasecmp(trg->data, src->data, + src->length); + } + + return lexbor_str_data_ncmp(trg->data, src->data, + src->length); + } + + return false; + + case LXB_CSS_SELECTOR_MATCH_INCLUDE: /* ~= */ + return lxb_selectors_match_class(trg, src, ins); + + case LXB_CSS_SELECTOR_MATCH_DASH: /* |= */ + if (trg->length == src->length) { + if (ins) { + return lexbor_str_data_ncasecmp(trg->data, src->data, + src->length); + } + + return lexbor_str_data_ncmp(trg->data, src->data, + src->length); + } + + if (trg->length > src->length) { + if (ins) { + res = lexbor_str_data_ncasecmp(trg->data, + src->data, src->length); + } + else { + res = lexbor_str_data_ncmp(trg->data, + src->data, src->length); + } + + if (res && trg->data[src->length] == '-') { + return true; + } + } + + return false; + + case LXB_CSS_SELECTOR_MATCH_PREFIX: /* ^= */ + if (src->length != 0 && trg->length >= src->length) { + if (ins) { + return lexbor_str_data_ncasecmp(trg->data, src->data, + src->length); + } + + return lexbor_str_data_ncmp(trg->data, src->data, + src->length); + } + + return false; + + case LXB_CSS_SELECTOR_MATCH_SUFFIX: /* $= */ + if (src->length != 0 && trg->length >= src->length) { + size_t dif = trg->length - src->length; + + if (ins) { + return lexbor_str_data_ncasecmp(trg->data + dif, + src->data, src->length); + } + + return lexbor_str_data_ncmp(trg->data + dif, src->data, + src->length); + } + + return false; + + case LXB_CSS_SELECTOR_MATCH_SUBSTRING: /* *= */ + if (src->length == 0) { + return false; + } + + if (ins) { + return lexbor_str_data_ncasecmp_contain(trg->data, trg->length, + src->data, src->length); + } + + return lexbor_str_data_ncmp_contain(trg->data, trg->length, + src->data, src->length); + default: + break; + } + + return false; +} + +static bool +lxb_selectors_pseudo_class(const lxb_css_selector_t *selector, + const lxb_dom_node_t *node) { lexbor_str_t *str; lxb_dom_attr_t *attr; - lxb_dom_node_t *root; - lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo; + const lxb_dom_node_t *root; + const lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo; static const lxb_char_t checkbox[] = "checkbox"; static const size_t checkbox_length = sizeof(checkbox) / sizeof(lxb_char_t) - 1; @@ -1305,8 +1545,8 @@ lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node) case LXB_CSS_SELECTOR_PSEUDO_CLASS_LINK: if (node->local_name == LXB_TAG_A - || node->local_name == LXB_TAG_AREA - || node->local_name == LXB_TAG_LINK) + || node->local_name == LXB_TAG_AREA + || node->local_name == LXB_TAG_LINK) { attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node), LXB_DOM_ATTR_HREF); @@ -1320,16 +1560,16 @@ lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node) case LXB_CSS_SELECTOR_PSEUDO_CLASS_ONLY_CHILD: return lxb_selectors_pseudo_class_first_child(node) - && lxb_selectors_pseudo_class_last_child(node); + && lxb_selectors_pseudo_class_last_child(node); case LXB_CSS_SELECTOR_PSEUDO_CLASS_ONLY_OF_TYPE: return lxb_selectors_pseudo_class_first_of_type(node) - && lxb_selectors_pseudo_class_last_of_type(node); + && lxb_selectors_pseudo_class_last_of_type(node); case LXB_CSS_SELECTOR_PSEUDO_CLASS_OPTIONAL: if (node->local_name == LXB_TAG_INPUT - || node->local_name == LXB_TAG_SELECT - || node->local_name == LXB_TAG_TEXTAREA) + || node->local_name == LXB_TAG_SELECT + || node->local_name == LXB_TAG_TEXTAREA) { attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node), LXB_DOM_ATTR_REQUIRED); @@ -1402,86 +1642,26 @@ lxb_selectors_pseudo_class(lxb_css_selector_t *selector, lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, - lxb_dom_node_t *node, - lxb_selectors_entry_t *entry) +lxb_selectors_pseudo_class_function(const lxb_css_selector_t *selector, + lxb_dom_node_t *node) { size_t index; - bool found = false; lxb_dom_node_t *base; - lxb_css_selector_anb_of_t *anb; - lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo; - - switch (pseudo->type) { - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_CURRENT: - entry->child = lxb_selectors_next(selectors, node, entry->child, - pseudo->data, - lxb_selectors_first_match, &found); - if (entry->child == NULL) { - return false; - } - - return found; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_DIR: - break; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_HAS: - entry->child = lxb_selectors_next(selectors, node, entry->child, - pseudo->data, - lxb_selectors_first_match, &found); - if (entry->child == NULL) { - return false; - } - - return found; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_IS: - entry->child = lxb_selectors_next(selectors, node, entry->child, - pseudo->data, - lxb_selectors_first_match, &found); - if (entry->child == NULL) { - return false; - } - - return found; + const lxb_css_selector_pseudo_t *pseudo; - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_LANG: - break; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NOT: - entry->child = lxb_selectors_next(selectors, node, entry->child, - pseudo->data, - lxb_selectors_first_match, &found); - if (entry->child == NULL) { - return false; - } - - return !found; + pseudo = &selector->u.pseudo; + switch (pseudo->type) { case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD: index = 0; - found = false; - anb = selector->u.pseudo.data; - if (anb->of != NULL) { + if (pseudo->type == LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_CHILD) { while (node != NULL) { if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + && node->local_name != LXB_TAG__EM_COMMENT) { - entry->child = lxb_selectors_current(selectors, node, entry->child, - anb->of, lxb_selectors_first_match, - &found); - if (entry->child == NULL) { - return false; - } - - if (found) { - index++; - } - - found = false; + index++; } node = node->prev; @@ -1490,51 +1670,37 @@ lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors, else { while (node != NULL) { if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + && node->local_name != LXB_TAG__EM_COMMENT) { index++; } - node = node->prev; + node = node->next; } } - return lxb_selectors_anb_calc(anb, index); + return lxb_selectors_anb_calc(pseudo->data, index); - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_COL: - break; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE: index = 0; - found = false; - anb = selector->u.pseudo.data; + base = node; - if (anb->of != NULL) { + if (pseudo->type == LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE) { while (node != NULL) { - if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + if(node->local_name == base->local_name + && node->ns == base->ns) { - entry->child = lxb_selectors_current(selectors, node, entry->child, - anb->of, lxb_selectors_first_match, - &found); - if (entry->child == NULL) { - return false; - } - - if (found) { - index++; - } - - found = false; + index++; } - node = node->next; + node = node->prev; } } else { while (node != NULL) { - if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + if(node->local_name == base->local_name + && node->ns == base->ns) { index++; } @@ -1543,66 +1709,24 @@ lxb_selectors_pseudo_class_function(lxb_selectors_t *selectors, } } - return lxb_selectors_anb_calc(anb, index); + return lxb_selectors_anb_calc(pseudo->data, index); + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_DIR: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_LANG: + case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_COL: case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_COL: + default: break; - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE: - index = 0; - found = false; - anb = selector->u.pseudo.data; - base = node; - - while (node != NULL) { - if(node->local_name == base->local_name - && node->ns == base->ns) - { - index++; - } - - node = node->next; - } - - return lxb_selectors_anb_calc(anb, index); - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE: - index = 0; - found = false; - anb = selector->u.pseudo.data; - base = node; - - while (node != NULL) { - if(node->local_name == base->local_name - && node->ns == base->ns) - { - index++; - } - - node = node->prev; - } - - return lxb_selectors_anb_calc(anb, index); - - case LXB_CSS_SELECTOR_PSEUDO_CLASS_FUNCTION_WHERE: - entry->child = lxb_selectors_next(selectors, node, entry->child, - pseudo->data, - lxb_selectors_first_match, &found); - if (entry->child == NULL) { - return false; - } - - return found; } return false; } static bool -lxb_selectors_pseudo_element(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, lxb_dom_node_t *node) +lxb_selectors_pseudo_element(const lxb_css_selector_t *selector, + const lxb_dom_node_t *node) { - lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo; + const lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo; switch (pseudo->type) { case LXB_CSS_SELECTOR_PSEUDO_ELEMENT_AFTER: @@ -1624,14 +1748,7 @@ lxb_selectors_pseudo_element(lxb_selectors_t *selectors, } static bool -lxb_selectors_pseudo_element_function(lxb_selectors_t *selectors, - lxb_css_selector_t *selector, lxb_dom_node_t *node) -{ - return false; -} - -static bool -lxb_selectors_pseudo_class_disabled(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_disabled(const lxb_dom_node_t *node) { lxb_dom_attr_t *attr; uintptr_t tag_id = node->local_name; @@ -1665,13 +1782,13 @@ lxb_selectors_pseudo_class_disabled(lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_first_child(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_first_child(const lxb_dom_node_t *node) { node = node->prev; while (node != NULL) { if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + && node->local_name != LXB_TAG__EM_COMMENT) { return false; } @@ -1683,14 +1800,14 @@ lxb_selectors_pseudo_class_first_child(lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_first_of_type(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_first_of_type(const lxb_dom_node_t *node) { - lxb_dom_node_t *root = node; + const lxb_dom_node_t *root = node; node = node->prev; while (node) { if (node->local_name == root->local_name - && node->ns == root->ns) + && node->ns == root->ns) { return false; } @@ -1702,13 +1819,13 @@ lxb_selectors_pseudo_class_first_of_type(lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_last_child(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_last_child(const lxb_dom_node_t *node) { node = node->next; while (node != NULL) { if (node->local_name != LXB_TAG__TEXT - && node->local_name != LXB_TAG__EM_COMMENT) + && node->local_name != LXB_TAG__EM_COMMENT) { return false; } @@ -1720,14 +1837,14 @@ lxb_selectors_pseudo_class_last_child(lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_last_of_type(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_last_of_type(const lxb_dom_node_t *node) { - lxb_dom_node_t *root = node; + const lxb_dom_node_t *root = node; node = node->next; while (node) { if (node->local_name == root->local_name - && node->ns == root->ns) + && node->ns == root->ns) { return false; } @@ -1739,12 +1856,12 @@ lxb_selectors_pseudo_class_last_of_type(lxb_dom_node_t *node) } static bool -lxb_selectors_pseudo_class_read_write(lxb_dom_node_t *node) +lxb_selectors_pseudo_class_read_write(const lxb_dom_node_t *node) { lxb_dom_attr_t *attr; if (node->local_name == LXB_TAG_INPUT - || node->local_name == LXB_TAG_TEXTAREA) + || node->local_name == LXB_TAG_TEXTAREA) { attr = lxb_dom_element_attr_by_id(lxb_dom_interface_element(node), LXB_DOM_ATTR_READONLY); @@ -1758,10 +1875,51 @@ lxb_selectors_pseudo_class_read_write(lxb_dom_node_t *node) return false; } +static bool +lxb_selectors_anb_calc(lxb_css_selector_anb_of_t *anb, size_t index) +{ + double num; + + if (anb->anb.a == 0) { + if (anb->anb.b >= 0 && (size_t) anb->anb.b == index) { + return true; + } + } + else { + num = ((double) index - (double) anb->anb.b) / (double) anb->anb.a; + + if (num >= 0.0f && (num - trunc(num)) == 0.0f) { + return true; + } + } + + return false; +} + static lxb_status_t -lxb_selectors_first_match(lxb_dom_node_t *node, - lxb_css_selector_specificity_t spec, void *ctx) +lxb_selectors_cb_ok(lxb_dom_node_t *node, + lxb_css_selector_specificity_t spec, void *ctx) { *((bool *) ctx) = true; - return LXB_STATUS_STOP; + return LXB_STATUS_OK; +} + +static lxb_status_t +lxb_selectors_cb_not(lxb_dom_node_t *node, + lxb_css_selector_specificity_t spec, void *ctx) +{ + *((bool *) ctx) = false; + return LXB_STATUS_OK; +} + +void +lxb_selectors_opt_set_noi(lxb_selectors_t *selectors, lxb_selectors_opt_t opt) +{ + lxb_selectors_opt_set(selectors, opt); +} + +const lxb_css_selector_list_t * +lxb_selectors_selector_noi(const lxb_selectors_t *selectors) +{ + return lxb_selectors_selector(selectors); } diff --git a/ext/dom/lexbor/lexbor/selectors/selectors.h b/ext/dom/lexbor/lexbor/selectors/selectors.h index 66ce7b6f60089..a9db864ff17fb 100644 --- a/ext/dom/lexbor/lexbor/selectors/selectors.h +++ b/ext/dom/lexbor/lexbor/selectors/selectors.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Alexander Borisov + * Copyright (C) 2021-2024 Alexander Borisov * * Author: Alexander Borisov */ @@ -15,58 +15,263 @@ extern "C" { #include "lexbor/selectors/base.h" #include "lexbor/dom/dom.h" #include "lexbor/css/selectors/selectors.h" +#include "lexbor/core/array_obj.h" -typedef lxb_status_t -(*lxb_selectors_cb_f)(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec, - void *ctx); +typedef enum { + LXB_SELECTORS_OPT_DEFAULT = 0x00, + + /* + * Includes the passed (root) node in the search. + * + * By default, the root node does not participate in selector searches, + * only its children. + * + * This behavior is logical, if you have found a node and then you want to + * search for other nodes in it, you don't need to check it again. + * + * But there are cases when it is necessary for root node to participate + * in the search. That's what this option is for. + */ + LXB_SELECTORS_OPT_MATCH_ROOT = 1 << 1, + /* + * Stop searching after the first match with any of the selectors + * in the list. + * + * By default, the callback will be triggered for each selector list. + * That is, if your node matches different selector lists, it will be + * returned multiple times in the callback. + * + * For example: + * HTML:
test
+ * Selectors: div, div[id="ok"], div:has(:not(a)) + * + * The default behavior will cause three callbacks with the same node (div). + * Because it will be found by every selector in the list. + * + * This option allows you to end the element check after the first match on + * any of the selectors. That is, the callback will be called only once + * for example above. This way we get rid of duplicates in the search. + */ + LXB_SELECTORS_OPT_MATCH_FIRST = 1 << 2 +} +lxb_selectors_opt_t; + +typedef struct lxb_selectors lxb_selectors_t; typedef struct lxb_selectors_entry lxb_selectors_entry_t; -typedef struct lxb_selectors_entry_child lxb_selectors_entry_child_t; +typedef struct lxb_selectors_nested lxb_selectors_nested_t; -typedef struct { - lexbor_dobject_t *objs; - lexbor_dobject_t *chld; +typedef lxb_status_t +(*lxb_selectors_cb_f)(lxb_dom_node_t *node, + lxb_css_selector_specificity_t spec, void *ctx); - lxb_status_t status; -} -lxb_selectors_t; +typedef lxb_selectors_entry_t * +(*lxb_selectors_state_cb_f)(lxb_selectors_t *selectors, + lxb_selectors_entry_t *entry); struct lxb_selectors_entry { - uintptr_t id; - lxb_css_selector_t *selector; - lxb_dom_node_t *node; - lxb_selectors_entry_t *next; - lxb_selectors_entry_t *prev; - lxb_selectors_entry_child_t *child; + uintptr_t id; + lxb_css_selector_combinator_t combinator; + const lxb_css_selector_t *selector; + lxb_dom_node_t *node; + lxb_selectors_entry_t *next; + lxb_selectors_entry_t *prev; + lxb_selectors_entry_t *following; + lxb_selectors_nested_t *nested; +}; + +struct lxb_selectors_nested { + lxb_selectors_entry_t *entry; + lxb_selectors_state_cb_f return_state; + + lxb_selectors_cb_f cb; + void *ctx; + + lxb_dom_node_t *root; + lxb_selectors_entry_t *last; + lxb_selectors_nested_t *parent; + + size_t index; + bool found; }; -struct lxb_selectors_entry_child { - lxb_selectors_entry_t *entry; - lxb_selectors_entry_child_t *next; +struct lxb_selectors { + lxb_selectors_state_cb_f state; + lexbor_dobject_t *objs; + lexbor_dobject_t *nested; + + lxb_selectors_nested_t *current; + lxb_selectors_entry_t *first; + + lxb_selectors_opt_t options; + lxb_status_t status; }; +/* + * Create lxb_selectors_t object. + * + * @return lxb_selectors_t * if successful, otherwise NULL. + */ LXB_API lxb_selectors_t * lxb_selectors_create(void); +/* + * Initialization of lxb_selectors_t object. + * + * Caches are initialized in this function. + * + * @param[in] lxb_selectors_t * + * + * @return LXB_STATUS_OK if successful, otherwise an error status value. + */ LXB_API lxb_status_t lxb_selectors_init(lxb_selectors_t *selectors); +/* + * Clears the object. Returns object to states as after initialization. + * + * After each call to lxb_selectors_find() and lxb_selectors_find_for_node(), + * the lxb_selectors_t object is cleared. That is, you don't need to call this + * function every time after searching by a selector. + * + * @param[in] lxb_url_parser_t * + */ LXB_API void lxb_selectors_clean(lxb_selectors_t *selectors); +/* + * Destroy lxb_selectors_t object. + * + * Destroying all caches. + * + * @param[in] lxb_selectors_t *. Can be NULL. + * @param[in] if false: only destroys internal caches. + * if true: destroys the lxb_selectors_t object and all internal caches. + * + * @return lxb_selectors_t * if self_destroy = false, otherwise NULL. + */ LXB_API lxb_selectors_t * lxb_selectors_destroy(lxb_selectors_t *selectors, bool self_destroy); +/* + * Search for nodes by selector list. + * + * Default Behavior: + * 1. The root node does not participate in the search, only its child nodes. + * 2. If a node matches multiple selector lists, a callback with that node + * will be called on each list. + * For example: + * HTML:
+ * Selectors: div, div[id="ok"], div:has(:not(a)) + * For each selector list, a callback with a "div" node will be called. + * + * To change the search behavior, see lxb_selectors_opt_set(). + * + * @param[in] lxb_selectors_t *. + * @param[in] lxb_dom_node_t *. The node from which the search will begin. + * @param[in] const lxb_css_selector_list_t *. Selectors List. + * @param[in] lxb_selectors_cb_f. Callback for a found node. + * @param[in] void *. Context for the callback. + * if true: destroys the lxb_selectors_t object and all internal caches. + * + * @return LXB_STATUS_OK if successful, otherwise an error status value. + */ LXB_API lxb_status_t lxb_selectors_find(lxb_selectors_t *selectors, lxb_dom_node_t *root, - lxb_css_selector_list_t *list, lxb_selectors_cb_f cb, void *ctx); + const lxb_css_selector_list_t *list, + lxb_selectors_cb_f cb, void *ctx); +/* + * Match a node to a Selectors List. + * + * In other words, the function checks which selector lists will find the + * specified node. + * + * Default Behavior: + * 1. If a node matches multiple selector lists, a callback with that node + * will be called on each list. + * For example: + * HTML:
+ * Node: div + * Selectors: div, div[id="ok"], div:has(:not(a)) + * For each selector list, a callback with a "div" node will be called. + * + * To change the search behavior, see lxb_selectors_opt_set(). + * + * @param[in] lxb_selectors_t *. + * @param[in] lxb_dom_node_t *. The node from which the search will begin. + * @param[in] const lxb_css_selector_list_t *. Selectors List. + * @param[in] lxb_selectors_cb_f. Callback for a found node. + * @param[in] void *. Context for the callback. + * if true: destroys the lxb_selectors_t object and all internal caches. + * + * @return LXB_STATUS_OK if successful, otherwise an error status value. + */ LXB_API lxb_status_t +lxb_selectors_match_node(lxb_selectors_t *selectors, lxb_dom_node_t *node, + const lxb_css_selector_list_t *list, + lxb_selectors_cb_f cb, void *ctx); + +/* + * Deprecated! + * This function does exactly the same thing as lxb_selectors_match_node(). + */ +LXB_API LXB_DEPRECATED(lxb_status_t lxb_selectors_find_reverse(lxb_selectors_t *selectors, lxb_dom_node_t *root, lxb_css_selector_list_t *list, - lxb_selectors_cb_f cb, void *ctx); + lxb_selectors_cb_f cb, void *ctx)); + +/* + * Inline functions. + */ + +/* + * The function sets the node search options. + * + * For more information, see lxb_selectors_opt_t. + * + * @param[in] lxb_selectors_t *. + * @param[in] lxb_selectors_opt_t. + */ +lxb_inline void +lxb_selectors_opt_set(lxb_selectors_t *selectors, lxb_selectors_opt_t opt) +{ + selectors->options = opt; +} + +/* + * Get the current selector. + * + * Function to get the selector by which the node was found. + * Use context (void *ctx) to pass the lxb_selectors_t object to the callback. + * + * @param[in] const lxb_selectors_t *. + * + * @return const lxb_css_selector_list_t *. + */ +lxb_inline const lxb_css_selector_list_t * +lxb_selectors_selector(const lxb_selectors_t *selectors) +{ + return selectors->current->entry->selector->list; +} + +/* + * Not inline for inline. + */ + +/* + * Same as lxb_selectors_opt_set() function, but not inline. + */ +LXB_API void +lxb_selectors_opt_set_noi(lxb_selectors_t *selectors, lxb_selectors_opt_t opt); + +/* + * Same as lxb_selectors_selector() function, but not inline. + */ +LXB_API const lxb_css_selector_list_t * +lxb_selectors_selector_noi(const lxb_selectors_t *selectors); #ifdef __cplusplus diff --git a/ext/dom/lexbor/lexbor/tag/tag.c b/ext/dom/lexbor/lexbor/tag/tag.c old mode 100755 new mode 100644 diff --git a/ext/dom/lexbor/lexbor/tag/tag.h b/ext/dom/lexbor/lexbor/tag/tag.h old mode 100755 new mode 100644