[librsvg: 1/2] Inherit xml:lang early




commit b679ebf7f66ba79fd56aacaf564e4c867aa2499e
Author: Michael Howell <michael notriddle com>
Date:   Tue Oct 19 09:49:14 2021 -0700

    Inherit xml:lang early
    
    It was already doing the attribute to property conversion, but
    the actual *inheritance* needs to also be handled before selector matching,
    which it wasn't doing correctly.
    
    Fixes #805
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/614>

 src/css.rs                                           |   3 ++-
 src/element.rs                                       |   9 +++++----
 src/properties.rs                                    |  12 +++++++++++-
 tests/fixtures/reftests/xml-lang-css-inherit-ref.png | Bin 0 -> 88 bytes
 tests/fixtures/reftests/xml-lang-css-inherit.svg     |   7 +++++++
 5 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/css.rs b/src/css.rs
index ba0c5800..842cc717 100644
--- a/src/css.rs
+++ b/src/css.rs
@@ -844,7 +844,8 @@ pub fn cascade(
         // xml:lang needs to be inherited before selector matching, so it
         // can't be done in the usual SpecifiedValues::to_computed_values,
         // which is called by cascade() and runs after matching.
-        node.borrow_element_mut().inherit_xml_lang();
+        let parent = node.parent().clone();
+        node.borrow_element_mut().inherit_xml_lang(parent);
 
         let mut match_ctx = MatchingContext::new(
             MatchingMode::Normal,
diff --git a/src/element.rs b/src/element.rs
index 5b19ecd8..f89d8e2b 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -160,8 +160,9 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
         self.class.as_deref()
     }
 
-    fn inherit_xml_lang(&mut self) {
-        self.specified_values.inherit_xml_lang(&mut self.values);
+    fn inherit_xml_lang(&mut self, parent: Option<Node>) {
+        self.specified_values
+            .inherit_xml_lang(&mut self.values, parent);
     }
 
     fn get_specified_values(&self) -> &SpecifiedValues {
@@ -501,8 +502,8 @@ impl Element {
         call_inner!(self, get_class)
     }
 
-    pub fn inherit_xml_lang(&mut self) {
-        call_inner!(self, inherit_xml_lang)
+    pub fn inherit_xml_lang(&mut self, parent: Option<Node>) {
+        call_inner!(self, inherit_xml_lang, parent)
     }
 
     pub fn get_specified_values(&self) -> &SpecifiedValues {
diff --git a/src/properties.rs b/src/properties.rs
index 0c82f69c..051232d4 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -746,9 +746,19 @@ impl SpecifiedValues {
     /// attribute. Presentational attributes can often be influenced by stylesheets,
     /// so they're cascaded after selector matching is done, but xml:lang can be queried by
     /// CSS selectors, so they need to be cascaded *first*.
-    pub fn inherit_xml_lang(&self, computed: &mut ComputedValues) {
+    pub fn inherit_xml_lang(
+        &self,
+        computed: &mut ComputedValues,
+        parent: Option<crate::node::Node>,
+    ) {
+        use crate::node::NodeBorrow;
         let prop_val = self.get_property(PropertyId::XmlLang);
         if let ParsedProperty::XmlLang(s) = prop_val {
+            if let Some(parent) = parent {
+                computed.set_value(ComputedValue::XmlLang(
+                    parent.borrow_element().get_computed_values().xml_lang(),
+                ));
+            }
             computed.set_value(ComputedValue::XmlLang(
                 s.compute(&computed.xml_lang(), computed),
             ));
diff --git a/tests/fixtures/reftests/xml-lang-css-inherit-ref.png 
b/tests/fixtures/reftests/xml-lang-css-inherit-ref.png
new file mode 100644
index 00000000..a1f5280a
Binary files /dev/null and b/tests/fixtures/reftests/xml-lang-css-inherit-ref.png differ
diff --git a/tests/fixtures/reftests/xml-lang-css-inherit.svg 
b/tests/fixtures/reftests/xml-lang-css-inherit.svg
new file mode 100644
index 00000000..498c92f1
--- /dev/null
+++ b/tests/fixtures/reftests/xml-lang-css-inherit.svg
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg"; width="10" height="10">
+  <style type="text/css">
+    .test { fill: red }
+    :lang(de) { fill: black }
+  </style>
+  <g class="test" xml:lang="de"><rect x="0" y="0" width="10" height="10"/></g>
+</svg>


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