HTMLSlotElement.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Variant.h>
  9. #include <AK/Vector.h>
  10. #include <LibJS/Heap/Handle.h>
  11. #include <LibWeb/DOM/Slot.h>
  12. #include <LibWeb/DOM/Slottable.h>
  13. #include <LibWeb/HTML/HTMLElement.h>
  14. namespace Web::HTML {
  15. struct AssignedNodesOptions {
  16. bool flatten { false };
  17. };
  18. class HTMLSlotElement final
  19. : public HTMLElement
  20. , public DOM::Slot {
  21. WEB_PLATFORM_OBJECT(HTMLSlotElement, HTMLElement);
  22. public:
  23. virtual ~HTMLSlotElement() override;
  24. Vector<JS::Handle<DOM::Node>> assigned_nodes(AssignedNodesOptions options = {});
  25. Vector<JS::Handle<DOM::Element>> assigned_elements(AssignedNodesOptions options = {});
  26. using SlottableHandle = Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Text>>;
  27. void assign(Vector<SlottableHandle> nodes);
  28. ReadonlySpan<DOM::Slottable> manually_assigned_nodes() const { return m_manually_assigned_nodes; }
  29. private:
  30. HTMLSlotElement(DOM::Document&, DOM::QualifiedName);
  31. virtual void initialize(JS::Realm&) override;
  32. virtual void visit_edges(JS::Cell::Visitor&) override;
  33. // https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes
  34. Vector<DOM::Slottable> m_manually_assigned_nodes;
  35. };
  36. }