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