HTMLMapElement.cpp 1.3 KB

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