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