[librsvg: 34/45] Pass a Session to the cascading machinery




commit 03fa7caa2772abc84b979ede060b0c1efaae5632
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 23 17:41:05 2022 -0500

    Pass a Session to the cascading machinery
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/731>

 src/css.rs        |  3 ++-
 src/document.rs   | 14 ++++++++++----
 src/element.rs    |  7 ++++---
 src/handle.rs     |  2 +-
 src/properties.rs | 17 +++++++++++------
 5 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/src/css.rs b/src/css.rs
index 2f646674e..5d5d0abd5 100644
--- a/src/css.rs
+++ b/src/css.rs
@@ -941,6 +941,7 @@ pub fn cascade(
     ua_stylesheets: &[Stylesheet],
     author_stylesheets: &[Stylesheet],
     user_stylesheets: &[Stylesheet],
+    session: &Session,
 ) {
     for mut node in root.descendants().filter(|n| n.is_element()) {
         let mut matches = Vec::new();
@@ -975,7 +976,7 @@ pub fn cascade(
                 .apply_style_declaration(m.declaration, m.origin);
         }
 
-        node.borrow_element_mut().set_style_attribute();
+        node.borrow_element_mut().set_style_attribute(session);
     }
 
     let values = ComputedValues::default();
diff --git a/src/document.rs b/src/document.rs
index 0af3d9e5c..21252e407 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -166,8 +166,14 @@ impl Document {
     ///
     /// This uses the default UserAgent stylesheet, the document's internal stylesheets,
     /// plus an extra set of stylesheets supplied by the caller.
-    pub fn cascade(&mut self, extra: &[Stylesheet]) {
-        css::cascade(&mut self.tree, &UA_STYLESHEETS, &self.stylesheets, extra);
+    pub fn cascade(&mut self, extra: &[Stylesheet], session: &Session) {
+        css::cascade(
+            &mut self.tree,
+            &UA_STYLESHEETS,
+            &self.stylesheets,
+            extra,
+            session,
+        );
     }
 }
 
@@ -609,7 +615,7 @@ impl DocumentBuilder {
                 if is_element_of_type!(root, Svg) {
                     let mut document = Document {
                         tree: root,
-                        session,
+                        session: session.clone(),
                         ids,
                         externs: RefCell::new(Resources::new()),
                         images: RefCell::new(Images::new()),
@@ -617,7 +623,7 @@ impl DocumentBuilder {
                         stylesheets,
                     };
 
-                    document.cascade(&[]);
+                    document.cascade(&[], &session);
 
                     Ok(document)
                 } else {
diff --git a/src/element.rs b/src/element.rs
index 2926680fe..7db33608d 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -232,7 +232,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
     }
 
     /// Applies CSS styles from the "style" attribute
-    fn set_style_attribute(&mut self) {
+    fn set_style_attribute(&mut self, session: &Session) {
         let style = self
             .attributes
             .iter()
@@ -244,6 +244,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
                 style,
                 Origin::Author,
                 &mut self.important_styles,
+                session,
             ) {
                 self.set_error(e);
             }
@@ -515,8 +516,8 @@ impl Element {
         call_inner!(self, apply_style_declaration, declaration, origin)
     }
 
-    pub fn set_style_attribute(&mut self) {
-        call_inner!(self, set_style_attribute);
+    pub fn set_style_attribute(&mut self, session: &Session) {
+        call_inner!(self, set_style_attribute, session);
     }
 
     pub fn is_in_error(&self) -> bool {
diff --git a/src/handle.rs b/src/handle.rs
index 6062d3f13..e18b2a17c 100644
--- a/src/handle.rs
+++ b/src/handle.rs
@@ -378,7 +378,7 @@ impl Handle {
     pub fn set_stylesheet(&mut self, css: &str) -> Result<(), LoadingError> {
         let mut stylesheet = Stylesheet::new(Origin::User);
         stylesheet.parse(css, &UrlResolver::new(None), self.session.clone())?;
-        self.document.cascade(&[stylesheet]);
+        self.document.cascade(&[stylesheet], &self.session);
         Ok(())
     }
 }
diff --git a/src/properties.rs b/src/properties.rs
index 8d4390d9f..2b077d4cd 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -840,7 +840,8 @@ impl SpecifiedValues {
                 let mut tok = String::new();
 
                 t.to_css(&mut tok).unwrap(); // FIXME: what do we do with a fmt::Error?
-                rsvg_log!(
+                rsvg_log_session!(
+                    session,
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    \
                      unexpected token '{}')",
                     attr.expanded(),
@@ -853,7 +854,8 @@ impl SpecifiedValues {
                 kind: ParseErrorKind::Basic(BasicParseErrorKind::EndOfInput),
                 ..
             }) => {
-                rsvg_log!(
+                rsvg_log_session!(
+                    session,
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    \
                      unexpected end of input)",
                     attr.expanded(),
@@ -865,7 +867,8 @@ impl SpecifiedValues {
                 kind: ParseErrorKind::Basic(_),
                 ..
             }) => {
-                rsvg_log!(
+                rsvg_log_session!(
+                    session,
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    \
                      unexpected error)",
                     attr.expanded(),
@@ -877,7 +880,8 @@ impl SpecifiedValues {
                 kind: ParseErrorKind::Custom(ref v),
                 ..
             }) => {
-                rsvg_log!(
+                rsvg_log_session!(
+                    session,
                     "(ignoring invalid presentation attribute {:?}\n    value=\"{}\"\n    {})",
                     attr.expanded(),
                     value,
@@ -954,6 +958,7 @@ impl SpecifiedValues {
         declarations: &str,
         origin: Origin,
         important_styles: &mut HashSet<QualName>,
+        session: &Session,
     ) -> Result<(), ElementError> {
         let mut input = ParserInput::new(declarations);
         let mut parser = Parser::new(&mut input);
@@ -962,7 +967,7 @@ impl SpecifiedValues {
             .filter_map(|r| match r {
                 Ok(decl) => Some(decl),
                 Err(e) => {
-                    rsvg_log!("Invalid declaration; ignoring: {:?}", e);
+                    rsvg_log_session!(session, "Invalid declaration; ignoring: {:?}", e);
                     None
                 }
             })
@@ -1118,7 +1123,7 @@ mod tests {
         let mut specified = SpecifiedValues::default();
 
         assert!(specified
-            .parse_style_declarations("", Origin::Author, &mut HashSet::new())
+            .parse_style_declarations("", Origin::Author, &mut HashSet::new(), &Session::default())
             .is_ok())
     }
 }


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