LibWeb: Allow to early break from InvalidationSet::for_each_property()

This commit is contained in:
Aliaksandr Kalenik 2025-01-29 01:45:34 +01:00 committed by Andreas Kling
commit 74dc335b28
Notes: github-actions[bot] 2025-01-29 08:31:36 +00:00
4 changed files with 22 additions and 9 deletions

View file

@ -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 {};
}