StyleSheetList.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/CSS/StyleSheetList.h>
  7. #include <LibWeb/DOM/Document.h>
  8. namespace Web::CSS {
  9. void StyleSheetList::add_sheet(NonnullRefPtr<CSSStyleSheet> sheet)
  10. {
  11. VERIFY(!m_sheets.contains_slow(sheet));
  12. m_sheets.append(move(sheet));
  13. ++m_generation;
  14. m_document.invalidate_style();
  15. }
  16. void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
  17. {
  18. m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
  19. ++m_generation;
  20. m_document.invalidate_style();
  21. }
  22. StyleSheetList::StyleSheetList(DOM::Document& document)
  23. : m_document(document)
  24. {
  25. }
  26. // https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
  27. bool StyleSheetList::is_supported_property_index(u32 index) const
  28. {
  29. // The object’s supported property indices are the numbers in the range zero to one less than the number of CSS style sheets represented by the collection.
  30. // If there are no such CSS style sheets, then there are no supported property indices.
  31. if (m_sheets.is_empty())
  32. return false;
  33. return index < m_sheets.size();
  34. }
  35. }