StyleSheetList.h 2.6 KB

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