static css_error node_has_attribute_substring(void *pw, void *node,
const css_qname *qname, lwc_string *substring,
bool *match);
+static css_error node_is_root(void *pw, void *node, bool *match);
/**
return CSS_OK;
}
+
+
+/**
+ * Test whether or not the given node is the document's root element
+ * This corresponds to the CSS :root pseudo-selector.
+ *
+ * \param pw Pointer to the current SVG parser state
+ * \param node Libdom SVG node to test
+ * \param match Pointer to the test result
+ *
+ * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
+ */
+css_error node_is_root(void *pw, void *node, bool *match)
+{
+ UNUSED(pw);
+ dom_node *parent;
+ dom_node_type type;
+ dom_exception err;
+
+ err = dom_node_get_parent_node((dom_node *)node, &parent);
+ if (err != DOM_NO_ERR) {
+ return CSS_NOMEM;
+ }
+
+ /* It's the root element if it doesn't have a parent element */
+ if (parent != NULL) {
+ err = dom_node_get_node_type(parent, &type);
+ dom_node_unref(parent);
+ if (err != DOM_NO_ERR) {
+ return CSS_NOMEM;
+ }
+ if (type != DOM_DOCUMENT_NODE) {
+ /* DOM_DOCUMENT_NODE is the only allowable
+ * type of parent node for the root element */
+ *match = false;
+ return CSS_OK;
+ }
+ }
+
+ *match = true;
+ return CSS_OK;
+}