Truly independent web browser
LibWeb: Synchronize the document font order only for document scopes
Tim Ledbetter3cf7cfe1f26e
diff --git a/Libraries/LibWeb/CSS/StyleScope.cpp b/Libraries/LibWeb/CSS/StyleScope.cppindex c61667c92f6..5825ac66ec2 100644--- a/Libraries/LibWeb/CSS/StyleScope.cpp+++ b/Libraries/LibWeb/CSS/StyleScope.cpp@@ -108,7 +108,8 @@ void StyleScope::add_sheet(StyleSheetState& sheet, StyleEngineUpdate style_enginsheet.load_pending_image_resources(document());insert_sheet_in_tree_order(sheet);- document().fonts()->synchronize_css_connected_font_order();+ if (m_node->is_document())+ document().fonts()->synchronize_css_connected_font_order();if (style_engine_update == StyleEngineUpdate::Record)record_stylesheet_attached(sheet, node(), following_sheet(sheet));@@ -196,7 +197,8 @@ void StyleScope::move_sheet(StyleSheetState& sheet, StyleScope& destination)VERIFY(position.has_value());m_style_sheets.remove(*position);insert_sheet_in_tree_order(sheet);- document().fonts()->synchronize_css_connected_font_order();+ if (m_node->is_document())+ document().fonts()->synchronize_css_connected_font_order();record_stylesheet_attached(sheet, node(), following_sheet(sheet));invalidate_rule_cache_after_style_sheet_change(node(), sheet);}diff --git a/Tests/LibWeb/Text/expected/css/shadow-root-style-sheet-keeps-document-font-order.txt b/Tests/LibWeb/Text/expected/css/shadow-root-style-sheet-keeps-document-font-order.txtnew file mode 100644index 00000000000..c48ae40273f--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/shadow-root-style-sheet-keeps-document-font-order.txt@@ -0,0 +1,4 @@+before shadow sheet: FirstFace, SecondFace, ManualFace+after shadow sheet: FirstFace, SecondFace, ManualFace+after removing shadow sheet: FirstFace, SecondFace, ManualFace+after moving a document sheet first: SecondFace, FirstFace, ManualFacediff --git a/Tests/LibWeb/Text/input/css/shadow-root-style-sheet-keeps-document-font-order.html b/Tests/LibWeb/Text/input/css/shadow-root-style-sheet-keeps-document-font-order.htmlnew file mode 100644index 00000000000..bdba7833ccf--- /dev/null+++ b/Tests/LibWeb/Text/input/css/shadow-root-style-sheet-keeps-document-font-order.html@@ -0,0 +1,44 @@+<!DOCTYPE html>+<style>+ @font-face {+ font-family: FirstFace;+ src: url("../../../Ref/data/fonts/Ahem.ttf");+ }+</style>+<style id="second">+ @font-face {+ font-family: SecondFace;+ src: url("../../../Ref/data/fonts/Ahem.ttf");+ }+</style>+<div id="host"></div>+<script src="../include.js"></script>+<script>+ test(() => {+ document.fonts.add(new FontFace("ManualFace", 'url("../../../Ref/data/fonts/Ahem.ttf")'));+ const families = () => [...document.fonts].map(face => face.family).join(", ");+ println(`before shadow sheet: ${families()}`);++ const shadowRoot = host.attachShadow({ mode: "open" });+ shadowRoot.innerHTML = `+ <style>+ @font-face {+ font-family: ShadowFace;+ src: url("../../../Ref/data/fonts/Ahem.ttf");+ }+ span { color: green; }+ </style>+ <span>x</span>+ `;+ document.body.offsetWidth;+ println(`after shadow sheet: ${families()}`);++ shadowRoot.querySelector("style").remove();+ document.body.offsetWidth;+ println(`after removing shadow sheet: ${families()}`);++ document.head.prepend(document.getElementById("second"));+ document.body.offsetWidth;+ println(`after moving a document sheet first: ${families()}`);+ });+</script>