[librsvg: 3/6] css: pass in NodeData, not the full Node



commit 1b6ad3ee79747f9750902164a2068f60d0921923
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jun 29 17:09:47 2019 +0200

    css: pass in NodeData, not the full Node
    
    We just need to access element_name/class/id and those are
    avaialble in NodeData.

 rsvg_internals/src/css.rs  | 9 ++++-----
 rsvg_internals/src/node.rs | 8 ++++----
 rsvg_internals/src/xml.rs  | 2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 830a6313..7869664a 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -23,7 +23,7 @@ use crate::allowed_url::AllowedUrl;
 use crate::croco::*;
 use crate::error::*;
 use crate::io::{self, BinaryData};
-use crate::node::RsvgNode;
+use crate::node::NodeData;
 use crate::properties::{parse_attribute_value_into_parsed_property, ParsedProperty};
 use crate::util::utf8_cstr;
 
@@ -204,7 +204,7 @@ impl CssRules {
         self.selectors_to_declarations.get(selector)
     }
 
-    fn selector_matches_node(&self, selector: &Selector, node: &RsvgNode) -> bool {
+    fn selector_matches_node(&self, selector: &Selector, node_data: &NodeData) -> bool {
         // Try to properly support all of the following, including inheritance:
         // *
         // #id
@@ -215,7 +215,6 @@ impl CssRules {
         //
         // This is basically a semi-compliant CSS2 selection engine
 
-        let node_data = node.borrow();
         let element_name = node_data.element_name();
         let id = node_data.get_id();
 
@@ -280,11 +279,11 @@ impl CssRules {
         false
     }
 
-    pub fn get_matches(&self, node: &RsvgNode) -> Vec<Selector> {
+    pub fn get_matches(&self, node_data: &NodeData) -> Vec<Selector> {
         self.selectors_to_declarations
             .iter()
             .filter_map(|(selector, _)| {
-                if self.selector_matches_node(selector, node) {
+                if self.selector_matches_node(selector, node_data) {
                     Some(selector)
                 } else {
                     None
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 9f5817da..b4fa92c7 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -218,11 +218,11 @@ impl NodeData {
     }
 
     /// Applies the CSS rules that match into the node's specified_values
-    fn set_css_styles(&self, node: &RsvgNode, css_rules: &CssRules) {
+    fn set_css_styles(&self, css_rules: &CssRules) {
         let mut specified_values = self.specified_values.borrow_mut();
         let mut important_styles = self.important_styles.borrow_mut();
 
-        for selector in &css_rules.get_matches(node) {
+        for selector in &css_rules.get_matches(self) {
             if let Some(decl_list) = css_rules.get_declarations(selector) {
                 for declaration in decl_list.iter() {
                     specified_values
@@ -254,8 +254,8 @@ impl NodeData {
 
     // Sets the node's specified values from the style-related attributes in the pbag.
     // Also applies CSS rules in our limited way based on the node's tag/class/id.
-    pub fn set_style(&self, node: &RsvgNode, css_rules: &CssRules) {
-        self.set_css_styles(node, css_rules);
+    pub fn set_style(&self, css_rules: &CssRules) {
+        self.set_css_styles(css_rules);
         self.set_style_attribute();
     }
 
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 0d47e39a..53618e9c 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -535,7 +535,7 @@ fn skip_namespace(s: &str) -> &str {
 }
 
 fn set_styles_recursively(node: &RsvgNode, css_rules: &CssRules) {
-    node.borrow().set_style(node, css_rules);
+    node.borrow().set_style(css_rules);
 
     for child in node.children() {
         set_styles_recursively(&child, css_rules);


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