HTMLSlotElement.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. JS_DECLARE_ALLOCATOR(HTMLSlotElement);
  23. public:
  24. virtual ~HTMLSlotElement() override;
  25. Vector<JS::Handle<DOM::Node>> assigned_nodes(AssignedNodesOptions options = {});
  26. Vector<JS::Handle<DOM::Element>> assigned_elements(AssignedNodesOptions options = {});
  27. using SlottableHandle = Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Text>>;
  28. void assign(Vector<SlottableHandle> nodes);
  29. ReadonlySpan<DOM::Slottable> manually_assigned_nodes() const { return m_manually_assigned_nodes; }
  30. private:
  31. HTMLSlotElement(DOM::Document&, DOM::QualifiedName);
  32. virtual bool is_html_slot_element() const override { return true; }
  33. virtual void initialize(JS::Realm&) override;
  34. virtual void visit_edges(JS::Cell::Visitor&) override;
  35. // https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes
  36. Vector<DOM::Slottable> m_manually_assigned_nodes;
  37. };
  38. }
  39. namespace Web::DOM {
  40. template<>
  41. inline bool Node::fast_is<HTML::HTMLSlotElement>() const { return is_html_slot_element(); }
  42. }