StyleComponentValueRule.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/RefPtr.h>
  10. #include <LibWeb/CSS/Parser/Token.h>
  11. namespace Web::CSS {
  12. class StyleBlockRule;
  13. class StyleFunctionRule;
  14. class StyleComponentValueRule {
  15. friend class Parser;
  16. public:
  17. enum class ComponentType {
  18. Token,
  19. Function,
  20. Block
  21. };
  22. explicit StyleComponentValueRule(ComponentType);
  23. ~StyleComponentValueRule();
  24. bool is_block() const { return m_type == ComponentType::Block; }
  25. StyleBlockRule const& block() const
  26. {
  27. VERIFY(is_block());
  28. return *m_block;
  29. }
  30. bool is_function() const { return m_type == ComponentType::Function; }
  31. StyleFunctionRule const& function() const
  32. {
  33. VERIFY(is_function());
  34. return *m_function;
  35. }
  36. bool is(Token::TokenType type) const
  37. {
  38. return m_type == ComponentType::Token && m_token.is(type);
  39. }
  40. Token const& token() const { return m_token; }
  41. operator Token() const { return m_token; }
  42. String to_string() const;
  43. private:
  44. ComponentType m_type;
  45. Token m_token;
  46. RefPtr<StyleFunctionRule> m_function;
  47. RefPtr<StyleBlockRule> m_block;
  48. };
  49. }