mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Allow to early break from InvalidationSet::for_each_property()
This commit is contained in:
parent
3295ed17ea
commit
74dc335b28
Notes:
github-actions[bot]
2025-01-29 08:31:36 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 74dc335b28
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3391
4 changed files with 22 additions and 9 deletions
|
@ -21,14 +21,20 @@ bool InvalidationSet::is_empty() const
|
||||||
return !m_needs_invalidate_self && !m_needs_invalidate_whole_subtree && m_properties.is_empty();
|
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)
|
if (m_needs_invalidate_self) {
|
||||||
callback({ Property::Type::InvalidateSelf });
|
if (callback({ Property::Type::InvalidateSelf }) == IterationDecision::Break)
|
||||||
if (m_needs_invalidate_whole_subtree)
|
return;
|
||||||
callback({ Property::Type::InvalidateWholeSubtree });
|
}
|
||||||
for (auto const& property : m_properties)
|
if (m_needs_invalidate_whole_subtree) {
|
||||||
callback(property);
|
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)
|
if (!first)
|
||||||
builder.builder().append(", "sv);
|
builder.builder().append(", "sv);
|
||||||
builder.builder().appendff("{}", property);
|
builder.builder().appendff("{}", property);
|
||||||
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
void set_needs_invalidate_pseudo_class(PseudoClass pseudo_class) { m_properties.set({ Property::Type::PseudoClass, pseudo_class }); }
|
void set_needs_invalidate_pseudo_class(PseudoClass pseudo_class) { m_properties.set({ Property::Type::PseudoClass, pseudo_class }); }
|
||||||
|
|
||||||
bool is_empty() const;
|
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:
|
private:
|
||||||
bool m_needs_invalidate_self { false };
|
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.
|
// we need to make all siblings are invalidated.
|
||||||
descendant_invalidation_set.set_needs_invalidate_whole_subtree();
|
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 {
|
} else {
|
||||||
descendant_invalidation_set.include_all_from(invalidation_set_for_rightmost_selector);
|
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) {
|
auto element_has_properties_from_invalidation_set = [&](Element& element) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
invalidation_set.for_each_property([&](auto const& property) {
|
invalidation_set.for_each_property([&](auto const& property) {
|
||||||
if (element.affected_by_invalidation_property(property))
|
if (element.affected_by_invalidation_property(property)) {
|
||||||
result = true;
|
result = true;
|
||||||
|
return IterationDecision::Break;
|
||||||
|
}
|
||||||
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue