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