[librsvg: 2/14] Extract function to run the main cascade



commit b4558d1ef81effb52223e76436c5dff013daf77d
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Nov 11 14:28:50 2019 -0600

    Extract function to run the main cascade

 rsvg_internals/src/css.rs      | 22 ++++++++++++++++++++--
 rsvg_internals/src/document.rs | 28 ++++++++++------------------
 2 files changed, 30 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 58a9eefc..ef986830 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -88,8 +88,8 @@ use url::Url;
 use crate::allowed_url::AllowedUrl;
 use crate::error::*;
 use crate::io::{self, BinaryData};
-use crate::node::{NodeType, RsvgNode};
-use crate::properties::{parse_property, ParsedProperty};
+use crate::node::{NodeCascade, NodeType, RsvgNode};
+use crate::properties::{parse_property, ComputedValues, ParsedProperty};
 use crate::text::NodeChars;
 
 /// A parsed CSS declaration
@@ -636,3 +636,21 @@ impl Stylesheet {
         }
     }
 }
+
+/// 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() {
+        for stylesheet in stylesheets {
+            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().set_style_attribute();
+    }
+
+    let values = ComputedValues::default();
+    root.cascade(&values);
+}
diff --git a/rsvg_internals/src/document.rs b/rsvg_internals/src/document.rs
index f648b808..3921f457 100644
--- a/rsvg_internals/src/document.rs
+++ b/rsvg_internals/src/document.rs
@@ -8,12 +8,11 @@ use std::rc::Rc;
 
 use crate::allowed_url::{AllowedUrl, AllowedUrlError, Fragment};
 use crate::create_node::create_node;
-use crate::css::Stylesheet;
+use crate::css::{cascade, Stylesheet};
 use crate::error::LoadingError;
 use crate::handle::LoadOptions;
 use crate::io::{self, BinaryData};
-use crate::node::{NodeCascade, NodeData, NodeType, RsvgNode};
-use crate::properties::ComputedValues;
+use crate::node::{NodeData, NodeType, RsvgNode};
 use crate::property_bag::PropertyBag;
 use crate::structure::{IntrinsicDimensions, Svg};
 use crate::surface_utils::shared_surface::SharedImageSurface;
@@ -320,26 +319,19 @@ impl DocumentBuilder {
     }
 
     pub fn build(self) -> Result<Document, LoadingError> {
-        let DocumentBuilder { load_options, tree, ids, stylesheets, .. } = self;
+        let DocumentBuilder {
+            load_options,
+            tree,
+            ids,
+            stylesheets,
+            ..
+        } = self;
 
         match tree {
             None => Err(LoadingError::SvgHasNoElements),
             Some(mut root) => {
                 if root.borrow().get_type() == NodeType::Svg {
-                    for mut node in root.descendants() {
-                        for stylesheet in &stylesheets {
-                            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().set_style_attribute();
-                    }
-
-                    let values = ComputedValues::default();
-                    root.cascade(&values);
+                    cascade(&mut root, &stylesheets);
 
                     Ok(Document {
                         tree: root.clone(),


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