CSSRule.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/String.h>
  9. #include <LibJS/Heap/GCPtr.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/CSS/CSSStyleDeclaration.h>
  12. #include <LibWeb/CSS/Selector.h>
  13. namespace Web::CSS {
  14. class CSSRule : public Bindings::PlatformObject {
  15. WEB_PLATFORM_OBJECT(CSSRule, Bindings::PlatformObject);
  16. public:
  17. virtual ~CSSRule() = default;
  18. // https://drafts.csswg.org/cssom/#dom-cssrule-type
  19. enum class Type : u16 {
  20. Style = 1,
  21. Import = 3,
  22. Media = 4,
  23. FontFace = 5,
  24. Keyframes = 7,
  25. Keyframe = 8,
  26. Namespace = 10,
  27. Supports = 12,
  28. };
  29. virtual Type type() const = 0;
  30. String css_text() const;
  31. void set_css_text(StringView);
  32. CSSRule* parent_rule() { return m_parent_rule.ptr(); }
  33. void set_parent_rule(CSSRule*);
  34. CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet.ptr(); }
  35. virtual void set_parent_style_sheet(CSSStyleSheet*);
  36. template<typename T>
  37. bool fast_is() const = delete;
  38. protected:
  39. explicit CSSRule(JS::Realm&);
  40. virtual String serialized() const = 0;
  41. virtual void visit_edges(Cell::Visitor&) override;
  42. JS::GCPtr<CSSRule> m_parent_rule;
  43. JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
  44. };
  45. }