dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / invalidation / adopted_style_sheet_invalidator.lucb
#==============================================================================================
#
# adopted_style_sheet_invalidator - style invalidation after a document's or shadow root's
# adoptedStyleSheets change
#
# DESCRIPTION:
# Port of LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp (lines 1-49).
#
# Copyright (c) 2026-present, the Ladybird developers
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp:17 Web::CSS::Invalidation::style_scope_for_document_or_shadow_root.
func css_invalidation_style_scope_for_document_or_shadow_root(document_or_shadow_root: DomNode*) -> CssStyleScope*:
if let shadow_root = as_if_dom_shadow_root(document_or_shadow_root):
return dom_shadow_root_style_scope(shadow_root)
return dom_document_style_scope(dom_node_document(document_or_shadow_root))
## Ported from Libraries/LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp:24 Web::CSS::Invalidation::invalidate_style_after_adopted_style_sheet_list_change.
func css_invalidation_invalidate_style_after_adopted_style_sheet_list_change(document_or_shadow_root: DomNode*):
css_style_scope_invalidate_rule_cache(css_invalidation_style_scope_for_document_or_shadow_root(document_or_shadow_root))
dom_node_invalidate_style(document_or_shadow_root, DomStyleInvalidationReason.adopted_style_sheets_list)
## Ported from Libraries/LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp:30 Web::CSS::Invalidation::invalidate_style_after_adopting_style_sheet.
pub func css_invalidation_invalidate_style_after_adopting_style_sheet(document_or_shadow_root: DomNode*, style_sheet: CssCssStyleSheet*):
css_css_style_sheet_add_owning_document_or_shadow_root(style_sheet, document_or_shadow_root)
css_css_style_sheet_load_pending_image_resources(style_sheet, dom_node_document(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.
_ = css_css_style_sheet_evaluate_media_queries(style_sheet, dom_node_document(document_or_shadow_root))
css_invalidation_invalidate_style_after_adopted_style_sheet_list_change(document_or_shadow_root)
## Ported from Libraries/LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp:43 Web::CSS::Invalidation::invalidate_style_after_removing_adopted_style_sheet.
pub func css_invalidation_invalidate_style_after_removing_adopted_style_sheet(document_or_shadow_root: DomNode*, style_sheet: CssCssStyleSheet*):
css_css_style_sheet_remove_owning_document_or_shadow_root(style_sheet, document_or_shadow_root)
css_invalidation_invalidate_style_after_adopted_style_sheet_list_change(document_or_shadow_root)