CSSRule.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <AK/String.h>
  9. #include <AK/Weakable.h>
  10. #include <LibWeb/Bindings/Wrappable.h>
  11. #include <LibWeb/CSS/CSSStyleDeclaration.h>
  12. #include <LibWeb/CSS/Selector.h>
  13. namespace Web::CSS {
  14. class CSSRule
  15. : public RefCounted<CSSRule>
  16. , public Bindings::Wrappable
  17. , public Weakable<CSSRule> {
  18. public:
  19. using WrapperType = Bindings::CSSRuleWrapper;
  20. virtual ~CSSRule() = default;
  21. // https://drafts.csswg.org/cssom/#dom-cssrule-type
  22. enum class Type : u16 {
  23. Style = 1,
  24. Import = 3,
  25. Media = 4,
  26. FontFace = 5,
  27. Supports = 12,
  28. };
  29. virtual StringView class_name() const = 0;
  30. virtual Type type() const = 0;
  31. String css_text() const;
  32. void set_css_text(StringView);
  33. CSSRule* parent_rule() { return m_parent_rule; }
  34. void set_parent_rule(CSSRule*);
  35. CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet; }
  36. virtual void set_parent_style_sheet(CSSStyleSheet*);
  37. template<typename T>
  38. bool fast_is() const = delete;
  39. protected:
  40. virtual String serialized() const = 0;
  41. WeakPtr<CSSRule> m_parent_rule;
  42. WeakPtr<CSSStyleSheet> m_parent_style_sheet;
  43. };
  44. }