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_ancestor_node(void *pw
, void *node
,
12 const css_qname
*qname
, void **ancestor
);
13 static css_error
named_parent_node(void *pw
, void *node
,
14 const css_qname
*qname
, void **parent
);
15 static css_error
named_sibling_node(void *pw
, void *node
,
16 const css_qname
*qname
, void **sibling
);
17 static css_error
named_generic_sibling_node(void *pw
, void *node
,
18 const css_qname
*qname
, void **sibling
);
19 static css_error
parent_node(void *pw
, void *node
, void **parent
);
20 static css_error
sibling_node(void *pw
, void *node
, void **sibling
);
21 static css_error
node_has_name(void *pw
, void *node
,
22 const css_qname
*qname
, bool *match
);
23 static css_error
node_has_class(void *pw
, void *node
,
24 lwc_string
*name
, bool *match
);
25 static css_error
node_has_id(void *pw
, void *node
,
26 lwc_string
*name
, bool *match
);
27 static css_error
node_has_attribute(void *pw
, void *node
,
28 const css_qname
*qname
, bool *match
);
29 static css_error
node_has_attribute_equal(void *pw
, void *node
,
30 const css_qname
*qname
, lwc_string
*value
,
32 static css_error
node_has_attribute_dashmatch(void *pw
, void *node
,
33 const css_qname
*qname
, lwc_string
*value
,
35 static css_error
node_has_attribute_includes(void *pw
, void *node
,
36 const css_qname
*qname
, lwc_string
*word
,
38 static css_error
node_has_attribute_prefix(void *pw
, void *node
,
39 const css_qname
*qname
, lwc_string
*prefix
,
41 static css_error
node_has_attribute_suffix(void *pw
, void *node
,
42 const css_qname
*qname
, lwc_string
*suffix
,
44 static css_error
node_has_attribute_substring(void *pw
, void *node
,
45 const css_qname
*qname
, lwc_string
*substring
,
47 static css_error
node_is_root(void *pw
, void *node
, bool *match
);
48 static css_error
node_count_siblings(void *pw
, void *node
,
49 bool same_name
, bool after
, int32_t *count
);
50 static css_error
node_is_empty(void *pw
, void *node
, bool *is_empty
);
51 static css_error
node_is_link(void *pw
, void *node
, bool *is_link
);
52 static css_error
node_is_visited(void *pw
, void *node
, bool *is_visited
);
53 static css_error
node_is_hover(void *pw
, void *node
, bool *is_hover
);
54 static css_error
node_is_active(void *pw
, void *node
, bool *is_active
);
55 static css_error
node_is_focus(void *pw
, void *node
, bool *is_focus
);
56 static css_error
node_is_enabled(void *pw
, void *node
, bool *is_enabled
);
57 static css_error
node_is_disabled(void *pw
, void *node
, bool *is_disabled
);
58 static css_error
node_is_checked(void *pw
, void *node
, bool *is_checked
);
59 static css_error
node_is_target(void *pw
, void *node
, bool *is_target
);
60 static css_error
node_is_lang(void *pw
, void *node
,
61 lwc_string
*lang
, bool *is_lang
);
62 static css_error
node_presentational_hint(void *pw
, void *node
,
63 uint32_t *nhints
, css_hint
**hints
);
64 static css_error
ua_default_for_property(void *pw
, uint32_t property
,
66 static css_error
set_libcss_node_data(void *pw
, void *node
,
67 void *libcss_node_data
);
68 static css_error
get_libcss_node_data(void *pw
, void *node
,
69 void **libcss_node_data
);
73 * Resolve a relative URL to an absolute one by doing nothing. This is
74 * the simplest possible implementation of a URL resolver, needed for
77 css_error
svgtiny_resolve_url(void *pw
,
78 const char *base
, lwc_string
*rel
, lwc_string
**abs
)
83 /* Copy the relative URL to the absolute one (the return
85 *abs
= lwc_string_ref(rel
);
90 * Create a stylesheet with the default set of params.
92 * \param sheet A stylesheet pointer, passed in by reference, that
93 * we use to store the newly-created stylesheet.
94 * \param inline_style True if this stylesheet represents an inline
95 * style, and false otherwise.
97 * \return The return value from css_stylesheet_create() is returned.
99 css_error
svgtiny_create_stylesheet(css_stylesheet
**sheet
,
102 css_stylesheet_params params
;
104 params
.params_version
= CSS_STYLESHEET_PARAMS_VERSION_1
;
105 params
.level
= CSS_LEVEL_DEFAULT
;
106 params
.charset
= NULL
;
109 params
.allow_quirks
= false;
110 params
.inline_style
= inline_style
;
111 params
.resolve
= svgtiny_resolve_url
;
112 params
.resolve_pw
= NULL
;
113 params
.import = NULL
;
114 params
.import_pw
= NULL
;
116 params
.color_pw
= NULL
;
118 params
.font_pw
= NULL
;
120 return css_stylesheet_create(¶ms
, sheet
);
124 /**************************/
125 /* libcss select handlers */
126 /**************************/
128 * From here on we implement the "select handler "API defined in
129 * libcss's include/libcss/select.h and discussed briefly in its
135 * Retrieve the given node's name
137 * \param pw Pointer to the current SVG parser state
138 * \param node Libdom SVG node
139 * \param qname Address at which to store the node name
141 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
143 css_error
node_name(void *pw
, void *node
, css_qname
*qname
)
147 struct svgtiny_parse_state
*state
;
149 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
150 if (err
!= DOM_NO_ERR
) {
154 state
= (struct svgtiny_parse_state
*)pw
;
155 qname
->ns
= lwc_string_ref(state
->interned_svg_xmlns
);
157 err
= dom_string_intern(name
, &qname
->name
);
158 if (err
!= DOM_NO_ERR
) {
159 dom_string_unref(name
);
163 dom_string_unref(name
);
170 * Retrieve the given node's classes
172 * \param pw Pointer to the current SVG parser state
173 * \param node Libdom SVG node
174 * \param classes Address at which to store the class name array
175 * \param n_classes Address at which to store the length of the class
178 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
180 * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
181 * because the underlying libdom function never fails
183 css_error
node_classes(void *pw
, void *node
,
184 lwc_string
***classes
, uint32_t *n_classes
)
189 err
= dom_element_get_classes((dom_node
*)node
, classes
, n_classes
);
191 /* The implementation does not do it, but the documentation
192 for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
193 possible here, so we handle it to be on the safe side. */
194 if (err
!= DOM_NO_ERR
) {
203 * Retrieve the given node's id
205 * \param pw Pointer to the current SVG parser state
206 * \param node Libdom SVG node
207 * \param id Address at which to store the id
209 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
211 css_error
node_id(void *pw
, void *node
, lwc_string
**id
)
215 struct svgtiny_parse_state
*state
;
217 /* Begin with the assumption that this node has no id */
220 state
= (struct svgtiny_parse_state
*)pw
;
221 err
= dom_element_get_attribute((dom_node
*)node
,
222 state
->interned_id
, &attr
);
223 if (err
!= DOM_NO_ERR
) {
226 else if (attr
== NULL
) {
227 /* The node has no id attribute and our return value
228 is already set to NULL so we're done */
232 /* If we found an id attribute (a dom_string), intern it into
233 an lwc_string that we can return, and then cleanup the
235 err
= dom_string_intern(attr
, id
);
236 if (err
!= DOM_NO_ERR
) {
237 dom_string_unref(attr
);
240 dom_string_unref(attr
);
246 * Find the first ancestor of the given element having the given name
248 * This function thinly wraps dom_element_named_ancestor_node(), which
249 * performs exactly the search we want.
251 * \param pw Pointer to the current SVG parser state
252 * \param node Libdom SVG node whose ancestor we want
253 * \param qname Name of the ancestor node to search for
254 * \param ancestor Address at which to store the ancestor node pointer
256 * \return Always returns CSS_OK
258 * \post If a suitable element is found, a pointer to it will be
259 * stored at the address pointed to by \a ancestor; otherwise,
260 * NULL will be stored at the address pointed to by \a ancestor
262 css_error
named_ancestor_node(void *pw
, void *node
,
263 const css_qname
*qname
, void **ancestor
)
267 /* It's OK if node isn't an element, libdom checks for it. */
268 dom_element_named_ancestor_node((dom_element
*)node
,
270 (struct dom_element
**)ancestor
);
272 /* A comment in named_parent_node() explains why we unref
274 dom_node_unref(*ancestor
);
281 * Find the first parent of the given element having the given name
283 * \param pw Pointer to the current SVG parser state
284 * \param node Libdom SVG node
285 * \param qname Name of the parent node to search for
286 * \param parent Address at which to store the parent node pointer
288 * \return Always returns CSS_OK
290 * \post If a suitable element is found, a pointer to it will be
291 * stored at the address pointed to by \a parent; otherwise,
292 * NULL will be stored at the address pointed to by \a parent
294 css_error
named_parent_node(void *pw
, void *node
,
295 const css_qname
*qname
, void **parent
)
298 /* dom_element_named_parent_node() was invented to implement
299 * this select handler so there isn't much for us to do except
300 * call it. It's OK if node isn't an element, libdom checks
302 dom_element_named_parent_node((dom_element
*)node
,
304 (struct dom_element
**)parent
);
306 /* Implementation detail: dom_element_named_parent_node()
307 * increments the reference count of the parent element before
308 * returning it to us. According to docs/RefCnt in the libdom
309 * repository, this will prevent the parent element from being
310 * destroyed if it is pruned from the DOM. That sounds good,
311 * since we don't want to be using a pointer to an object that
312 * has been destroyed... but we also have no way of later
313 * decrementing the reference count ourselves, and don't want
314 * to make the returned node eternal. Decrementing the
315 * reference counter now allows it to be destroyed when the
316 * DOM no longer needs it, and so long as no other parts of
317 * libsvgtiny are messing with the DOM during parsing, that
318 * shouldn't (ha ha) cause any problems. */
319 dom_node_unref(*parent
);
326 * Find the "next-sibling" of the given element having the given name
328 * This search corresponds to the "+ foo" combinator in CSS and will
329 * find only "foo" element nodes that immediately precede the given
330 * node under the same parent in the DOM. In CSS the tree is viewed
331 * top-down and in libdom it is viewed from the bottom-up; as a result
332 * "next" and "previous" are sometimes backwards. This is case-sensitive.
334 * \param pw Pointer to the current SVG parser state
335 * \param node Libdom SVG node
336 * \param qname Name of the sibling node to search for
337 * \param sibling Address at which to store the sibling node pointer
339 * \return Always returns CSS_OK
341 * \post If a suitable element is found, a pointer to it will be
342 * stored at the address pointed to by \a sibling; otherwise,
343 * NULL will be stored at the address pointed to by \a sibling
345 css_error
named_sibling_node(void *pw
, void *node
,
346 const css_qname
*qname
, void **sibling
)
349 dom_node
*n
= node
; /* the current node */
350 dom_node
*prev
; /* the previous node */
355 *sibling
= NULL
; /* default to nothing found */
357 /* Begin the search; the first iteration we do outside of the
358 * loop. Implementation detil: dom_node_get_previous_sibling()
359 * increments the reference counter on the returned node. A
360 * comment within named_parent_node() explains why we
361 * decrement it ASAP. */
362 err
= dom_node_get_previous_sibling(n
, &n
);
363 if (err
!= DOM_NO_ERR
) {
368 /* We're looking for the first ELEMENT sibling */
369 err
= dom_node_get_node_type(n
, &type
);
370 if (err
!= DOM_NO_ERR
) {
375 if (type
== DOM_ELEMENT_NODE
) {
376 /* We found an element node, does it have the
378 err
= dom_node_get_node_name(n
, &name
);
379 if (err
!= DOM_NO_ERR
) {
384 if (dom_string_lwc_isequal(name
,
386 /* The name is right, return it */
390 /* There's only one next-sibling element node
391 * and we've already found it, so if its name
392 * wasn't right, we return the default value
394 dom_string_unref(name
);
399 /* Not an element node, so we move on the the previous
400 * previous sibling */
401 err
= dom_node_get_previous_sibling(n
, &prev
);
402 if (err
!= DOM_NO_ERR
) {
416 * Find the first "subsequent-sibling" of the given element having the
419 * This search corresponds to the "~ foo" combinator in CSS and will
420 * find only "foo" element nodes that precede the given node (under
421 * the same parent) in the DOM. In CSS the tree is viewed top-down and
422 * in libdom it is viewed from the bottom-up; as a result "next" and
423 * "previous" are sometimes backwards. This is case-sensitive.
425 * \param pw Pointer to the current SVG parser state
426 * \param node Libdom SVG node
427 * \param qname Name of the sibling node to search for
428 * \param sibling Address at which to store the sibling node pointer
430 * \return Always returns CSS_OK
432 * \post If a suitable element is found, a pointer to it will be
433 * stored at the address pointed to by \a sibling; otherwise,
434 * NULL will be stored at the address pointed to by \a sibling
436 css_error
named_generic_sibling_node(void *pw
, void *node
,
437 const css_qname
*qname
, void **sibling
)
440 dom_node
*n
= node
; /* the current node */
441 dom_node
*prev
; /* the previous node */
447 *sibling
= NULL
; /* default to nothing found */
449 /* Begin the search; the first iteration we do outside of the
450 * loop. Implementation detil: dom_node_get_previous_sibling()
451 * increments the reference counter on the returned node. A
452 * comment within named_parent_node() explains why we
453 * decrement it ASAP. */
454 err
= dom_node_get_previous_sibling(n
, &n
);
455 if (err
!= DOM_NO_ERR
) {
460 err
= dom_node_get_node_type(n
, &type
);
461 if (err
!= DOM_NO_ERR
) {
466 if (type
== DOM_ELEMENT_NODE
) {
467 /* We only want ELEMENT nodes */
468 err
= dom_node_get_node_name(n
, &name
);
469 if (err
!= DOM_NO_ERR
) {
474 if (dom_string_lwc_isequal(name
,
476 /* Found one. Save it and stop the search */
477 dom_string_unref(name
);
483 dom_string_unref(name
);
486 /* This sibling wasn't an element with the desired
487 name, so move on to the previous sibling */
488 err
= dom_node_get_previous_sibling(n
, &prev
);
489 if (err
!= DOM_NO_ERR
) {
503 * Return a pointer to the given node's parent
505 * \param pw Pointer to the current SVG parser state
506 * \param node Libdom SVG node
507 * \param parent Address at which to store the node's parent pointer
509 * \return Always returns CSS_OK
511 css_error
parent_node(void *pw
, void *node
, void **parent
)
514 /* Libdom basically implements this for us */
515 dom_element_parent_node(node
, (struct dom_element
**)parent
);
517 /* See the comment in named_parent_node() for why we decrement
518 * this reference counter here. */
519 dom_node_unref(*parent
);
526 * Find the "next-sibling" of the given element
528 * This search corresponds "+ *" in CSS and will find the first
529 * element node that immediately precedes the given node under the
530 * same parent in the DOM. In CSS the tree is viewed top-down and in
531 * libdom it is viewed from the bottom-up; as a result "next" and
532 * "previous" are sometimes backwards.
534 * \param pw Pointer to the current SVG parser state
535 * \param node Libdom SVG node
536 * \param sibling Address at which to store the sibling node pointer
538 * \return Always returns CSS_OK
540 * \post If a suitable element is found, a pointer to it will be
541 * stored at the address pointed to by \a sibling; otherwise,
542 * NULL will be stored at the address pointed to by \a sibling
544 css_error
sibling_node(void *pw
, void *node
, void **sibling
)
547 dom_node
*n
= node
; /* the current node */
548 dom_node
*prev
; /* the previous node */
552 *sibling
= NULL
; /* default to nothing found */
554 /* Begin the search; the first iteration we do outside of the
555 * loop. Implementation detil: dom_node_get_previous_sibling()
556 * increments the reference counter on the returned node. A
557 * comment within named_parent_node() explains why we
558 * decrement it ASAP. */
559 err
= dom_node_get_previous_sibling(n
, &n
);
560 if (err
!= DOM_NO_ERR
) {
565 err
= dom_node_get_node_type(n
, &type
);
566 if (err
!= DOM_NO_ERR
) {
571 if (type
== DOM_ELEMENT_NODE
) {
572 /* We found a sibling node that is also an
573 element and that's all we wanted. */
579 /* This sibling node was not an element; move on to
580 the previous sibling */
581 err
= dom_node_get_previous_sibling(n
, &prev
);
582 if (err
!= DOM_NO_ERR
) {
596 * Test the given node for the given name
598 * This will return true (via the "match" pointer) if the libdom node
599 * has the given name or if that name is the universal selector;
600 * otherwise it returns false. The comparison is case-sensitive. It
601 * corresponds to a rule like "body { ... }" in CSS.
603 * \param pw Pointer to the current SVG parser state
604 * \param node Libdom SVG node to test
605 * \param qname Name to check for
606 * \param match Pointer to the test result
608 * \return Always returns CSS_OK
610 css_error
node_has_name(void *pw
, void *node
,
611 const css_qname
*qname
, bool *match
)
613 struct svgtiny_parse_state
*state
;
617 /* Start by checking to see if qname is the universal selector */
618 state
= (struct svgtiny_parse_state
*)pw
;
619 if (lwc_string_isequal(qname
->name
,
620 state
->interned_universal
, match
) == lwc_error_ok
) {
622 /* It's the universal selector. In NetSurf, all node
623 * names match the universal selector, and nothing in
624 * the libcss documentation suggests another approach,
625 * so we follow NetSurf here. */
630 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
631 if (err
!= DOM_NO_ERR
) {
635 /* Unlike with HTML, SVG element names are case-sensitive */
636 *match
= dom_string_lwc_isequal(name
, qname
->name
);
637 dom_string_unref(name
);
644 * Test the given node for the given class
646 * This will return true (via the "match" pointer) if the libdom node
647 * has the given class. The comparison is case-sensitive. It
648 * corresponds to node.class in CSS.
650 * \param pw Pointer to the current SVG parser state
651 * \param node Libdom SVG node to test
652 * \param name Class name to check for
653 * \param match Pointer to the test result
655 * \return Always returns CSS_OK
657 css_error
node_has_class(void *pw
, void *node
,
658 lwc_string
*name
, bool *match
)
661 /* libdom implements this for us and apparently it cannot fail */
662 dom_element_has_class((dom_node
*)node
, name
, match
);
668 * Test the given node for the given id
670 * This will return true (via the "match" pointer) if the libdom node
671 * has the given id. The comparison is case-sensitive. It corresponds
674 * \param pw Pointer to the current SVG parser state
675 * \param node Libdom SVG node to test
676 * \param name Id to check for
677 * \param match Pointer to the test result
679 * \return Always returns CSS_OK
681 css_error
node_has_id(void *pw
, void *node
,
682 lwc_string
*name
, bool *match
)
686 struct svgtiny_parse_state
*state
;
688 attr
= NULL
; /* a priori the "id" attribute may not exist */
689 *match
= false; /* default to no match */
691 state
= (struct svgtiny_parse_state
*)pw
;
692 err
= dom_element_get_attribute((dom_node
*)node
,
693 state
->interned_id
, &attr
);
694 if (err
!= DOM_NO_ERR
|| attr
== NULL
) {
698 *match
= dom_string_lwc_isequal(attr
, name
);
699 dom_string_unref(attr
);
706 * Test the given node for the given attribute
708 * This will return true (via the "match" pointer) if the libdom node
709 * has an attribute with the given name. The comparison is
710 * case-sensitive. It corresponds to node[attr] in CSS.
712 * \param pw Pointer to the current SVG parser state
713 * \param node Libdom SVG node to test
714 * \param qname Attribute name to check for
715 * \param match Pointer to the test result
717 * \return Returns CSS_OK if successful and CSS_NOMEM if anything
720 css_error
node_has_attribute(void *pw
, void *node
,
721 const css_qname
*qname
, bool *match
)
727 /* intern the attribute name as a dom_string so we can
728 * delegate to dom_element_has_attribute() */
729 err
= dom_string_create_interned(
730 (const uint8_t *) lwc_string_data(qname
->name
),
731 lwc_string_length(qname
->name
),
733 if (err
!= DOM_NO_ERR
) {
737 err
= dom_element_has_attribute((dom_node
*)node
, name
, match
);
738 if (err
!= DOM_NO_ERR
) {
739 dom_string_unref(name
);
743 dom_string_unref(name
);
749 * Test the given node for an attribute with a specific value
751 * This will return true (via the "match" pointer) if the libdom node
752 * has an attribute with the given name and value. The comparison is
753 * case-sensitive. It corresponds to node[attr=value] in CSS.
755 * \param pw Pointer to the current SVG parser state
756 * \param node Libdom SVG node to test
757 * \param qname Attribute name to check for
758 * \param value Attribute value to check for
759 * \param match Pointer to the test result
761 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
762 * intern the attribute name (which usually indicates memory
765 css_error
node_has_attribute_equal(void *pw
, void *node
,
766 const css_qname
*qname
, lwc_string
*value
,
769 /* Implementation note: NetSurf always returns "no match" when
770 * the value is empty (length zero). We allow it, because why
775 dom_string
*attr_val
;
778 /* Intern the attribute name as a dom_string so we can
779 * use dom_element_get_attribute() */
780 err
= dom_string_create_interned(
781 (const uint8_t *) lwc_string_data(qname
->name
),
782 lwc_string_length(qname
->name
),
784 if (err
!= DOM_NO_ERR
) {
788 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
789 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
790 /* There was an error getting the attribute's value or
791 * the attribute doesn't exist. So, no match? */
792 dom_string_unref(name
);
797 /* Otherwise, we have the attribute value from the given node
798 * and all we need to do is compare. */
799 dom_string_unref(name
);
800 *match
= dom_string_lwc_isequal(attr_val
, value
);
801 dom_string_unref(attr_val
);
808 * Test the given node for an attribute with a specific value,
809 * possibly followed by a single hyphen
811 * This will return true (via the "match" pointer) if the libdom node
812 * has an attribute with the given name and value or with the given
813 * name and a value that is followed by exactly one hyphen. The
814 * comparison is case-sensitive. This corresponds to [attr|=value]
817 * \param pw Pointer to the current SVG parser state
818 * \param node Libdom SVG node to test
819 * \param qname Attribute name to check for
820 * \param value Attribute value to check for
821 * \param match Pointer to the test result
823 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
824 * intern the attribute name (which usually indicates memory
827 css_error
node_has_attribute_dashmatch(void *pw
, void *node
,
828 const css_qname
*qname
, lwc_string
*value
,
831 /* Implementation note: NetSurf always returns "no match" when
832 * the value is empty (length zero). We allow it, because why
837 dom_string
*attr_val
;
840 const char *vdata
; /* to hold the data underlying "value" */
842 const char *avdata
; /* to hold the found attribute value data */
845 /* Intern the attribute name as a dom_string so we can
846 * use dom_element_get_attribute() */
847 err
= dom_string_create_interned(
848 (const uint8_t *) lwc_string_data(qname
->name
),
849 lwc_string_length(qname
->name
),
851 if (err
!= DOM_NO_ERR
) {
855 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
856 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
857 /* There was an error getting the attribute's value or
858 * the attribute doesn't exist. So, no match? */
859 dom_string_unref(name
);
864 /* Otherwise, we have the attribute value from the given node
865 * and all we need to do is compare. */
866 dom_string_unref(name
);
867 *match
= dom_string_lwc_isequal(attr_val
, value
);
869 /* Exact match, we're done */
870 dom_string_unref(attr_val
);
874 /* No exact match, try it with a hyphen on the end */
875 vdata
= lwc_string_data(value
); /* needle */
876 vdata_len
= lwc_string_length(value
);
877 avdata
= dom_string_data(attr_val
); /* haystack */
878 avdata_len
= dom_string_byte_length(attr_val
);
879 dom_string_unref(attr_val
);
881 if (avdata_len
> vdata_len
&& avdata
[vdata_len
] == '-') {
882 if (strncasecmp(avdata
, vdata
, vdata_len
) == 0) {
883 /* If there's a hyphen in the right position,
884 * it suffices to compare the strings only up
895 * Test the given node for an attribute whose value is a
896 * space-separated list of words, one of which is the given word
898 * This will return true (via the "match" pointer) if the libdom node
899 * has an attribute with the given name and whose value when
900 * considered as a space-separated list of words contains the given
901 * word. The comparison is case-sensitive. This corresponds to
902 * [attr~=value] in CSS.
904 * \param pw Pointer to the current SVG parser state
905 * \param node Libdom SVG node to test
906 * \param qname Attribute name to check for
907 * \param word Value word to check for
908 * \param match Pointer to the test result
910 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
911 * intern the attribute name (which usually indicates memory
914 css_error
node_has_attribute_includes(void *pw
, void *node
,
915 const css_qname
*qname
, lwc_string
*word
,
921 dom_string
*attr_val
;
923 size_t wordlen
; /* length of "word" */
925 /* pointers used to parse a space-separated list of words */
930 *match
= false; /* default to no match */
932 wordlen
= lwc_string_length(word
);
934 /* In this case, the spec says that "if 'val' is the
935 * empty string, it will never represent anything." */
939 /* Intern the attribute name as a dom_string so we can
940 * use dom_element_get_attribute() */
941 err
= dom_string_create_interned(
942 (const uint8_t *) lwc_string_data(qname
->name
),
943 lwc_string_length(qname
->name
),
945 if (err
!= DOM_NO_ERR
) {
949 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
950 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
951 /* There was an error getting the attribute's value or
952 * the attribute doesn't exist. So, no match? */
953 dom_string_unref(name
);
957 /* Parse the list comparing each word against "word" */
958 start
= dom_string_data(attr_val
);
959 end
= start
+ dom_string_byte_length(attr_val
);
960 dom_string_unref(attr_val
);
962 for (p
= start
; p
<= end
; p
++) {
963 /* Move forward until we find the end of the first word */
964 if (*p
== ' ' || *p
== '\0') {
965 /* If the length of that word is the length of the
966 * word we're looking for, do the comparison. */
967 if ((size_t) (p
- start
) == wordlen
&&
969 lwc_string_data(word
),
974 /* No match? Set "start" to the beginning of
975 * the next word and loop. */
985 * Test the given node for an attribute whose value begins with the
988 * This will return true (via the "match" pointer) if the libdom node
989 * has an attribute with the given name and whose value begins with
990 * the given prefix string. The comparison is case-sensitive. This
991 * corresponds to [attr^=value] in CSS.
993 * \param pw Pointer to the current SVG parser state
994 * \param node Libdom SVG node to test
995 * \param qname Attribute name to check for
996 * \param prefix Value prefix to check for
997 * \param match Pointer to the test result
999 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1000 * intern the attribute name (which usually indicates memory
1003 css_error
node_has_attribute_prefix(void *pw
, void *node
,
1004 const css_qname
*qname
, lwc_string
*prefix
,
1009 dom_string
*attr_val
;
1011 const char *avdata
; /* attribute value data */
1012 size_t avdata_len
; /* length of that attribute value data */
1013 size_t prefixlen
; /* length of "prefix" */
1015 prefixlen
= lwc_string_length(prefix
);
1016 if (prefixlen
== 0) {
1017 /* In this case, the spec says that "if 'val' is the
1018 * empty string, it will never represent anything." */
1022 /* Intern the attribute name as a dom_string so we can
1023 * use dom_element_get_attribute() */
1024 err
= dom_string_create_interned(
1025 (const uint8_t *) lwc_string_data(qname
->name
),
1026 lwc_string_length(qname
->name
),
1028 if (err
!= DOM_NO_ERR
) {
1032 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1033 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1034 /* There was an error getting the attribute's value or
1035 * the attribute doesn't exist. So, no match? */
1036 dom_string_unref(name
);
1041 /* Otherwise, we have the attribute value from the given node,
1042 * and the first thing we want to do is check to see if the
1043 * whole thing matches the prefix. */
1044 dom_string_unref(name
);
1045 *match
= dom_string_lwc_isequal(attr_val
, prefix
);
1047 /* If not, check to see if an, uh, prefix matches the
1049 if (*match
== false) {
1050 avdata
= dom_string_data(attr_val
);
1051 avdata_len
= dom_string_byte_length(attr_val
);
1052 if ((avdata_len
>= prefixlen
) &&
1053 (strncasecmp(avdata
,
1054 lwc_string_data(prefix
),
1056 /* Use strncasecmp to compare only the first
1057 * "n" characters, where "n" is the length of
1063 dom_string_unref(attr_val
);
1070 * Test the given node for an attribute whose value end with the
1073 * This will return true (via the "match" pointer) if the libdom node
1074 * has an attribute with the given name and whose value ends with
1075 * the given suffix string. The comparison is case-sensitive. This
1076 * corresponds to [attr$=value] in CSS.
1078 * \param pw Pointer to the current SVG parser state
1079 * \param node Libdom SVG node to test
1080 * \param qname Attribute name to check for
1081 * \param suffix Value suffix to check for
1082 * \param match Pointer to the test result
1084 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1085 * intern the attribute name (which usually indicates memory
1088 css_error
node_has_attribute_suffix(void *pw
, void *node
,
1089 const css_qname
*qname
, lwc_string
*suffix
,
1094 dom_string
*attr_val
;
1096 const char *avdata
; /* attribute value data */
1097 size_t avdata_len
; /* length of that attribute value data */
1098 size_t suffixlen
; /* length of "suffix" */
1100 /* convenience pointer we'll use when matching the suffix */
1101 const char *suffix_start
;
1103 suffixlen
= lwc_string_length(suffix
);
1104 if (suffixlen
== 0) {
1105 /* In this case, the spec says that "if 'val' is the
1106 * empty string, it will never represent anything." */
1110 /* Intern the attribute name as a dom_string so we can
1111 * use dom_element_get_attribute() */
1112 err
= dom_string_create_interned(
1113 (const uint8_t *) lwc_string_data(qname
->name
),
1114 lwc_string_length(qname
->name
),
1116 if (err
!= DOM_NO_ERR
) {
1120 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1121 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1122 /* There was an error getting the attribute's value or
1123 * the attribute doesn't exist. So, no match? */
1124 dom_string_unref(name
);
1129 /* Otherwise, we have the attribute value from the given node,
1130 * and the first thing we want to do is check to see if the
1131 * whole thing matches the suffix. */
1132 dom_string_unref(name
);
1133 *match
= dom_string_lwc_isequal(attr_val
, suffix
);
1135 /* If not, check to see if an, uh, suffix matches the
1137 if (*match
== false) {
1138 avdata
= dom_string_data(attr_val
);
1139 avdata_len
= dom_string_byte_length(attr_val
);
1141 suffix_start
= (char *)(avdata
+ avdata_len
- suffixlen
);
1143 if ((avdata_len
>= suffixlen
) &&
1144 (strncasecmp(suffix_start
,
1145 lwc_string_data(suffix
),
1147 /* Use strncasecmp to compare only the last
1148 * "n" characters, where "n" is the length of
1154 dom_string_unref(attr_val
);
1161 * Implement node_has_attribute_substring() with optional case-
1162 * insensitivity. This corresponds to [attr*=value i] in CSS and is
1163 * not supported by libcss yet, but it allows us to factor out some
1166 static css_error
_node_has_attribute_substring(void *pw
, void *node
,
1167 const css_qname
*qname
, lwc_string
*substring
,
1168 bool *match
, bool insensitive
)
1172 dom_string
*attr_val
;
1174 size_t attr_len
; /* length of attr_val */
1175 size_t substrlen
; /* length of "substring" */
1177 /* Convenience pointers we use when comparing substrings */
1181 substrlen
= lwc_string_length(substring
);
1182 if (substrlen
== 0) {
1183 /* In this case, the spec says that "if 'val' is the
1184 * empty string, it will never represent anything." */
1188 /* Intern the attribute name as a dom_string so we can
1189 * use dom_element_get_attribute() */
1190 err
= dom_string_create_interned(
1191 (const uint8_t *) lwc_string_data(qname
->name
),
1192 lwc_string_length(qname
->name
),
1194 if (err
!= DOM_NO_ERR
) {
1198 err
= dom_element_get_attribute((dom_node
*)node
, name
, &attr_val
);
1199 if ((err
!= DOM_NO_ERR
) || (attr_val
== NULL
)) {
1200 /* There was an error getting the attribute's value or
1201 * the attribute doesn't exist. So, no match? */
1202 dom_string_unref(name
);
1207 /* Otherwise, we have the attribute value from the given node,
1208 * and the first thing we want to do is check to see if the
1209 * whole thing matches the substring. */
1210 dom_string_unref(name
);
1213 *match
= dom_string_caseless_lwc_isequal(attr_val
, substring
);
1216 *match
= dom_string_lwc_isequal(attr_val
, substring
);
1219 /* If not, check to see if an, uh, substring matches the
1221 if (*match
== false) {
1222 p
= dom_string_data(attr_val
);
1224 /* Check every long-enough suffix for a prefix match */
1225 attr_len
= dom_string_byte_length(attr_val
);
1226 if (attr_len
>= substrlen
) {
1227 p_max
= p
+ attr_len
- substrlen
;
1228 while (p
<= p_max
) {
1230 lwc_string_data(substring
),
1240 dom_string_unref(attr_val
);
1246 * Test the given node for an attribute whose value contains the
1249 * This will return true (via the "match" pointer) if the libdom node
1250 * has an attribute with the given name and whose value contains the
1251 * given substring. The comparison is case-sensitive. This corresponds
1252 * to [attr*=value] in CSS.
1254 * \param pw Pointer to the current SVG parser state
1255 * \param node Libdom SVG node to test
1256 * \param qname Attribute name to check for
1257 * \param substring Value substring to check for
1258 * \param match Pointer to the test result
1260 * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot
1261 * intern the attribute name (which usually indicates memory
1264 css_error
node_has_attribute_substring(void *pw
, void *node
,
1265 const css_qname
*qname
, lwc_string
*substring
,
1268 return _node_has_attribute_substring(pw
, node
, qname
, substring
,
1274 * Test whether or not the given node is the document's root element
1275 * This corresponds to the CSS :root pseudo-selector.
1277 * \param pw Pointer to the current SVG parser state
1278 * \param node Libdom SVG node to test
1279 * \param match Pointer to the test result
1281 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1283 css_error
node_is_root(void *pw
, void *node
, bool *match
)
1290 err
= dom_node_get_parent_node((dom_node
*)node
, &parent
);
1291 if (err
!= DOM_NO_ERR
) {
1295 /* It's the root element if it doesn't have a parent element */
1296 if (parent
!= NULL
) {
1297 err
= dom_node_get_node_type(parent
, &type
);
1298 dom_node_unref(parent
);
1299 if (err
!= DOM_NO_ERR
) {
1302 if (type
!= DOM_DOCUMENT_NODE
) {
1303 /* DOM_DOCUMENT_NODE is the only allowable
1304 * type of parent node for the root element */
1316 * Used internally in node_count_siblings() to "count" the given
1317 * sibling node. It factors out the node type and name checks.
1319 static int node_count_siblings_check(dom_node
*dnode
,
1326 dom_string
*dnode_name
;
1328 /* We flip this to 1 if/when we count this node */
1331 if (dnode
== NULL
) {
1335 exc
= dom_node_get_node_type(dnode
, &type
);
1336 if ((exc
!= DOM_NO_ERR
) || (type
!= DOM_ELEMENT_NODE
)) {
1337 /* We only count element siblings */
1341 /* ... with the right name */
1344 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1346 if ((exc
== DOM_NO_ERR
) && (dnode_name
!= NULL
)) {
1347 if (dom_string_isequal(name
,
1351 dom_string_unref(dnode_name
);
1362 * Count the given node's sibling elements
1364 * This counts the given node's sibling elements in one direction,
1365 * either forwards or backwards, in the DOM. Keep in mind that the
1366 * libdom tree is upside-down compared to the CSS one; so "next" and
1367 * "previous" are actually reversed; the default is to count preceding
1368 * libdom siblings which correspond to subsequent CSS siblings.
1370 * This operation is central to the CSS :first-child, :nth-child, and
1371 * :last-child (et cetera) pseudo-selectors.
1373 * If same_name is true, then only nodes having the same
1374 * (case-sensitive) name as the given node are counted.
1376 * \param pw Pointer to the current SVG parser state
1377 * \param node Libdom SVG node whose siblings we're counting
1378 * \param same_name Whether or not to count only siblings having
1379 * the same name as the given node
1380 * \param after Count subsequent siblings rather than precedent
1381 * ones (the default)
1382 * \param count Pointer to the return value, the number of sibling
1385 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1387 css_error
node_count_siblings(void *pw
, void *node
,
1388 bool same_name
, bool after
, int32_t *count
)
1392 dom_node
*dnode
; /* node, but with the right type */
1393 dom_string
*dnode_name
;
1394 dom_node
*next
; /* "next" sibling (depends on direction) */
1396 /* Pointer to the "next sibling" function */
1397 dom_exception (*next_func
)(dom_node
*, dom_node
**);
1402 dnode
= (dom_node
*)node
;
1404 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1405 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1410 /* Increment the reference counter for dnode for as long as
1411 * we retain a reference to it. */
1412 dnode
= dom_node_ref(dnode
);
1414 next_func
= dom_node_get_previous_sibling
;
1416 next_func
= dom_node_get_next_sibling
;
1420 exc
= next_func(dnode
, &next
);
1421 if (exc
!= DOM_NO_ERR
) {
1425 /* If next_func worked, we're about to swap "next"
1426 * with "dnode" meaning that we will no longer retain
1427 * a reference to the current dnode. */
1428 dom_node_unref(dnode
);
1431 *count
+= node_count_siblings_check(dnode
,
1434 } while (dnode
!= NULL
);
1436 if (dnode_name
!= NULL
) {
1437 dom_string_unref(dnode_name
);
1445 * Determine whether or not the given element is empty
1447 * An element is "nonempty" if it has a child that is either an
1448 * element node or a text node.
1450 * \param pw Pointer to the current SVG parser state
1451 * \param node Libdom SVG node to check for emptiness
1452 * \param is_empty Pointer to the return value
1454 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1456 css_error
node_is_empty(void *pw
, void *node
, bool *is_empty
)
1459 dom_node
*child
; /* current child node pointer */
1460 dom_node
*next
; /* next child node pointer */
1461 dom_node_type type
; /* what type of node is "child" */
1464 /* Assume that it's empty by default */
1467 /* Get the given node's first child. Implementation detail:
1468 * this increments the reference counter on the child node. */
1469 err
= dom_node_get_first_child((dom_node
*)node
, &child
);
1470 if (err
!= DOM_NO_ERR
) {
1474 /* And now loop through all children looking for a
1475 * text/element node. If we find one, the original
1476 * node is "nonempty" */
1477 while (child
!= NULL
) {
1478 err
= dom_node_get_node_type(child
, &type
);
1479 if (err
!= DOM_NO_ERR
) {
1480 dom_node_unref(child
);
1484 if (type
== DOM_ELEMENT_NODE
|| type
== DOM_TEXT_NODE
) {
1486 dom_node_unref(child
);
1490 err
= dom_node_get_next_sibling(child
, &next
);
1491 if (err
!= DOM_NO_ERR
) {
1492 dom_node_unref(child
);
1496 /* If we're moving to the next node, we can release
1497 * the reference to the current one */
1498 dom_node_unref(child
);
1507 * Determine whether or not the given node is a link
1509 * A node is a link if it is an element node whose name is "a" and if
1510 * it has an "href" attribute (case-sensitive). This selector
1511 * corresponds to node:link pseudo-class in CSS.
1513 * This pseudo-class is a bit awkward because the two standards (HTML5
1514 * and CSS) disagree on what it means, and because libsvgtiny does not
1515 * have enough information to determine if a link has been "visited"
1516 * yet -- that's a UI property. CSS says that :link is for unvisited
1517 * links, which we can't determine. HTML5 says that each link must
1518 * be either a :link or :visited. Since we can't decide either way,
1519 * It seems less wrong to declare that all links are unvisited; i.e.
1520 * that they match :link.
1522 * \param pw Pointer to the current SVG parser state
1523 * \param node Libdom SVG node to check
1524 * \param is_link Pointer to the boolean return value
1526 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1528 css_error
node_is_link(void *pw
, void *node
, bool *is_link
)
1531 dom_node
*dnode
; /* node, but with the right type */
1532 dom_string
*dnode_name
;
1534 struct svgtiny_parse_state
* state
;
1536 dnode
= (dom_node
*)node
;
1538 has_href
= false; /* assume no href attribute */
1539 *is_link
= false; /* assume that it's not a link */
1541 exc
= dom_node_get_node_name(dnode
, &dnode_name
);
1542 if ((exc
!= DOM_NO_ERR
) || (dnode_name
== NULL
)) {
1546 state
= (struct svgtiny_parse_state
*)pw
;
1547 if (dom_string_isequal(dnode_name
, state
->interned_a
)) {
1548 exc
= dom_element_has_attribute(node
,
1549 state
->interned_href
,
1551 if (exc
== DOM_NO_ERR
&& has_href
) {
1556 dom_string_unref(dnode_name
);
1561 * Check if the given node is a link that has been visited already
1563 * This check always fails because the SVG DOM does not have the
1564 * necessary information (it's a UI property).
1566 * \param pw Pointer to the current SVG parser state; unused
1567 * \param node Libdom SVG node to check; unused
1568 * \param is_visited Pointer to the boolean return value
1570 * \return Always returns CSS_OK
1572 css_error
node_is_visited(void *pw
, void *node
, bool *is_visited
)
1576 *is_visited
= false;
1582 * Check if the given node is being "hovered" over
1584 * This check always fails because the SVG DOM does not have the
1585 * necessary information (it's a UI property).
1587 * \param pw Pointer to the current SVG parser state; unused
1588 * \param node Libdom SVG node to check; unused
1589 * \param is_hover Pointer to the boolean return value
1591 * \return Always returns CSS_OK
1593 css_error
node_is_hover(void *pw
, void *node
, bool *is_hover
)
1603 * Check if the given node is "active"
1605 * This check always fails because the SVG DOM does not have the
1606 * necessary information (it's a UI property).
1608 * \param pw Pointer to the current SVG parser state; unused
1609 * \param node Libdom SVG node to check; unused
1610 * \param is_active Pointer to the boolean return value
1612 * \return Always returns CSS_OK
1614 css_error
node_is_active(void *pw
, void *node
, bool *is_active
)
1624 * Check if the given node has the focus
1626 * This check always fails because the SVG DOM does not have the
1627 * necessary information (it's a UI property).
1629 * \param pw Pointer to the current SVG parser state; unused
1630 * \param node Libdom SVG node to check; unused
1631 * \param is_focus Pointer to the boolean return value
1633 * \return Always returns CSS_OK
1635 css_error
node_is_focus(void *pw
, void *node
, bool *is_focus
)
1645 * Check if the given node is enabled
1647 * This check always fails because the SVG DOM does not have the
1648 * necessary information (it's a UI property).
1650 * \param pw Pointer to the current SVG parser state; unused
1651 * \param node Libdom SVG node to check; unused
1652 * \param is_enabled Pointer to the boolean return value
1654 * \return Always returns CSS_OK
1656 css_error
node_is_enabled(void *pw
, void *node
, bool *is_enabled
)
1660 *is_enabled
= false;
1666 * Check if the given node is disabled
1668 * This check always fails because the SVG DOM does not have the
1669 * necessary information (it's a UI property). Beware, until they are
1670 * implemented, this is NOT the logical negation of node_is_enabled!
1672 * \param pw Pointer to the current SVG parser state; unused
1673 * \param node Libdom SVG node to check; unused
1674 * \param is_disabled Pointer to the boolean return value
1676 * \return Always returns CSS_OK
1678 css_error
node_is_disabled(void *pw
, void *node
, bool *is_disabled
)
1682 *is_disabled
= false;
1688 * Test whether or not the given node is "checked"
1690 * This test always fails because the SVG DOM does not have the
1691 * necessary information (it's a UI property).
1693 * \param pw Pointer to the current SVG parser state; unused
1694 * \param node Libdom SVG node to check; unused
1695 * \param is_checked Pointer to the boolean return value
1697 * \return Always returns CSS_OK
1699 css_error
node_is_checked(void *pw
, void *node
, bool *is_checked
)
1703 *is_checked
= false;
1709 * Check if the given node is the "target" of the document URL
1711 * This test always fails because the SVG DOM does not have the
1712 * necessary information (it's a UI property).
1714 * \param pw Pointer to the current SVG parser state; unused
1715 * \param node Libdom SVG node to check; unused
1716 * \param is_target Pointer to the boolean return value
1718 * \return Always returns CSS_OK
1720 css_error
node_is_target(void *pw
, void *node
, bool *is_target
)
1730 * Check if the given node is the given language
1732 * This test is corresponds to the CSS :lang() selector and is not
1733 * fully implemented yet: it looks only for "lang" attributes on the
1734 * given element and its parents, and performs a simple substring
1735 * check. This results in a partial implementation of CSS Level 3 for
1736 * SVG 2.0. In particular, it ignores all "xml:lang" attributes in
1737 * favor of the "lang" attribute that is defined only in SVG 2.0.
1739 * \param pw Pointer to the current SVG parser state; unused
1740 * \param node Libdom SVG node to check
1741 * \param lang The language to match
1742 * \param is_lang Pointer to the boolean return value
1744 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
1746 static css_error
node_is_lang(void *pw
, void *node
,
1747 lwc_string
*lang
, bool *is_lang
)
1750 /* SVG2 elements support both "lang" and "xml:lang"
1751 * attributes; earlier versions have only the XML
1752 * attribute. It would not be too hard to add support for
1753 * xml:lang" here. The main difficulty standing in the way of
1754 * a full Level 4 implementation is the complexity of the
1757 * https://www.w3.org/TR/selectors-4/#the-lang-pseudo
1762 dom_exception d_err
;
1763 dom_node
*n
; /* current node */
1764 dom_node
*p
; /* parent node */
1765 bool match
; /* retval from node_has_attribute_substring() */
1767 /* Define the attribute name "lang" that we're looking for.
1768 * We only use a css_qname here because that's what the
1769 * node_has_attribute_substring() takes; the namespace
1770 * portion of it is irrelevant. */
1774 if (lwc_intern_string("lang", 4, &attr
.name
) != lwc_error_ok
) {
1778 *is_lang
= false; /* default to no match */
1779 n
= (dom_node
*)node
;
1781 /* Loop through all parents of the given node looking for a
1782 * substring match */
1784 c_err
= _node_has_attribute_substring(pw
, (void *)n
, &attr
,
1785 lang
, &match
, true);
1786 if (c_err
!= CSS_OK
) {
1787 lwc_string_destroy(attr
.name
);
1791 /* matched this element; we're done */
1792 lwc_string_destroy(attr
.name
);
1797 /* no match on this element, try its parent */
1798 d_err
= dom_node_get_parent_node(n
, &p
);
1799 if (d_err
!= DOM_NO_ERR
) {
1800 lwc_string_destroy(attr
.name
);
1806 /* If we never find a match we may wind up here */
1807 lwc_string_destroy(attr
.name
);
1813 * Return presentational hints for the given node
1815 * Unless an SVG is being rendered from within an HTML document,
1816 * there are no presentational hints. We always return an empty
1819 * \param pw Pointer to the current SVG parser state; unused
1820 * \param node Libdom SVG node whose hints we want; unused
1821 * \param nhints How many hints are returned (return by reference)
1822 * \param hints Array of css_hint structures (return by reference)
1824 * \return Always returns CSS_OK
1826 css_error
node_presentational_hint(void *pw
, void *node
,
1827 uint32_t *nhints
, css_hint
**hints
)
1838 * User-agent defaults for CSS properties
1840 * For the moment, we provide no defaults, because libsvgtiny does not
1841 * yet support any CSS properties that might need them.
1843 * \param pw Pointer to the current SVG parser state; unused
1844 * \param property LibCSS property identifier; unused
1845 * \param hint Pointer to hint object (a return value); unused
1847 * \return Always returns CSS_INVALID
1849 css_error
ua_default_for_property(void *pw
, uint32_t property
,
1860 * Store libcss data on 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_set_user_data()
1866 * \param pw Pointer to the current SVG parser state
1867 * \param node Libdom SVG node on which to store the data
1868 * \param libcss_node_data Pointer to the data to store
1870 * \return Always returns CSS_OK
1872 css_error
set_libcss_node_data(void *pw
, void *node
,
1873 void *libcss_node_data
)
1875 struct svgtiny_parse_state
*state
;
1878 /* A unique "userdata key" (a string) is used to identify this
1879 * data. The fourth parameter (NULL) is a "user handler
1880 * function." We will eventually have one, but for now we set
1881 * it to NULL to avoid a circular reference mess that would
1882 * break the build temporarily. */
1883 state
= (struct svgtiny_parse_state
*)pw
;
1884 dom_node_set_user_data((dom_node
*)node
,
1885 state
->interned_userdata_key
,
1890 /* dom_node_set_user_data() always returns DOM_NO_ERR */
1896 * Retrieve libcss data from a node
1898 * This is part of the libcss select handler API that we need to
1899 * implement. It is essentially a thin dom_node_get_user_data()
1902 * \param pw Pointer to the current SVG parser state
1903 * \param node Libdom SVG node from which to get the data
1904 * \param libcss_node_data Address at which to store a pointer to the data
1906 * \return Always returns CSS_OK
1908 css_error
get_libcss_node_data(void *pw
, void *node
,
1909 void **libcss_node_data
)
1911 struct svgtiny_parse_state
*state
;
1913 /* A unique "userdata key" (a string) is used to identify this
1915 state
= (struct svgtiny_parse_state
*)pw
;
1916 dom_node_get_user_data((dom_node
*)node
,
1917 state
->interned_userdata_key
,
1920 /* dom_node_get_user_data() always returns DOM_NO_ERR */