HTMLSlotElement.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. virtual void attribute_change_steps(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
  36. // https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes
  37. Vector<DOM::Slottable> m_manually_assigned_nodes;
  38. };
  39. }
  40. namespace Web::DOM {
  41. template<>
  42. inline bool Node::fast_is<HTML::HTMLSlotElement>() const { return is_html_slot_element(); }
  43. }