StyleSheetList.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. int generation() const { return m_generation; }
  35. void bump_generation() { ++m_generation; }
  36. private:
  37. explicit StyleSheetList(DOM::Document&);
  38. DOM::Document& m_document;
  39. NonnullRefPtrVector<CSSStyleSheet> m_sheets;
  40. int m_generation { 0 };
  41. };
  42. }
  43. namespace Web::Bindings {
  44. StyleSheetListWrapper* wrap(JS::GlobalObject&, CSS::StyleSheetList&);
  45. }