mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-24 03:02:23 +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
Notes:
sideshowbarker
2024-07-19 11:36:05 +09:00
Author: https://github.com/awesomekling
Commit: 4d9740ecef
5 changed files with 57 additions and 11 deletions
|
@ -321,11 +321,14 @@ void HtmlView::scroll_to_anchor(const StringView& name)
|
|||
|
||||
HTMLAnchorElement* element = nullptr;
|
||||
document()->for_each_in_subtree([&](auto& node) {
|
||||
if (!is<HTMLAnchorElement>(node))
|
||||
return;
|
||||
auto& anchor_element = to<HTMLAnchorElement>(node);
|
||||
if (anchor_element.name() == name)
|
||||
element = &anchor_element;
|
||||
if (is<HTMLAnchorElement>(node)) {
|
||||
auto& anchor_element = to<HTMLAnchorElement>(node);
|
||||
if (anchor_element.name() == name) {
|
||||
element = &anchor_element;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
if (!element) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue