mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-23 09:48:56 +00:00
LibWeb/CSS: Take AbstractElement in for_each_matching_rules()
This commit is contained in:
parent
cdc4f7c989
commit
fa790e5095
Notes:
github-actions[bot]
2025-09-11 16:47:12 +00:00
Author: https://github.com/AtkinsSJ
Commit: fa790e5095
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6118
3 changed files with 13 additions and 13 deletions
|
@ -564,7 +564,7 @@ Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::AbstractE
|
||||||
};
|
};
|
||||||
|
|
||||||
auto add_rules_from_cache = [&](RuleCache const& rule_cache) {
|
auto add_rules_from_cache = [&](RuleCache const& rule_cache) {
|
||||||
rule_cache.for_each_matching_rules(abstract_element.element(), abstract_element.pseudo_element(), [&](auto const& matching_rules) {
|
rule_cache.for_each_matching_rules(abstract_element, [&](auto const& matching_rules) {
|
||||||
add_rules_to_run(matching_rules);
|
add_rules_to_run(matching_rules);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
@ -3388,40 +3388,40 @@ void RuleCache::add_rule(MatchingRule const& matching_rule, Optional<PseudoEleme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleCache::for_each_matching_rules(DOM::Element const& element, Optional<PseudoElement> pseudo_element, Function<IterationDecision(Vector<MatchingRule> const&)> callback) const
|
void RuleCache::for_each_matching_rules(DOM::AbstractElement abstract_element, Function<IterationDecision(Vector<MatchingRule> const&)> callback) const
|
||||||
{
|
{
|
||||||
for (auto const& class_name : element.class_names()) {
|
for (auto const& class_name : abstract_element.element().class_names()) {
|
||||||
if (auto it = rules_by_class.find(class_name); it != rules_by_class.end()) {
|
if (auto it = rules_by_class.find(class_name); it != rules_by_class.end()) {
|
||||||
if (callback(it->value) == IterationDecision::Break)
|
if (callback(it->value) == IterationDecision::Break)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (auto id = element.id(); id.has_value()) {
|
if (auto id = abstract_element.element().id(); id.has_value()) {
|
||||||
if (auto it = rules_by_id.find(id.value()); it != rules_by_id.end()) {
|
if (auto it = rules_by_id.find(id.value()); it != rules_by_id.end()) {
|
||||||
if (callback(it->value) == IterationDecision::Break)
|
if (callback(it->value) == IterationDecision::Break)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (auto it = rules_by_tag_name.find(element.lowercased_local_name()); it != rules_by_tag_name.end()) {
|
if (auto it = rules_by_tag_name.find(abstract_element.element().lowercased_local_name()); it != rules_by_tag_name.end()) {
|
||||||
if (callback(it->value) == IterationDecision::Break)
|
if (callback(it->value) == IterationDecision::Break)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pseudo_element.has_value()) {
|
if (abstract_element.pseudo_element().has_value()) {
|
||||||
if (Selector::PseudoElementSelector::is_known_pseudo_element_type(pseudo_element.value())) {
|
if (Selector::PseudoElementSelector::is_known_pseudo_element_type(abstract_element.pseudo_element().value())) {
|
||||||
if (callback(rules_by_pseudo_element.at(to_underlying(pseudo_element.value()))) == IterationDecision::Break)
|
if (callback(rules_by_pseudo_element.at(to_underlying(abstract_element.pseudo_element().value()))) == IterationDecision::Break)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// NOTE: We don't cache rules for unknown pseudo-elements. They can't match anything anyway.
|
// NOTE: We don't cache rules for unknown pseudo-elements. They can't match anything anyway.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.is_document_element()) {
|
if (abstract_element.element().is_document_element()) {
|
||||||
if (callback(root_rules) == IterationDecision::Break)
|
if (callback(root_rules) == IterationDecision::Break)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IterationDecision decision = IterationDecision::Continue;
|
IterationDecision decision = IterationDecision::Continue;
|
||||||
element.for_each_attribute([&](auto& name, auto&) {
|
abstract_element.element().for_each_attribute([&](auto& name, auto&) {
|
||||||
if (auto it = rules_by_attribute_name.find(name); it != rules_by_attribute_name.end()) {
|
if (auto it = rules_by_attribute_name.find(name); it != rules_by_attribute_name.end()) {
|
||||||
decision = callback(it->value);
|
decision = callback(it->value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ struct RuleCache {
|
||||||
HashMap<FlyString, NonnullRefPtr<Animations::KeyframeEffect::KeyFrameSet>> rules_by_animation_keyframes;
|
HashMap<FlyString, NonnullRefPtr<Animations::KeyframeEffect::KeyFrameSet>> rules_by_animation_keyframes;
|
||||||
|
|
||||||
void add_rule(MatchingRule const&, Optional<PseudoElement>, bool contains_root_pseudo_class);
|
void add_rule(MatchingRule const&, Optional<PseudoElement>, bool contains_root_pseudo_class);
|
||||||
void for_each_matching_rules(DOM::Element const&, Optional<PseudoElement>, Function<IterationDecision(Vector<MatchingRule> const&)> callback) const;
|
void for_each_matching_rules(DOM::AbstractElement, Function<IterationDecision(Vector<MatchingRule> const&)> callback) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FontLoader;
|
class FontLoader;
|
||||||
|
|
|
@ -1845,9 +1845,9 @@ void Document::invalidate_style_for_elements_affected_by_pseudo_class_change(CSS
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto matches_different_set_of_rules_after_state_change = [&](Element const& element) {
|
auto matches_different_set_of_rules_after_state_change = [&](Element& element) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
rules.for_each_matching_rules(element, {}, [&](auto& rules) {
|
rules.for_each_matching_rules({ element }, [&](auto& rules) {
|
||||||
for (auto& rule : rules) {
|
for (auto& rule : rules) {
|
||||||
bool before = does_rule_match_on_element(element, rule);
|
bool before = does_rule_match_on_element(element, rule);
|
||||||
TemporaryChange change { element_slot, node };
|
TemporaryChange change { element_slot, node };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue