mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
Instead of doing a full document style invalidation when a stylesheet is dynamically added, we now analyze the new sheet's selectors to determine which elements could potentially be affected, and only invalidate those. This works by building an InvalidationSet from the rightmost compound selector (the "subject") of each rule in the new stylesheet, extracting class, ID, tag name, attribute, and pseudo-class features. We then walk the DOM tree and only mark elements matching those features as needing a style update. If any selector has a rightmost compound that is purely universal (no identifying features), or uses a pseudo-class not supported by the invalidation set matching logic, we fall back to full invalidation.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibWeb/CSS/InvalidationSet.h>
|
|
#include <LibWeb/CSS/Selector.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
enum class ExcludePropertiesNestedInNotPseudoClass : bool {
|
|
No,
|
|
Yes,
|
|
};
|
|
|
|
enum class InsideNthChildPseudoClass {
|
|
No,
|
|
Yes,
|
|
};
|
|
|
|
struct StyleInvalidationData;
|
|
|
|
void build_invalidation_sets_for_simple_selector(Selector::SimpleSelector const&, InvalidationSet&, ExcludePropertiesNestedInNotPseudoClass, StyleInvalidationData&, InsideNthChildPseudoClass);
|
|
|
|
struct StyleInvalidationData {
|
|
HashMap<InvalidationSet::Property, InvalidationSet> descendant_invalidation_sets;
|
|
HashTable<FlyString> ids_used_in_has_selectors;
|
|
HashTable<FlyString> class_names_used_in_has_selectors;
|
|
HashTable<FlyString> attribute_names_used_in_has_selectors;
|
|
HashTable<FlyString> tag_names_used_in_has_selectors;
|
|
HashTable<PseudoClass> pseudo_classes_used_in_has_selectors;
|
|
|
|
void build_invalidation_sets_for_selector(Selector const& selector);
|
|
};
|
|
|
|
}
|