DeclarationOrAtRule.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
  8. #include <LibWeb/CSS/Parser/StyleRule.h>
  9. namespace Web::CSS {
  10. class DeclarationOrAtRule {
  11. friend class Parser;
  12. public:
  13. explicit DeclarationOrAtRule(RefPtr<StyleRule> at);
  14. explicit DeclarationOrAtRule(StyleDeclarationRule declaration);
  15. ~DeclarationOrAtRule();
  16. enum class DeclarationType {
  17. At,
  18. Declaration,
  19. };
  20. bool is_at_rule() const { return m_type == DeclarationType::At; }
  21. bool is_declaration() const { return m_type == DeclarationType::Declaration; }
  22. StyleRule const& at_rule() const
  23. {
  24. VERIFY(is_at_rule());
  25. return *m_at;
  26. }
  27. StyleDeclarationRule const& declaration() const
  28. {
  29. VERIFY(is_declaration());
  30. return m_declaration;
  31. }
  32. String to_string() const;
  33. private:
  34. DeclarationType m_type;
  35. RefPtr<StyleRule> m_at;
  36. StyleDeclarationRule m_declaration;
  37. };
  38. }