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
ua_default_for_property(void *pw
, uint32_t property
,
62 static css_error
set_libcss_node_data(void *pw
, void *node
,
63 void *libcss_node_data
);
64 static css_error
get_libcss_node_data(void *pw
, void *node
,
65 void **libcss_node_data
);
69 * Resolve a relative URL to an absolute one by doing nothing. This is
70 * the simplest possible implementation of a URL resolver, needed for
73 css_error
svgtiny_resolve_url(void *pw
,
74 const char *base
, lwc_string
*rel
, lwc_string
**abs
)
79 /* Copy the relative URL to the absolute one (the return
81 *abs
= lwc_string_ref(rel
);
86 * Create a stylesheet with the default set of params.
88 * \param sheet A stylesheet pointer, passed in by reference, that
89 * we use to store the newly-created stylesheet.
90 * \param inline_style True if this stylesheet represents an inline
91 * style, and false otherwise.
93 * \return The return value from css_stylesheet_create() is returned.
95 css_error
svgtiny_create_stylesheet(css_stylesheet
**sheet
,
98 css_stylesheet_params params
;
100 params
.params_version
= CSS_STYLESHEET_PARAMS_VERSION_1
;
101 params
.level
= CSS_LEVEL_DEFAULT
;
102 params
.charset
= NULL
;
105 params
.allow_quirks
= false;
106 params
.inline_style
= inline_style
;
107 params
.resolve
= svgtiny_resolve_url
;
108 params
.resolve_pw
= NULL
;
109 params
.import = NULL
;
110 params
.import_pw
= NULL
;
112 params
.color_pw
= NULL
;
114 params
.font_pw
= NULL
;
116 return css_stylesheet_create(¶ms
, sheet
);
120 /**************************/
121 /* libcss select handlers */
122 /**************************/
124 * From here on we implement the "select handler "API defined in
125 * libcss's include/libcss/select.h and discussed briefly in its
131 * Retrieve the given node's name
133 * \param pw Pointer to the current SVG parser state
134 * \param node Libdom SVG node
135 * \param qname Address at which to store the node name
137 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
139 css_error
node_name(void *pw
, void *node
, css_qname
*qname
)
143 struct svgtiny_parse_state
*state
;
145 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
146 if (err
!= DOM_NO_ERR
) {
150 state
= (struct svgtiny_parse_state
*)pw
;
151 qname
->ns
= lwc_string_ref(state
->interned_svg_xmlns
);
153 err
= dom_string_intern(name
, &qname
->name
);
154 if (err
!= DOM_NO_ERR
) {
155 dom_string_unref(name
);
159 dom_string_unref(name
);
166 * Retrieve the given node's classes
168 * \param pw Pointer to the current SVG parser state
169 * \param node Libdom SVG node
170 * \param classes Address at which to store the class name array
171 * \param n_classes Address at which to store the length of the class
174 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
176 * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
177 * because the underlying libdom function never fails
179 css_error
node_classes(void *pw
, void *node
,
180 lwc_string
***classes
, uint32_t *n_classes
)
185 err
= dom_element_get_classes((dom_node
*)node
, classes
, n_classes
);
187 /* The implementation does not do it, but the documentation
188 for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
189 possible here, so we handle it to be on the safe side. */
190 if (err
!= DOM_NO_ERR
) {
199 * Retrieve the given node's id
201 * \param pw Pointer to the current SVG parser state
202 * \param node Libdom SVG node
203 * \param id Address at which to store the id
205 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
207 css_error
node_id(void *pw
, void *node
, lwc_string
**id
)
211 struct svgtiny_parse_state
*state
;
213 /* Begin with the assumption that this node has no id */
216 state
= (struct svgtiny_parse_state
*)pw
;
217 err
= dom_element_get_attribute((dom_node
*)node
,
218 state
->interned_id
, &attr
);
219 if (err
!= DOM_NO_ERR
) {
222 else if (attr
== NULL
) {
223 /* The node has no id attribute and our return value
224 is already set to NULL so we're done */
228 /* If we found an id attribute (a dom_string), intern it into
229 an lwc_string that we can return, and then cleanup the
231 err
= dom_string_intern(attr
, id
);
232 if (err
!= DOM_NO_ERR
) {
233 dom_string_unref(attr
);
236 dom_string_unref(attr
);
243 * Find the first parent of the given element having the given name
245 * \param pw Pointer to the current SVG parser state
246 * \param node Libdom SVG node
247 * \param qname Name of the parent node to search for
248 * \param parent Address at which to store the parent node pointer
250 * \return Always returns CSS_OK
252 * \post If a suitable element is found, a pointer to it will be
253 * stored at the address pointed to by \a parent; otherwise,
254 * NULL will be stored at the address pointed to by \a parent
256 css_error
named_parent_node(void *pw
, void *node
,
257 const css_qname
*qname
, void **parent
)
260 /* dom_element_named_parent_node() was invented to implement
261 * this select handler so there isn't much for us to do except
262 * call it. It's OK if node isn't an element, libdom checks
264 dom_element_named_parent_node((dom_element
*)node
,
266 (struct dom_element
**)parent
);
268 /* Implementation detail: dom_element_named_parent_node()
269 * increments the reference count of the parent element before
270 * returning it to us. According to docs/RefCnt in the libdom
271 * repository, this will prevent the parent element from being
272 * destroyed if it is pruned from the DOM. That sounds good,
273 * since we don't want to be using a pointer to an object that
274 * has been destroyed... but we also have no way of later
275 * decrementing the reference count ourselves, and don't want
276 * to make the returned node eternal. Decrementing the
277 * reference counter now allows it to be destroyed when the
278 * DOM no longer needs it, and so long as no other parts of
279 * libsvgtiny are messing with the DOM during parsing, that
280 * shouldn't (ha ha) cause any problems. */
281 dom_node_unref(*parent
);
288 * Find the "next-sibling" of the given element having the given name
290 * This search corresponds to the "+ foo" combinator in CSS and will
291 * find only "foo" element nodes that immediately precede the given
292 * node under the same parent in the DOM. In CSS the tree is viewed
293 * top-down and in libdom it is viewed from the bottom-up; as a result
294 * "next" and "previous" are sometimes backwards. This is case-sensitive.
296 * \param pw Pointer to the current SVG parser state
297 * \param node Libdom SVG node
298 * \param qname Name of the sibling node to search for
299 * \param sibling Address at which to store the sibling node pointer
301 * \return Always returns CSS_OK
303 * \post If a suitable element is found, a pointer to it will be
304 * stored at the address pointed to by \a sibling; otherwise,
305 * NULL will be stored at the address pointed to by \a sibling
307 css_error
named_sibling_node(void *pw
, void *node
,
308 const css_qname
*qname
, void **sibling
)
311 dom_node
*n
= node
; /* the current node */
312 dom_node
*prev
; /* the previous node */
317 *sibling
= NULL
; /* default to nothing found */
319 /* Begin the search; the first iteration we do outside of the
320 * loop. Implementation detil: dom_node_get_previous_sibling()
321 * increments the reference counter on the returned node. A
322 * comment within named_parent_node() explains why we
323 * decrement it ASAP. */
324 err
= dom_node_get_previous_sibling(n
, &n
);
325 if (err
!= DOM_NO_ERR
) {
330 /* We're looking for the first ELEMENT sibling */
331 err
= dom_node_get_node_type(n
, &type
);
332 if (err
!= DOM_NO_ERR
) {
337 if (type
== DOM_ELEMENT_NODE
) {
338 /* We found an element node, does it have the
340 err
= dom_node_get_node_name(n
, &name
);
341 if (err
!= DOM_NO_ERR
) {
346 if (dom_string_lwc_isequal(name
,
348 /* The name is right, return it */
352 /* There's only one next-sibling element node
353 * and we've already found it, so if its name
354 * wasn't right, we return the default value
356 dom_string_unref(name
);
361 /* Not an element node, so we move on the the previous
362 * previous sibling */
363 err
= dom_node_get_previous_sibling(n
, &prev
);
364 if (err
!= DOM_NO_ERR
) {
378 * Find the first "subsequent-sibling" of the given element having the
381 * This search corresponds to the "~ foo" combinator in CSS and will
382 * find only "foo" element nodes that precede the given node (under
383 * the same parent) in the DOM. In CSS the tree is viewed top-down and
384 * in libdom it is viewed from the bottom-up; as a result "next" and
385 * "previous" are sometimes backwards. This is case-sensitive.
387 * \param pw Pointer to the current SVG parser state
388 * \param node Libdom SVG node
389 * \param qname Name of the sibling node to search for
390 * \param sibling Address at which to store the sibling node pointer
392 * \return Always returns CSS_OK
394 * \post If a suitable element is found, a pointer to it will be
395 * stored at the address pointed to by \a sibling; otherwise,
396 * NULL will be stored at the address pointed to by \a sibling
398 css_error
named_generic_sibling_node(void *pw
, void *node
,
399 const css_qname
*qname
, void **sibling
)
402 dom_node
*n
= node
; /* the current node */
403 dom_node
*prev
; /* the previous node */
409 *sibling
= NULL
; /* default to nothing found */
411 /* Begin the search; the first iteration we do outside of the
412 * loop. Implementation detil: dom_node_get_previous_sibling()
413 * increments the reference counter on the returned node. A
414 * comment within named_parent_node() explains why we
415 * decrement it ASAP. */
416 err
= dom_node_get_previous_sibling(n
, &n
);
417 if (err
!= DOM_NO_ERR
) {
422 err
= dom_node_get_node_type(n
, &type
);
423 if (err
!= DOM_NO_ERR
) {
428 if (type
== DOM_ELEMENT_NODE
) {
429 /* We only want ELEMENT nodes */
430 err
= dom_node_get_node_name(n
, &name
);
431 if (err
!= DOM_NO_ERR
) {
436 if (dom_string_lwc_isequal(name
,
438 /* Found one. Save it and stop the search */
439 dom_string_unref(name
);
445 dom_string_unref(name
);
448 /* This sibling wasn't an element with the desired
449 name, so move on to the previous sibling */
450 err
= dom_node_get_previous_sibling(n
, &prev
);
451 if (err
!= DOM_NO_ERR
) {
465 * Return a pointer to the given node's parent
467 * \param pw Pointer to the current SVG parser state
468 * \param node Libdom SVG node
469 * \param parent Address at which to store the node's parent pointer
471 * \return Always returns CSS_OK
473 css_error
parent_node(void *pw
, void *node
, void **parent
)
476 /* Libdom basically implements this for us */
477 dom_element_parent_node(node
, (struct dom_element
**)parent
);
479 /* See the comment in named_parent_node() for why we decrement
480 * this reference counter here. */
481 dom_node_unref(*parent
);
488 * Find the "next-sibling" of the given element
490 * This search corresponds "+ *" in CSS and will find the first
491 * element node that immediately precedes the given node under the
492 * same parent in the DOM. In CSS the tree is viewed top-down and in
493 * libdom it is viewed from the bottom-up; as a result "next" and
494 * "previous" are sometimes backwards.
496 * \param pw Pointer to the current SVG parser state
497 * \param node Libdom SVG node
498 * \param sibling Address at which to store the sibling node pointer
500 * \return Always returns CSS_OK
502 * \post If a suitable element is found, a pointer to it will be
503 * stored at the address pointed to by \a sibling; otherwise,
504 * NULL will be stored at the address pointed to by \a sibling
506 css_error
sibling_node(void *pw
, void *node
, void **sibling
)
509 dom_node
*n
= node
; /* the current node */
510 dom_node
*prev
; /* the previous node */
514 *sibling
= NULL
; /* default to nothing found */
516 /* Begin the search; the first iteration we do outside of the
517 * loop. Implementation detil: dom_node_get_previous_sibling()
518 * increments the reference counter on the returned node. A
519 * comment within named_parent_node() explains why we
520 * decrement it ASAP. */
521 err
= dom_node_get_previous_sibling(n
, &n
);
522 if (err
!= DOM_NO_ERR
) {
527 err
= dom_node_get_node_type(n
, &type
);
528 if (err
!= DOM_NO_ERR
) {
533 if (type
== DOM_ELEMENT_NODE
) {
534 /* We found a sibling node that is also an
535 element and that's all we wanted. */
541 /* This sibling node was not an element; move on to
542 the previous sibling */
543 err
= dom_node_get_previous_sibling(n
, &prev
);
544 if (err
!= DOM_NO_ERR
) {
558 * Test the given node for the given name
560 * This will return true (via the "match" pointer) if the libdom node
561 * has the given name or if that name is the universal selector;
562 * otherwise it returns false. The comparison is case-sensitive. It
563 * corresponds to a rule like "body { ... }" in CSS.
565 * \param pw Pointer to the current SVG parser state
566 * \param node Libdom SVG node to test
567 * \param qname Name to check for
568 * \param match Pointer to the test result
570 * \return Always returns CSS_OK
572 css_error
node_has_name(void *pw
, void *node
,
573 const css_qname
*qname
, bool *match
)
575 struct svgtiny_parse_state
*state
;
579 /* Start by checking to see if qname is the universal selector */
580 state
= (struct svgtiny_parse_state
*)pw
;
581 if (lwc_string_isequal(qname
->name
,
582 state
->interned_universal
, match
) == lwc_error_ok
) {
584 /* It's the universal selector. In NetSurf, all node
585 * names match the universal selector, and nothing in
586 * the libcss documentation suggests another approach,
587 * so we follow NetSurf here. */
592 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
593 if (err
!= DOM_NO_ERR
) {
597 /* Unlike with HTML, SVG element names are case-sensitive */
598 *match
= dom_string_lwc_isequal(name
, qname
->name
);
599 dom_string_unref(name
);
606 * Test the given node for the given class
608 * This will return true (via the "match" pointer) if the libdom node
609 * has the given class. The comparison is case-sensitive. It
610 * corresponds to node.class in CSS.
612 * \param pw Pointer to the current SVG parser state
613 * \param node Libdom SVG node to test
614 * \param name Class name to check for
615 * \param match Pointer to the test result
617 * \return Always returns CSS_OK
619 css_error
node_has_class(void *pw
, void *node
,
620 lwc_string
*name
, bool *match
)
623 /* libdom implements this for us and apparently it cannot fail */
624 dom_element_has_class((dom_node
*)node
, name
, match
);
630 * Test the given node for the given id
632 * This will return true (via the "match" pointer) if the libdom node
633 * has the given id. The comparison is case-sensitive. It corresponds
636 * \param pw Pointer to the current SVG parser state
637 * \param node Libdom SVG node to test
638 * \param name Id to check for
639 * \param match Pointer to the test result
641 * \return Always returns CSS_OK
643 css_error
node_has_id(void *pw
, void *node
,
644 lwc_string
*name
, bool *match
)
648 struct svgtiny_parse_state
*state
;
650 attr
= NULL
; /* a priori the "id" attribute may not exist */
651 *match
= false; /* default to no match */
653 state
= (struct svgtiny_parse_state
*)pw
;
654 err
= dom_element_get_attribute((dom_node
*)node
,
655 state
->interned_id
, &attr
);
656 if (err
!= DOM_NO_ERR
|| attr
== NULL
) {
660 *match
= dom_string_lwc_isequal(attr
, name
);
661 dom_string_unref(attr
);
668 * Test the given node for the given attribute
670 * This will return true (via the "match" pointer) if the libdom node
671 * has an attribute with the given name. The comparison is
672 * case-sensitive. It corresponds to node[attr] in CSS.
674 * \param pw Pointer to the current SVG parser state
675 * \param node Libdom SVG node to test
676 * \param qname Attribute name to check for
677 * \param match Pointer to the test result
679 * \return Returns CSS_OK if successful and CSS_NOMEM if anything
682 css_error
node_has_attribute(void *pw
, void *node
,
683 const css_qname
*qname
, bool *match
)
689 /* intern the attribute name as a dom_string so we can
690 * delegate to dom_element_has_attribute() */
691 err
= dom_string_create_interned(
692 (const uint8_t *) lwc_string_data(qname
->name
),
693 lwc_string_length(qname
->name
),
695 if (err
!= DOM_NO_ERR
) {
699 err
= dom_element_has_attribute((dom_node
*)node
, name
, match
);
700 if (err
!= DOM_NO_ERR
) {
701 dom_string_unref(name
);
705 dom_string_unref(name
);
711 * Test the given node for an attribute with a specific value
713 * This will return true (via the "match" pointer) if the libdom node
714 * has an attribute with the given name and value. The comparison is
715 * case-sensitive. It corresponds to node[attr=value] in CSS.
717 * \param pw Pointer to the current SVG parser state
718 * \param node Libdom SVG node to test
719 * \param qname Attribute name to check for
720 * \param value Attribute value to check for
721 * \param match Pointer to the test result
723 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
724 * intern the attribute name (which usually indicates memory
727 css_error
node_has_attribute_equal(void *pw
, void *node
,
728 const css_qname
*qname
, lwc_string
*value
,
731 /* Implementation note: NetSurf always returns "no match" when
732 * the value is empty (length zero). We allow it, because why
737 dom_string
*attr_val
;
740 /* Intern the attribute name as a dom_string so we can
741 * use dom_element_get_attribute() */
742 err
= dom_string_create_interned(
743 (const uint8_t *) lwc_string_data(qname
->name
),
744 lwc_string_length(qname
->name
),
746 if (err
!= DOM_NO_ERR
) {
750 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
751 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
752 /* There was an error getting the attribute's value or
753 * the attribute doesn't exist. So, no match? */
754 dom_string_unref(name
);
759 /* Otherwise, we have the attribute value from the given node
760 * and all we need to do is compare. */
761 dom_string_unref(name
);
762 *match
= dom_string_lwc_isequal(attr_val
, value
);
763 dom_string_unref(attr_val
);
770 * Test the given node for an attribute with a specific value,
771 * possibly followed by a single hyphen
773 * This will return true (via the "match" pointer) if the libdom node
774 * has an attribute with the given name and value or with the given
775 * name and a value that is followed by exactly one hyphen. The
776 * comparison is case-sensitive. This corresponds to [attr|=value]
779 * \param pw Pointer to the current SVG parser state
780 * \param node Libdom SVG node to test
781 * \param qname Attribute name to check for
782 * \param value Attribute value to check for
783 * \param match Pointer to the test result
785 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
786 * intern the attribute name (which usually indicates memory
789 css_error
node_has_attribute_dashmatch(void *pw
, void *node
,
790 const css_qname
*qname
, lwc_string
*value
,
793 /* Implementation note: NetSurf always returns "no match" when
794 * the value is empty (length zero). We allow it, because why
799 dom_string
*attr_val
;
802 const char *vdata
; /* to hold the data underlying "value" */
804 const char *avdata
; /* to hold the found attribute value data */
807 /* Intern the attribute name as a dom_string so we can
808 * use dom_element_get_attribute() */
809 err
= dom_string_create_interned(
810 (const uint8_t *) lwc_string_data(qname
->name
),
811 lwc_string_length(qname
->name
),
813 if (err
!= DOM_NO_ERR
) {
817 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
818 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
819 /* There was an error getting the attribute's value or
820 * the attribute doesn't exist. So, no match? */
821 dom_string_unref(name
);
826 /* Otherwise, we have the attribute value from the given node
827 * and all we need to do is compare. */
828 dom_string_unref(name
);
829 *match
= dom_string_lwc_isequal(attr_val
, value
);
831 /* Exact match, we're done */
832 dom_string_unref(attr_val
);
836 /* No exact match, try it with a hyphen on the end */
837 vdata
= lwc_string_data(value
); /* needle */
838 vdata_len
= lwc_string_length(value
);
839 avdata
= dom_string_data(attr_val
); /* haystack */
840 avdata_len
= dom_string_byte_length(attr_val
);
841 dom_string_unref(attr_val
);
843 if (avdata_len
> vdata_len
&& avdata
[vdata_len
] == '-') {
844 if (strncasecmp(avdata
, vdata
, vdata_len
) == 0) {
845 /* If there's a hyphen in the right position,
846 * it suffices to compare the strings only up
857 * Test the given node for an attribute whose value is a
858 * space-separated list of words, one of which is the given word
860 * This will return true (via the "match" pointer) if the libdom node
861 * has an attribute with the given name and whose value when
862 * considered as a space-separated list of words contains the given
863 * word. The comparison is case-sensitive. This corresponds to
864 * [attr~=value] in CSS.
866 * \param pw Pointer to the current SVG parser state
867 * \param node Libdom SVG node to test
868 * \param qname Attribute name to check for
869 * \param word Value word to check for
870 * \param match Pointer to the test result
872 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
873 * intern the attribute name (which usually indicates memory
876 css_error
node_has_attribute_includes(void *pw
, void *node
,
877 const css_qname
*qname
, lwc_string
*word
,
883 dom_string
*attr_val
;
885 size_t wordlen
; /* length of "word" */
887 /* pointers used to parse a space-separated list of words */
892 *match
= false; /* default to no match */
894 wordlen
= lwc_string_length(word
);
896 /* In this case, the spec says that "if 'val' is the
897 * empty string, it will never represent anything." */
901 /* Intern the attribute name as a dom_string so we can
902 * use dom_element_get_attribute() */
903 err
= dom_string_create_interned(
904 (const uint8_t *) lwc_string_data(qname
->name
),
905 lwc_string_length(qname
->name
),
907 if (err
!= DOM_NO_ERR
) {
911 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
912 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
913 /* There was an error getting the attribute's value or
914 * the attribute doesn't exist. So, no match? */
915 dom_string_unref(name
);
919 /* Parse the list comparing each word against "word" */
920 start
= dom_string_data(attr_val
);
921 end
= start
+ dom_string_byte_length(attr_val
);
922 dom_string_unref(attr_val
);
924 for (p
= start
; p
<= end
; p
++) {
925 /* Move forward until we find the end of the first word */
926 if (*p
== ' ' || *p
== '\0') {
927 /* If the length of that word is the length of the
928 * word we're looking for, do the comparison. */
929 if ((size_t) (p
- start
) == wordlen
&&
931 lwc_string_data(word
),
936 /* No match? Set "start" to the beginning of
937 * the next word and loop. */
947 * Test the given node for an attribute whose value begins with the
950 * This will return true (via the "match" pointer) if the libdom node
951 * has an attribute with the given name and whose value begins with
952 * the given prefix string. The comparison is case-sensitive. This
953 * corresponds to [attr^=value] in CSS.
955 * \param pw Pointer to the current SVG parser state
956 * \param node Libdom SVG node to test
957 * \param qname Attribute name to check for
958 * \param prefix Value prefix to check for
959 * \param match Pointer to the test result
961 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
962 * intern the attribute name (which usually indicates memory
965 css_error
node_has_attribute_prefix(void *pw
, void *node
,
966 const css_qname
*qname
, lwc_string
*prefix
,
971 dom_string
*attr_val
;
973 const char *avdata
; /* attribute value data */
974 size_t avdata_len
; /* length of that attribute value data */
975 size_t prefixlen
; /* length of "prefix" */
977 prefixlen
= lwc_string_length(prefix
);
978 if (prefixlen
== 0) {
979 /* In this case, the spec says that "if 'val' is the
980 * empty string, it will never represent anything." */
984 /* Intern the attribute name as a dom_string so we can
985 * use dom_element_get_attribute() */
986 err
= dom_string_create_interned(
987 (const uint8_t *) lwc_string_data(qname
->name
),
988 lwc_string_length(qname
->name
),
990 if (err
!= DOM_NO_ERR
) {
994 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
995 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
996 /* There was an error getting the attribute's value or
997 * the attribute doesn't exist. So, no match? */
998 dom_string_unref(name
);
1003 /* Otherwise, we have the attribute value from the given node,
1004 * and the first thing we want to do is check to see if the
1005 * whole thing matches the prefix. */
1006 dom_string_unref(name
);
1007 *match
= dom_string_lwc_isequal(attr_val
, prefix
);
1009 /* If not, check to see if an, uh, prefix matches the
1011 if (*match
== false) {
1012 avdata
= dom_string_data(attr_val
);
1013 avdata_len
= dom_string_byte_length(attr_val
);
1014 if ((avdata_len
>= prefixlen
) &&
1015 (strncasecmp(avdata
,
1016 lwc_string_data(prefix
),
1018 /* Use strncasecmp to compare only the first
1019 * "n" characters, where "n" is the length of
1025 dom_string_unref(attr_val
);
1032 * Test the given node for an attribute whose value end with the
1035 * This will return true (via the "match" pointer) if the libdom node
1036 * has an attribute with the given name and whose value ends with
1037 * the given suffix string. The comparison is case-sensitive. This
1038 * corresponds to [attr$=value] in CSS.
1040 * \param pw Pointer to the current SVG parser state
1041 * \param node Libdom SVG node to test
1042 * \param qname Attribute name to check for
1043 * \param suffix Value suffix to check for
1044 * \param match Pointer to the test result
1046 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1047 * intern the attribute name (which usually indicates memory
1050 css_error
node_has_attribute_suffix(void *pw
, void *node
,
1051 const css_qname
*qname
, lwc_string
*suffix
,
1056 dom_string
*attr_val
;
1058 const char *avdata
; /* attribute value data */
1059 size_t avdata_len
; /* length of that attribute value data */
1060 size_t suffixlen
; /* length of "suffix" */
1062 /* convenience pointer we'll use when matching the suffix */
1063 const char *suffix_start
;
1065 suffixlen
= lwc_string_length(suffix
);
1066 if (suffixlen
== 0) {
1067 /* In this case, the spec says that "if 'val' is the
1068 * empty string, it will never represent anything." */
1072 /* Intern the attribute name as a dom_string so we can
1073 * use dom_element_get_attribute() */
1074 err
= dom_string_create_interned(
1075 (const uint8_t *) lwc_string_data(qname
->name
),
1076 lwc_string_length(qname
->name
),
1078 if (err
!= DOM_NO_ERR
) {
1082 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1083 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1084 /* There was an error getting the attribute's value or
1085 * the attribute doesn't exist. So, no match? */
1086 dom_string_unref(name
);
1091 /* Otherwise, we have the attribute value from the given node,
1092 * and the first thing we want to do is check to see if the
1093 * whole thing matches the suffix. */
1094 dom_string_unref(name
);
1095 *match
= dom_string_lwc_isequal(attr_val
, suffix
);
1097 /* If not, check to see if an, uh, suffix matches the
1099 if (*match
== false) {
1100 avdata
= dom_string_data(attr_val
);
1101 avdata_len
= dom_string_byte_length(attr_val
);
1103 suffix_start
= (char *)(avdata
+ avdata_len
- suffixlen
);
1105 if ((avdata_len
>= suffixlen
) &&
1106 (strncasecmp(suffix_start
,
1107 lwc_string_data(suffix
),
1109 /* Use strncasecmp to compare only the last
1110 * "n" characters, where "n" is the length of
1116 dom_string_unref(attr_val
);
1123 * Implement node_has_attribute_substring() with optional case-
1124 * insensitivity. This corresponds to [attr*=value i] in CSS and is
1125 * not supported by libcss yet, but it allows us to factor out some
1128 static css_error
_node_has_attribute_substring(void *pw
, void *node
,
1129 const css_qname
*qname
, lwc_string
*substring
,
1130 bool *match
, bool insensitive
)
1134 dom_string
*attr_val
;
1136 size_t attr_len
; /* length of attr_val */
1137 size_t substrlen
; /* length of "substring" */
1139 /* Convenience pointers we use when comparing substrings */
1143 substrlen
= lwc_string_length(substring
);
1144 if (substrlen
== 0) {
1145 /* In this case, the spec says that "if 'val' is the
1146 * empty string, it will never represent anything." */
1150 /* Intern the attribute name as a dom_string so we can
1151 * use dom_element_get_attribute() */
1152 err
= dom_string_create_interned(
1153 (const uint8_t *) lwc_string_data(qname
->name
),
1154 lwc_string_length(qname
->name
),
1156 if (err
!= DOM_NO_ERR
) {
1160 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1161 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1162 /* There was an error getting the attribute's value or
1163 * the attribute doesn't exist. So, no match? */
1164 dom_string_unref(name
);
1169 /* Otherwise, we have the attribute value from the given node,
1170 * and the first thing we want to do is check to see if the
1171 * whole thing matches the substring. */
1172 dom_string_unref(name
);
1175 *match
= dom_string_caseless_lwc_isequal(attr_val
, substring
);
1178 *match
= dom_string_lwc_isequal(attr_val
, substring
);
1181 /* If not, check to see if an, uh, substring matches the
1183 if (*match
== false) {
1184 p
= dom_string_data(attr_val
);
1186 /* Check every long-enough suffix for a prefix match */
1187 attr_len
= dom_string_byte_length(attr_val
);
1188 if (attr_len
>= substrlen
) {
1189 p_max
= p
+ attr_len
- substrlen
;
1190 while (p
<= p_max
) {
1192 lwc_string_data(substring
),
1202 dom_string_unref(attr_val
);
1208 * Test the given node for an attribute whose value contains the
1211 * This will return true (via the "match" pointer) if the libdom node
1212 * has an attribute with the given name and whose value contains the
1213 * given substring. The comparison is case-sensitive. This corresponds
1214 * to [attr*=value] in CSS.
1216 * \param pw Pointer to the current SVG parser state
1217 * \param node Libdom SVG node to test
1218 * \param qname Attribute name to check for
1219 * \param substring Value substring to check for
1220 * \param match Pointer to the test result
1222 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1223 * intern the attribute name (which usually indicates memory
1226 css_error
node_has_attribute_substring(void *pw
, void *node
,
1227 const css_qname
*qname
, lwc_string
*substring
,
1230 return _node_has_attribute_substring(pw
, node
, qname
, substring
,
1236 * Test whether or not the given node is the document's root element
1237 * This corresponds to the CSS :root pseudo-selector.
1239 * \param pw Pointer to the current SVG parser state
1240 * \param node Libdom SVG node to test
1241 * \param match Pointer to the test result
1243 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1245 css_error
node_is_root(void *pw
, void *node
, bool *match
)
1252 err
= dom_node_get_parent_node((dom_node
*)node
, &parent
);
1253 if (err
!= DOM_NO_ERR
) {
1257 /* It's the root element if it doesn't have a parent element */
1258 if (parent
!= NULL
) {
1259 err
= dom_node_get_node_type(parent
, &type
);
1260 dom_node_unref(parent
);
1261 if (err
!= DOM_NO_ERR
) {
1264 if (type
!= DOM_DOCUMENT_NODE
) {
1265 /* DOM_DOCUMENT_NODE is the only allowable
1266 * type of parent node for the root element */
1278 * Used internally in node_count_siblings() to "count" the given
1279 * sibling node. It factors out the node type and name checks.
1281 static int node_count_siblings_check(dom_node
*dnode
,
1288 dom_string
*dnode_name
;
1290 /* We flip this to 1 if/when we count this node */
1293 if (dnode
== NULL
) {
1297 exc
= dom_node_get_node_type(dnode
, &type
);
1298 if ((exc
!= DOM_NO_ERR
) || (type
!= DOM_ELEMENT_NODE
)) {
1299 /* We only count element siblings */
1303 /* ... with the right name */
1306 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1308 if ((exc
== DOM_NO_ERR
) && (dnode_name
!= NULL
)) {
1309 if (dom_string_isequal(name
,
1313 dom_string_unref(dnode_name
);
1324 * Count the given node's sibling elements
1326 * This counts the given node's sibling elements in one direction,
1327 * either forwards or backwards, in the DOM. Keep in mind that the
1328 * libdom tree is upside-down compared to the CSS one; so "next" and
1329 * "previous" are actually reversed; the default is to count preceding
1330 * libdom siblings which correspond to subsequent CSS siblings.
1332 * This operation is central to the CSS :first-child, :nth-child, and
1333 * :last-child (et cetera) pseudo-selectors.
1335 * If same_name is true, then only nodes having the same
1336 * (case-sensitive) name as the given node are counted.
1338 * \param pw Pointer to the current SVG parser state
1339 * \param node Libdom SVG node whose siblings we're counting
1340 * \param same_name Whether or not to count only siblings having
1341 * the same name as the given node
1342 * \param after Count subsequent siblings rather than precedent
1343 * ones (the default)
1344 * \param count Pointer to the return value, the number of sibling
1347 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1349 css_error
node_count_siblings(void *pw
, void *node
,
1350 bool same_name
, bool after
, int32_t *count
)
1354 dom_node
*dnode
; /* node, but with the right type */
1355 dom_string
*dnode_name
;
1356 dom_node
*next
; /* "next" sibling (depends on direction) */
1358 /* Pointer to the "next sibling" function */
1359 dom_exception (*next_func
)(dom_node
*, dom_node
**);
1364 dnode
= (dom_node
*)node
;
1366 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1367 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1372 /* Increment the reference counter for dnode for as long as
1373 * we retain a reference to it. */
1374 dnode
= dom_node_ref(dnode
);
1376 next_func
= dom_node_get_previous_sibling
;
1378 next_func
= dom_node_get_next_sibling
;
1382 exc
= next_func(dnode
, &next
);
1383 if (exc
!= DOM_NO_ERR
) {
1387 /* If next_func worked, we're about to swap "next"
1388 * with "dnode" meaning that we will no longer retain
1389 * a reference to the current dnode. */
1390 dom_node_unref(dnode
);
1393 *count
+= node_count_siblings_check(dnode
,
1396 } while (dnode
!= NULL
);
1398 if (dnode_name
!= NULL
) {
1399 dom_string_unref(dnode_name
);
1407 * Determine whether or not the given element is empty
1409 * An element is "nonempty" if it has a child that is either an
1410 * element node or a text node.
1412 * \param pw Pointer to the current SVG parser state
1413 * \param node Libdom SVG node to check for emptiness
1414 * \param is_empty Pointer to the return value
1416 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1418 css_error
node_is_empty(void *pw
, void *node
, bool *is_empty
)
1421 dom_node
*child
; /* current child node pointer */
1422 dom_node
*next
; /* next child node pointer */
1423 dom_node_type type
; /* what type of node is "child" */
1426 /* Assume that it's empty by default */
1429 /* Get the given node's first child. Implementation detail:
1430 * this increments the reference counter on the child node. */
1431 err
= dom_node_get_first_child((dom_node
*)node
, &child
);
1432 if (err
!= DOM_NO_ERR
) {
1436 /* And now loop through all children looking for a
1437 * text/element node. If we find one, the original
1438 * node is "nonempty" */
1439 while (child
!= NULL
) {
1440 err
= dom_node_get_node_type(child
, &type
);
1441 if (err
!= DOM_NO_ERR
) {
1442 dom_node_unref(child
);
1446 if (type
== DOM_ELEMENT_NODE
|| type
== DOM_TEXT_NODE
) {
1448 dom_node_unref(child
);
1452 err
= dom_node_get_next_sibling(child
, &next
);
1453 if (err
!= DOM_NO_ERR
) {
1454 dom_node_unref(child
);
1458 /* If we're moving to the next node, we can release
1459 * the reference to the current one */
1460 dom_node_unref(child
);
1469 * Determine whether or not the given node is a link
1471 * A node is a link if it is an element node whose name is "a" and if
1472 * it has an "href" attribute (case-sensitive). This selector
1473 * corresponds to node:link pseudo-class in CSS.
1475 * This pseudo-class is a bit awkward because the two standards (HTML5
1476 * and CSS) disagree on what it means, and because libsvgtiny does not
1477 * have enough information to determine if a link has been "visited"
1478 * yet -- that's a UI property. CSS says that :link is for unvisited
1479 * links, which we can't determine. HTML5 says that each link must
1480 * be either a :link or :visited. Since we can't decide either way,
1481 * It seems less wrong to declare that all links are unvisited; i.e.
1482 * that they match :link.
1484 * \param pw Pointer to the current SVG parser state
1485 * \param node Libdom SVG node to check
1486 * \param is_link Pointer to the boolean return value
1488 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1490 css_error
node_is_link(void *pw
, void *node
, bool *is_link
)
1493 dom_node
*dnode
; /* node, but with the right type */
1494 dom_string
*dnode_name
;
1496 struct svgtiny_parse_state
* state
;
1498 dnode
= (dom_node
*)node
;
1500 has_href
= false; /* assume no href attribute */
1501 *is_link
= false; /* assume that it's not a link */
1503 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1504 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1508 state
= (struct svgtiny_parse_state
*)pw
;
1509 if (dom_string_isequal(dnode_name
, state
->interned_a
)) {
1510 exc
= dom_element_has_attribute(node
,
1511 state
->interned_href
,
1513 if (exc
== DOM_NO_ERR
&& has_href
) {
1518 dom_string_unref(dnode_name
);
1523 * Check if the given node is a link that has been visited already
1525 * This check always fails because the SVG DOM does not have the
1526 * necessary information (it's a UI property).
1528 * \param pw Pointer to the current SVG parser state; unused
1529 * \param node Libdom SVG node to check; unused
1530 * \param is_visited Pointer to the boolean return value
1532 * \return Always returns CSS_OK
1534 css_error
node_is_visited(void *pw
, void *node
, bool *is_visited
)
1538 *is_visited
= false;
1544 * Check if the given node is being "hovered" over
1546 * This check always fails because the SVG DOM does not have the
1547 * necessary information (it's a UI property).
1549 * \param pw Pointer to the current SVG parser state; unused
1550 * \param node Libdom SVG node to check; unused
1551 * \param is_hover Pointer to the boolean return value
1553 * \return Always returns CSS_OK
1555 css_error
node_is_hover(void *pw
, void *node
, bool *is_hover
)
1565 * Check if the given node is "active"
1567 * This check always fails because the SVG DOM does not have the
1568 * necessary information (it's a UI property).
1570 * \param pw Pointer to the current SVG parser state; unused
1571 * \param node Libdom SVG node to check; unused
1572 * \param is_active Pointer to the boolean return value
1574 * \return Always returns CSS_OK
1576 css_error
node_is_active(void *pw
, void *node
, bool *is_active
)
1586 * Check if the given node has the focus
1588 * This check always fails because the SVG DOM does not have the
1589 * necessary information (it's a UI property).
1591 * \param pw Pointer to the current SVG parser state; unused
1592 * \param node Libdom SVG node to check; unused
1593 * \param is_focus Pointer to the boolean return value
1595 * \return Always returns CSS_OK
1597 css_error
node_is_focus(void *pw
, void *node
, bool *is_focus
)
1607 * Check if the given node is enabled
1609 * This check always fails because the SVG DOM does not have the
1610 * necessary information (it's a UI property).
1612 * \param pw Pointer to the current SVG parser state; unused
1613 * \param node Libdom SVG node to check; unused
1614 * \param is_enabled Pointer to the boolean return value
1616 * \return Always returns CSS_OK
1618 css_error
node_is_enabled(void *pw
, void *node
, bool *is_enabled
)
1622 *is_enabled
= false;
1628 * Check if the given node is disabled
1630 * This check always fails because the SVG DOM does not have the
1631 * necessary information (it's a UI property). Beware, until they are
1632 * implemented, this is NOT the logical negation of node_is_enabled!
1634 * \param pw Pointer to the current SVG parser state; unused
1635 * \param node Libdom SVG node to check; unused
1636 * \param is_disabled Pointer to the boolean return value
1638 * \return Always returns CSS_OK
1640 css_error
node_is_disabled(void *pw
, void *node
, bool *is_disabled
)
1644 *is_disabled
= false;
1650 * Test whether or not the given node is "checked"
1652 * This test always fails because the SVG DOM does not have the
1653 * necessary information (it's a UI property).
1655 * \param pw Pointer to the current SVG parser state; unused
1656 * \param node Libdom SVG node to check; unused
1657 * \param is_checked Pointer to the boolean return value
1659 * \return Always returns CSS_OK
1661 css_error
node_is_checked(void *pw
, void *node
, bool *is_checked
)
1665 *is_checked
= false;
1671 * Check if the given node is the "target" of the document URL
1673 * This test always fails because the SVG DOM does not have the
1674 * necessary information (it's a UI property).
1676 * \param pw Pointer to the current SVG parser state; unused
1677 * \param node Libdom SVG node to check; unused
1678 * \param is_target Pointer to the boolean return value
1680 * \return Always returns CSS_OK
1682 css_error
node_is_target(void *pw
, void *node
, bool *is_target
)
1692 * Check if the given node is the given language
1694 * This test is corresponds to the CSS :lang() selector and is not
1695 * fully implemented yet: it looks only for "lang" attributes on the
1696 * given element and its parents, and performs a simple substring
1697 * check. This results in a partial implementation of CSS Level 3 for
1698 * SVG 2.0. In particular, it ignores all "xml:lang" attributes in
1699 * favor of the "lang" attribute that is defined only in SVG 2.0.
1701 * \param pw Pointer to the current SVG parser state; unused
1702 * \param node Libdom SVG node to check
1703 * \param lang The language to match
1704 * \param is_lang Pointer to the boolean return value
1706 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1708 static css_error
node_is_lang(void *pw
, void *node
,
1709 lwc_string
*lang
, bool *is_lang
)
1712 /* SVG2 elements support both "lang" and "xml:lang"
1713 * attributes; earlier versions have only the XML
1714 * attribute. It would not be too hard to add support for
1715 * xml:lang" here. The main difficulty standing in the way of
1716 * a full Level 4 implementation is the complexity of the
1719 * https://www.w3.org/TR/selectors-4/#the-lang-pseudo
1724 dom_exception d_err
;
1725 dom_node
*n
; /* current node */
1726 dom_node
*p
; /* parent node */
1727 bool match
; /* retval from node_has_attribute_substring() */
1729 /* Define the attribute name "lang" that we're looking for.
1730 * We only use a css_qname here because that's what the
1731 * node_has_attribute_substring() takes; the namespace
1732 * portion of it is irrelevant. */
1736 if (lwc_intern_string("lang", 4, &attr
.name
) != lwc_error_ok
) {
1740 *is_lang
= false; /* default to no match */
1741 n
= (dom_node
*)node
;
1743 /* Loop through all parents of the given node looking for a
1744 * substring match */
1746 c_err
= _node_has_attribute_substring(pw
, (void *)n
, &attr
,
1747 lang
, &match
, true);
1748 if (c_err
!= CSS_OK
) {
1749 lwc_string_destroy(attr
.name
);
1753 /* matched this element; we're done */
1754 lwc_string_destroy(attr
.name
);
1759 /* no match on this element, try its parent */
1760 d_err
= dom_node_get_parent_node(n
, &p
);
1761 if (d_err
!= DOM_NO_ERR
) {
1762 lwc_string_destroy(attr
.name
);
1768 /* If we never find a match we may wind up here */
1769 lwc_string_destroy(attr
.name
);
1775 * User-agent defaults for CSS properties
1777 * For the moment, we provide no defaults, because libsvgtiny does not
1778 * yet support any CSS properties that might need them.
1780 * \param pw Pointer to the current SVG parser state; unused
1781 * \param property LibCSS property identifier; unused
1782 * \param hint Pointer to hint object (a return value); unused
1784 * \return Always returns CSS_INVALID
1786 css_error
ua_default_for_property(void *pw
, uint32_t property
,
1797 * Store libcss data on a node
1799 * This is part of the libcss select handler API that we need to
1800 * implement. It is essentially a thin dom_node_set_user_data()
1803 * \param pw Pointer to the current SVG parser state
1804 * \param node Libdom SVG node on which to store the data
1805 * \param libcss_node_data Pointer to the data to store
1807 * \return Always returns CSS_OK
1809 css_error
set_libcss_node_data(void *pw
, void *node
,
1810 void *libcss_node_data
)
1812 struct svgtiny_parse_state
*state
;
1815 /* A unique "userdata key" (a string) is used to identify this
1816 * data. The fourth parameter (NULL) is a "user handler
1817 * function." We will eventually have one, but for now we set
1818 * it to NULL to avoid a circular reference mess that would
1819 * break the build temporarily. */
1820 state
= (struct svgtiny_parse_state
*)pw
;
1821 dom_node_set_user_data((dom_node
*)node
,
1822 state
->interned_userdata_key
,
1827 /* dom_node_set_user_data() always returns DOM_NO_ERR */
1833 * Retrieve libcss data from a node
1835 * This is part of the libcss select handler API that we need to
1836 * implement. It is essentially a thin dom_node_get_user_data()
1839 * \param pw Pointer to the current SVG parser state
1840 * \param node Libdom SVG node from which to get the data
1841 * \param libcss_node_data Address at which to store a pointer to the data
1843 * \return Always returns CSS_OK
1845 css_error
get_libcss_node_data(void *pw
, void *node
,
1846 void **libcss_node_data
)
1848 struct svgtiny_parse_state
*state
;
1850 /* A unique "userdata key" (a string) is used to identify this
1852 state
= (struct svgtiny_parse_state
*)pw
;
1853 dom_node_get_user_data((dom_node
*)node
,
1854 state
->interned_userdata_key
,
1857 /* dom_node_get_user_data() always returns DOM_NO_ERR */