mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Allow to early break from InvalidationSet::for_each_property()
This commit is contained in:
committed by
Andreas Kling
parent
3295ed17ea
commit
74dc335b28
@@ -21,14 +21,20 @@ bool InvalidationSet::is_empty() const
|
||||
return !m_needs_invalidate_self && !m_needs_invalidate_whole_subtree && m_properties.is_empty();
|
||||
}
|
||||
|
||||
void InvalidationSet::for_each_property(Function<void(Property const&)> const& callback) const
|
||||
void InvalidationSet::for_each_property(Function<IterationDecision(Property const&)> const& callback) const
|
||||
{
|
||||
if (m_needs_invalidate_self)
|
||||
callback({ Property::Type::InvalidateSelf });
|
||||
if (m_needs_invalidate_whole_subtree)
|
||||
callback({ Property::Type::InvalidateWholeSubtree });
|
||||
for (auto const& property : m_properties)
|
||||
callback(property);
|
||||
if (m_needs_invalidate_self) {
|
||||
if (callback({ Property::Type::InvalidateSelf }) == IterationDecision::Break)
|
||||
return;
|
||||
}
|
||||
if (m_needs_invalidate_whole_subtree) {
|
||||
if (callback({ Property::Type::InvalidateWholeSubtree }) == IterationDecision::Break)
|
||||
return;
|
||||
}
|
||||
for (auto const& property : m_properties) {
|
||||
if (callback(property) == IterationDecision::Break)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,6 +98,7 @@ ErrorOr<void> Formatter<Web::CSS::InvalidationSet>::format(FormatBuilder& builde
|
||||
if (!first)
|
||||
builder.builder().append(", "sv);
|
||||
builder.builder().appendff("{}", property);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
void set_needs_invalidate_pseudo_class(PseudoClass pseudo_class) { m_properties.set({ Property::Type::PseudoClass, pseudo_class }); }
|
||||
|
||||
bool is_empty() const;
|
||||
void for_each_property(Function<void(Property const&)> const& callback) const;
|
||||
void for_each_property(Function<IterationDecision(Property const&)> const& callback) const;
|
||||
|
||||
private:
|
||||
bool m_needs_invalidate_self { false };
|
||||
|
||||
@@ -190,6 +190,7 @@ static InvalidationSet build_invalidation_sets_for_selector_impl(StyleInvalidati
|
||||
// we need to make all siblings are invalidated.
|
||||
descendant_invalidation_set.set_needs_invalidate_whole_subtree();
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -216,6 +217,8 @@ static InvalidationSet build_invalidation_sets_for_selector_impl(StyleInvalidati
|
||||
} else {
|
||||
descendant_invalidation_set.include_all_from(invalidation_set_for_rightmost_selector);
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,8 +489,11 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector<CSS::Invalida
|
||||
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))
|
||||
if (element.affected_by_invalidation_property(property)) {
|
||||
result = true;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user