StyleValue.h 858 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <AK/AKString.h>
  3. #include <AK/RefCounted.h>
  4. #include <AK/RefPtr.h>
  5. #include <AK/StringView.h>
  6. class StyleValue : public RefCounted<StyleValue> {
  7. public:
  8. static NonnullRefPtr<StyleValue> parse(const StringView&);
  9. virtual ~StyleValue();
  10. enum Type {
  11. Invalid,
  12. Inherit,
  13. Initial,
  14. Primitive,
  15. };
  16. Type type() const { return m_type; }
  17. virtual String to_string() const = 0;
  18. protected:
  19. explicit StyleValue(Type);
  20. private:
  21. Type m_type { Type::Invalid };
  22. };
  23. class PrimitiveStyleValue : public StyleValue {
  24. public:
  25. virtual ~PrimitiveStyleValue() override {}
  26. PrimitiveStyleValue(const String& string)
  27. : StyleValue(Type::Primitive)
  28. , m_string(string)
  29. {
  30. }
  31. String to_string() const override { return m_string; }
  32. private:
  33. String m_string;
  34. };