From 618b8574574f8c1404b637d338c67fbba771f692 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 20 Mar 2022 16:18:43 +0100 Subject: [PATCH] LibWeb: Evaluate @media CSS rules when updating style In case we have new @media rules, we need to make sure we've evaluated them before actually recomputing styles for the document. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 6 ++++++ Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 12016473da..3d67b113c9 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -627,6 +627,7 @@ void Document::update_style() return; if (!needs_full_style_update() && !needs_style_update() && !child_needs_style_update()) return; + evaluate_media_rules(); if (update_style_recursively(*this)) invalidate_layout(); m_needs_full_style_update = false; @@ -1375,6 +1376,11 @@ void Document::evaluate_media_queries_and_report_changes() } // Also not in the spec, but this is as good a place as any to evaluate @media rules! + evaluate_media_rules(); +} + +void Document::evaluate_media_rules() +{ bool any_media_queries_changed_match_state = false; for (auto& style_sheet : style_sheets().sheets()) { if (style_sheet.evaluate_media_queries(window())) diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 94ce18bcd5..b55f474fda 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -345,6 +345,8 @@ private: void tear_down_layout_tree(); + void evaluate_media_rules(); + ExceptionOr run_the_document_write_steps(String); void increment_referencing_node_count()