Parcourir la source

LibWeb: Don't apply disabled adopted style sheets to the document

Previously, we would apply any adopted style sheet to the document if
its alternate flag was not set. This meant that all adopted style
sheets would be applied, since constructed style sheets never have this
flag set.
Tim Ledbetter il y a 1 an
Parent
commit
f4e0c5395a

+ 1 - 0
Tests/LibWeb/Text/expected/css/constructed-style-sheets.txt

@@ -0,0 +1 @@
+Disabled constructed style sheet applies to document: false

+ 20 - 0
Tests/LibWeb/Text/input/css/constructed-style-sheets.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        function constructedStyleSheetAppliesToDocument(options) {
+            const textDiv = document.createElement("div");
+            document.body.appendChild(textDiv);
+            const sheet = new CSSStyleSheet(options);
+            const newColor = "rgb(0, 128, 0)";
+            sheet.replaceSync(`div { color: ${newColor}; }`);
+            document.adoptedStyleSheets = [sheet];
+            const styleSheetAppliedToDocument = getComputedStyle(textDiv).color === newColor;
+            document.body.removeChild(textDiv);
+            document.adoptedStyleSheets = [];
+            return styleSheetAppliedToDocument;
+        }
+
+        println(`Disabled constructed style sheet applies to document: ${constructedStyleSheetAppliesToDocument({ disabled: true })}`);
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -4904,7 +4904,7 @@ void Document::for_each_css_style_sheet(Function<void(CSS::CSSStyleSheet&)>&& ca
 
     if (m_adopted_style_sheets) {
         m_adopted_style_sheets->for_each<CSS::CSSStyleSheet>([&](auto& style_sheet) {
-            if (!(style_sheet.is_alternate() && style_sheet.disabled()))
+            if (!style_sheet.disabled())
                 callback(style_sheet);
         });
     }