StyleSheetList.cpp 1.3 KB

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