Truly independent web browser
/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.h>
#include <LibWeb/CSS/StyleSheetInvalidation.h>
#include <LibWeb/CSS/StyleSheetState.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Node.h>
namespace Web::CSS::Invalidation {
void invalidate_style_after_adopting_style_sheet(DOM::Node& document_or_shadow_root, StyleSheetState& style_sheet)
{
style_sheet.add_owning_document_or_shadow_root(document_or_shadow_root);
// Evaluate the sheet's media queries before the next style update so the cascade can see its rules. Otherwise the
// rule cache may be rebuilt (e.g. via a :has() invalidation pass) before Document::evaluate_media_rules has a
// chance to populate MediaList::m_matches.
style_sheet.evaluate_media_queries(document_or_shadow_root.document());
invalidate_rule_cache_after_style_sheet_change(document_or_shadow_root, style_sheet);
}
void invalidate_style_after_removing_adopted_style_sheet(DOM::Node& document_or_shadow_root, StyleSheetState& style_sheet)
{
style_sheet.remove_owning_document_or_shadow_root(document_or_shadow_root);
invalidate_rule_cache_after_style_sheet_change(document_or_shadow_root, style_sheet);
}
}