[librsvg: 4/14] Use matches_selector() instead of matches_selector_list() so we can get the specificity



commit 812363337cbe03d5a4acafb793e382b6de8bd0e0
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Nov 11 14:53:26 2019 -0600

    Use matches_selector() instead of matches_selector_list() so we can get the specificity

 rsvg_internals/src/css.rs | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index a3c6a2c3..a7617a5e 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -610,33 +610,44 @@ impl Stylesheet {
     }
 
     /// Appends the style declarations that match a specified node to a given vector
-    fn get_matches<'a>(&'a self, node: &RsvgNode, acc: &mut Vec<&'a Declaration>) {
+    fn get_matches<'a>(&'a self, node: &RsvgNode, acc: &mut Vec<Match<'a>>) {
         let mut match_ctx = MatchingContext::new(
             MatchingMode::Normal,
-
             // FIXME: how the fuck does one set up a bloom filter here?
             None,
-
             // n_index_cache,
             None,
-
             QuirksMode::NoQuirks,
         );
 
         for rule in &self.qualified_rules {
-            if selectors::matching::matches_selector_list(
-                &rule.selectors,
-                &RsvgElement(node.clone()),
-                &mut match_ctx,
-            ) {
-                for decl in rule.declarations.iter() {
-                    acc.push(decl);
+            for selector in &rule.selectors.0 {
+                // This magic call is stolen from selectors::matching::matches_selector_list()
+                if selectors::matching::matches_selector(
+                    selector,
+                    0,
+                    None,
+                    &RsvgElement(node.clone()),
+                    &mut match_ctx,
+                    &mut |_, _| {},
+                ) {
+                    for decl in rule.declarations.iter() {
+                        acc.push(Match {
+                            declaration: decl,
+                            specificity: selector.specificity(),
+                        });
+                    }
                 }
             }
         }
     }
 }
 
+struct Match<'a> {
+    declaration: &'a Declaration,
+    specificity: u32,
+}
+
 /// Runs the CSS cascade on the specified tree from all the stylesheets
 pub fn cascade(root: &mut RsvgNode, stylesheets: &[Stylesheet]) {
     for mut node in root.descendants() {
@@ -644,7 +655,7 @@ pub fn cascade(root: &mut RsvgNode, stylesheets: &[Stylesheet]) {
             let mut decls = Vec::new();
             stylesheet.get_matches(&node, &mut decls);
             for decl in decls {
-                node.borrow_mut().apply_style_declaration(decl);
+                node.borrow_mut().apply_style_declaration(decl.declaration);
             }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]