StyleSheetList.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.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/LegacyPlatformObject.h>
  9. #include <LibWeb/CSS/CSSStyleSheet.h>
  10. namespace Web::CSS {
  11. class StyleSheetList : public Bindings::LegacyPlatformObject {
  12. WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::LegacyPlatformObject);
  13. public:
  14. static WebIDL::ExceptionOr<JS::NonnullGCPtr<StyleSheetList>> create(DOM::Document& document);
  15. void add_sheet(CSSStyleSheet&);
  16. void remove_sheet(CSSStyleSheet&);
  17. Vector<JS::NonnullGCPtr<CSSStyleSheet>> const& sheets() const { return m_sheets; }
  18. Vector<JS::NonnullGCPtr<CSSStyleSheet>>& sheets() { return m_sheets; }
  19. CSSStyleSheet* item(size_t index) const
  20. {
  21. if (index >= m_sheets.size())
  22. return {};
  23. return const_cast<CSSStyleSheet*>(m_sheets[index].ptr());
  24. }
  25. size_t length() const { return m_sheets.size(); }
  26. virtual bool is_supported_property_index(u32 index) const override;
  27. virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
  28. DOM::Document& document() { return m_document; }
  29. DOM::Document const& document() const { return m_document; }
  30. private:
  31. explicit StyleSheetList(DOM::Document&);
  32. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  33. virtual void visit_edges(Cell::Visitor&) override;
  34. // ^Bindings::LegacyPlatformObject
  35. virtual bool supports_indexed_properties() const override { return true; }
  36. virtual bool supports_named_properties() const override { return false; }
  37. virtual bool has_indexed_property_setter() const override { return false; }
  38. virtual bool has_named_property_setter() const override { return false; }
  39. virtual bool has_named_property_deleter() const override { return false; }
  40. virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
  41. virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
  42. virtual bool has_global_interface_extended_attribute() const override { return false; }
  43. virtual bool indexed_property_setter_has_identifier() const override { return false; }
  44. virtual bool named_property_setter_has_identifier() const override { return false; }
  45. virtual bool named_property_deleter_has_identifier() const override { return false; }
  46. void sort_sheets();
  47. JS::NonnullGCPtr<DOM::Document> m_document;
  48. Vector<JS::NonnullGCPtr<CSSStyleSheet>> m_sheets;
  49. };
  50. }