]> gitweb.michael.orlitzky.com - libsvgtiny.git/blob - src/svgtiny_css.c
008cefb7d95b63caa7979eb139f8ea3597c768b0
[libsvgtiny.git] / src / svgtiny_css.c
1 #include <libcss/libcss.h>
2 #include <strings.h> /* strncasecmp */
3
4 #include "svgtiny.h"
5 #include "svgtiny_internal.h"
6
7 static css_error node_name(void *pw, void *node, css_qname *qname);
8 static css_error node_classes(void *pw, void *node,
9 lwc_string ***classes, uint32_t *n_classes);
10 static css_error node_id(void *pw, void *node, lwc_string **id);
11 static css_error named_parent_node(void *pw, void *node,
12 const css_qname *qname, void **parent);
13 static css_error named_sibling_node(void *pw, void *node,
14 const css_qname *qname, void **sibling);
15 static css_error named_generic_sibling_node(void *pw, void *node,
16 const css_qname *qname, void **sibling);
17 static css_error parent_node(void *pw, void *node, void **parent);
18 static css_error sibling_node(void *pw, void *node, void **sibling);
19 static css_error node_has_name(void *pw, void *node,
20 const css_qname *qname, bool *match);
21 static css_error node_has_class(void *pw, void *node,
22 lwc_string *name, bool *match);
23 static css_error node_has_id(void *pw, void *node,
24 lwc_string *name, bool *match);
25 static css_error node_has_attribute(void *pw, void *node,
26 const css_qname *qname, bool *match);
27 static css_error node_has_attribute_equal(void *pw, void *node,
28 const css_qname *qname, lwc_string *value,
29 bool *match);
30 static css_error node_has_attribute_dashmatch(void *pw, void *node,
31 const css_qname *qname, lwc_string *value,
32 bool *match);
33 static css_error node_has_attribute_includes(void *pw, void *node,
34 const css_qname *qname, lwc_string *word,
35 bool *match);
36 static css_error node_has_attribute_prefix(void *pw, void *node,
37 const css_qname *qname, lwc_string *prefix,
38 bool *match);
39 static css_error node_has_attribute_suffix(void *pw, void *node,
40 const css_qname *qname, lwc_string *suffix,
41 bool *match);
42 static css_error node_has_attribute_substring(void *pw, void *node,
43 const css_qname *qname, lwc_string *substring,
44 bool *match);
45 static css_error node_is_root(void *pw, void *node, bool *match);
46 static css_error node_count_siblings(void *pw, void *node,
47 bool same_name, bool after, int32_t *count);
48 static css_error node_is_empty(void *pw, void *node, bool *is_empty);
49 static css_error node_is_link(void *pw, void *node, bool *is_link);
50 static css_error node_is_hover(void *pw, void *node, bool *is_hover);
51 static css_error node_is_active(void *pw, void *node, bool *is_active);
52 static css_error node_is_focus(void *pw, void *node, bool *is_focus);
53
54
55 /**
56 * Resolve a relative URL to an absolute one by doing nothing. This is
57 * the simplest possible implementation of a URL resolver, needed for
58 * parsing CSS.
59 */
60 css_error svgtiny_resolve_url(void *pw,
61 const char *base, lwc_string *rel, lwc_string **abs)
62 {
63 UNUSED(pw);
64 UNUSED(base);
65
66 /* Copy the relative URL to the absolute one (the return
67 value) */
68 *abs = lwc_string_ref(rel);
69 return CSS_OK;
70 }
71
72 /**
73 * Create a stylesheet with the default set of params.
74 *
75 * \param sheet A stylesheet pointer, passed in by reference, that
76 * we use to store the newly-created stylesheet.
77 * \param inline_style True if this stylesheet represents an inline
78 * style, and false otherwise.
79 *
80 * \return The return value from css_stylesheet_create() is returned.
81 */
82 css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
83 bool inline_style)
84 {
85 css_stylesheet_params params;
86
87 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
88 params.level = CSS_LEVEL_DEFAULT;
89 params.charset = NULL;
90 params.url = "";
91 params.title = NULL;
92 params.allow_quirks = false;
93 params.inline_style = inline_style;
94 params.resolve = svgtiny_resolve_url;
95 params.resolve_pw = NULL;
96 params.import = NULL;
97 params.import_pw = NULL;
98 params.color = NULL;
99 params.color_pw = NULL;
100 params.font = NULL;
101 params.font_pw = NULL;
102
103 return css_stylesheet_create(&params, sheet);
104 }
105
106
107 /**************************/
108 /* libcss select handlers */
109 /**************************/
110 /*
111 * From here on we implement the "select handler "API defined in
112 * libcss's include/libcss/select.h and discussed briefly in its
113 * docs/API document.
114 */
115
116
117 /**
118 * Retrieve the given node's name
119 *
120 * \param pw Pointer to the current SVG parser state
121 * \param node Libdom SVG node
122 * \param qname Address at which to store the node name
123 *
124 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
125 */
126 css_error node_name(void *pw, void *node, css_qname *qname)
127 {
128 dom_string *name;
129 dom_exception err;
130 struct svgtiny_parse_state *state;
131
132 err = dom_node_get_node_name((dom_node *)node, &name);
133 if (err != DOM_NO_ERR) {
134 return CSS_NOMEM;
135 }
136
137 state = (struct svgtiny_parse_state *)pw;
138 qname->ns = lwc_string_ref(state->interned_svg_xmlns);
139
140 err = dom_string_intern(name, &qname->name);
141 if (err != DOM_NO_ERR) {
142 dom_string_unref(name);
143 return CSS_NOMEM;
144 }
145
146 dom_string_unref(name);
147
148 return CSS_OK;
149 }
150
151
152 /**
153 * Retrieve the given node's classes
154 *
155 * \param pw Pointer to the current SVG parser state
156 * \param node Libdom SVG node
157 * \param classes Address at which to store the class name array
158 * \param n_classes Address at which to store the length of the class
159 * name array
160 *
161 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
162 *
163 * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
164 * because the underlying libdom function never fails
165 */
166 css_error node_classes(void *pw, void *node,
167 lwc_string ***classes, uint32_t *n_classes)
168 {
169 UNUSED(pw);
170 dom_exception err;
171
172 err = dom_element_get_classes((dom_node *)node, classes, n_classes);
173
174 /* The implementation does not do it, but the documentation
175 for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
176 possible here, so we handle it to be on the safe side. */
177 if (err != DOM_NO_ERR) {
178 return CSS_NOMEM;
179 }
180
181 return CSS_OK;
182 }
183
184
185 /**
186 * Retrieve the given node's id
187 *
188 * \param pw Pointer to the current SVG parser state
189 * \param node Libdom SVG node
190 * \param id Address at which to store the id
191 *
192 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
193 */
194 css_error node_id(void *pw, void *node, lwc_string **id)
195 {
196 dom_string *attr;
197 dom_exception err;
198 struct svgtiny_parse_state *state;
199
200 /* Begin with the assumption that this node has no id */
201 *id = NULL;
202
203 state = (struct svgtiny_parse_state *)pw;
204 err = dom_element_get_attribute((dom_node *)node,
205 state->interned_id, &attr);
206 if (err != DOM_NO_ERR) {
207 return CSS_NOMEM;
208 }
209 else if (attr == NULL) {
210 /* The node has no id attribute and our return value
211 is already set to NULL so we're done */
212 return CSS_OK;
213 }
214
215 /* If we found an id attribute (a dom_string), intern it into
216 an lwc_string that we can return, and then cleanup the
217 dom_string. */
218 err = dom_string_intern(attr, id);
219 if (err != DOM_NO_ERR) {
220 dom_string_unref(attr);
221 return CSS_NOMEM;
222 }
223 dom_string_unref(attr);
224 return CSS_OK;
225 }
226
227
228
229 /**
230 * Find the first parent of the given element having the given name
231 *
232 * \param pw Pointer to the current SVG parser state
233 * \param node Libdom SVG node
234 * \param qname Name of the parent node to search for
235 * \param parent Address at which to store the parent node pointer
236 *
237 * \return Always returns CSS_OK
238 *
239 * \post If a suitable element is found, a pointer to it will be
240 * stored at the address pointed to by \a parent; otherwise,
241 * NULL will be stored at the address pointed to by \a parent
242 */
243 css_error named_parent_node(void *pw, void *node,
244 const css_qname *qname, void **parent)
245 {
246 UNUSED(pw);
247 /* dom_element_named_parent_node() was invented to implement
248 * this select handler so there isn't much for us to do except
249 * call it. It's OK if node isn't an element, libdom checks
250 * for it. */
251 dom_element_named_parent_node((dom_element *)node,
252 qname->name,
253 (struct dom_element **)parent);
254
255 /* Implementation detail: dom_element_named_parent_node()
256 * increments the reference count of the parent element before
257 * returning it to us. According to docs/RefCnt in the libdom
258 * repository, this will prevent the parent element from being
259 * destroyed if it is pruned from the DOM. That sounds good,
260 * since we don't want to be using a pointer to an object that
261 * has been destroyed... but we also have no way of later
262 * decrementing the reference count ourselves, and don't want
263 * to make the returned node eternal. Decrementing the
264 * reference counter now allows it to be destroyed when the
265 * DOM no longer needs it, and so long as no other parts of
266 * libsvgtiny are messing with the DOM during parsing, that
267 * shouldn't (ha ha) cause any problems. */
268 dom_node_unref(*parent);
269
270 return CSS_OK;
271 }
272
273
274 /**
275 * Find the "next-sibling" of the given element having the given name
276 *
277 * This search corresponds to the "+ foo" combinator in CSS and will
278 * find only "foo" element nodes that immediately precede the given
279 * node under the same parent in the DOM. In CSS the tree is viewed
280 * top-down and in libdom it is viewed from the bottom-up; as a result
281 * "next" and "previous" are sometimes backwards. This is case-sensitive.
282 *
283 * \param pw Pointer to the current SVG parser state
284 * \param node Libdom SVG node
285 * \param qname Name of the sibling node to search for
286 * \param sibling Address at which to store the sibling node pointer
287 *
288 * \return Always returns CSS_OK
289 *
290 * \post If a suitable element is found, a pointer to it will be
291 * stored at the address pointed to by \a sibling; otherwise,
292 * NULL will be stored at the address pointed to by \a sibling
293 */
294 css_error named_sibling_node(void *pw, void *node,
295 const css_qname *qname, void **sibling)
296 {
297 UNUSED(pw);
298 dom_node *n = node; /* the current node */
299 dom_node *prev; /* the previous node */
300 dom_exception err;
301 dom_node_type type;
302 dom_string *name;
303
304 *sibling = NULL; /* default to nothing found */
305
306 /* Begin the search; the first iteration we do outside of the
307 * loop. Implementation detil: dom_node_get_previous_sibling()
308 * increments the reference counter on the returned node. A
309 * comment within named_parent_node() explains why we
310 * decrement it ASAP. */
311 err = dom_node_get_previous_sibling(n, &n);
312 if (err != DOM_NO_ERR) {
313 return CSS_OK;
314 }
315
316 while (n != NULL) {
317 /* We're looking for the first ELEMENT sibling */
318 err = dom_node_get_node_type(n, &type);
319 if (err != DOM_NO_ERR) {
320 dom_node_unref(n);
321 return CSS_OK;
322 }
323
324 if (type == DOM_ELEMENT_NODE) {
325 /* We found an element node, does it have the
326 * right name? */
327 err = dom_node_get_node_name(n, &name);
328 if (err != DOM_NO_ERR) {
329 dom_node_unref(n);
330 return CSS_OK;
331 }
332
333 if (dom_string_lwc_isequal(name,
334 qname->name)) {
335 /* The name is right, return it */
336 *sibling = n;
337 }
338
339 /* There's only one next-sibling element node
340 * and we've already found it, so if its name
341 * wasn't right, we return the default value
342 * of NULL below */
343 dom_string_unref(name);
344 dom_node_unref(n);
345 return CSS_OK;
346 }
347
348 /* Not an element node, so we move on the the previous
349 * previous sibling */
350 err = dom_node_get_previous_sibling(n, &prev);
351 if (err != DOM_NO_ERR) {
352 dom_node_unref(n);
353 return CSS_OK;
354 }
355
356 dom_node_unref(n);
357 n = prev;
358 }
359
360 return CSS_OK;
361 }
362
363
364 /**
365 * Find the first "subsequent-sibling" of the given element having the
366 * given name
367 *
368 * This search corresponds to the "~ foo" combinator in CSS and will
369 * find only "foo" element nodes that precede the given node (under
370 * the same parent) in the DOM. In CSS the tree is viewed top-down and
371 * in libdom it is viewed from the bottom-up; as a result "next" and
372 * "previous" are sometimes backwards. This is case-sensitive.
373 *
374 * \param pw Pointer to the current SVG parser state
375 * \param node Libdom SVG node
376 * \param qname Name of the sibling node to search for
377 * \param sibling Address at which to store the sibling node pointer
378 *
379 * \return Always returns CSS_OK
380 *
381 * \post If a suitable element is found, a pointer to it will be
382 * stored at the address pointed to by \a sibling; otherwise,
383 * NULL will be stored at the address pointed to by \a sibling
384 */
385 css_error named_generic_sibling_node(void *pw, void *node,
386 const css_qname *qname, void **sibling)
387 {
388 UNUSED(pw);
389 dom_node *n = node; /* the current node */
390 dom_node *prev; /* the previous node */
391 dom_exception err;
392 dom_node_type type;
393 dom_string *name;
394
395
396 *sibling = NULL; /* default to nothing found */
397
398 /* Begin the search; the first iteration we do outside of the
399 * loop. Implementation detil: dom_node_get_previous_sibling()
400 * increments the reference counter on the returned node. A
401 * comment within named_parent_node() explains why we
402 * decrement it ASAP. */
403 err = dom_node_get_previous_sibling(n, &n);
404 if (err != DOM_NO_ERR) {
405 return CSS_OK;
406 }
407
408 while (n != NULL) {
409 err = dom_node_get_node_type(n, &type);
410 if (err != DOM_NO_ERR) {
411 dom_node_unref(n);
412 return CSS_OK;
413 }
414
415 if (type == DOM_ELEMENT_NODE) {
416 /* We only want ELEMENT nodes */
417 err = dom_node_get_node_name(n, &name);
418 if (err != DOM_NO_ERR) {
419 dom_node_unref(n);
420 return CSS_OK;
421 }
422
423 if (dom_string_lwc_isequal(name,
424 qname->name)) {
425 /* Found one. Save it and stop the search */
426 dom_string_unref(name);
427 dom_node_unref(n);
428 *sibling = n;
429 return CSS_OK;
430 }
431
432 dom_string_unref(name);
433 }
434
435 /* This sibling wasn't an element with the desired
436 name, so move on to the previous sibling */
437 err = dom_node_get_previous_sibling(n, &prev);
438 if (err != DOM_NO_ERR) {
439 dom_node_unref(n);
440 return CSS_OK;
441 }
442
443 dom_node_unref(n);
444 n = prev;
445 }
446
447 return CSS_OK;
448 }
449
450
451 /**
452 * Return a pointer to the given node's parent
453 *
454 * \param pw Pointer to the current SVG parser state
455 * \param node Libdom SVG node
456 * \param parent Address at which to store the node's parent pointer
457 *
458 * \return Always returns CSS_OK
459 */
460 css_error parent_node(void *pw, void *node, void **parent)
461 {
462 UNUSED(pw);
463 /* Libdom basically implements this for us */
464 dom_element_parent_node(node, (struct dom_element **)parent);
465
466 /* See the comment in named_parent_node() for why we decrement
467 * this reference counter here. */
468 dom_node_unref(*parent);
469
470 return CSS_OK;
471 }
472
473
474 /**
475 * Find the "next-sibling" of the given element
476 *
477 * This search corresponds "+ *" in CSS and will find the first
478 * element node that immediately precedes the given node under the
479 * same parent in the DOM. In CSS the tree is viewed top-down and in
480 * libdom it is viewed from the bottom-up; as a result "next" and
481 * "previous" are sometimes backwards.
482 *
483 * \param pw Pointer to the current SVG parser state
484 * \param node Libdom SVG node
485 * \param sibling Address at which to store the sibling node pointer
486 *
487 * \return Always returns CSS_OK
488 *
489 * \post If a suitable element is found, a pointer to it will be
490 * stored at the address pointed to by \a sibling; otherwise,
491 * NULL will be stored at the address pointed to by \a sibling
492 */
493 css_error sibling_node(void *pw, void *node, void **sibling)
494 {
495 UNUSED(pw);
496 dom_node *n = node; /* the current node */
497 dom_node *prev; /* the previous node */
498 dom_exception err;
499 dom_node_type type;
500
501 *sibling = NULL; /* default to nothing found */
502
503 /* Begin the search; the first iteration we do outside of the
504 * loop. Implementation detil: dom_node_get_previous_sibling()
505 * increments the reference counter on the returned node. A
506 * comment within named_parent_node() explains why we
507 * decrement it ASAP. */
508 err = dom_node_get_previous_sibling(n, &n);
509 if (err != DOM_NO_ERR) {
510 return CSS_OK;
511 }
512
513 while (n != NULL) {
514 err = dom_node_get_node_type(n, &type);
515 if (err != DOM_NO_ERR) {
516 dom_node_unref(n);
517 return CSS_OK;
518 }
519
520 if (type == DOM_ELEMENT_NODE) {
521 /* We found a sibling node that is also an
522 element and that's all we wanted. */
523 *sibling = n;
524 dom_node_unref(n);
525 return CSS_OK;
526 }
527
528 /* This sibling node was not an element; move on to
529 the previous sibling */
530 err = dom_node_get_previous_sibling(n, &prev);
531 if (err != DOM_NO_ERR) {
532 dom_node_unref(n);
533 return CSS_OK;
534 }
535
536 dom_node_unref(n);
537 n = prev;
538 }
539
540 return CSS_OK;
541 }
542
543
544 /**
545 * Test the given node for the given name
546 *
547 * This will return true (via the "match" pointer) if the libdom node
548 * has the given name or if that name is the universal selector;
549 * otherwise it returns false. The comparison is case-sensitive. It
550 * corresponds to a rule like "body { ... }" in CSS.
551 *
552 * \param pw Pointer to the current SVG parser state
553 * \param node Libdom SVG node to test
554 * \param qname Name to check for
555 * \param match Pointer to the test result
556 *
557 * \return Always returns CSS_OK
558 */
559 css_error node_has_name(void *pw, void *node,
560 const css_qname *qname, bool *match)
561 {
562 struct svgtiny_parse_state *state;
563 dom_string *name;
564 dom_exception err;
565
566 /* Start by checking to see if qname is the universal selector */
567 state = (struct svgtiny_parse_state *)pw;
568 if (lwc_string_isequal(qname->name,
569 state->interned_universal, match) == lwc_error_ok) {
570 if (*match) {
571 /* It's the universal selector. In NetSurf, all node
572 * names match the universal selector, and nothing in
573 * the libcss documentation suggests another approach,
574 * so we follow NetSurf here. */
575 return CSS_OK;
576 }
577 }
578
579 err = dom_node_get_node_name((dom_node *)node, &name);
580 if (err != DOM_NO_ERR) {
581 return CSS_OK;
582 }
583
584 /* Unlike with HTML, SVG element names are case-sensitive */
585 *match = dom_string_lwc_isequal(name, qname->name);
586 dom_string_unref(name);
587
588 return CSS_OK;
589 }
590
591
592 /**
593 * Test the given node for the given class
594 *
595 * This will return true (via the "match" pointer) if the libdom node
596 * has the given class. The comparison is case-sensitive. It
597 * corresponds to node.class in CSS.
598 *
599 * \param pw Pointer to the current SVG parser state
600 * \param node Libdom SVG node to test
601 * \param name Class name to check for
602 * \param match Pointer to the test result
603 *
604 * \return Always returns CSS_OK
605 */
606 css_error node_has_class(void *pw, void *node,
607 lwc_string *name, bool *match)
608 {
609 UNUSED(pw);
610 /* libdom implements this for us and apparently it cannot fail */
611 dom_element_has_class((dom_node *)node, name, match);
612 return CSS_OK;
613 }
614
615
616 /**
617 * Test the given node for the given id
618 *
619 * This will return true (via the "match" pointer) if the libdom node
620 * has the given id. The comparison is case-sensitive. It corresponds
621 * to node#id in CSS.
622 *
623 * \param pw Pointer to the current SVG parser state
624 * \param node Libdom SVG node to test
625 * \param name Id to check for
626 * \param match Pointer to the test result
627 *
628 * \return Always returns CSS_OK
629 */
630 css_error node_has_id(void *pw, void *node,
631 lwc_string *name, bool *match)
632 {
633 dom_string *attr;
634 dom_exception err;
635 struct svgtiny_parse_state *state;
636
637 attr = NULL; /* a priori the "id" attribute may not exist */
638 *match = false; /* default to no match */
639
640 state = (struct svgtiny_parse_state *)pw;
641 err = dom_element_get_attribute((dom_node *)node,
642 state->interned_id, &attr);
643 if (err != DOM_NO_ERR || attr == NULL) {
644 return CSS_OK;
645 }
646
647 *match = dom_string_lwc_isequal(attr, name);
648 dom_string_unref(attr);
649
650 return CSS_OK;
651 }
652
653
654 /**
655 * Test the given node for the given attribute
656 *
657 * This will return true (via the "match" pointer) if the libdom node
658 * has an attribute with the given name. The comparison is
659 * case-sensitive. It corresponds to node[attr] in CSS.
660 *
661 * \param pw Pointer to the current SVG parser state
662 * \param node Libdom SVG node to test
663 * \param qname Attribute name to check for
664 * \param match Pointer to the test result
665 *
666 * \return Returns CSS_OK if successful and CSS_NOMEM if anything
667 * goes wrong
668 */
669 css_error node_has_attribute(void *pw, void *node,
670 const css_qname *qname, bool *match)
671 {
672 UNUSED(pw);
673 dom_string *name;
674 dom_exception err;
675
676 /* intern the attribute name as a dom_string so we can
677 * delegate to dom_element_has_attribute() */
678 err = dom_string_create_interned(
679 (const uint8_t *) lwc_string_data(qname->name),
680 lwc_string_length(qname->name),
681 &name);
682 if (err != DOM_NO_ERR) {
683 return CSS_NOMEM;
684 }
685
686 err = dom_element_has_attribute((dom_node *)node, name, match);
687 if (err != DOM_NO_ERR) {
688 dom_string_unref(name);
689 return CSS_OK;
690 }
691
692 dom_string_unref(name);
693 return CSS_OK;
694 }
695
696
697 /**
698 * Test the given node for an attribute with a specific value
699 *
700 * This will return true (via the "match" pointer) if the libdom node
701 * has an attribute with the given name and value. The comparison is
702 * case-sensitive. It corresponds to node[attr=value] in CSS.
703 *
704 * \param pw Pointer to the current SVG parser state
705 * \param node Libdom SVG node to test
706 * \param qname Attribute name to check for
707 * \param value Attribute value to check for
708 * \param match Pointer to the test result
709 *
710 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
711 * intern the attribute name (which usually indicates memory
712 * exhaustion)
713 */
714 css_error node_has_attribute_equal(void *pw, void *node,
715 const css_qname *qname, lwc_string *value,
716 bool *match)
717 {
718 /* Implementation note: NetSurf always returns "no match" when
719 * the value is empty (length zero). We allow it, because why
720 * not? */
721
722 UNUSED(pw);
723 dom_string *name;
724 dom_string *attr_val;
725 dom_exception err;
726
727 /* Intern the attribute name as a dom_string so we can
728 * use dom_element_get_attribute() */
729 err = dom_string_create_interned(
730 (const uint8_t *) lwc_string_data(qname->name),
731 lwc_string_length(qname->name),
732 &name);
733 if (err != DOM_NO_ERR) {
734 return CSS_NOMEM;
735 }
736
737 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
738 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
739 /* There was an error getting the attribute's value or
740 * the attribute doesn't exist. So, no match? */
741 dom_string_unref(name);
742 *match = false;
743 return CSS_OK;
744 }
745
746 /* Otherwise, we have the attribute value from the given node
747 * and all we need to do is compare. */
748 dom_string_unref(name);
749 *match = dom_string_lwc_isequal(attr_val, value);
750 dom_string_unref(attr_val);
751
752 return CSS_OK;
753 }
754
755
756 /**
757 * Test the given node for an attribute with a specific value,
758 * possibly followed by a single hyphen
759 *
760 * This will return true (via the "match" pointer) if the libdom node
761 * has an attribute with the given name and value or with the given
762 * name and a value that is followed by exactly one hyphen. The
763 * comparison is case-sensitive. This corresponds to [attr|=value]
764 * in CSS.
765 *
766 * \param pw Pointer to the current SVG parser state
767 * \param node Libdom SVG node to test
768 * \param qname Attribute name to check for
769 * \param value Attribute value to check for
770 * \param match Pointer to the test result
771 *
772 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
773 * intern the attribute name (which usually indicates memory
774 * exhaustion)
775 */
776 css_error node_has_attribute_dashmatch(void *pw, void *node,
777 const css_qname *qname, lwc_string *value,
778 bool *match)
779 {
780 /* Implementation note: NetSurf always returns "no match" when
781 * the value is empty (length zero). We allow it, because why
782 * not? */
783
784 UNUSED(pw);
785 dom_string *name;
786 dom_string *attr_val;
787 dom_exception err;
788
789 const char *vdata; /* to hold the data underlying "value" */
790 size_t vdata_len;
791 const char *avdata; /* to hold the found attribute value data */
792 size_t avdata_len;
793
794 /* Intern the attribute name as a dom_string so we can
795 * use dom_element_get_attribute() */
796 err = dom_string_create_interned(
797 (const uint8_t *) lwc_string_data(qname->name),
798 lwc_string_length(qname->name),
799 &name);
800 if (err != DOM_NO_ERR) {
801 return CSS_NOMEM;
802 }
803
804 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
805 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
806 /* There was an error getting the attribute's value or
807 * the attribute doesn't exist. So, no match? */
808 dom_string_unref(name);
809 *match = false;
810 return CSS_OK;
811 }
812
813 /* Otherwise, we have the attribute value from the given node
814 * and all we need to do is compare. */
815 dom_string_unref(name);
816 *match = dom_string_lwc_isequal(attr_val, value);
817 if (*match) {
818 /* Exact match, we're done */
819 dom_string_unref(attr_val);
820 return CSS_OK;
821 }
822
823 /* No exact match, try it with a hyphen on the end */
824 vdata = lwc_string_data(value); /* needle */
825 vdata_len = lwc_string_length(value);
826 avdata = dom_string_data(attr_val); /* haystack */
827 avdata_len = dom_string_byte_length(attr_val);
828 dom_string_unref(attr_val);
829
830 if (avdata_len > vdata_len && avdata[vdata_len] == '-') {
831 if (strncasecmp(avdata, vdata, vdata_len) == 0) {
832 /* If there's a hyphen in the right position,
833 * it suffices to compare the strings only up
834 * to the hyphen */
835 *match = true;
836 }
837 }
838
839 return CSS_OK;
840 }
841
842
843 /**
844 * Test the given node for an attribute whose value is a
845 * space-separated list of words, one of which is the given word
846 *
847 * This will return true (via the "match" pointer) if the libdom node
848 * has an attribute with the given name and whose value when
849 * considered as a space-separated list of words contains the given
850 * word. The comparison is case-sensitive. This corresponds to
851 * [attr~=value] in CSS.
852 *
853 * \param pw Pointer to the current SVG parser state
854 * \param node Libdom SVG node to test
855 * \param qname Attribute name to check for
856 * \param word Value word to check for
857 * \param match Pointer to the test result
858 *
859 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
860 * intern the attribute name (which usually indicates memory
861 * exhaustion)
862 */
863 css_error node_has_attribute_includes(void *pw, void *node,
864 const css_qname *qname, lwc_string *word,
865 bool *match)
866 {
867 UNUSED(pw);
868
869 dom_string *name;
870 dom_string *attr_val;
871 dom_exception err;
872 size_t wordlen; /* length of "word" */
873
874 /* pointers used to parse a space-separated list of words */
875 const char *p;
876 const char *start;
877 const char *end;
878
879 *match = false; /* default to no match */
880
881 wordlen = lwc_string_length(word);
882 if (wordlen == 0) {
883 /* In this case, the spec says that "if 'val' is the
884 * empty string, it will never represent anything." */
885 return CSS_OK;
886 }
887
888 /* Intern the attribute name as a dom_string so we can
889 * use dom_element_get_attribute() */
890 err = dom_string_create_interned(
891 (const uint8_t *) lwc_string_data(qname->name),
892 lwc_string_length(qname->name),
893 &name);
894 if (err != DOM_NO_ERR) {
895 return CSS_NOMEM;
896 }
897
898 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
899 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
900 /* There was an error getting the attribute's value or
901 * the attribute doesn't exist. So, no match? */
902 dom_string_unref(name);
903 return CSS_OK;
904 }
905
906 /* Parse the list comparing each word against "word" */
907 start = dom_string_data(attr_val);
908 end = start + dom_string_byte_length(attr_val);
909 dom_string_unref(attr_val);
910
911 for (p = start; p <= end; p++) {
912 /* Move forward until we find the end of the first word */
913 if (*p == ' ' || *p == '\0') {
914 /* If the length of that word is the length of the
915 * word we're looking for, do the comparison. */
916 if ((size_t) (p - start) == wordlen &&
917 strncasecmp(start,
918 lwc_string_data(word),
919 wordlen) == 0) {
920 *match = true;
921 break;
922 }
923 /* No match? Set "start" to the beginning of
924 * the next word and loop. */
925 start = p + 1;
926 }
927 }
928
929 return CSS_OK;
930 }
931
932
933 /**
934 * Test the given node for an attribute whose value begins with the
935 * given prefix
936 *
937 * This will return true (via the "match" pointer) if the libdom node
938 * has an attribute with the given name and whose value begins with
939 * the given prefix string. The comparison is case-sensitive. This
940 * corresponds to [attr^=value] in CSS.
941 *
942 * \param pw Pointer to the current SVG parser state
943 * \param node Libdom SVG node to test
944 * \param qname Attribute name to check for
945 * \param prefix Value prefix to check for
946 * \param match Pointer to the test result
947 *
948 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
949 * intern the attribute name (which usually indicates memory
950 * exhaustion)
951 */
952 css_error node_has_attribute_prefix(void *pw, void *node,
953 const css_qname *qname, lwc_string *prefix,
954 bool *match)
955 {
956 UNUSED(pw);
957 dom_string *name;
958 dom_string *attr_val;
959 dom_exception err;
960 const char *avdata; /* attribute value data */
961 size_t avdata_len; /* length of that attribute value data */
962 size_t prefixlen; /* length of "prefix" */
963
964 prefixlen = lwc_string_length(prefix);
965 if (prefixlen == 0) {
966 /* In this case, the spec says that "if 'val' is the
967 * empty string, it will never represent anything." */
968 return CSS_OK;
969 }
970
971 /* Intern the attribute name as a dom_string so we can
972 * use dom_element_get_attribute() */
973 err = dom_string_create_interned(
974 (const uint8_t *) lwc_string_data(qname->name),
975 lwc_string_length(qname->name),
976 &name);
977 if (err != DOM_NO_ERR) {
978 return CSS_NOMEM;
979 }
980
981 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
982 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
983 /* There was an error getting the attribute's value or
984 * the attribute doesn't exist. So, no match? */
985 dom_string_unref(name);
986 *match = false;
987 return CSS_OK;
988 }
989
990 /* Otherwise, we have the attribute value from the given node,
991 * and the first thing we want to do is check to see if the
992 * whole thing matches the prefix. */
993 dom_string_unref(name);
994 *match = dom_string_lwc_isequal(attr_val, prefix);
995
996 /* If not, check to see if an, uh, prefix matches the
997 * prefix */
998 if (*match == false) {
999 avdata = dom_string_data(attr_val);
1000 avdata_len = dom_string_byte_length(attr_val);
1001 if ((avdata_len >= prefixlen) &&
1002 (strncasecmp(avdata,
1003 lwc_string_data(prefix),
1004 prefixlen) == 0)) {
1005 /* Use strncasecmp to compare only the first
1006 * "n" characters, where "n" is the length of
1007 * the prefix. */
1008 *match = true;
1009 }
1010 }
1011
1012 dom_string_unref(attr_val);
1013
1014 return CSS_OK;
1015 }
1016
1017
1018 /**
1019 * Test the given node for an attribute whose value end with the
1020 * given suffix
1021 *
1022 * This will return true (via the "match" pointer) if the libdom node
1023 * has an attribute with the given name and whose value ends with
1024 * the given suffix string. The comparison is case-sensitive. This
1025 * corresponds to [attr$=value] in CSS.
1026 *
1027 * \param pw Pointer to the current SVG parser state
1028 * \param node Libdom SVG node to test
1029 * \param qname Attribute name to check for
1030 * \param suffix Value suffix to check for
1031 * \param match Pointer to the test result
1032 *
1033 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1034 * intern the attribute name (which usually indicates memory
1035 * exhaustion)
1036 */
1037 css_error node_has_attribute_suffix(void *pw, void *node,
1038 const css_qname *qname, lwc_string *suffix,
1039 bool *match)
1040 {
1041 UNUSED(pw);
1042 dom_string *name;
1043 dom_string *attr_val;
1044 dom_exception err;
1045 const char *avdata; /* attribute value data */
1046 size_t avdata_len; /* length of that attribute value data */
1047 size_t suffixlen; /* length of "suffix" */
1048
1049 /* convenience pointer we'll use when matching the suffix */
1050 const char *suffix_start;
1051
1052 suffixlen = lwc_string_length(suffix);
1053 if (suffixlen == 0) {
1054 /* In this case, the spec says that "if 'val' is the
1055 * empty string, it will never represent anything." */
1056 return CSS_OK;
1057 }
1058
1059 /* Intern the attribute name as a dom_string so we can
1060 * use dom_element_get_attribute() */
1061 err = dom_string_create_interned(
1062 (const uint8_t *) lwc_string_data(qname->name),
1063 lwc_string_length(qname->name),
1064 &name);
1065 if (err != DOM_NO_ERR) {
1066 return CSS_NOMEM;
1067 }
1068
1069 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
1070 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
1071 /* There was an error getting the attribute's value or
1072 * the attribute doesn't exist. So, no match? */
1073 dom_string_unref(name);
1074 *match = false;
1075 return CSS_OK;
1076 }
1077
1078 /* Otherwise, we have the attribute value from the given node,
1079 * and the first thing we want to do is check to see if the
1080 * whole thing matches the suffix. */
1081 dom_string_unref(name);
1082 *match = dom_string_lwc_isequal(attr_val, suffix);
1083
1084 /* If not, check to see if an, uh, suffix matches the
1085 * suffix */
1086 if (*match == false) {
1087 avdata = dom_string_data(attr_val);
1088 avdata_len = dom_string_byte_length(attr_val);
1089
1090 suffix_start = (char *)(avdata + avdata_len - suffixlen);
1091
1092 if ((avdata_len >= suffixlen) &&
1093 (strncasecmp(suffix_start,
1094 lwc_string_data(suffix),
1095 suffixlen) == 0)) {
1096 /* Use strncasecmp to compare only the last
1097 * "n" characters, where "n" is the length of
1098 * the suffix. */
1099 *match = true;
1100 }
1101 }
1102
1103 dom_string_unref(attr_val);
1104
1105 return CSS_OK;
1106 }
1107
1108
1109 /**
1110 * Test the given node for an attribute whose value contains the
1111 * given substring
1112 *
1113 * This will return true (via the "match" pointer) if the libdom node
1114 * has an attribute with the given name and whose value contains the
1115 * given substring. The comparison is case-sensitive. This corresponds
1116 * to [attr*=value] in CSS.
1117 *
1118 * \param pw Pointer to the current SVG parser state
1119 * \param node Libdom SVG node to test
1120 * \param qname Attribute name to check for
1121 * \param substring Value substring to check for
1122 * \param match Pointer to the test result
1123 *
1124 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1125 * intern the attribute name (which usually indicates memory
1126 * exhaustion)
1127 */
1128 css_error node_has_attribute_substring(void *pw, void *node,
1129 const css_qname *qname, lwc_string *substring,
1130 bool *match)
1131 {
1132 UNUSED(pw);
1133 dom_string *name;
1134 dom_string *attr_val;
1135 dom_exception err;
1136 size_t attr_len; /* length of attr_val */
1137 size_t substrlen; /* length of "substring" */
1138
1139 /* Convenience pointers we use when comparing substrings */
1140 const char *p;
1141 const char *p_max;
1142
1143 substrlen = lwc_string_length(substring);
1144 if (substrlen == 0) {
1145 /* In this case, the spec says that "if 'val' is the
1146 * empty string, it will never represent anything." */
1147 return CSS_OK;
1148 }
1149
1150 /* Intern the attribute name as a dom_string so we can
1151 * use dom_element_get_attribute() */
1152 err = dom_string_create_interned(
1153 (const uint8_t *) lwc_string_data(qname->name),
1154 lwc_string_length(qname->name),
1155 &name);
1156 if (err != DOM_NO_ERR) {
1157 return CSS_NOMEM;
1158 }
1159
1160 err = dom_element_get_attribute((dom_node *)node, name, &attr_val);
1161 if ((err != DOM_NO_ERR) || (attr_val == NULL)) {
1162 /* There was an error getting the attribute's value or
1163 * the attribute doesn't exist. So, no match? */
1164 dom_string_unref(name);
1165 *match = false;
1166 return CSS_OK;
1167 }
1168
1169 /* Otherwise, we have the attribute value from the given node,
1170 * and the first thing we want to do is check to see if the
1171 * whole thing matches the substring. */
1172 dom_string_unref(name);
1173 *match = dom_string_lwc_isequal(attr_val, substring);
1174
1175 /* If not, check to see if an, uh, substring matches the
1176 * substring */
1177 if (*match == false) {
1178 p = dom_string_data(attr_val);
1179
1180 /* Check every long-enough suffix for a prefix match */
1181 attr_len = dom_string_byte_length(attr_val);
1182 if (attr_len >= substrlen) {
1183 p_max = p + attr_len - substrlen;
1184 while (p <= p_max) {
1185 if (strncasecmp(p,
1186 lwc_string_data(substring),
1187 substrlen) == 0) {
1188 *match = true;
1189 break;
1190 }
1191 p++;
1192 }
1193 }
1194 }
1195
1196 dom_string_unref(attr_val);
1197
1198 return CSS_OK;
1199 }
1200
1201
1202 /**
1203 * Test whether or not the given node is the document's root element
1204 * This corresponds to the CSS :root pseudo-selector.
1205 *
1206 * \param pw Pointer to the current SVG parser state
1207 * \param node Libdom SVG node to test
1208 * \param match Pointer to the test result
1209 *
1210 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1211 */
1212 css_error node_is_root(void *pw, void *node, bool *match)
1213 {
1214 UNUSED(pw);
1215 dom_node *parent;
1216 dom_node_type type;
1217 dom_exception err;
1218
1219 err = dom_node_get_parent_node((dom_node *)node, &parent);
1220 if (err != DOM_NO_ERR) {
1221 return CSS_NOMEM;
1222 }
1223
1224 /* It's the root element if it doesn't have a parent element */
1225 if (parent != NULL) {
1226 err = dom_node_get_node_type(parent, &type);
1227 dom_node_unref(parent);
1228 if (err != DOM_NO_ERR) {
1229 return CSS_NOMEM;
1230 }
1231 if (type != DOM_DOCUMENT_NODE) {
1232 /* DOM_DOCUMENT_NODE is the only allowable
1233 * type of parent node for the root element */
1234 *match = false;
1235 return CSS_OK;
1236 }
1237 }
1238
1239 *match = true;
1240 return CSS_OK;
1241 }
1242
1243
1244 /**
1245 * Used internally in node_count_siblings() to "count" the given
1246 * sibling node. It factors out the node type and name checks.
1247 */
1248 static int node_count_siblings_check(dom_node *dnode,
1249 bool check_name,
1250 dom_string *name)
1251 {
1252 int ret;
1253 dom_node_type type;
1254 dom_exception exc;
1255 dom_string *dnode_name;
1256
1257 /* We flip this to 1 if/when we count this node */
1258 ret = 0;
1259
1260 if (dnode == NULL) {
1261 return ret;
1262 }
1263
1264 exc = dom_node_get_node_type(dnode, &type);
1265 if ((exc != DOM_NO_ERR) || (type != DOM_ELEMENT_NODE)) {
1266 /* We only count element siblings */
1267 return ret;
1268 }
1269
1270 /* ... with the right name */
1271 if (check_name) {
1272 dnode_name = NULL;
1273 exc = dom_node_get_node_name(dnode, &dnode_name);
1274
1275 if ((exc == DOM_NO_ERR) && (dnode_name != NULL)) {
1276 if (dom_string_isequal(name,
1277 dnode_name)) {
1278 ret = 1;
1279 }
1280 dom_string_unref(dnode_name);
1281 }
1282 }
1283 else {
1284 ret = 1;
1285 }
1286
1287 return ret;
1288 }
1289
1290 /**
1291 * Count the given node's sibling elements
1292 *
1293 * This counts the given node's sibling elements in one direction,
1294 * either forwards or backwards, in the DOM. Keep in mind that the
1295 * libdom tree is upside-down compared to the CSS one; so "next" and
1296 * "previous" are actually reversed; the default is to count preceding
1297 * libdom siblings which correspond to subsequent CSS siblings.
1298 *
1299 * This operation is central to the CSS :first-child, :nth-child, and
1300 * :last-child (et cetera) pseudo-selectors.
1301 *
1302 * If same_name is true, then only nodes having the same
1303 * (case-sensitive) name as the given node are counted.
1304 *
1305 * \param pw Pointer to the current SVG parser state
1306 * \param node Libdom SVG node whose siblings we're counting
1307 * \param same_name Whether or not to count only siblings having
1308 * the same name as the given node
1309 * \param after Count subsequent siblings rather than precedent
1310 * ones (the default)
1311 * \param count Pointer to the return value, the number of sibling
1312 * elements
1313 *
1314 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1315 */
1316 css_error node_count_siblings(void *pw, void *node,
1317 bool same_name, bool after, int32_t *count)
1318 {
1319 UNUSED(pw);
1320 dom_exception exc;
1321 dom_node *dnode; /* node, but with the right type */
1322 dom_string *dnode_name;
1323 dom_node *next; /* "next" sibling (depends on direction) */
1324
1325 /* Pointer to the "next sibling" function */
1326 dom_exception (*next_func)(dom_node *, dom_node **);
1327
1328 *count = 0;
1329
1330 dnode_name = NULL;
1331 dnode = (dom_node *)node;
1332 if (same_name) {
1333 exc = dom_node_get_node_name(dnode, &dnode_name);
1334 if ((exc != DOM_NO_ERR) || (dnode_name == NULL)) {
1335 return CSS_NOMEM;
1336 }
1337 }
1338
1339 /* Increment the reference counter for dnode for as long as
1340 * we retain a reference to it. */
1341 dnode = dom_node_ref(dnode);
1342
1343 next_func = dom_node_get_previous_sibling;
1344 if (after) {
1345 next_func = dom_node_get_next_sibling;
1346 }
1347
1348 do {
1349 exc = next_func(dnode, &next);
1350 if (exc != DOM_NO_ERR) {
1351 break;
1352 }
1353
1354 /* If next_func worked, we're about to swap "next"
1355 * with "dnode" meaning that we will no longer retain
1356 * a reference to the current dnode. */
1357 dom_node_unref(dnode);
1358 dnode = next;
1359
1360 *count += node_count_siblings_check(dnode,
1361 same_name,
1362 dnode_name);
1363 } while (dnode != NULL);
1364
1365 if (dnode_name != NULL) {
1366 dom_string_unref(dnode_name);
1367 }
1368
1369 return CSS_OK;
1370 }
1371
1372
1373 /**
1374 * Determine whether or not the given element is empty
1375 *
1376 * An element is "nonempty" if it has a child that is either an
1377 * element node or a text node.
1378 *
1379 * \param pw Pointer to the current SVG parser state
1380 * \param node Libdom SVG node to check for emptiness
1381 * \param is_empty Pointer to the return value
1382 *
1383 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1384 */
1385 css_error node_is_empty(void *pw, void *node, bool *is_empty)
1386 {
1387 UNUSED(pw);
1388 dom_node *child; /* current child node pointer */
1389 dom_node *next; /* next child node pointer */
1390 dom_node_type type; /* what type of node is "child" */
1391 dom_exception err;
1392
1393 /* Assume that it's empty by default */
1394 *is_empty = true;
1395
1396 /* Get the given node's first child. Implementation detail:
1397 * this increments the reference counter on the child node. */
1398 err = dom_node_get_first_child((dom_node *)node, &child);
1399 if (err != DOM_NO_ERR) {
1400 return CSS_NOMEM;
1401 }
1402
1403 /* And now loop through all children looking for a
1404 * text/element node. If we find one, the original
1405 * node is "nonempty" */
1406 while (child != NULL) {
1407 err = dom_node_get_node_type(child, &type);
1408 if (err != DOM_NO_ERR) {
1409 dom_node_unref(child);
1410 return CSS_NOMEM;
1411 }
1412
1413 if (type == DOM_ELEMENT_NODE || type == DOM_TEXT_NODE) {
1414 *is_empty = false;
1415 dom_node_unref(child);
1416 return CSS_OK;
1417 }
1418
1419 err = dom_node_get_next_sibling(child, &next);
1420 if (err != DOM_NO_ERR) {
1421 dom_node_unref(child);
1422 return CSS_NOMEM;
1423 }
1424
1425 /* If we're moving to the next node, we can release
1426 * the reference to the current one */
1427 dom_node_unref(child);
1428 child = next;
1429 }
1430
1431 return CSS_OK;
1432 }
1433
1434
1435 /**
1436 * Determine whether or not the given node is a link
1437 *
1438 * A node is a link if it is an element node whose name is "a" and if
1439 * it has an "href" attribute (case-sensitive). This selector
1440 * corresponds to node:link pseudo-class in CSS.
1441 *
1442 * This pseudo-class is a bit awkward because the two standards (HTML5
1443 * and CSS) disagree on what it means, and because libsvgtiny does not
1444 * have enough information to determine if a link has been "visited"
1445 * yet -- that's a UI property. CSS says that :link is for unvisited
1446 * links, which we can't determine. HTML5 says that each link must
1447 * be either a :link or :visited. Since we can't decide either way,
1448 * It seems less wrong to declare that all links are unvisited; i.e.
1449 * that they match :link.
1450 *
1451 * \param pw Pointer to the current SVG parser state
1452 * \param node Libdom SVG node to check
1453 * \param is_link Pointer to the boolean return value
1454 *
1455 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1456 */
1457 css_error node_is_link(void *pw, void *node, bool *is_link)
1458 {
1459 dom_exception exc;
1460 dom_node *dnode; /* node, but with the right type */
1461 dom_string *dnode_name;
1462 bool has_href;
1463 struct svgtiny_parse_state* state;
1464
1465 dnode = (dom_node *)node;
1466 dnode_name = NULL;
1467 has_href = false; /* assume no href attribute */
1468 *is_link = false; /* assume that it's not a link */
1469
1470 exc = dom_node_get_node_name(dnode, &dnode_name);
1471 if ((exc != DOM_NO_ERR) || (dnode_name == NULL)) {
1472 return CSS_NOMEM;
1473 }
1474
1475 state = (struct svgtiny_parse_state *)pw;
1476 if (dom_string_isequal(dnode_name, state->interned_a)) {
1477 exc = dom_element_has_attribute(node,
1478 state->interned_href,
1479 &has_href);
1480 if (exc == DOM_NO_ERR && has_href) {
1481 *is_link = true;
1482 }
1483 }
1484
1485 dom_string_unref(dnode_name);
1486 return CSS_OK;
1487 }
1488
1489
1490 /**
1491 * Check if the given node is being "hovered" over
1492 *
1493 * This check always fails because the SVG DOM does not have the
1494 * necessary information (it's a UI property).
1495 *
1496 * \param pw Pointer to the current SVG parser state; unused
1497 * \param node Libdom SVG node to check; unused
1498 * \param is_hover Pointer to the boolean return value
1499 *
1500 * \return Always returns CSS_OK
1501 */
1502 css_error node_is_hover(void *pw, void *node, bool *is_hover)
1503 {
1504 UNUSED(pw);
1505 UNUSED(node);
1506 *is_hover = false;
1507 return CSS_OK;
1508 }
1509
1510
1511 /**
1512 * Check if the given node is "active"
1513 *
1514 * This check always fails because the SVG DOM does not have the
1515 * necessary information (it's a UI property).
1516 *
1517 * \param pw Pointer to the current SVG parser state; unused
1518 * \param node Libdom SVG node to check; unused
1519 * \param is_active Pointer to the boolean return value
1520 *
1521 * \return Always returns CSS_OK
1522 */
1523 css_error node_is_active(void *pw, void *node, bool *is_active)
1524 {
1525 UNUSED(pw);
1526 UNUSED(node);
1527 *is_active = false;
1528 return CSS_OK;
1529 }
1530
1531
1532 /**
1533 * Check if the given node has the focus
1534 *
1535 * This check always fails because the SVG DOM does not have the
1536 * necessary information (it's a UI property).
1537 *
1538 * \param pw Pointer to the current SVG parser state; unused
1539 * \param node Libdom SVG node to check; unused
1540 * \param is_focus Pointer to the boolean return value
1541 *
1542 * \return Always returns CSS_OK
1543 */
1544 css_error node_is_focus(void *pw, void *node, bool *is_focus)
1545 {
1546 UNUSED(pw);
1547 UNUSED(node);
1548 *is_focus = false;
1549 return CSS_OK;
1550 }