X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny_css.c;h=6d345a753dacf4764cb3353ce983a1a8e651241c;hb=49fb0b4d04ca7e1bfb54a1021e469ed7ef7bf3f5;hp=c7faffddef88e447fc1618805cbb450050ff955a;hpb=99489346fc8214d7c9473b89361b0c8d17b985db;p=libsvgtiny.git diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index c7faffd..6d345a7 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -15,6 +15,10 @@ static css_error named_generic_sibling_node(void *pw, void *node, const css_qname *qname, void **sibling); static css_error parent_node(void *pw, void *node, void **parent); static css_error sibling_node(void *pw, void *node, void **sibling); +static css_error node_has_name(void *pw, void *node, + const css_qname *qname, bool *match); +static css_error node_has_class(void *pw, void *node, + lwc_string *name, bool *match); /** @@ -504,3 +508,75 @@ css_error sibling_node(void *pw, void *node, void **sibling) return CSS_OK; } + + +/** + * Test the given node for the given name + * + * This will return true (via the "match" pointer) if the libdom node + * has the given name or if that name is the universal selector; + * otherwise it returns false. The comparison is case-sensitive. It + * corresponds to a rule like "body { ... }" in CSS. + * + * \param pw Pointer to the current SVG parser state + * \param node Libdom SVG node to test + * \param qname Name to check for + * \param match Pointer to the test result + * + * \return Always returns CSS_OK + */ +css_error node_has_name(void *pw, void *node, + const css_qname *qname, bool *match) +{ + struct svgtiny_parse_state *state; + dom_string *name; + dom_exception err; + + /* Start by checking to see if qname is the universal selector */ + state = (struct svgtiny_parse_state *)pw; + if (lwc_string_isequal(qname->name, + state->interned_universal, match) == lwc_error_ok) { + if (*match) { + /* It's the universal selector. In NetSurf, all node + * names match the universal selector, and nothing in + * the libcss documentation suggests another approach, + * so we follow NetSurf here. */ + return CSS_OK; + } + } + + err = dom_node_get_node_name((dom_node *)node, &name); + if (err != DOM_NO_ERR) { + return CSS_OK; + } + + /* Unlike with HTML, SVG element names are case-sensitive */ + *match = dom_string_lwc_isequal(name, qname->name); + dom_string_unref(name); + + return CSS_OK; +} + + +/** + * Test the given node for the given class + * + * This will return true (via the "match" pointer) if the libdom node + * has the given class. The comparison is case-sensitive. It + * corresponds to node.class in CSS. + * + * \param pw Pointer to the current SVG parser state + * \param node Libdom SVG node to test + * \param name Class name to check for + * \param match Pointer to the test result + * + * \return Always returns CSS_OK + */ +css_error node_has_class(void *pw, void *node, + lwc_string *name, bool *match) +{ + UNUSED(pw); + /* libdom implements this for us and apparently it cannot fail */ + dom_element_has_class((dom_node *)node, name, match); + return CSS_OK; +}