HTMLTableRowElement.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/HTMLCollection.h>
  7. #include <LibWeb/HTML/HTMLTableCellElement.h>
  8. #include <LibWeb/HTML/HTMLTableRowElement.h>
  9. namespace Web::HTML {
  10. HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. }
  14. HTMLTableRowElement::~HTMLTableRowElement() = default;
  15. // https://html.spec.whatwg.org/multipage/tables.html#dom-tr-cells
  16. NonnullRefPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
  17. {
  18. // The cells attribute must return an HTMLCollection rooted at this tr element,
  19. // whose filter matches only td and th elements that are children of the tr element.
  20. // FIXME: This should return the same HTMLCollection object every time,
  21. // but that would cause a reference cycle since HTMLCollection refs the root.
  22. return DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) {
  23. return element.parent() == this
  24. && is<HTMLTableCellElement>(element);
  25. });
  26. }
  27. }