php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
active_formatting.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
8
12
13
14static lxb_html_element_t lxb_html_tree_active_formatting_marker_static;
15
16static lxb_dom_node_t *lxb_html_tree_active_formatting_marker_node_static =
17 (lxb_dom_node_t *) &lxb_html_tree_active_formatting_marker_static;
18
19
22{
23 return &lxb_html_tree_active_formatting_marker_static;
24}
25
26void
28{
29 void **list = tree->active_formatting->list;
30
31 while (tree->active_formatting->length != 0) {
33
34 if (list[tree->active_formatting->length]
35 == &lxb_html_tree_active_formatting_marker_static)
36 {
37 break;
38 }
39 }
40}
41
42void
44 lxb_dom_node_t *node)
45{
46 size_t delta;
47 void **list = tree->active_formatting->list;
48 size_t idx = tree->active_formatting->length;
49
50 while (idx != 0) {
51 idx--;
52
53 if (list[idx] == node) {
54 delta = tree->active_formatting->length - idx - 1;
55
56 memmove(list + idx, list + idx + 1, sizeof(void *) * delta);
57
59
60 break;
61 }
62 }
63}
64
65bool
67 lxb_dom_node_t *node,
68 size_t *return_pos)
69{
70 void **list = tree->active_formatting->list;
71
72 for (size_t i = 0; i < tree->active_formatting->length; i++) {
73 if (list[i] == node) {
74 if (return_pos) {
75 *return_pos = i;
76 }
77
78 return true;
79 }
80 }
81
82 if (return_pos) {
83 *return_pos = 0;
84 }
85
86 return false;
87}
88
89bool
91 lxb_dom_node_t *node,
92 size_t *return_pos)
93{
94 void **list = tree->active_formatting->list;
95 size_t len = tree->active_formatting->length;
96
97 while (len != 0) {
98 len--;
99
100 if (list[len] == node) {
101 if (return_pos) {
102 *return_pos = len;
103 }
104
105 return true;
106 }
107 }
108
109 if (return_pos) {
110 *return_pos = 0;
111 }
112
113 return false;
114}
115
118{
119 /* Step 1 */
120 if (tree->active_formatting->length == 0) {
121 return LXB_STATUS_OK;
122 }
123
125 void **list = af->list;
126
127 /* Step 2-3 */
128 size_t af_idx = af->length - 1;
129
130 if(list[af_idx] == &lxb_html_tree_active_formatting_marker_static
132 NULL))
133 {
134 return LXB_STATUS_OK;
135 }
136
137 /*
138 * Step 4-6
139 * Rewind
140 */
141 while (af_idx != 0) {
142 af_idx--;
143
144 if(list[af_idx] == &lxb_html_tree_active_formatting_marker_static ||
146 NULL))
147 {
148 /* Step 7 */
149 af_idx++;
150
151 break;
152 }
153 }
154
155 /*
156 * Step 8-10
157 * Create
158 */
159 lxb_dom_node_t *node;
160 lxb_html_element_t *element;
161 lxb_html_token_t fake_token = {0};
162
163 while (af_idx < af->length) {
164 node = list[af_idx];
165
166 fake_token.tag_id = node->local_name;
167 fake_token.base_element = node;
168
169 element = lxb_html_tree_insert_html_element(tree, &fake_token);
170 if (element == NULL) {
172 }
173
174 /* Step 9 */
175 list[af_idx] = lxb_dom_interface_node(element);
176
177 /* Step 10 */
178 af_idx++;
179 }
180
181 return LXB_STATUS_OK;
182}
183
186 lxb_tag_id_t tag_idx,
187 size_t *return_idx)
188{
190 size_t idx = tree->active_formatting->length;
191
192 while (idx) {
193 idx--;
194
195 if (list[idx] == lxb_html_tree_active_formatting_marker_node_static) {
196 return NULL;
197 }
198
199 if (list[idx]->local_name == tag_idx && list[idx]->ns == LXB_NS_HTML) {
200 if (return_idx) {
201 *return_idx = idx;
202 }
203
204 return list[idx];
205 }
206 }
207
208 return NULL;
209}
210
211void
213 lxb_dom_node_t *node)
214{
216 size_t idx = tree->active_formatting->length;
217 size_t earliest_idx = (idx ? (idx - 1) : 0);
218 size_t count = 0;
219
220 while (idx) {
221 idx--;
222
223 if (list[idx] == lxb_html_tree_active_formatting_marker_node_static) {
224 break;
225 }
226
227 if(list[idx]->local_name == node->local_name && list[idx]->ns == node->ns
230 {
231 count++;
232 earliest_idx = idx;
233 }
234 }
235
236 if(count >= 3) {
237 lxb_html_tree_active_formatting_remove(tree, earliest_idx);
238 }
239
241}
bool lxb_html_tree_active_formatting_find_by_node_reverse(lxb_html_tree_t *tree, lxb_dom_node_t *node, size_t *return_pos)
void lxb_html_tree_active_formatting_remove_by_node(lxb_html_tree_t *tree, lxb_dom_node_t *node)
void lxb_html_tree_active_formatting_up_to_last_marker(lxb_html_tree_t *tree)
bool lxb_html_tree_active_formatting_find_by_node(lxb_html_tree_t *tree, lxb_dom_node_t *node, size_t *return_pos)
lxb_html_element_t * lxb_html_tree_active_formatting_marker(void)
lxb_dom_node_t * lxb_html_tree_active_formatting_between_last_marker(lxb_html_tree_t *tree, lxb_tag_id_t tag_idx, size_t *return_idx)
void lxb_html_tree_active_formatting_push_with_check_dupl(lxb_html_tree_t *tree, lxb_dom_node_t *node)
lxb_status_t lxb_html_tree_active_formatting_reconstruct_elements(lxb_html_tree_t *tree)
lxb_inline void lxb_html_tree_active_formatting_remove(lxb_html_tree_t *tree, size_t idx)
lxb_inline lxb_status_t lxb_html_tree_active_formatting_push(lxb_html_tree_t *tree, lxb_dom_node_t *node)
size_t len
Definition apprentice.c:174
count(Countable|array $value, int $mode=COUNT_NORMAL)
@ LXB_STATUS_ERROR_MEMORY_ALLOCATION
Definition base.h:51
@ LXB_STATUS_OK
Definition base.h:49
#define lxb_dom_interface_element(obj)
Definition interface.h:28
#define lxb_dom_interface_node(obj)
Definition interface.h:31
struct lxb_dom_node lxb_dom_node_t
Definition interface.h:38
#define NULL
Definition gdcache.h:45
struct lxb_html_tree lxb_html_tree_t
Definition base.h:28
struct lxb_html_element lxb_html_element_t
Definition interface.h:111
bool lxb_dom_element_compare(lxb_dom_element_t *first, lxb_dom_element_t *second)
Definition element.c:477
@ LXB_NS_HTML
Definition const.h:26
bool lxb_html_tree_open_elements_find_by_node_reverse(lxb_html_tree_t *tree, lxb_dom_node_t *node, size_t *return_pos)
#define memmove(a, b, c)
size_t length
Definition array.h:20
void ** list
Definition array.h:18
uintptr_t ns
Definition node.h:48
uintptr_t local_name
Definition node.h:46
lxb_tag_id_t tag_id
Definition token.h:48
void * base_element
Definition token.h:45
lexbor_array_t * active_formatting
Definition tree.h:48
uintptr_t lxb_tag_id_t
Definition const.h:21
lxb_inline lxb_html_element_t * lxb_html_tree_insert_html_element(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition tree.h:307
unsigned int lxb_status_t
Definition types.h:28