From 168dad55b6278cd45e0f0b2aed802ce9bace3274 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:59:28 +0100 Subject: [PATCH 6/6] Patch out unused CSS style code --- source/lexbor/css/rule.h | 2 ++ source/lexbor/html/interfaces/document.c | 29 +++++++++++++++++++ source/lexbor/html/interfaces/document.h | 2 -- source/lexbor/html/interfaces/element.c | 29 +++++++++++++++++++ source/lexbor/html/interfaces/style_element.c | 6 ++++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/source/lexbor/css/rule.h b/source/lexbor/css/rule.h index 7cc4f0b..bd191f9 100644 --- a/source/lexbor/css/rule.h +++ b/source/lexbor/css/rule.h @@ -339,6 +339,7 @@ lxb_css_rule_ref_dec(lxb_css_rule_t *rule) lxb_inline void lxb_css_rule_ref_dec_destroy(lxb_css_rule_t *rule) { +#if 0 if (rule->ref_count > 0) { rule->ref_count--; } @@ -346,6 +347,7 @@ lxb_css_rule_ref_dec_destroy(lxb_css_rule_t *rule) if (rule->ref_count == 0) { (void) lxb_css_rule_destroy(rule, true); } +#endif } lxb_inline void diff --git a/source/lexbor/html/interfaces/document.c b/source/lexbor/html/interfaces/document.c index bd3c02b..aa305a9 100644 --- a/source/lexbor/html/interfaces/document.c +++ b/source/lexbor/html/interfaces/document.c @@ -58,6 +58,7 @@ static lxb_html_document_css_custom_entry_t * lxb_html_document_css_customs_insert(lxb_html_document_t *document, const lxb_char_t *key, size_t length); +#if 0 static lxb_status_t lxb_html_document_style_remove_by_rule_cb(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec, @@ -74,6 +75,7 @@ lxb_html_document_style_cb(lxb_dom_node_t *node, static lxb_status_t lxb_html_document_done(lxb_html_document_t *document); +#endif lxb_status_t @@ -86,6 +88,7 @@ lxb_html_document_parser_prepare(lxb_html_document_t *document); static lexbor_action_t lxb_html_document_title_walker(lxb_dom_node_t *node, void *ctx); +#if 0 static lxb_status_t lxb_html_document_event_insert(lxb_dom_node_t *node); @@ -112,6 +115,7 @@ lxb_html_document_event_destroy(lxb_dom_node_t *node); static lxb_status_t lxb_html_document_event_set_value(lxb_dom_node_t *node, const lxb_char_t *value, size_t length); +#endif lxb_html_document_t * @@ -171,7 +175,9 @@ lxb_html_document_interface_destroy(lxb_html_document_t *document) if (doc->node.owner_document == doc) { (void) lxb_html_parser_unref(doc->parser); +#if 0 lxb_html_document_css_destroy(document); +#endif } (void) lxb_dom_document_destroy(doc); @@ -193,11 +199,14 @@ lxb_html_document_clean(lxb_html_document_t *document) document->iframe_srcdoc = NULL; document->ready_state = LXB_HTML_DOCUMENT_READY_STATE_UNDEF; +#if 0 lxb_html_document_css_clean(document); +#endif lxb_dom_document_clean(lxb_dom_interface_document(document)); } +#if 0 lxb_status_t lxb_html_document_css_init(lxb_html_document_t *document) { @@ -330,6 +339,7 @@ lxb_html_document_css_clean(lxb_html_document_t *document) lexbor_dobject_clean(css->weak); } } +#endif void lxb_html_document_css_parser_attach(lxb_html_document_t *document, @@ -575,6 +585,7 @@ void lxb_html_document_stylesheet_destroy_all(lxb_html_document_t *document, bool destroy_memory) { +#if 0 size_t length; lxb_css_stylesheet_t *sst; lxb_html_document_css_t *css = &document->css; @@ -586,29 +597,37 @@ lxb_html_document_stylesheet_destroy_all(lxb_html_document_t *document, (void) lxb_css_stylesheet_destroy(sst, destroy_memory); } +#endif } lxb_status_t lxb_html_document_style_attach(lxb_html_document_t *document, lxb_css_rule_style_t *style) { +#if 0 lxb_html_document_css_t *css = &document->css; return lxb_selectors_find(css->selectors, lxb_dom_interface_node(document), style->selector, lxb_html_document_style_cb, style); +#endif + return LXB_STATUS_OK; } lxb_status_t lxb_html_document_style_remove(lxb_html_document_t *document, lxb_css_rule_style_t *style) { +#if 0 lxb_html_document_css_t *css = &document->css; return lxb_selectors_find(css->selectors, lxb_dom_interface_node(document), style->selector, lxb_html_document_style_remove_by_rule_cb, style); +#endif + return LXB_STATUS_OK; } +#if 0 static lxb_status_t lxb_html_document_style_remove_by_rule_cb(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec, @@ -646,20 +665,25 @@ lxb_html_document_style_remove_avl_cb(lexbor_avl_t *avl, style, context->list); return LXB_STATUS_OK; } +#endif lxb_status_t lxb_html_document_style_attach_by_element(lxb_html_document_t *document, lxb_html_element_t *element, lxb_css_rule_style_t *style) { +#if 0 lxb_html_document_css_t *css = &document->css; return lxb_selectors_match_node(css->selectors, lxb_dom_interface_node(element), style->selector, lxb_html_document_style_cb, style); +#endif + return LXB_STATUS_OK; } +#if 0 static lxb_status_t lxb_html_document_style_cb(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec, void *ctx) @@ -675,6 +699,7 @@ lxb_html_document_style_cb(lxb_dom_node_t *node, return lxb_html_element_style_list_append(lxb_html_interface_element(node), style->declarations, spec); } +#endif lxb_html_document_t * lxb_html_document_destroy(lxb_html_document_t *document) @@ -851,6 +876,7 @@ lxb_html_document_parser_prepare(lxb_html_document_t *document) return LXB_STATUS_OK; } +#if 0 static lxb_status_t lxb_html_document_done(lxb_html_document_t *document) { @@ -875,6 +901,7 @@ lxb_html_document_done(lxb_html_document_t *document) return LXB_STATUS_OK; } +#endif const lxb_char_t * lxb_html_document_title(lxb_html_document_t *document, size_t *len) @@ -962,6 +989,7 @@ lxb_html_document_import_node(lxb_html_document_t *doc, lxb_dom_node_t *node, return lxb_dom_document_import_node(&doc->dom_document, node, deep); } +#if 0 static lxb_status_t lxb_html_document_event_insert(lxb_dom_node_t *node) { @@ -1233,6 +1261,7 @@ lxb_html_document_event_set_value(lxb_dom_node_t *node, return lxb_html_element_style_parse(lxb_html_interface_element(node), value, length); } +#endif /* * No inline functions for ABI. diff --git a/source/lexbor/html/interfaces/document.h b/source/lexbor/html/interfaces/document.h index 7e8d1ea..827ff64 100644 --- a/source/lexbor/html/interfaces/document.h +++ b/source/lexbor/html/interfaces/document.h @@ -20,7 +20,6 @@ extern "C" { #include "lexbor/dom/interfaces/attr.h" #include "lexbor/dom/interfaces/document.h" #include "lexbor/css/css.h" -#include "lexbor/selectors/selectors.h" typedef lxb_status_t @@ -45,7 +44,6 @@ typedef struct { lxb_css_memory_t *memory; lxb_css_selectors_t *css_selectors; lxb_css_parser_t *parser; - lxb_selectors_t *selectors; lexbor_avl_t *styles; lexbor_array_t *stylesheets; diff --git a/source/lexbor/html/interfaces/element.c b/source/lexbor/html/interfaces/element.c index 229d3d7..363040c 100644 --- a/source/lexbor/html/interfaces/element.c +++ b/source/lexbor/html/interfaces/element.c @@ -38,9 +38,11 @@ static lxb_status_t lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root, lexbor_avl_node_t *node, void *ctx); +#if 0 static lxb_status_t lxb_html_element_style_serialize_str_cb(const lxb_char_t *data, size_t len, void *ctx); +#endif lxb_html_element_t * @@ -102,6 +104,7 @@ const lxb_css_rule_declaration_t * lxb_html_element_style_by_name(lxb_html_element_t *element, const lxb_char_t *name, size_t size) { +#if 0 uintptr_t id; lxb_html_style_node_t *node; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; @@ -115,11 +118,14 @@ lxb_html_element_style_by_name(lxb_html_element_t *element, node = (void *) lexbor_avl_search(doc->css.styles, element->style, id); return (node != NULL) ? node->entry.value : NULL; +#endif + return NULL; } const lxb_css_rule_declaration_t * lxb_html_element_style_by_id(lxb_html_element_t *element, uintptr_t id) { +#if 0 const lxb_html_style_node_t *node; node = lxb_html_element_style_node_by_id(element, id); @@ -128,6 +134,8 @@ lxb_html_element_style_by_id(lxb_html_element_t *element, uintptr_t id) } return node->entry.value; +#endif + return NULL; } const lxb_html_style_node_t * @@ -144,6 +152,7 @@ const lxb_html_style_node_t * lxb_html_element_style_node_by_name(lxb_html_element_t *element, const lxb_char_t *name, size_t size) { +#if 0 uintptr_t id; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; lxb_html_document_t *doc = lxb_html_interface_document(ddoc); @@ -155,11 +164,14 @@ lxb_html_element_style_node_by_name(lxb_html_element_t *element, return (lxb_html_style_node_t *) lexbor_avl_search(doc->css.styles, element->style, id); +#endif + return NULL; } const void * lxb_html_element_css_property_by_id(lxb_html_element_t *element, uintptr_t id) { +#if 0 lxb_css_rule_declaration_t *declr; const lxb_html_style_node_t *node; @@ -171,6 +183,8 @@ lxb_html_element_css_property_by_id(lxb_html_element_t *element, uintptr_t id) declr = node->entry.value; return declr->u.user; +#endif + return NULL; } lxb_status_t @@ -224,6 +238,7 @@ lxb_status_t lxb_html_element_style_parse(lxb_html_element_t *element, const lxb_char_t *style, size_t size) { +#if 0 lxb_css_rule_declaration_list_t *list; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; @@ -240,6 +255,8 @@ lxb_html_element_style_parse(lxb_html_element_t *element, return lxb_html_element_style_list_append(element, list, lxb_css_selector_sp_up_s(0)); +#endif + return LXB_STATUS_ERROR; } lxb_status_t @@ -393,6 +410,7 @@ void lxb_html_element_style_remove_by_name(lxb_html_element_t *element, const lxb_char_t *name, size_t size) { +#if 0 uintptr_t id; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; lxb_html_document_t *doc = lxb_html_interface_document(ddoc); @@ -403,11 +421,13 @@ lxb_html_element_style_remove_by_name(lxb_html_element_t *element, } lxb_html_element_style_remove_by_id(element, id); +#endif } void lxb_html_element_style_remove_by_id(lxb_html_element_t *element, uintptr_t id) { +#if 0 lxb_html_style_node_t *node; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; lxb_html_document_t *doc = lxb_html_interface_document(ddoc); @@ -417,6 +437,7 @@ lxb_html_element_style_remove_by_id(lxb_html_element_t *element, uintptr_t id) if (node != NULL) { lxb_html_element_style_remove_all(doc, &element->style, node); } +#endif } lxb_html_style_node_t * @@ -576,6 +597,7 @@ static lxb_status_t lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root, lexbor_avl_node_t *node, void *ctx) { +#if 0 lxb_status_t status; lexbor_serialize_ctx_t *context = ctx; @@ -589,6 +611,8 @@ lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root, context->count = 1; return lxb_css_rule_serialize(node->value, context->cb, context->ctx); +#endif + return LXB_STATUS_ERROR; } lxb_status_t @@ -596,6 +620,7 @@ lxb_html_element_style_serialize_str(lxb_html_element_t *element, lexbor_str_t *str, lxb_html_element_style_opt_t opt) { +#if 0 lxb_dom_document_t *doc; lxb_html_element_style_ctx_t context; @@ -614,8 +639,11 @@ lxb_html_element_style_serialize_str(lxb_html_element_t *element, return lxb_html_element_style_serialize(element, opt, lxb_html_element_style_serialize_str_cb, &context); +#endif + return LXB_STATUS_ERROR; } +#if 0 static lxb_status_t lxb_html_element_style_serialize_str_cb(const lxb_char_t *data, size_t len, void *ctx) @@ -630,3 +658,4 @@ lxb_html_element_style_serialize_str_cb(const lxb_char_t *data, return LXB_STATUS_OK; } +#endif diff --git a/source/lexbor/html/interfaces/style_element.c b/source/lexbor/html/interfaces/style_element.c index 66d55c4..9a402ef 100644 --- a/source/lexbor/html/interfaces/style_element.c +++ b/source/lexbor/html/interfaces/style_element.c @@ -35,7 +35,9 @@ lxb_html_style_element_interface_destroy(lxb_html_style_element_t *style_element (void) lxb_dom_node_interface_destroy(lxb_dom_interface_node(style_element)); if (sst != NULL) { +#if 0 (void) lxb_css_stylesheet_destroy(sst, true); +#endif } return NULL; @@ -44,8 +46,10 @@ lxb_html_style_element_interface_destroy(lxb_html_style_element_t *style_element lxb_status_t lxb_html_style_element_parse(lxb_html_style_element_t *element) { +#if 0 lexbor_str_t *str; lxb_dom_text_t *text; +#endif lxb_dom_node_t *node; lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document; @@ -61,11 +65,13 @@ lxb_html_style_element_parse(lxb_html_style_element_t *element) return LXB_STATUS_OK; } +#if 0 text = lxb_dom_interface_text(lxb_dom_interface_node(element)->first_child); str = &text->char_data.data; element->stylesheet = lxb_css_stylesheet_parse(css->parser, str->data, str->length); +#endif if (element->stylesheet == NULL) { return css->parser->status; } -- 2.44.0