diff --git a/Tests/LibWeb/Text/expected/HTML/map-element.txt b/Tests/LibWeb/Text/expected/HTML/map-element.txt new file mode 100644 index 00000000000..814ea015591 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/map-element.txt @@ -0,0 +1,2 @@ +1. 10 +2. 11 diff --git a/Tests/LibWeb/Text/input/HTML/map-element.html b/Tests/LibWeb/Text/input/HTML/map-element.html new file mode 100644 index 00000000000..d424a8924d4 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/map-element.html @@ -0,0 +1,35 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp index 99515fa882b..6fa6712b2a5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace Web::HTML { @@ -24,4 +25,22 @@ void HTMLMapElement::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLMapElement); } +void HTMLMapElement::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_areas); +} + +// https://html.spec.whatwg.org/multipage/image-maps.html#dom-map-areas +JS::NonnullGCPtr HTMLMapElement::areas() +{ + // The areas attribute must return an HTMLCollection rooted at the map element, whose filter matches only area elements. + if (!m_areas) { + m_areas = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](Element const& element) { + return is(element); + }); + } + return *m_areas; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.h index 088b63da28b..d6986176ff6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.h @@ -6,6 +6,7 @@ #pragma once +#include #include namespace Web::HTML { @@ -17,10 +18,15 @@ class HTMLMapElement final : public HTMLElement { public: virtual ~HTMLMapElement() override; + JS::NonnullGCPtr areas(); + private: HTMLMapElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; + + JS::GCPtr m_areas; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.idl index 8e074d80c56..ab8427ac129 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.idl @@ -7,6 +7,6 @@ interface HTMLMapElement : HTMLElement { [HTMLConstructor] constructor(); [CEReactions, Reflect] attribute DOMString name; - // FIXME: [SameObject] readonly attribute HTMLCollection areas; + [SameObject] readonly attribute HTMLCollection areas; };