HTMLMapElement.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/HTML/HTMLAreaElement.h>
  8. #include <LibWeb/HTML/HTMLMapElement.h>
  9. namespace Web::HTML {
  10. JS_DEFINE_ALLOCATOR(HTMLMapElement);
  11. HTMLMapElement::HTMLMapElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLMapElement::~HTMLMapElement() = default;
  16. void HTMLMapElement::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLMapElement);
  20. }
  21. void HTMLMapElement::visit_edges(Cell::Visitor& visitor)
  22. {
  23. Base::visit_edges(visitor);
  24. visitor.visit(m_areas);
  25. }
  26. // https://html.spec.whatwg.org/multipage/image-maps.html#dom-map-areas
  27. JS::NonnullGCPtr<DOM::HTMLCollection> HTMLMapElement::areas()
  28. {
  29. // The areas attribute must return an HTMLCollection rooted at the map element, whose filter matches only area elements.
  30. if (!m_areas) {
  31. m_areas = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](Element const& element) {
  32. return is<HTML::HTMLAreaElement>(element);
  33. });
  34. }
  35. return *m_areas;
  36. }
  37. }