ShadowRoot.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/DocumentFragment.h>
  8. namespace Web::DOM {
  9. class ShadowRoot final : public DocumentFragment {
  10. public:
  11. ShadowRoot(Document&, Element&);
  12. bool closed() const { return m_closed; }
  13. bool delegates_focus() const { return m_delegates_focus; }
  14. void set_delegates_focus(bool delegates_focus) { m_delegates_focus = delegates_focus; }
  15. bool available_to_element_internals() const { return m_available_to_element_internals; }
  16. void set_available_to_element_internals(bool available_to_element_internals) { m_available_to_element_internals = available_to_element_internals; }
  17. // ^EventTarget
  18. virtual EventTarget* get_parent(const Event&) override;
  19. // NOTE: This is intended for the JS bindings.
  20. String mode() const { return m_closed ? "closed" : "open"; }
  21. String inner_html() const;
  22. ExceptionOr<void> set_inner_html(String const&);
  23. private:
  24. // ^Node
  25. virtual FlyString node_name() const override { return "#shadow-root"; }
  26. virtual bool is_shadow_root() const final { return true; }
  27. // NOTE: The specification doesn't seem to specify a default value for closed. Assuming false for now.
  28. bool m_closed { false };
  29. bool m_delegates_focus { false };
  30. bool m_available_to_element_internals { false };
  31. };
  32. template<>
  33. inline bool Node::fast_is<ShadowRoot>() const { return is_shadow_root(); }
  34. }