1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:07:34 +00:00

LibWeb: Implement basic support for Document.all

The finer details are missing here, but the basic API is up.
This commit is contained in:
Andreas Kling 2022-09-18 02:17:11 +02:00
parent 3df9861814
commit e6ef366859
3 changed files with 17 additions and 0 deletions

View file

@ -323,6 +323,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_links); visitor.visit(m_links);
visitor.visit(m_forms); visitor.visit(m_forms);
visitor.visit(m_scripts); visitor.visit(m_scripts);
visitor.visit(m_all);
for (auto& script : m_scripts_to_execute_when_parsing_has_finished) for (auto& script : m_scripts_to_execute_when_parsing_has_finished)
visitor.visit(script.ptr()); visitor.visit(script.ptr());
@ -1041,6 +1042,17 @@ JS::NonnullGCPtr<HTMLCollection> Document::scripts()
return *m_scripts; return *m_scripts;
} }
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-all
JS::NonnullGCPtr<HTMLCollection> Document::all()
{
if (!m_all) {
m_all = HTMLCollection::create(*this, [](Element const&) {
return true;
});
}
return *m_all;
}
Color Document::link_color() const Color Document::link_color() const
{ {
if (m_link_color.has_value()) if (m_link_color.has_value())

View file

@ -183,6 +183,7 @@ public:
JS::NonnullGCPtr<HTMLCollection> links(); JS::NonnullGCPtr<HTMLCollection> links();
JS::NonnullGCPtr<HTMLCollection> forms(); JS::NonnullGCPtr<HTMLCollection> forms();
JS::NonnullGCPtr<HTMLCollection> scripts(); JS::NonnullGCPtr<HTMLCollection> scripts();
JS::NonnullGCPtr<HTMLCollection> all();
String const& source() const { return m_source; } String const& source() const { return m_source; }
void set_source(String const& source) { m_source = source; } void set_source(String const& source) { m_source = source; }
@ -494,6 +495,7 @@ private:
JS::GCPtr<HTMLCollection> m_links; JS::GCPtr<HTMLCollection> m_links;
JS::GCPtr<HTMLCollection> m_forms; JS::GCPtr<HTMLCollection> m_forms;
JS::GCPtr<HTMLCollection> m_scripts; JS::GCPtr<HTMLCollection> m_scripts;
JS::GCPtr<HTMLCollection> m_all;
}; };
} }

View file

@ -69,6 +69,9 @@ interface Document : Node {
readonly attribute HTMLCollection forms; readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection scripts; readonly attribute HTMLCollection scripts;
// FIXME: Should return an HTMLAllCollection
readonly attribute HTMLCollection all;
Element createElement(DOMString tagName); Element createElement(DOMString tagName);
Element createElementNS(DOMString? namespace, DOMString qualifiedName); Element createElementNS(DOMString? namespace, DOMString qualifiedName);
DocumentFragment createDocumentFragment(); DocumentFragment createDocumentFragment();