CSSStyleSheet.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2019-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/CSS/CSSStyleSheet.h>
  7. #include <LibWeb/DOM/ExceptionOr.h>
  8. namespace Web::CSS {
  9. CSSStyleSheet::CSSStyleSheet(NonnullRefPtrVector<CSSRule> rules)
  10. : m_rules(CSSRuleList::create(move(rules)))
  11. {
  12. }
  13. CSSStyleSheet::~CSSStyleSheet()
  14. {
  15. }
  16. // https://drafts.csswg.org/cssom/#dom-cssstylesheet-insertrule
  17. DOM::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsigned index)
  18. {
  19. // FIXME: 1. If the origin-clean flag is unset, throw a SecurityError exception.
  20. // FIXME: 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
  21. // Let parsed rule be the return value of invoking parse a rule with rule.
  22. // If parsed rule is a syntax error, return parsed rule.
  23. // If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException.
  24. // Return the result of invoking insert a CSS rule rule in the CSS rules at index.
  25. (void)index;
  26. (void)rule;
  27. TODO();
  28. }
  29. // https://drafts.csswg.org/cssom/#dom-cssstylesheet-deleterule
  30. DOM::ExceptionOr<void> CSSStyleSheet::delete_rule(unsigned index)
  31. {
  32. // FIXME: 1. If the origin-clean flag is unset, throw a SecurityError exception.
  33. // FIXME: 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
  34. // 3. Remove a CSS rule in the CSS rules at index.
  35. return m_rules->remove_a_css_rule(index);
  36. }
  37. // https://drafts.csswg.org/cssom/#dom-cssstylesheet-removerule
  38. DOM::ExceptionOr<void> CSSStyleSheet::remove_rule(unsigned index)
  39. {
  40. // The removeRule(index) method must run the same steps as deleteRule().
  41. return delete_rule(index);
  42. }
  43. }