1From 168dad55b6278cd45e0f0b2aed802ce9bace3274 Mon Sep 17 00:00:00 2001
2From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
3Date: Sun, 7 Jan 2024 21:59:28 +0100
4Subject: [PATCH 6/6] Patch out unused CSS style code
5
6---
7 source/lexbor/css/rule.h                      |  2 ++
8 source/lexbor/html/interfaces/document.c      | 29 +++++++++++++++++++
9 source/lexbor/html/interfaces/document.h      |  2 --
10 source/lexbor/html/interfaces/element.c       | 29 +++++++++++++++++++
11 source/lexbor/html/interfaces/style_element.c |  6 ++++
12 5 files changed, 66 insertions(+), 2 deletions(-)
13
14diff --git a/source/lexbor/css/rule.h b/source/lexbor/css/rule.h
15index 7cc4f0b..bd191f9 100644
16--- a/source/lexbor/css/rule.h
17+++ b/source/lexbor/css/rule.h
18@@ -339,6 +339,7 @@ lxb_css_rule_ref_dec(lxb_css_rule_t *rule)
19 lxb_inline void
20 lxb_css_rule_ref_dec_destroy(lxb_css_rule_t *rule)
21 {
22+#if 0
23     if (rule->ref_count > 0) {
24         rule->ref_count--;
25     }
26@@ -346,6 +347,7 @@ lxb_css_rule_ref_dec_destroy(lxb_css_rule_t *rule)
27     if (rule->ref_count == 0) {
28         (void) lxb_css_rule_destroy(rule, true);
29     }
30+#endif
31 }
32
33 lxb_inline void
34diff --git a/source/lexbor/html/interfaces/document.c b/source/lexbor/html/interfaces/document.c
35index bd3c02b..aa305a9 100644
36--- a/source/lexbor/html/interfaces/document.c
37+++ b/source/lexbor/html/interfaces/document.c
38@@ -58,6 +58,7 @@ static lxb_html_document_css_custom_entry_t *
39 lxb_html_document_css_customs_insert(lxb_html_document_t *document,
40                                      const lxb_char_t *key, size_t length);
41
42+#if 0
43 static lxb_status_t
44 lxb_html_document_style_remove_by_rule_cb(lxb_dom_node_t *node,
45                                           lxb_css_selector_specificity_t spec,
46@@ -74,6 +75,7 @@ lxb_html_document_style_cb(lxb_dom_node_t *node,
47
48 static lxb_status_t
49 lxb_html_document_done(lxb_html_document_t *document);
50+#endif
51
52
53 lxb_status_t
54@@ -86,6 +88,7 @@ lxb_html_document_parser_prepare(lxb_html_document_t *document);
55 static lexbor_action_t
56 lxb_html_document_title_walker(lxb_dom_node_t *node, void *ctx);
57
58+#if 0
59 static lxb_status_t
60 lxb_html_document_event_insert(lxb_dom_node_t *node);
61
62@@ -112,6 +115,7 @@ lxb_html_document_event_destroy(lxb_dom_node_t *node);
63 static lxb_status_t
64 lxb_html_document_event_set_value(lxb_dom_node_t *node,
65                                   const lxb_char_t *value, size_t length);
66+#endif
67
68
69 lxb_html_document_t *
70@@ -171,7 +175,9 @@ lxb_html_document_interface_destroy(lxb_html_document_t *document)
71
72     if (doc->node.owner_document == doc) {
73         (void) lxb_html_parser_unref(doc->parser);
74+#if 0
75         lxb_html_document_css_destroy(document);
76+#endif
77     }
78
79     (void) lxb_dom_document_destroy(doc);
80@@ -193,11 +199,14 @@ lxb_html_document_clean(lxb_html_document_t *document)
81     document->iframe_srcdoc = NULL;
82     document->ready_state = LXB_HTML_DOCUMENT_READY_STATE_UNDEF;
83
84+#if 0
85     lxb_html_document_css_clean(document);
86+#endif
87
88     lxb_dom_document_clean(lxb_dom_interface_document(document));
89 }
90
91+#if 0
92 lxb_status_t
93 lxb_html_document_css_init(lxb_html_document_t *document)
94 {
95@@ -330,6 +339,7 @@ lxb_html_document_css_clean(lxb_html_document_t *document)
96         lexbor_dobject_clean(css->weak);
97     }
98 }
99+#endif
100
101 void
102 lxb_html_document_css_parser_attach(lxb_html_document_t *document,
103@@ -575,6 +585,7 @@ void
104 lxb_html_document_stylesheet_destroy_all(lxb_html_document_t *document,
105                                          bool destroy_memory)
106 {
107+#if 0
108     size_t length;
109     lxb_css_stylesheet_t *sst;
110     lxb_html_document_css_t *css = &document->css;
111@@ -586,29 +597,37 @@ lxb_html_document_stylesheet_destroy_all(lxb_html_document_t *document,
112
113         (void) lxb_css_stylesheet_destroy(sst, destroy_memory);
114     }
115+#endif
116 }
117
118 lxb_status_t
119 lxb_html_document_style_attach(lxb_html_document_t *document,
120                                lxb_css_rule_style_t *style)
121 {
122+#if 0
123     lxb_html_document_css_t *css = &document->css;
124
125     return lxb_selectors_find(css->selectors, lxb_dom_interface_node(document),
126                               style->selector, lxb_html_document_style_cb, style);
127+#endif
128+    return LXB_STATUS_OK;
129 }
130
131 lxb_status_t
132 lxb_html_document_style_remove(lxb_html_document_t *document,
133                                lxb_css_rule_style_t *style)
134 {
135+#if 0
136     lxb_html_document_css_t *css = &document->css;
137
138     return lxb_selectors_find(css->selectors, lxb_dom_interface_node(document),
139                               style->selector,
140                               lxb_html_document_style_remove_by_rule_cb, style);
141+#endif
142+    return LXB_STATUS_OK;
143 }
144
145+#if 0
146 static lxb_status_t
147 lxb_html_document_style_remove_by_rule_cb(lxb_dom_node_t *node,
148                                           lxb_css_selector_specificity_t spec,
149@@ -646,20 +665,25 @@ lxb_html_document_style_remove_avl_cb(lexbor_avl_t *avl,
150                                           style, context->list);
151     return LXB_STATUS_OK;
152 }
153+#endif
154
155 lxb_status_t
156 lxb_html_document_style_attach_by_element(lxb_html_document_t *document,
157                                           lxb_html_element_t *element,
158                                           lxb_css_rule_style_t *style)
159 {
160+#if 0
161     lxb_html_document_css_t *css = &document->css;
162
163     return lxb_selectors_match_node(css->selectors,
164                                     lxb_dom_interface_node(element),
165                                     style->selector,
166                                     lxb_html_document_style_cb, style);
167+#endif
168+    return LXB_STATUS_OK;
169 }
170
171+#if 0
172 static lxb_status_t
173 lxb_html_document_style_cb(lxb_dom_node_t *node,
174                            lxb_css_selector_specificity_t spec, void *ctx)
175@@ -675,6 +699,7 @@ lxb_html_document_style_cb(lxb_dom_node_t *node,
176     return lxb_html_element_style_list_append(lxb_html_interface_element(node),
177                                               style->declarations, spec);
178 }
179+#endif
180
181 lxb_html_document_t *
182 lxb_html_document_destroy(lxb_html_document_t *document)
183@@ -851,6 +876,7 @@ lxb_html_document_parser_prepare(lxb_html_document_t *document)
184     return LXB_STATUS_OK;
185 }
186
187+#if 0
188 static lxb_status_t
189 lxb_html_document_done(lxb_html_document_t *document)
190 {
191@@ -875,6 +901,7 @@ lxb_html_document_done(lxb_html_document_t *document)
192
193     return LXB_STATUS_OK;
194 }
195+#endif
196
197 const lxb_char_t *
198 lxb_html_document_title(lxb_html_document_t *document, size_t *len)
199@@ -962,6 +989,7 @@ lxb_html_document_import_node(lxb_html_document_t *doc, lxb_dom_node_t *node,
200     return lxb_dom_document_import_node(&doc->dom_document, node, deep);
201 }
202
203+#if 0
204 static lxb_status_t
205 lxb_html_document_event_insert(lxb_dom_node_t *node)
206 {
207@@ -1233,6 +1261,7 @@ lxb_html_document_event_set_value(lxb_dom_node_t *node,
208     return lxb_html_element_style_parse(lxb_html_interface_element(node),
209                                         value, length);
210 }
211+#endif
212
213 /*
214  * No inline functions for ABI.
215diff --git a/source/lexbor/html/interfaces/document.h b/source/lexbor/html/interfaces/document.h
216index 7e8d1ea..827ff64 100644
217--- a/source/lexbor/html/interfaces/document.h
218+++ b/source/lexbor/html/interfaces/document.h
219@@ -20,7 +20,6 @@ extern "C" {
220 #include "lexbor/dom/interfaces/attr.h"
221 #include "lexbor/dom/interfaces/document.h"
222 #include "lexbor/css/css.h"
223-#include "lexbor/selectors/selectors.h"
224
225
226 typedef lxb_status_t
227@@ -45,7 +44,6 @@ typedef struct {
228     lxb_css_memory_t    *memory;
229     lxb_css_selectors_t *css_selectors;
230     lxb_css_parser_t    *parser;
231-    lxb_selectors_t     *selectors;
232
233     lexbor_avl_t        *styles;
234     lexbor_array_t      *stylesheets;
235diff --git a/source/lexbor/html/interfaces/element.c b/source/lexbor/html/interfaces/element.c
236index 229d3d7..363040c 100644
237--- a/source/lexbor/html/interfaces/element.c
238+++ b/source/lexbor/html/interfaces/element.c
239@@ -38,9 +38,11 @@ static lxb_status_t
240 lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root,
241                                     lexbor_avl_node_t *node, void *ctx);
242
243+#if 0
244 static lxb_status_t
245 lxb_html_element_style_serialize_str_cb(const lxb_char_t *data,
246                                         size_t len, void *ctx);
247+#endif
248
249
250 lxb_html_element_t *
251@@ -102,6 +104,7 @@ const lxb_css_rule_declaration_t *
252 lxb_html_element_style_by_name(lxb_html_element_t *element,
253                                const lxb_char_t *name, size_t size)
254 {
255+#if 0
256     uintptr_t id;
257     lxb_html_style_node_t *node;
258     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
259@@ -115,11 +118,14 @@ lxb_html_element_style_by_name(lxb_html_element_t *element,
260     node = (void *) lexbor_avl_search(doc->css.styles, element->style, id);
261
262     return (node != NULL) ? node->entry.value : NULL;
263+#endif
264+    return NULL;
265 }
266
267 const lxb_css_rule_declaration_t *
268 lxb_html_element_style_by_id(lxb_html_element_t *element, uintptr_t id)
269 {
270+#if 0
271     const lxb_html_style_node_t *node;
272
273     node = lxb_html_element_style_node_by_id(element, id);
274@@ -128,6 +134,8 @@ lxb_html_element_style_by_id(lxb_html_element_t *element, uintptr_t id)
275     }
276
277     return node->entry.value;
278+#endif
279+    return NULL;
280 }
281
282 const lxb_html_style_node_t *
283@@ -144,6 +152,7 @@ const lxb_html_style_node_t *
284 lxb_html_element_style_node_by_name(lxb_html_element_t *element,
285                                     const lxb_char_t *name, size_t size)
286 {
287+#if 0
288     uintptr_t id;
289     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
290     lxb_html_document_t *doc = lxb_html_interface_document(ddoc);
291@@ -155,11 +164,14 @@ lxb_html_element_style_node_by_name(lxb_html_element_t *element,
292
293     return (lxb_html_style_node_t *) lexbor_avl_search(doc->css.styles,
294                                                        element->style, id);
295+#endif
296+    return NULL;
297 }
298
299 const void *
300 lxb_html_element_css_property_by_id(lxb_html_element_t *element, uintptr_t id)
301 {
302+#if 0
303     lxb_css_rule_declaration_t *declr;
304     const lxb_html_style_node_t *node;
305
306@@ -171,6 +183,8 @@ lxb_html_element_css_property_by_id(lxb_html_element_t *element, uintptr_t id)
307     declr = node->entry.value;
308
309     return declr->u.user;
310+#endif
311+    return NULL;
312 }
313
314 lxb_status_t
315@@ -224,6 +238,7 @@ lxb_status_t
316 lxb_html_element_style_parse(lxb_html_element_t *element,
317                              const lxb_char_t *style, size_t size)
318 {
319+#if 0
320     lxb_css_rule_declaration_list_t *list;
321
322     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
323@@ -240,6 +255,8 @@ lxb_html_element_style_parse(lxb_html_element_t *element,
324
325     return lxb_html_element_style_list_append(element, list,
326                                               lxb_css_selector_sp_up_s(0));
327+#endif
328+    return LXB_STATUS_ERROR;
329 }
330
331 lxb_status_t
332@@ -393,6 +410,7 @@ void
333 lxb_html_element_style_remove_by_name(lxb_html_element_t *element,
334                                       const lxb_char_t *name, size_t size)
335 {
336+#if 0
337     uintptr_t id;
338     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
339     lxb_html_document_t *doc = lxb_html_interface_document(ddoc);
340@@ -403,11 +421,13 @@ lxb_html_element_style_remove_by_name(lxb_html_element_t *element,
341     }
342
343     lxb_html_element_style_remove_by_id(element, id);
344+#endif
345 }
346
347 void
348 lxb_html_element_style_remove_by_id(lxb_html_element_t *element, uintptr_t id)
349 {
350+#if 0
351     lxb_html_style_node_t *node;
352     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
353     lxb_html_document_t *doc = lxb_html_interface_document(ddoc);
354@@ -417,6 +437,7 @@ lxb_html_element_style_remove_by_id(lxb_html_element_t *element, uintptr_t id)
355     if (node != NULL) {
356         lxb_html_element_style_remove_all(doc, &element->style, node);
357     }
358+#endif
359 }
360
361 lxb_html_style_node_t *
362@@ -576,6 +597,7 @@ static lxb_status_t
363 lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root,
364                                     lexbor_avl_node_t *node, void *ctx)
365 {
366+#if 0
367     lxb_status_t status;
368     lexbor_serialize_ctx_t *context = ctx;
369
370@@ -589,6 +611,8 @@ lxb_html_element_style_serialize_cb(lexbor_avl_t *avl, lexbor_avl_node_t **root,
371     context->count = 1;
372
373     return lxb_css_rule_serialize(node->value, context->cb, context->ctx);
374+#endif
375+    return LXB_STATUS_ERROR;
376 }
377
378 lxb_status_t
379@@ -596,6 +620,7 @@ lxb_html_element_style_serialize_str(lxb_html_element_t *element,
380                                      lexbor_str_t *str,
381                                      lxb_html_element_style_opt_t opt)
382 {
383+#if 0
384     lxb_dom_document_t *doc;
385     lxb_html_element_style_ctx_t context;
386
387@@ -614,8 +639,11 @@ lxb_html_element_style_serialize_str(lxb_html_element_t *element,
388
389     return lxb_html_element_style_serialize(element, opt,
390                             lxb_html_element_style_serialize_str_cb, &context);
391+#endif
392+    return LXB_STATUS_ERROR;
393 }
394
395+#if 0
396 static lxb_status_t
397 lxb_html_element_style_serialize_str_cb(const lxb_char_t *data,
398                                         size_t len, void *ctx)
399@@ -630,3 +658,4 @@ lxb_html_element_style_serialize_str_cb(const lxb_char_t *data,
400
401     return LXB_STATUS_OK;
402 }
403+#endif
404diff --git a/source/lexbor/html/interfaces/style_element.c b/source/lexbor/html/interfaces/style_element.c
405index 66d55c4..9a402ef 100644
406--- a/source/lexbor/html/interfaces/style_element.c
407+++ b/source/lexbor/html/interfaces/style_element.c
408@@ -35,7 +35,9 @@ lxb_html_style_element_interface_destroy(lxb_html_style_element_t *style_element
409     (void) lxb_dom_node_interface_destroy(lxb_dom_interface_node(style_element));
410
411     if (sst != NULL) {
412+#if 0
413         (void) lxb_css_stylesheet_destroy(sst, true);
414+#endif
415     }
416
417     return NULL;
418@@ -44,8 +46,10 @@ lxb_html_style_element_interface_destroy(lxb_html_style_element_t *style_element
419 lxb_status_t
420 lxb_html_style_element_parse(lxb_html_style_element_t *element)
421 {
422+#if 0
423     lexbor_str_t *str;
424     lxb_dom_text_t *text;
425+#endif
426     lxb_dom_node_t *node;
427
428     lxb_dom_document_t *ddoc = lxb_dom_interface_node(element)->owner_document;
429@@ -61,11 +65,13 @@ lxb_html_style_element_parse(lxb_html_style_element_t *element)
430         return LXB_STATUS_OK;
431     }
432
433+#if 0
434     text = lxb_dom_interface_text(lxb_dom_interface_node(element)->first_child);
435     str = &text->char_data.data;
436
437     element->stylesheet = lxb_css_stylesheet_parse(css->parser, str->data,
438                                                    str->length);
439+#endif
440     if (element->stylesheet == NULL) {
441         return css->parser->status;
442     }
443--
4442.44.0
445
446