diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-18 02:17:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-18 02:17:29 +0200 |
commit | e6ef3668597111baa017abc3e987dec170191db5 (patch) | |
tree | 84ed4917288bac13b88d9aa46ab629b25fd9f17f /Userland/Libraries/LibWeb | |
parent | 3df9861814219915a4c4643ea57d4db7f9af2776 (diff) | |
download | serenity-e6ef3668597111baa017abc3e987dec170191db5.zip |
LibWeb: Implement basic support for Document.all
The finer details are missing here, but the basic API is up.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.idl | 3 |
3 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 237efce65c..b55d3564aa 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -323,6 +323,7 @@ void Document::visit_edges(Cell::Visitor& visitor) visitor.visit(m_links); visitor.visit(m_forms); visitor.visit(m_scripts); + visitor.visit(m_all); for (auto& script : m_scripts_to_execute_when_parsing_has_finished) visitor.visit(script.ptr()); @@ -1041,6 +1042,17 @@ JS::NonnullGCPtr<HTMLCollection> Document::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 { if (m_link_color.has_value()) diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 6f5b1496a1..d7ae532478 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -183,6 +183,7 @@ public: JS::NonnullGCPtr<HTMLCollection> links(); JS::NonnullGCPtr<HTMLCollection> forms(); JS::NonnullGCPtr<HTMLCollection> scripts(); + JS::NonnullGCPtr<HTMLCollection> all(); String const& source() const { return m_source; } void set_source(String const& source) { m_source = source; } @@ -494,6 +495,7 @@ private: JS::GCPtr<HTMLCollection> m_links; JS::GCPtr<HTMLCollection> m_forms; JS::GCPtr<HTMLCollection> m_scripts; + JS::GCPtr<HTMLCollection> m_all; }; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index a7d979c220..f479068872 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -69,6 +69,9 @@ interface Document : Node { readonly attribute HTMLCollection forms; readonly attribute HTMLCollection scripts; + // FIXME: Should return an HTMLAllCollection + readonly attribute HTMLCollection all; + Element createElement(DOMString tagName); Element createElementNS(DOMString? namespace, DOMString qualifiedName); DocumentFragment createDocumentFragment(); |