CSSGroupingRule.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Bindings/MainThreadVM.h>
  8. #include <LibWeb/CSS/CSSGroupingRule.h>
  9. #include <LibWeb/CSS/CSSRuleList.h>
  10. #include <LibWeb/HTML/Window.h>
  11. namespace Web::CSS {
  12. CSSGroupingRule::CSSGroupingRule(HTML::Window& window_object, CSSRuleList& rules)
  13. : CSSRule(window_object)
  14. , m_rules(rules)
  15. {
  16. set_prototype(&window_object.cached_web_prototype("CSSGroupingRule"));
  17. for (auto& rule : m_rules)
  18. rule.set_parent_rule(this);
  19. }
  20. void CSSGroupingRule::visit_edges(Cell::Visitor& visitor)
  21. {
  22. Base::visit_edges(visitor);
  23. visitor.visit(&m_rules);
  24. }
  25. WebIDL::ExceptionOr<u32> CSSGroupingRule::insert_rule(StringView rule, u32 index)
  26. {
  27. TRY(m_rules.insert_a_css_rule(rule, index));
  28. // NOTE: The spec doesn't say where to set the parent rule, so we'll do it here.
  29. m_rules.item(index)->set_parent_rule(this);
  30. return index;
  31. }
  32. WebIDL::ExceptionOr<void> CSSGroupingRule::delete_rule(u32 index)
  33. {
  34. return m_rules.remove_a_css_rule(index);
  35. }
  36. void CSSGroupingRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
  37. {
  38. m_rules.for_each_effective_style_rule(callback);
  39. }
  40. void CSSGroupingRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet)
  41. {
  42. CSSRule::set_parent_style_sheet(parent_style_sheet);
  43. for (auto& rule : m_rules)
  44. rule.set_parent_style_sheet(parent_style_sheet);
  45. }
  46. }