mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibHTML: Add Document::get_element_by_id() and get_elements_by_name()
These will be useful for implementing various things. They don't do any caching at the moment, but that might become valuable in the future. To facilitate this change, I also made it possible to abort a tree walk with for_each_in_subtree() by returning IterationDecision::Break from the callback.
This commit is contained in:
parent
465a33443c
commit
4d9740ecef
5 changed files with 57 additions and 11 deletions
|
@ -54,12 +54,27 @@ public:
|
|||
bool is_child_allowed(const T&) const { return true; }
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_in_subtree(Callback callback)
|
||||
IterationDecision for_each_in_subtree(Callback callback) const
|
||||
{
|
||||
callback(static_cast<T&>(*this));
|
||||
if (callback(static_cast<const T&>(*this)) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
child->for_each_in_subtree(callback);
|
||||
if (child->for_each_in_subtree(callback) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
IterationDecision for_each_in_subtree(Callback callback)
|
||||
{
|
||||
if (callback(static_cast<T&>(*this)) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (child->for_each_in_subtree(callback) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue