]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: implement node_has_name() select handler
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 12 Oct 2023 22:10:05 +0000 (18:10 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 9 Jun 2025 01:13:06 +0000 (21:13 -0400)
src/svgtiny_css.c

index 19b7ce8247532a92aac8fbddb5a3ce035575d2b1..39340b6935d49016fe11901804a4eef3b8446f94 100644 (file)
@@ -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,49 @@ 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;
+       *match = dom_string_lwc_isequal(state->interned_universal, qname->name);
+       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;
+}