X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny_css.c;h=e2af9a41d6a6402f04d56e73286aee096ff6c775;hb=c88ec5e238bb43f3832ec3c54a6d2f5c49e6076a;hp=c7faffddef88e447fc1618805cbb450050ff955a;hpb=99489346fc8214d7c9473b89361b0c8d17b985db;p=libsvgtiny.git diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index c7faffd..e2af9a4 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -15,6 +15,8 @@ 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); /** @@ -504,3 +506,51 @@ 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; +}