[librsvg: 9/14] Copy the stylesheet's origin into the Match struct



commit c7197eb82bad98a8b8ed6643cb7e889f8ed813e2
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Nov 11 16:30:35 2019 -0600

    Copy the stylesheet's origin into the Match struct

 rsvg_internals/src/css.rs | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index ccae1c8e..b3b0e12a 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -542,6 +542,7 @@ impl selectors::Element for RsvgElement {
 /// Origin for a stylesheet, per https://www.w3.org/TR/CSS22/cascade.html#cascading-order
 ///
 /// This is used when sorting selector matches according to their origin and specificity.
+#[derive(Copy, Clone)]
 pub enum Origin {
     UserAgent,
     User,
@@ -554,6 +555,18 @@ pub struct Stylesheet {
     qualified_rules: Vec<QualifiedRule>,
 }
 
+/// A match during the selector matching process
+///
+/// This struct comes from `Stylesheet.get_matches()`, and represents
+/// that a certain node matched a CSS rule which has a selector with a
+/// certain `specificity`.  The stylesheet's `origin` is also given here
+/// to aid sorting the results.
+struct Match<'a> {
+    declaration: &'a Declaration,
+    specificity: u32,
+    origin: Origin,
+}
+
 impl Stylesheet {
     pub fn new(origin: Origin) -> Stylesheet {
         Stylesheet {
@@ -655,6 +668,7 @@ impl Stylesheet {
                         acc.push(Match {
                             declaration: decl,
                             specificity: selector.specificity(),
+                            origin: self.origin,
                         });
                     }
                 }
@@ -663,11 +677,6 @@ impl Stylesheet {
     }
 }
 
-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() {


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