StyleSheetList.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtrVector.h>
  8. #include <AK/RefCounted.h>
  9. #include <LibWeb/Bindings/Wrappable.h>
  10. #include <LibWeb/CSS/CSSStyleSheet.h>
  11. #include <LibWeb/Forward.h>
  12. namespace Web::CSS {
  13. class StyleSheetList
  14. : public RefCounted<StyleSheetList>
  15. , public Bindings::Wrappable {
  16. public:
  17. using WrapperType = Bindings::StyleSheetListWrapper;
  18. static NonnullRefPtr<StyleSheetList> create(DOM::Document& document)
  19. {
  20. return adopt_ref(*new StyleSheetList(document));
  21. }
  22. void add_sheet(NonnullRefPtr<CSSStyleSheet>);
  23. void remove_sheet(CSSStyleSheet&);
  24. NonnullRefPtrVector<CSSStyleSheet> const& sheets() const { return m_sheets; }
  25. NonnullRefPtrVector<CSSStyleSheet>& sheets() { return m_sheets; }
  26. RefPtr<CSSStyleSheet> item(size_t index) const
  27. {
  28. if (index >= m_sheets.size())
  29. return {};
  30. return m_sheets[index];
  31. }
  32. size_t length() const { return m_sheets.size(); }
  33. bool is_supported_property_index(u32) const;
  34. private:
  35. explicit StyleSheetList(DOM::Document&);
  36. DOM::Document& m_document;
  37. NonnullRefPtrVector<CSSStyleSheet> m_sheets;
  38. };
  39. }
  40. namespace Web::Bindings {
  41. StyleSheetListWrapper* wrap(JS::GlobalObject&, CSS::StyleSheetList&);
  42. }