StyleSheetList.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/CSS/CSSStyleSheet.h>
  10. namespace Web::CSS {
  11. class StyleSheetList final : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::PlatformObject);
  13. JS_DECLARE_ALLOCATOR(StyleSheetList);
  14. public:
  15. [[nodiscard]] static JS::NonnullGCPtr<StyleSheetList> create(JS::NonnullGCPtr<DOM::Node> document_or_shadow_root);
  16. void add_a_css_style_sheet(CSS::CSSStyleSheet&);
  17. void remove_a_css_style_sheet(CSS::CSSStyleSheet&);
  18. void create_a_css_style_sheet(String type, DOM::Element* owner_node, String media, String title, bool alternate, bool origin_clean, Optional<String> location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet&);
  19. Vector<JS::NonnullGCPtr<CSSStyleSheet>> const& sheets() const { return m_sheets; }
  20. Vector<JS::NonnullGCPtr<CSSStyleSheet>>& sheets() { return m_sheets; }
  21. CSSStyleSheet* item(size_t index) const
  22. {
  23. if (index >= m_sheets.size())
  24. return {};
  25. return const_cast<CSSStyleSheet*>(m_sheets[index].ptr());
  26. }
  27. size_t length() const { return m_sheets.size(); }
  28. virtual Optional<JS::Value> item_value(size_t index) const override;
  29. [[nodiscard]] DOM::Document& document();
  30. [[nodiscard]] DOM::Document const& document() const;
  31. [[nodiscard]] DOM::Node& document_or_shadow_root() { return m_document_or_shadow_root; }
  32. [[nodiscard]] DOM::Node const& document_or_shadow_root() const { return m_document_or_shadow_root; }
  33. private:
  34. explicit StyleSheetList(JS::NonnullGCPtr<DOM::Node> document_or_shadow_root);
  35. virtual void initialize(JS::Realm&) override;
  36. virtual void visit_edges(Cell::Visitor&) override;
  37. void add_sheet(CSSStyleSheet&);
  38. void remove_sheet(CSSStyleSheet&);
  39. JS::NonnullGCPtr<DOM::Node> m_document_or_shadow_root;
  40. Vector<JS::NonnullGCPtr<CSSStyleSheet>> m_sheets;
  41. // https://www.w3.org/TR/cssom/#preferred-css-style-sheet-set-name
  42. String m_preferred_css_style_sheet_set_name;
  43. // https://www.w3.org/TR/cssom/#last-css-style-sheet-set-name
  44. Optional<String> m_last_css_style_sheet_set_name;
  45. };
  46. }