1 #include <libcss/libcss.h>
2 #include <strings.h> /* strncasecmp */
5 #include "svgtiny_internal.h"
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
,
30 static css_error
node_has_attribute_dashmatch(void *pw
, void *node
,
31 const css_qname
*qname
, lwc_string
*value
,
33 static css_error
node_has_attribute_includes(void *pw
, void *node
,
34 const css_qname
*qname
, lwc_string
*word
,
36 static css_error
node_has_attribute_prefix(void *pw
, void *node
,
37 const css_qname
*qname
, lwc_string
*prefix
,
39 static css_error
node_has_attribute_suffix(void *pw
, void *node
,
40 const css_qname
*qname
, lwc_string
*suffix
,
42 static css_error
node_has_attribute_substring(void *pw
, void *node
,
43 const css_qname
*qname
, lwc_string
*substring
,
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_visited(void *pw
, void *node
, bool *is_visited
);
51 static css_error
node_is_hover(void *pw
, void *node
, bool *is_hover
);
52 static css_error
node_is_active(void *pw
, void *node
, bool *is_active
);
53 static css_error
node_is_focus(void *pw
, void *node
, bool *is_focus
);
54 static css_error
node_is_enabled(void *pw
, void *node
, bool *is_enabled
);
55 static css_error
node_is_disabled(void *pw
, void *node
, bool *is_disabled
);
56 static css_error
node_is_checked(void *pw
, void *node
, bool *is_checked
);
57 static css_error
node_is_target(void *pw
, void *node
, bool *is_target
);
58 static css_error
node_is_lang(void *pw
, void *node
,
59 lwc_string
*lang
, bool *is_lang
);
60 static css_error
node_presentational_hint(void *pw
, void *node
,
61 uint32_t *nhints
, css_hint
**hints
);
62 static css_error
ua_default_for_property(void *pw
, uint32_t property
,
64 static css_error
set_libcss_node_data(void *pw
, void *node
,
65 void *libcss_node_data
);
66 static css_error
get_libcss_node_data(void *pw
, void *node
,
67 void **libcss_node_data
);
71 * Resolve a relative URL to an absolute one by doing nothing. This is
72 * the simplest possible implementation of a URL resolver, needed for
75 css_error
svgtiny_resolve_url(void *pw
,
76 const char *base
, lwc_string
*rel
, lwc_string
**abs
)
81 /* Copy the relative URL to the absolute one (the return
83 *abs
= lwc_string_ref(rel
);
88 * Create a stylesheet with the default set of params.
90 * \param sheet A stylesheet pointer, passed in by reference, that
91 * we use to store the newly-created stylesheet.
92 * \param inline_style True if this stylesheet represents an inline
93 * style, and false otherwise.
95 * \return The return value from css_stylesheet_create() is returned.
97 css_error
svgtiny_create_stylesheet(css_stylesheet
**sheet
,
100 css_stylesheet_params params
;
102 params
.params_version
= CSS_STYLESHEET_PARAMS_VERSION_1
;
103 params
.level
= CSS_LEVEL_DEFAULT
;
104 params
.charset
= NULL
;
107 params
.allow_quirks
= false;
108 params
.inline_style
= inline_style
;
109 params
.resolve
= svgtiny_resolve_url
;
110 params
.resolve_pw
= NULL
;
111 params
.import = NULL
;
112 params
.import_pw
= NULL
;
114 params
.color_pw
= NULL
;
116 params
.font_pw
= NULL
;
118 return css_stylesheet_create(¶ms
, sheet
);
122 /**************************/
123 /* libcss select handlers */
124 /**************************/
126 * From here on we implement the "select handler "API defined in
127 * libcss's include/libcss/select.h and discussed briefly in its
133 * Retrieve the given node's name
135 * \param pw Pointer to the current SVG parser state
136 * \param node Libdom SVG node
137 * \param qname Address at which to store the node name
139 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
141 css_error
node_name(void *pw
, void *node
, css_qname
*qname
)
145 struct svgtiny_parse_state
*state
;
147 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
148 if (err
!= DOM_NO_ERR
) {
152 state
= (struct svgtiny_parse_state
*)pw
;
153 qname
->ns
= lwc_string_ref(state
->interned_svg_xmlns
);
155 err
= dom_string_intern(name
, &qname
->name
);
156 if (err
!= DOM_NO_ERR
) {
157 dom_string_unref(name
);
161 dom_string_unref(name
);
168 * Retrieve the given node's classes
170 * \param pw Pointer to the current SVG parser state
171 * \param node Libdom SVG node
172 * \param classes Address at which to store the class name array
173 * \param n_classes Address at which to store the length of the class
176 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
178 * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
179 * because the underlying libdom function never fails
181 css_error
node_classes(void *pw
, void *node
,
182 lwc_string
***classes
, uint32_t *n_classes
)
187 err
= dom_element_get_classes((dom_node
*)node
, classes
, n_classes
);
189 /* The implementation does not do it, but the documentation
190 for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
191 possible here, so we handle it to be on the safe side. */
192 if (err
!= DOM_NO_ERR
) {
201 * Retrieve the given node's id
203 * \param pw Pointer to the current SVG parser state
204 * \param node Libdom SVG node
205 * \param id Address at which to store the id
207 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
209 css_error
node_id(void *pw
, void *node
, lwc_string
**id
)
213 struct svgtiny_parse_state
*state
;
215 /* Begin with the assumption that this node has no id */
218 state
= (struct svgtiny_parse_state
*)pw
;
219 err
= dom_element_get_attribute((dom_node
*)node
,
220 state
->interned_id
, &attr
);
221 if (err
!= DOM_NO_ERR
) {
224 else if (attr
== NULL
) {
225 /* The node has no id attribute and our return value
226 is already set to NULL so we're done */
230 /* If we found an id attribute (a dom_string), intern it into
231 an lwc_string that we can return, and then cleanup the
233 err
= dom_string_intern(attr
, id
);
234 if (err
!= DOM_NO_ERR
) {
235 dom_string_unref(attr
);
238 dom_string_unref(attr
);
245 * Find the first parent of the given element having the given name
247 * \param pw Pointer to the current SVG parser state
248 * \param node Libdom SVG node
249 * \param qname Name of the parent node to search for
250 * \param parent Address at which to store the parent node pointer
252 * \return Always returns CSS_OK
254 * \post If a suitable element is found, a pointer to it will be
255 * stored at the address pointed to by \a parent; otherwise,
256 * NULL will be stored at the address pointed to by \a parent
258 css_error
named_parent_node(void *pw
, void *node
,
259 const css_qname
*qname
, void **parent
)
262 /* dom_element_named_parent_node() was invented to implement
263 * this select handler so there isn't much for us to do except
264 * call it. It's OK if node isn't an element, libdom checks
266 dom_element_named_parent_node((dom_element
*)node
,
268 (struct dom_element
**)parent
);
270 /* Implementation detail: dom_element_named_parent_node()
271 * increments the reference count of the parent element before
272 * returning it to us. According to docs/RefCnt in the libdom
273 * repository, this will prevent the parent element from being
274 * destroyed if it is pruned from the DOM. That sounds good,
275 * since we don't want to be using a pointer to an object that
276 * has been destroyed... but we also have no way of later
277 * decrementing the reference count ourselves, and don't want
278 * to make the returned node eternal. Decrementing the
279 * reference counter now allows it to be destroyed when the
280 * DOM no longer needs it, and so long as no other parts of
281 * libsvgtiny are messing with the DOM during parsing, that
282 * shouldn't (ha ha) cause any problems. */
283 dom_node_unref(*parent
);
290 * Find the "next-sibling" of the given element having the given name
292 * This search corresponds to the "+ foo" combinator in CSS and will
293 * find only "foo" element nodes that immediately precede the given
294 * node under the same parent in the DOM. In CSS the tree is viewed
295 * top-down and in libdom it is viewed from the bottom-up; as a result
296 * "next" and "previous" are sometimes backwards. This is case-sensitive.
298 * \param pw Pointer to the current SVG parser state
299 * \param node Libdom SVG node
300 * \param qname Name of the sibling node to search for
301 * \param sibling Address at which to store the sibling node pointer
303 * \return Always returns CSS_OK
305 * \post If a suitable element is found, a pointer to it will be
306 * stored at the address pointed to by \a sibling; otherwise,
307 * NULL will be stored at the address pointed to by \a sibling
309 css_error
named_sibling_node(void *pw
, void *node
,
310 const css_qname
*qname
, void **sibling
)
313 dom_node
*n
= node
; /* the current node */
314 dom_node
*prev
; /* the previous node */
319 *sibling
= NULL
; /* default to nothing found */
321 /* Begin the search; the first iteration we do outside of the
322 * loop. Implementation detil: dom_node_get_previous_sibling()
323 * increments the reference counter on the returned node. A
324 * comment within named_parent_node() explains why we
325 * decrement it ASAP. */
326 err
= dom_node_get_previous_sibling(n
, &n
);
327 if (err
!= DOM_NO_ERR
) {
332 /* We're looking for the first ELEMENT sibling */
333 err
= dom_node_get_node_type(n
, &type
);
334 if (err
!= DOM_NO_ERR
) {
339 if (type
== DOM_ELEMENT_NODE
) {
340 /* We found an element node, does it have the
342 err
= dom_node_get_node_name(n
, &name
);
343 if (err
!= DOM_NO_ERR
) {
348 if (dom_string_lwc_isequal(name
,
350 /* The name is right, return it */
354 /* There's only one next-sibling element node
355 * and we've already found it, so if its name
356 * wasn't right, we return the default value
358 dom_string_unref(name
);
363 /* Not an element node, so we move on the the previous
364 * previous sibling */
365 err
= dom_node_get_previous_sibling(n
, &prev
);
366 if (err
!= DOM_NO_ERR
) {
380 * Find the first "subsequent-sibling" of the given element having the
383 * This search corresponds to the "~ foo" combinator in CSS and will
384 * find only "foo" element nodes that precede the given node (under
385 * the same parent) in the DOM. In CSS the tree is viewed top-down and
386 * in libdom it is viewed from the bottom-up; as a result "next" and
387 * "previous" are sometimes backwards. This is case-sensitive.
389 * \param pw Pointer to the current SVG parser state
390 * \param node Libdom SVG node
391 * \param qname Name of the sibling node to search for
392 * \param sibling Address at which to store the sibling node pointer
394 * \return Always returns CSS_OK
396 * \post If a suitable element is found, a pointer to it will be
397 * stored at the address pointed to by \a sibling; otherwise,
398 * NULL will be stored at the address pointed to by \a sibling
400 css_error
named_generic_sibling_node(void *pw
, void *node
,
401 const css_qname
*qname
, void **sibling
)
404 dom_node
*n
= node
; /* the current node */
405 dom_node
*prev
; /* the previous node */
411 *sibling
= NULL
; /* default to nothing found */
413 /* Begin the search; the first iteration we do outside of the
414 * loop. Implementation detil: dom_node_get_previous_sibling()
415 * increments the reference counter on the returned node. A
416 * comment within named_parent_node() explains why we
417 * decrement it ASAP. */
418 err
= dom_node_get_previous_sibling(n
, &n
);
419 if (err
!= DOM_NO_ERR
) {
424 err
= dom_node_get_node_type(n
, &type
);
425 if (err
!= DOM_NO_ERR
) {
430 if (type
== DOM_ELEMENT_NODE
) {
431 /* We only want ELEMENT nodes */
432 err
= dom_node_get_node_name(n
, &name
);
433 if (err
!= DOM_NO_ERR
) {
438 if (dom_string_lwc_isequal(name
,
440 /* Found one. Save it and stop the search */
441 dom_string_unref(name
);
447 dom_string_unref(name
);
450 /* This sibling wasn't an element with the desired
451 name, so move on to the previous sibling */
452 err
= dom_node_get_previous_sibling(n
, &prev
);
453 if (err
!= DOM_NO_ERR
) {
467 * Return a pointer to the given node's parent
469 * \param pw Pointer to the current SVG parser state
470 * \param node Libdom SVG node
471 * \param parent Address at which to store the node's parent pointer
473 * \return Always returns CSS_OK
475 css_error
parent_node(void *pw
, void *node
, void **parent
)
478 /* Libdom basically implements this for us */
479 dom_element_parent_node(node
, (struct dom_element
**)parent
);
481 /* See the comment in named_parent_node() for why we decrement
482 * this reference counter here. */
483 dom_node_unref(*parent
);
490 * Find the "next-sibling" of the given element
492 * This search corresponds "+ *" in CSS and will find the first
493 * element node that immediately precedes the given node under the
494 * same parent in the DOM. In CSS the tree is viewed top-down and in
495 * libdom it is viewed from the bottom-up; as a result "next" and
496 * "previous" are sometimes backwards.
498 * \param pw Pointer to the current SVG parser state
499 * \param node Libdom SVG node
500 * \param sibling Address at which to store the sibling node pointer
502 * \return Always returns CSS_OK
504 * \post If a suitable element is found, a pointer to it will be
505 * stored at the address pointed to by \a sibling; otherwise,
506 * NULL will be stored at the address pointed to by \a sibling
508 css_error
sibling_node(void *pw
, void *node
, void **sibling
)
511 dom_node
*n
= node
; /* the current node */
512 dom_node
*prev
; /* the previous node */
516 *sibling
= NULL
; /* default to nothing found */
518 /* Begin the search; the first iteration we do outside of the
519 * loop. Implementation detil: dom_node_get_previous_sibling()
520 * increments the reference counter on the returned node. A
521 * comment within named_parent_node() explains why we
522 * decrement it ASAP. */
523 err
= dom_node_get_previous_sibling(n
, &n
);
524 if (err
!= DOM_NO_ERR
) {
529 err
= dom_node_get_node_type(n
, &type
);
530 if (err
!= DOM_NO_ERR
) {
535 if (type
== DOM_ELEMENT_NODE
) {
536 /* We found a sibling node that is also an
537 element and that's all we wanted. */
543 /* This sibling node was not an element; move on to
544 the previous sibling */
545 err
= dom_node_get_previous_sibling(n
, &prev
);
546 if (err
!= DOM_NO_ERR
) {
560 * Test the given node for the given name
562 * This will return true (via the "match" pointer) if the libdom node
563 * has the given name or if that name is the universal selector;
564 * otherwise it returns false. The comparison is case-sensitive. It
565 * corresponds to a rule like "body { ... }" in CSS.
567 * \param pw Pointer to the current SVG parser state
568 * \param node Libdom SVG node to test
569 * \param qname Name to check for
570 * \param match Pointer to the test result
572 * \return Always returns CSS_OK
574 css_error
node_has_name(void *pw
, void *node
,
575 const css_qname
*qname
, bool *match
)
577 struct svgtiny_parse_state
*state
;
581 /* Start by checking to see if qname is the universal selector */
582 state
= (struct svgtiny_parse_state
*)pw
;
583 if (lwc_string_isequal(qname
->name
,
584 state
->interned_universal
, match
) == lwc_error_ok
) {
586 /* It's the universal selector. In NetSurf, all node
587 * names match the universal selector, and nothing in
588 * the libcss documentation suggests another approach,
589 * so we follow NetSurf here. */
594 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
595 if (err
!= DOM_NO_ERR
) {
599 /* Unlike with HTML, SVG element names are case-sensitive */
600 *match
= dom_string_lwc_isequal(name
, qname
->name
);
601 dom_string_unref(name
);
608 * Test the given node for the given class
610 * This will return true (via the "match" pointer) if the libdom node
611 * has the given class. The comparison is case-sensitive. It
612 * corresponds to node.class in CSS.
614 * \param pw Pointer to the current SVG parser state
615 * \param node Libdom SVG node to test
616 * \param name Class name to check for
617 * \param match Pointer to the test result
619 * \return Always returns CSS_OK
621 css_error
node_has_class(void *pw
, void *node
,
622 lwc_string
*name
, bool *match
)
625 /* libdom implements this for us and apparently it cannot fail */
626 dom_element_has_class((dom_node
*)node
, name
, match
);
632 * Test the given node for the given id
634 * This will return true (via the "match" pointer) if the libdom node
635 * has the given id. The comparison is case-sensitive. It corresponds
638 * \param pw Pointer to the current SVG parser state
639 * \param node Libdom SVG node to test
640 * \param name Id to check for
641 * \param match Pointer to the test result
643 * \return Always returns CSS_OK
645 css_error
node_has_id(void *pw
, void *node
,
646 lwc_string
*name
, bool *match
)
650 struct svgtiny_parse_state
*state
;
652 attr
= NULL
; /* a priori the "id" attribute may not exist */
653 *match
= false; /* default to no match */
655 state
= (struct svgtiny_parse_state
*)pw
;
656 err
= dom_element_get_attribute((dom_node
*)node
,
657 state
->interned_id
, &attr
);
658 if (err
!= DOM_NO_ERR
|| attr
== NULL
) {
662 *match
= dom_string_lwc_isequal(attr
, name
);
663 dom_string_unref(attr
);
670 * Test the given node for the given attribute
672 * This will return true (via the "match" pointer) if the libdom node
673 * has an attribute with the given name. The comparison is
674 * case-sensitive. It corresponds to node[attr] in CSS.
676 * \param pw Pointer to the current SVG parser state
677 * \param node Libdom SVG node to test
678 * \param qname Attribute name to check for
679 * \param match Pointer to the test result
681 * \return Returns CSS_OK if successful and CSS_NOMEM if anything
684 css_error
node_has_attribute(void *pw
, void *node
,
685 const css_qname
*qname
, bool *match
)
691 /* intern the attribute name as a dom_string so we can
692 * delegate to dom_element_has_attribute() */
693 err
= dom_string_create_interned(
694 (const uint8_t *) lwc_string_data(qname
->name
),
695 lwc_string_length(qname
->name
),
697 if (err
!= DOM_NO_ERR
) {
701 err
= dom_element_has_attribute((dom_node
*)node
, name
, match
);
702 if (err
!= DOM_NO_ERR
) {
703 dom_string_unref(name
);
707 dom_string_unref(name
);
713 * Test the given node for an attribute with a specific value
715 * This will return true (via the "match" pointer) if the libdom node
716 * has an attribute with the given name and value. The comparison is
717 * case-sensitive. It corresponds to node[attr=value] in CSS.
719 * \param pw Pointer to the current SVG parser state
720 * \param node Libdom SVG node to test
721 * \param qname Attribute name to check for
722 * \param value Attribute value to check for
723 * \param match Pointer to the test result
725 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
726 * intern the attribute name (which usually indicates memory
729 css_error
node_has_attribute_equal(void *pw
, void *node
,
730 const css_qname
*qname
, lwc_string
*value
,
733 /* Implementation note: NetSurf always returns "no match" when
734 * the value is empty (length zero). We allow it, because why
739 dom_string
*attr_val
;
742 /* Intern the attribute name as a dom_string so we can
743 * use dom_element_get_attribute() */
744 err
= dom_string_create_interned(
745 (const uint8_t *) lwc_string_data(qname
->name
),
746 lwc_string_length(qname
->name
),
748 if (err
!= DOM_NO_ERR
) {
752 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
753 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
754 /* There was an error getting the attribute's value or
755 * the attribute doesn't exist. So, no match? */
756 dom_string_unref(name
);
761 /* Otherwise, we have the attribute value from the given node
762 * and all we need to do is compare. */
763 dom_string_unref(name
);
764 *match
= dom_string_lwc_isequal(attr_val
, value
);
765 dom_string_unref(attr_val
);
772 * Test the given node for an attribute with a specific value,
773 * possibly followed by a single hyphen
775 * This will return true (via the "match" pointer) if the libdom node
776 * has an attribute with the given name and value or with the given
777 * name and a value that is followed by exactly one hyphen. The
778 * comparison is case-sensitive. This corresponds to [attr|=value]
781 * \param pw Pointer to the current SVG parser state
782 * \param node Libdom SVG node to test
783 * \param qname Attribute name to check for
784 * \param value Attribute value to check for
785 * \param match Pointer to the test result
787 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
788 * intern the attribute name (which usually indicates memory
791 css_error
node_has_attribute_dashmatch(void *pw
, void *node
,
792 const css_qname
*qname
, lwc_string
*value
,
795 /* Implementation note: NetSurf always returns "no match" when
796 * the value is empty (length zero). We allow it, because why
801 dom_string
*attr_val
;
804 const char *vdata
; /* to hold the data underlying "value" */
806 const char *avdata
; /* to hold the found attribute value data */
809 /* Intern the attribute name as a dom_string so we can
810 * use dom_element_get_attribute() */
811 err
= dom_string_create_interned(
812 (const uint8_t *) lwc_string_data(qname
->name
),
813 lwc_string_length(qname
->name
),
815 if (err
!= DOM_NO_ERR
) {
819 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
820 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
821 /* There was an error getting the attribute's value or
822 * the attribute doesn't exist. So, no match? */
823 dom_string_unref(name
);
828 /* Otherwise, we have the attribute value from the given node
829 * and all we need to do is compare. */
830 dom_string_unref(name
);
831 *match
= dom_string_lwc_isequal(attr_val
, value
);
833 /* Exact match, we're done */
834 dom_string_unref(attr_val
);
838 /* No exact match, try it with a hyphen on the end */
839 vdata
= lwc_string_data(value
); /* needle */
840 vdata_len
= lwc_string_length(value
);
841 avdata
= dom_string_data(attr_val
); /* haystack */
842 avdata_len
= dom_string_byte_length(attr_val
);
843 dom_string_unref(attr_val
);
845 if (avdata_len
> vdata_len
&& avdata
[vdata_len
] == '-') {
846 if (strncasecmp(avdata
, vdata
, vdata_len
) == 0) {
847 /* If there's a hyphen in the right position,
848 * it suffices to compare the strings only up
859 * Test the given node for an attribute whose value is a
860 * space-separated list of words, one of which is the given word
862 * This will return true (via the "match" pointer) if the libdom node
863 * has an attribute with the given name and whose value when
864 * considered as a space-separated list of words contains the given
865 * word. The comparison is case-sensitive. This corresponds to
866 * [attr~=value] in CSS.
868 * \param pw Pointer to the current SVG parser state
869 * \param node Libdom SVG node to test
870 * \param qname Attribute name to check for
871 * \param word Value word to check for
872 * \param match Pointer to the test result
874 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
875 * intern the attribute name (which usually indicates memory
878 css_error
node_has_attribute_includes(void *pw
, void *node
,
879 const css_qname
*qname
, lwc_string
*word
,
885 dom_string
*attr_val
;
887 size_t wordlen
; /* length of "word" */
889 /* pointers used to parse a space-separated list of words */
894 *match
= false; /* default to no match */
896 wordlen
= lwc_string_length(word
);
898 /* In this case, the spec says that "if 'val' is the
899 * empty string, it will never represent anything." */
903 /* Intern the attribute name as a dom_string so we can
904 * use dom_element_get_attribute() */
905 err
= dom_string_create_interned(
906 (const uint8_t *) lwc_string_data(qname
->name
),
907 lwc_string_length(qname
->name
),
909 if (err
!= DOM_NO_ERR
) {
913 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
914 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
915 /* There was an error getting the attribute's value or
916 * the attribute doesn't exist. So, no match? */
917 dom_string_unref(name
);
921 /* Parse the list comparing each word against "word" */
922 start
= dom_string_data(attr_val
);
923 end
= start
+ dom_string_byte_length(attr_val
);
924 dom_string_unref(attr_val
);
926 for (p
= start
; p
<= end
; p
++) {
927 /* Move forward until we find the end of the first word */
928 if (*p
== ' ' || *p
== '\0') {
929 /* If the length of that word is the length of the
930 * word we're looking for, do the comparison. */
931 if ((size_t) (p
- start
) == wordlen
&&
933 lwc_string_data(word
),
938 /* No match? Set "start" to the beginning of
939 * the next word and loop. */
949 * Test the given node for an attribute whose value begins with the
952 * This will return true (via the "match" pointer) if the libdom node
953 * has an attribute with the given name and whose value begins with
954 * the given prefix string. The comparison is case-sensitive. This
955 * corresponds to [attr^=value] in CSS.
957 * \param pw Pointer to the current SVG parser state
958 * \param node Libdom SVG node to test
959 * \param qname Attribute name to check for
960 * \param prefix Value prefix to check for
961 * \param match Pointer to the test result
963 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
964 * intern the attribute name (which usually indicates memory
967 css_error
node_has_attribute_prefix(void *pw
, void *node
,
968 const css_qname
*qname
, lwc_string
*prefix
,
973 dom_string
*attr_val
;
975 const char *avdata
; /* attribute value data */
976 size_t avdata_len
; /* length of that attribute value data */
977 size_t prefixlen
; /* length of "prefix" */
979 prefixlen
= lwc_string_length(prefix
);
980 if (prefixlen
== 0) {
981 /* In this case, the spec says that "if 'val' is the
982 * empty string, it will never represent anything." */
986 /* Intern the attribute name as a dom_string so we can
987 * use dom_element_get_attribute() */
988 err
= dom_string_create_interned(
989 (const uint8_t *) lwc_string_data(qname
->name
),
990 lwc_string_length(qname
->name
),
992 if (err
!= DOM_NO_ERR
) {
996 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
997 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
998 /* There was an error getting the attribute's value or
999 * the attribute doesn't exist. So, no match? */
1000 dom_string_unref(name
);
1005 /* Otherwise, we have the attribute value from the given node,
1006 * and the first thing we want to do is check to see if the
1007 * whole thing matches the prefix. */
1008 dom_string_unref(name
);
1009 *match
= dom_string_lwc_isequal(attr_val
, prefix
);
1011 /* If not, check to see if an, uh, prefix matches the
1013 if (*match
== false) {
1014 avdata
= dom_string_data(attr_val
);
1015 avdata_len
= dom_string_byte_length(attr_val
);
1016 if ((avdata_len
>= prefixlen
) &&
1017 (strncasecmp(avdata
,
1018 lwc_string_data(prefix
),
1020 /* Use strncasecmp to compare only the first
1021 * "n" characters, where "n" is the length of
1027 dom_string_unref(attr_val
);
1034 * Test the given node for an attribute whose value end with the
1037 * This will return true (via the "match" pointer) if the libdom node
1038 * has an attribute with the given name and whose value ends with
1039 * the given suffix string. The comparison is case-sensitive. This
1040 * corresponds to [attr$=value] in CSS.
1042 * \param pw Pointer to the current SVG parser state
1043 * \param node Libdom SVG node to test
1044 * \param qname Attribute name to check for
1045 * \param suffix Value suffix to check for
1046 * \param match Pointer to the test result
1048 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1049 * intern the attribute name (which usually indicates memory
1052 css_error
node_has_attribute_suffix(void *pw
, void *node
,
1053 const css_qname
*qname
, lwc_string
*suffix
,
1058 dom_string
*attr_val
;
1060 const char *avdata
; /* attribute value data */
1061 size_t avdata_len
; /* length of that attribute value data */
1062 size_t suffixlen
; /* length of "suffix" */
1064 /* convenience pointer we'll use when matching the suffix */
1065 const char *suffix_start
;
1067 suffixlen
= lwc_string_length(suffix
);
1068 if (suffixlen
== 0) {
1069 /* In this case, the spec says that "if 'val' is the
1070 * empty string, it will never represent anything." */
1074 /* Intern the attribute name as a dom_string so we can
1075 * use dom_element_get_attribute() */
1076 err
= dom_string_create_interned(
1077 (const uint8_t *) lwc_string_data(qname
->name
),
1078 lwc_string_length(qname
->name
),
1080 if (err
!= DOM_NO_ERR
) {
1084 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1085 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1086 /* There was an error getting the attribute's value or
1087 * the attribute doesn't exist. So, no match? */
1088 dom_string_unref(name
);
1093 /* Otherwise, we have the attribute value from the given node,
1094 * and the first thing we want to do is check to see if the
1095 * whole thing matches the suffix. */
1096 dom_string_unref(name
);
1097 *match
= dom_string_lwc_isequal(attr_val
, suffix
);
1099 /* If not, check to see if an, uh, suffix matches the
1101 if (*match
== false) {
1102 avdata
= dom_string_data(attr_val
);
1103 avdata_len
= dom_string_byte_length(attr_val
);
1105 suffix_start
= (char *)(avdata
+ avdata_len
- suffixlen
);
1107 if ((avdata_len
>= suffixlen
) &&
1108 (strncasecmp(suffix_start
,
1109 lwc_string_data(suffix
),
1111 /* Use strncasecmp to compare only the last
1112 * "n" characters, where "n" is the length of
1118 dom_string_unref(attr_val
);
1125 * Implement node_has_attribute_substring() with optional case-
1126 * insensitivity. This corresponds to [attr*=value i] in CSS and is
1127 * not supported by libcss yet, but it allows us to factor out some
1130 static css_error
_node_has_attribute_substring(void *pw
, void *node
,
1131 const css_qname
*qname
, lwc_string
*substring
,
1132 bool *match
, bool insensitive
)
1136 dom_string
*attr_val
;
1138 size_t attr_len
; /* length of attr_val */
1139 size_t substrlen
; /* length of "substring" */
1141 /* Convenience pointers we use when comparing substrings */
1145 substrlen
= lwc_string_length(substring
);
1146 if (substrlen
== 0) {
1147 /* In this case, the spec says that "if 'val' is the
1148 * empty string, it will never represent anything." */
1152 /* Intern the attribute name as a dom_string so we can
1153 * use dom_element_get_attribute() */
1154 err
= dom_string_create_interned(
1155 (const uint8_t *) lwc_string_data(qname
->name
),
1156 lwc_string_length(qname
->name
),
1158 if (err
!= DOM_NO_ERR
) {
1162 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1163 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1164 /* There was an error getting the attribute's value or
1165 * the attribute doesn't exist. So, no match? */
1166 dom_string_unref(name
);
1171 /* Otherwise, we have the attribute value from the given node,
1172 * and the first thing we want to do is check to see if the
1173 * whole thing matches the substring. */
1174 dom_string_unref(name
);
1177 *match
= dom_string_caseless_lwc_isequal(attr_val
, substring
);
1180 *match
= dom_string_lwc_isequal(attr_val
, substring
);
1183 /* If not, check to see if an, uh, substring matches the
1185 if (*match
== false) {
1186 p
= dom_string_data(attr_val
);
1188 /* Check every long-enough suffix for a prefix match */
1189 attr_len
= dom_string_byte_length(attr_val
);
1190 if (attr_len
>= substrlen
) {
1191 p_max
= p
+ attr_len
- substrlen
;
1192 while (p
<= p_max
) {
1194 lwc_string_data(substring
),
1204 dom_string_unref(attr_val
);
1210 * Test the given node for an attribute whose value contains the
1213 * This will return true (via the "match" pointer) if the libdom node
1214 * has an attribute with the given name and whose value contains the
1215 * given substring. The comparison is case-sensitive. This corresponds
1216 * to [attr*=value] in CSS.
1218 * \param pw Pointer to the current SVG parser state
1219 * \param node Libdom SVG node to test
1220 * \param qname Attribute name to check for
1221 * \param substring Value substring to check for
1222 * \param match Pointer to the test result
1224 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1225 * intern the attribute name (which usually indicates memory
1228 css_error
node_has_attribute_substring(void *pw
, void *node
,
1229 const css_qname
*qname
, lwc_string
*substring
,
1232 return _node_has_attribute_substring(pw
, node
, qname
, substring
,
1238 * Test whether or not the given node is the document's root element
1239 * This corresponds to the CSS :root pseudo-selector.
1241 * \param pw Pointer to the current SVG parser state
1242 * \param node Libdom SVG node to test
1243 * \param match Pointer to the test result
1245 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1247 css_error
node_is_root(void *pw
, void *node
, bool *match
)
1254 err
= dom_node_get_parent_node((dom_node
*)node
, &parent
);
1255 if (err
!= DOM_NO_ERR
) {
1259 /* It's the root element if it doesn't have a parent element */
1260 if (parent
!= NULL
) {
1261 err
= dom_node_get_node_type(parent
, &type
);
1262 dom_node_unref(parent
);
1263 if (err
!= DOM_NO_ERR
) {
1266 if (type
!= DOM_DOCUMENT_NODE
) {
1267 /* DOM_DOCUMENT_NODE is the only allowable
1268 * type of parent node for the root element */
1280 * Used internally in node_count_siblings() to "count" the given
1281 * sibling node. It factors out the node type and name checks.
1283 static int node_count_siblings_check(dom_node
*dnode
,
1290 dom_string
*dnode_name
;
1292 /* We flip this to 1 if/when we count this node */
1295 if (dnode
== NULL
) {
1299 exc
= dom_node_get_node_type(dnode
, &type
);
1300 if ((exc
!= DOM_NO_ERR
) || (type
!= DOM_ELEMENT_NODE
)) {
1301 /* We only count element siblings */
1305 /* ... with the right name */
1308 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1310 if ((exc
== DOM_NO_ERR
) && (dnode_name
!= NULL
)) {
1311 if (dom_string_isequal(name
,
1315 dom_string_unref(dnode_name
);
1326 * Count the given node's sibling elements
1328 * This counts the given node's sibling elements in one direction,
1329 * either forwards or backwards, in the DOM. Keep in mind that the
1330 * libdom tree is upside-down compared to the CSS one; so "next" and
1331 * "previous" are actually reversed; the default is to count preceding
1332 * libdom siblings which correspond to subsequent CSS siblings.
1334 * This operation is central to the CSS :first-child, :nth-child, and
1335 * :last-child (et cetera) pseudo-selectors.
1337 * If same_name is true, then only nodes having the same
1338 * (case-sensitive) name as the given node are counted.
1340 * \param pw Pointer to the current SVG parser state
1341 * \param node Libdom SVG node whose siblings we're counting
1342 * \param same_name Whether or not to count only siblings having
1343 * the same name as the given node
1344 * \param after Count subsequent siblings rather than precedent
1345 * ones (the default)
1346 * \param count Pointer to the return value, the number of sibling
1349 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1351 css_error
node_count_siblings(void *pw
, void *node
,
1352 bool same_name
, bool after
, int32_t *count
)
1356 dom_node
*dnode
; /* node, but with the right type */
1357 dom_string
*dnode_name
;
1358 dom_node
*next
; /* "next" sibling (depends on direction) */
1360 /* Pointer to the "next sibling" function */
1361 dom_exception (*next_func
)(dom_node
*, dom_node
**);
1366 dnode
= (dom_node
*)node
;
1368 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1369 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1374 /* Increment the reference counter for dnode for as long as
1375 * we retain a reference to it. */
1376 dnode
= dom_node_ref(dnode
);
1378 next_func
= dom_node_get_previous_sibling
;
1380 next_func
= dom_node_get_next_sibling
;
1384 exc
= next_func(dnode
, &next
);
1385 if (exc
!= DOM_NO_ERR
) {
1389 /* If next_func worked, we're about to swap "next"
1390 * with "dnode" meaning that we will no longer retain
1391 * a reference to the current dnode. */
1392 dom_node_unref(dnode
);
1395 *count
+= node_count_siblings_check(dnode
,
1398 } while (dnode
!= NULL
);
1400 if (dnode_name
!= NULL
) {
1401 dom_string_unref(dnode_name
);
1409 * Determine whether or not the given element is empty
1411 * An element is "nonempty" if it has a child that is either an
1412 * element node or a text node.
1414 * \param pw Pointer to the current SVG parser state
1415 * \param node Libdom SVG node to check for emptiness
1416 * \param is_empty Pointer to the return value
1418 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1420 css_error
node_is_empty(void *pw
, void *node
, bool *is_empty
)
1423 dom_node
*child
; /* current child node pointer */
1424 dom_node
*next
; /* next child node pointer */
1425 dom_node_type type
; /* what type of node is "child" */
1428 /* Assume that it's empty by default */
1431 /* Get the given node's first child. Implementation detail:
1432 * this increments the reference counter on the child node. */
1433 err
= dom_node_get_first_child((dom_node
*)node
, &child
);
1434 if (err
!= DOM_NO_ERR
) {
1438 /* And now loop through all children looking for a
1439 * text/element node. If we find one, the original
1440 * node is "nonempty" */
1441 while (child
!= NULL
) {
1442 err
= dom_node_get_node_type(child
, &type
);
1443 if (err
!= DOM_NO_ERR
) {
1444 dom_node_unref(child
);
1448 if (type
== DOM_ELEMENT_NODE
|| type
== DOM_TEXT_NODE
) {
1450 dom_node_unref(child
);
1454 err
= dom_node_get_next_sibling(child
, &next
);
1455 if (err
!= DOM_NO_ERR
) {
1456 dom_node_unref(child
);
1460 /* If we're moving to the next node, we can release
1461 * the reference to the current one */
1462 dom_node_unref(child
);
1471 * Determine whether or not the given node is a link
1473 * A node is a link if it is an element node whose name is "a" and if
1474 * it has an "href" attribute (case-sensitive). This selector
1475 * corresponds to node:link pseudo-class in CSS.
1477 * This pseudo-class is a bit awkward because the two standards (HTML5
1478 * and CSS) disagree on what it means, and because libsvgtiny does not
1479 * have enough information to determine if a link has been "visited"
1480 * yet -- that's a UI property. CSS says that :link is for unvisited
1481 * links, which we can't determine. HTML5 says that each link must
1482 * be either a :link or :visited. Since we can't decide either way,
1483 * It seems less wrong to declare that all links are unvisited; i.e.
1484 * that they match :link.
1486 * \param pw Pointer to the current SVG parser state
1487 * \param node Libdom SVG node to check
1488 * \param is_link Pointer to the boolean return value
1490 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1492 css_error
node_is_link(void *pw
, void *node
, bool *is_link
)
1495 dom_node
*dnode
; /* node, but with the right type */
1496 dom_string
*dnode_name
;
1498 struct svgtiny_parse_state
* state
;
1500 dnode
= (dom_node
*)node
;
1502 has_href
= false; /* assume no href attribute */
1503 *is_link
= false; /* assume that it's not a link */
1505 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1506 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1510 state
= (struct svgtiny_parse_state
*)pw
;
1511 if (dom_string_isequal(dnode_name
, state
->interned_a
)) {
1512 exc
= dom_element_has_attribute(node
,
1513 state
->interned_href
,
1515 if (exc
== DOM_NO_ERR
&& has_href
) {
1520 dom_string_unref(dnode_name
);
1525 * Check if the given node is a link that has been visited already
1527 * This check always fails because the SVG DOM does not have the
1528 * necessary information (it's a UI property).
1530 * \param pw Pointer to the current SVG parser state; unused
1531 * \param node Libdom SVG node to check; unused
1532 * \param is_visited Pointer to the boolean return value
1534 * \return Always returns CSS_OK
1536 css_error
node_is_visited(void *pw
, void *node
, bool *is_visited
)
1540 *is_visited
= false;
1546 * Check if the given node is being "hovered" over
1548 * This check always fails because the SVG DOM does not have the
1549 * necessary information (it's a UI property).
1551 * \param pw Pointer to the current SVG parser state; unused
1552 * \param node Libdom SVG node to check; unused
1553 * \param is_hover Pointer to the boolean return value
1555 * \return Always returns CSS_OK
1557 css_error
node_is_hover(void *pw
, void *node
, bool *is_hover
)
1567 * Check if the given node is "active"
1569 * This check always fails because the SVG DOM does not have the
1570 * necessary information (it's a UI property).
1572 * \param pw Pointer to the current SVG parser state; unused
1573 * \param node Libdom SVG node to check; unused
1574 * \param is_active Pointer to the boolean return value
1576 * \return Always returns CSS_OK
1578 css_error
node_is_active(void *pw
, void *node
, bool *is_active
)
1588 * Check if the given node has the focus
1590 * This check always fails because the SVG DOM does not have the
1591 * necessary information (it's a UI property).
1593 * \param pw Pointer to the current SVG parser state; unused
1594 * \param node Libdom SVG node to check; unused
1595 * \param is_focus Pointer to the boolean return value
1597 * \return Always returns CSS_OK
1599 css_error
node_is_focus(void *pw
, void *node
, bool *is_focus
)
1609 * Check if the given node is enabled
1611 * This check always fails because the SVG DOM does not have the
1612 * necessary information (it's a UI property).
1614 * \param pw Pointer to the current SVG parser state; unused
1615 * \param node Libdom SVG node to check; unused
1616 * \param is_enabled Pointer to the boolean return value
1618 * \return Always returns CSS_OK
1620 css_error
node_is_enabled(void *pw
, void *node
, bool *is_enabled
)
1624 *is_enabled
= false;
1630 * Check if the given node is disabled
1632 * This check always fails because the SVG DOM does not have the
1633 * necessary information (it's a UI property). Beware, until they are
1634 * implemented, this is NOT the logical negation of node_is_enabled!
1636 * \param pw Pointer to the current SVG parser state; unused
1637 * \param node Libdom SVG node to check; unused
1638 * \param is_disabled Pointer to the boolean return value
1640 * \return Always returns CSS_OK
1642 css_error
node_is_disabled(void *pw
, void *node
, bool *is_disabled
)
1646 *is_disabled
= false;
1652 * Test whether or not the given node is "checked"
1654 * This test always fails because the SVG DOM does not have the
1655 * necessary information (it's a UI property).
1657 * \param pw Pointer to the current SVG parser state; unused
1658 * \param node Libdom SVG node to check; unused
1659 * \param is_checked Pointer to the boolean return value
1661 * \return Always returns CSS_OK
1663 css_error
node_is_checked(void *pw
, void *node
, bool *is_checked
)
1667 *is_checked
= false;
1673 * Check if the given node is the "target" of the document URL
1675 * This test always fails because the SVG DOM does not have the
1676 * necessary information (it's a UI property).
1678 * \param pw Pointer to the current SVG parser state; unused
1679 * \param node Libdom SVG node to check; unused
1680 * \param is_target Pointer to the boolean return value
1682 * \return Always returns CSS_OK
1684 css_error
node_is_target(void *pw
, void *node
, bool *is_target
)
1694 * Check if the given node is the given language
1696 * This test is corresponds to the CSS :lang() selector and is not
1697 * fully implemented yet: it looks only for "lang" attributes on the
1698 * given element and its parents, and performs a simple substring
1699 * check. This results in a partial implementation of CSS Level 3 for
1700 * SVG 2.0. In particular, it ignores all "xml:lang" attributes in
1701 * favor of the "lang" attribute that is defined only in SVG 2.0.
1703 * \param pw Pointer to the current SVG parser state; unused
1704 * \param node Libdom SVG node to check
1705 * \param lang The language to match
1706 * \param is_lang Pointer to the boolean return value
1708 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1710 static css_error
node_is_lang(void *pw
, void *node
,
1711 lwc_string
*lang
, bool *is_lang
)
1714 /* SVG2 elements support both "lang" and "xml:lang"
1715 * attributes; earlier versions have only the XML
1716 * attribute. It would not be too hard to add support for
1717 * xml:lang" here. The main difficulty standing in the way of
1718 * a full Level 4 implementation is the complexity of the
1721 * https://www.w3.org/TR/selectors-4/#the-lang-pseudo
1726 dom_exception d_err
;
1727 dom_node
*n
; /* current node */
1728 dom_node
*p
; /* parent node */
1729 bool match
; /* retval from node_has_attribute_substring() */
1731 /* Define the attribute name "lang" that we're looking for.
1732 * We only use a css_qname here because that's what the
1733 * node_has_attribute_substring() takes; the namespace
1734 * portion of it is irrelevant. */
1738 if (lwc_intern_string("lang", 4, &attr
.name
) != lwc_error_ok
) {
1742 *is_lang
= false; /* default to no match */
1743 n
= (dom_node
*)node
;
1745 /* Loop through all parents of the given node looking for a
1746 * substring match */
1748 c_err
= _node_has_attribute_substring(pw
, (void *)n
, &attr
,
1749 lang
, &match
, true);
1750 if (c_err
!= CSS_OK
) {
1751 lwc_string_destroy(attr
.name
);
1755 /* matched this element; we're done */
1756 lwc_string_destroy(attr
.name
);
1761 /* no match on this element, try its parent */
1762 d_err
= dom_node_get_parent_node(n
, &p
);
1763 if (d_err
!= DOM_NO_ERR
) {
1764 lwc_string_destroy(attr
.name
);
1770 /* If we never find a match we may wind up here */
1771 lwc_string_destroy(attr
.name
);
1777 * Return presentational hints for the given node
1779 * Unless an SVG is being rendered from within an HTML document,
1780 * there are no presentational hints. We always return an empty
1783 * \param pw Pointer to the current SVG parser state; unused
1784 * \param node Libdom SVG node whose hints we want; unused
1785 * \param nhints How many hints are returned (return by reference)
1786 * \param hints Array of css_hint structures (return by reference)
1788 * \return Always returns CSS_OK
1790 css_error
node_presentational_hint(void *pw
, void *node
,
1791 uint32_t *nhints
, css_hint
**hints
)
1802 * User-agent defaults for CSS properties
1804 * For the moment, we provide no defaults, because libsvgtiny does not
1805 * yet support any CSS properties that might need them.
1807 * \param pw Pointer to the current SVG parser state; unused
1808 * \param property LibCSS property identifier; unused
1809 * \param hint Pointer to hint object (a return value); unused
1811 * \return Always returns CSS_INVALID
1813 css_error
ua_default_for_property(void *pw
, uint32_t property
,
1824 * Store libcss data on a node
1826 * This is part of the libcss select handler API that we need to
1827 * implement. It is essentially a thin dom_node_set_user_data()
1830 * \param pw Pointer to the current SVG parser state
1831 * \param node Libdom SVG node on which to store the data
1832 * \param libcss_node_data Pointer to the data to store
1834 * \return Always returns CSS_OK
1836 css_error
set_libcss_node_data(void *pw
, void *node
,
1837 void *libcss_node_data
)
1839 struct svgtiny_parse_state
*state
;
1842 /* A unique "userdata key" (a string) is used to identify this
1843 * data. The fourth parameter (NULL) is a "user handler
1844 * function." We will eventually have one, but for now we set
1845 * it to NULL to avoid a circular reference mess that would
1846 * break the build temporarily. */
1847 state
= (struct svgtiny_parse_state
*)pw
;
1848 dom_node_set_user_data((dom_node
*)node
,
1849 state
->interned_userdata_key
,
1854 /* dom_node_set_user_data() always returns DOM_NO_ERR */
1860 * Retrieve libcss data from a node
1862 * This is part of the libcss select handler API that we need to
1863 * implement. It is essentially a thin dom_node_get_user_data()
1866 * \param pw Pointer to the current SVG parser state
1867 * \param node Libdom SVG node from which to get the data
1868 * \param libcss_node_data Address at which to store a pointer to the data
1870 * \return Always returns CSS_OK
1872 css_error
get_libcss_node_data(void *pw
, void *node
,
1873 void **libcss_node_data
)
1875 struct svgtiny_parse_state
*state
;
1877 /* A unique "userdata key" (a string) is used to identify this
1879 state
= (struct svgtiny_parse_state
*)pw
;
1880 dom_node_get_user_data((dom_node
*)node
,
1881 state
->interned_userdata_key
,
1884 /* dom_node_get_user_data() always returns DOM_NO_ERR */