StyleRule.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/FlyString.h>
  9. #include <AK/RefCounted.h>
  10. #include <AK/Vector.h>
  11. #include <LibWeb/CSS/Parser/Block.h>
  12. #include <LibWeb/CSS/Parser/ComponentValue.h>
  13. namespace Web::CSS::Parser {
  14. class StyleRule : public RefCounted<StyleRule> {
  15. public:
  16. enum class Type {
  17. At,
  18. Qualified,
  19. };
  20. static NonnullRefPtr<StyleRule> make_at_rule(FlyString name, Vector<ComponentValue> prelude, RefPtr<Block> block)
  21. {
  22. return adopt_ref(*new StyleRule(Type::At, move(name), move(prelude), move(block)));
  23. }
  24. static NonnullRefPtr<StyleRule> make_qualified_rule(Vector<ComponentValue> prelude, RefPtr<Block> block)
  25. {
  26. return adopt_ref(*new StyleRule(Type::Qualified, {}, move(prelude), move(block)));
  27. }
  28. ~StyleRule();
  29. bool is_qualified_rule() const { return m_type == Type::Qualified; }
  30. bool is_at_rule() const { return m_type == Type::At; }
  31. Vector<ComponentValue> const& prelude() const { return m_prelude; }
  32. RefPtr<Block const> block() const { return m_block; }
  33. StringView at_rule_name() const { return m_at_rule_name; }
  34. String to_string() const;
  35. private:
  36. StyleRule(Type, FlyString name, Vector<ComponentValue> prelude, RefPtr<Block>);
  37. Type const m_type;
  38. FlyString m_at_rule_name;
  39. Vector<ComponentValue> m_prelude;
  40. RefPtr<Block> m_block;
  41. };
  42. }