Bug 1540385 - Fix revalidation in <svg:use> subtree. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 04 Apr 2019 03:46:55 +0000
changeset 467940 625e9335159cefd680bfd517ac7c3310b80a9bf8
parent 467939 70a90b960aef224ca2b85718e534e7a9b8c1e5f1
child 467941 3fcf0136398320330aa0dddfaec1c34d63dad831
push id112667
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:12:45 +0000
treeherdermozilla-inbound@230bb363f2f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1540385
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540385 - Fix revalidation in <svg:use> subtree. r=heycam So as to avoid incorrectly sharing styles across elements. Differential Revision: https://phabricator.services.mozilla.com/D25918
servo/components/style/dom.rs
testing/web-platform/tests/css/selectors/sharing-in-svg-use-ref.html
testing/web-platform/tests/css/selectors/sharing-in-svg-use.html
--- a/servo/components/style/dom.rs
+++ b/servo/components/style/dom.rs
@@ -820,21 +820,25 @@ pub trait TElement:
     /// data if it comes from Shadow DOM, None if it comes from XBL.
     ///
     /// Returns whether normal document author rules should apply.
     fn each_applicable_non_document_style_rule_data<'a, F>(&self, mut f: F) -> bool
     where
         Self: 'a,
         F: FnMut(&'a CascadeData, QuirksMode, Option<Self>),
     {
+        use rule_collector::containing_shadow_ignoring_svg_use;
+
         let mut doc_rules_apply = !self.each_xbl_cascade_data(|data, quirks_mode| {
             f(data, quirks_mode, None);
         });
 
-        if let Some(shadow) = self.containing_shadow() {
+        // Use the same rules to look for the containing host as we do for rule
+        // collection.
+        if let Some(shadow) = containing_shadow_ignoring_svg_use(*self) {
             doc_rules_apply = false;
             if let Some(data) = shadow.style_data() {
                 f(
                     data,
                     self.as_node().owner_doc().quirks_mode(),
                     Some(shadow.host()),
                 );
             }
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/selectors/sharing-in-svg-use-ref.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>CSS Test reference</title>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="author" title="Mozilla" href="https://mozilla.org">
+<svg width="200" height="100">
+  <defs>
+    <g id="p0">
+      <rect width="100" height="100" style="fill: blue" />
+      <rect x="100" y="0" width="100" height="100" style="fill: purple" />
+    </g>
+  </defs>
+  <use href="#p0" x="0" y="0" />
+</svg>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/selectors/sharing-in-svg-use.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<title>CSS Test: nth-of-type should work in an svg use subtree</title>
+<link rel="help" href="https://drafts.csswg.org/selectors-4/#child-index">
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1540385">
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="author" title="Mozilla" href="https://mozilla.org">
+<link rel="match" href="sharing-in-svg-use-ref.html">
+<style>
+rect:nth-of-type(1) {
+  fill: blue;
+}
+rect:nth-of-type(2) {
+  fill: purple;
+}
+</style>
+<!-- Should see two different colors -->
+<svg width="200" height="100">
+  <defs>
+    <g id="p0">
+      <rect width="100" height="100" />
+      <rect x="100" y="0" width="100" height="100" />
+    </g>
+  </defs>
+  <use href="#p0" x="0" y="0" />
+</svg>