Rule.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2023, 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 Rule : public RefCounted<Rule> {
  15. public:
  16. enum class Type {
  17. At,
  18. Qualified,
  19. };
  20. static NonnullRefPtr<Rule> make_at_rule(FlyString name, Vector<ComponentValue> prelude, RefPtr<Block> block)
  21. {
  22. return adopt_ref(*new Rule(Type::At, move(name), move(prelude), move(block)));
  23. }
  24. static NonnullRefPtr<Rule> make_qualified_rule(Vector<ComponentValue> prelude, RefPtr<Block> block)
  25. {
  26. return adopt_ref(*new Rule(Type::Qualified, {}, move(prelude), move(block)));
  27. }
  28. ~Rule();
  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. private:
  35. Rule(Type, FlyString name, Vector<ComponentValue> prelude, RefPtr<Block>);
  36. Type const m_type;
  37. FlyString m_at_rule_name;
  38. Vector<ComponentValue> m_prelude;
  39. RefPtr<Block> m_block;
  40. };
  41. }