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