StyleComponentValueRule.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 <LibWeb/CSS/Parser/StyleBlockRule.h>
  9. #include <LibWeb/CSS/Parser/StyleFunctionRule.h>
  10. #include <LibWeb/CSS/Parser/Token.h>
  11. namespace Web::CSS {
  12. class StyleComponentValueRule {
  13. friend class Parser;
  14. public:
  15. enum class ComponentType {
  16. Token,
  17. Function,
  18. Block
  19. };
  20. explicit StyleComponentValueRule(ComponentType);
  21. ~StyleComponentValueRule();
  22. bool is_block() const { return m_type == ComponentType::Block; }
  23. StyleBlockRule const& block() const { return m_block; }
  24. bool is_function() const { return m_type == ComponentType::Function; }
  25. StyleFunctionRule const& function() const { return m_function; }
  26. bool is(Token::TokenType type) const
  27. {
  28. return m_type == ComponentType::Token && m_token.is(type);
  29. }
  30. Token const& token() const { return m_token; }
  31. operator Token() const { return m_token; }
  32. String to_string() const;
  33. private:
  34. ComponentType m_type;
  35. Token m_token;
  36. StyleFunctionRule m_function;
  37. StyleBlockRule m_block;
  38. };
  39. }