mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 05:47:34 +00:00
LibHTML: Add TreeNode::for_each_in_subtree_of_type<T>()
This allows you to iterate a subtree and get a callback for every node where is<T>(node) == true. This makes for quite pleasant DOM traversal.
This commit is contained in:
parent
54bd322881
commit
1aea8f116b
5 changed files with 56 additions and 25 deletions
|
@ -34,11 +34,8 @@ void LayoutDocument::layout()
|
|||
void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Rect& a_viewport_rect)
|
||||
{
|
||||
FloatRect viewport_rect(a_viewport_rect.x(), a_viewport_rect.y(), a_viewport_rect.width(), a_viewport_rect.height());
|
||||
for_each_in_subtree([&](auto& layout_node) {
|
||||
if (is<LayoutImage>(layout_node)) {
|
||||
auto& image = to<LayoutImage>(layout_node);
|
||||
const_cast<HTMLImageElement&>(image.node()).set_volatile({}, !viewport_rect.intersects(image.rect()));
|
||||
}
|
||||
for_each_in_subtree_of_type<LayoutImage>([&](auto& layout_image) {
|
||||
const_cast<HTMLImageElement&>(layout_image.node()).set_volatile({}, !viewport_rect.intersects(layout_image.rect()));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue