CSSRule.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/DeprecatedString.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. Supports = 12,
  25. };
  26. virtual Type type() const = 0;
  27. DeprecatedString css_text() const;
  28. void set_css_text(StringView);
  29. CSSRule* parent_rule() { return m_parent_rule.ptr(); }
  30. void set_parent_rule(CSSRule*);
  31. CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet.ptr(); }
  32. virtual void set_parent_style_sheet(CSSStyleSheet*);
  33. template<typename T>
  34. bool fast_is() const = delete;
  35. protected:
  36. explicit CSSRule(JS::Realm&);
  37. virtual DeprecatedString serialized() const = 0;
  38. virtual void visit_edges(Cell::Visitor&) override;
  39. JS::GCPtr<CSSRule> m_parent_rule;
  40. JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
  41. };
  42. }