1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibWeb: Add method to check if element affected by invalidation set

...by replacing existing method to check if an element is affected by
invalidation property. It turned out there is no need to check if an
element is affected only by some specific property, so it's more
convenient to have a method that accepts the whole set.
This commit is contained in:
Aliaksandr Kalenik 2025-01-29 02:41:06 +01:00 committed by Andreas Kling
parent 74dc335b28
commit e33037ad52
Notes: github-actions[bot] 2025-01-29 08:31:28 +00:00
3 changed files with 53 additions and 53 deletions

View file

@ -1149,8 +1149,9 @@ bool Element::affected_by_hover() const
return false;
}
bool Element::affected_by_invalidation_property(CSS::InvalidationSet::Property const& property) const
bool Element::includes_properties_from_invalidation_set(CSS::InvalidationSet const& set) const
{
auto includes_property = [&](CSS::InvalidationSet::Property const& property) {
switch (property.type) {
case CSS::InvalidationSet::Property::Type::Class:
return m_classes.contains_slow(property.name());
@ -1195,6 +1196,17 @@ bool Element::affected_by_invalidation_property(CSS::InvalidationSet::Property c
default:
VERIFY_NOT_REACHED();
}
};
bool includes_any = false;
set.for_each_property([&](auto const& property) {
if (includes_property(property)) {
includes_any = true;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return includes_any;
}
bool Element::has_pseudo_elements() const

View file

@ -266,7 +266,7 @@ public:
static GC::Ptr<Layout::NodeWithStyle> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, GC::Ref<CSS::ComputedProperties>, Element*);
bool affected_by_hover() const;
bool affected_by_invalidation_property(CSS::InvalidationSet::Property const&) const;
bool includes_properties_from_invalidation_set(CSS::InvalidationSet const&) const;
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, GC::Ptr<Layout::NodeWithStyle>);
GC::Ptr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;

View file

@ -486,18 +486,6 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector<CSS::Invalida
set_needs_style_update(true);
}
auto element_has_properties_from_invalidation_set = [&](Element& element) {
bool result = false;
invalidation_set.for_each_property([&](auto const& property) {
if (element.affected_by_invalidation_property(property)) {
result = true;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return result;
};
auto invalidate_entire_subtree = [&](Node& subtree_root) {
subtree_root.for_each_shadow_including_inclusive_descendant([&](Node& node) {
if (!node.is_element())
@ -506,7 +494,7 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector<CSS::Invalida
bool needs_style_recalculation = false;
if (invalidation_set.needs_invalidate_whole_subtree()) {
needs_style_recalculation = true;
} else if (element_has_properties_from_invalidation_set(element)) {
} else if (element.includes_properties_from_invalidation_set(invalidation_set)) {
needs_style_recalculation = true;
} else if (options.invalidate_elements_that_use_css_custom_properties && element.style_uses_css_custom_properties()) {
needs_style_recalculation = true;