StyleSheetList.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. sheet->set_style_sheet_list({}, this);
  13. m_sheets.append(sheet);
  14. m_document.style_computer().invalidate_rule_cache();
  15. m_document.style_computer().load_fonts_from_sheet(*sheet);
  16. m_document.invalidate_style();
  17. }
  18. void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
  19. {
  20. sheet.set_style_sheet_list({}, nullptr);
  21. m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
  22. m_document.style_computer().invalidate_rule_cache();
  23. m_document.invalidate_style();
  24. }
  25. StyleSheetList::StyleSheetList(DOM::Document& document)
  26. : m_document(document)
  27. {
  28. }
  29. // https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
  30. bool StyleSheetList::is_supported_property_index(u32 index) const
  31. {
  32. // 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.
  33. // If there are no such CSS style sheets, then there are no supported property indices.
  34. if (m_sheets.is_empty())
  35. return false;
  36. return index < m_sheets.size();
  37. }
  38. }