1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:57:44 +00:00

LibWeb: Implement a slow but functional HTMLCollection :^)

HTMLCollection is an awkward legacy interface from the DOM spec.

It provides a live view of a DOM subtree, with some kind of filtering
that determines which elements are part of the collection.

We now return HTMLCollection objects from these APIs:

- getElementsByClassName()
- getElementsByName()
- getElementsByTagName()

This initial implementation does not do any kind of caching, since that
is quite a tricky problem, and there will be plenty of time for tricky
problems later on when the engine is more mature.
This commit is contained in:
Andreas Kling 2021-04-22 21:11:20 +02:00
parent 49f3d88baf
commit e4df1b223f
14 changed files with 207 additions and 55 deletions

View file

@ -6,6 +6,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/InProcessWebView.h>
@ -161,9 +162,9 @@ void Frame::scroll_to_anchor(const String& fragment)
auto element = document()->get_element_by_id(fragment);
if (!element) {
auto candidates = document()->get_elements_by_name(fragment);
for (auto& candidate : candidates) {
if (is<HTML::HTMLAnchorElement>(candidate)) {
element = downcast<HTML::HTMLAnchorElement>(candidate);
for (auto& candidate : candidates->collect_matching_elements()) {
if (is<HTML::HTMLAnchorElement>(*candidate)) {
element = downcast<HTML::HTMLAnchorElement>(*candidate);
break;
}
}