| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | #include <AK/AKString.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:58:45 +02:00
										 |  |  | #include <AK/RefCounted.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | #include <AK/RefPtr.h>
 | 
					
						
							|  |  |  | #include <AK/StringView.h>
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | #include <LibHTML/CSS/Length.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 15:29:31 +02:00
										 |  |  | class StyleValue : public RefCounted<StyleValue> { | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     virtual ~StyleValue(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  |     enum class Type { | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  |         Invalid, | 
					
						
							|  |  |  |         Inherit, | 
					
						
							|  |  |  |         Initial, | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  |         String, | 
					
						
							|  |  |  |         Length, | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Type type() const { return m_type; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 07:14:23 +02:00
										 |  |  |     bool is_inherit() const { return type() == Type::Inherit; } | 
					
						
							|  |  |  |     bool is_initial() const { return type() == Type::Initial; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 06:31:47 +02:00
										 |  |  |     virtual String to_string() const = 0; | 
					
						
							| 
									
										
										
										
											2019-07-26 08:05:14 +02:00
										 |  |  |     virtual Length to_length() const { return {}; } | 
					
						
							| 
									
										
										
										
											2019-06-25 06:31:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-18 08:09:56 +02:00
										 |  |  |     virtual bool is_auto() const { return false; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  |     explicit StyleValue(Type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     Type m_type { Type::Invalid }; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | class StringStyleValue : public StyleValue { | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     static NonnullRefPtr<StringStyleValue> create(const String& string) | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |         return adopt(*new StringStyleValue(string)); | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     virtual ~StringStyleValue() override {} | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 06:31:47 +02:00
										 |  |  |     String to_string() const override { return m_string; } | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     explicit StringStyleValue(const String& string) | 
					
						
							|  |  |  |         : StyleValue(Type::String) | 
					
						
							|  |  |  |         , m_string(string) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-22 21:48:21 +02:00
										 |  |  |     String m_string; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class LengthStyleValue : public StyleValue { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     static NonnullRefPtr<LengthStyleValue> create(const Length& length) | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |         return adopt(*new LengthStyleValue(length)); | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     virtual ~LengthStyleValue() override {} | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 08:05:14 +02:00
										 |  |  |     virtual String to_string() const override { return m_length.to_string(); } | 
					
						
							|  |  |  |     virtual Length to_length() const override { return m_length; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Length& length() const { return m_length; } | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-18 08:09:56 +02:00
										 |  |  |     virtual bool is_auto() const override { return m_length.is_auto(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-07-04 15:49:16 +02:00
										 |  |  |     explicit LengthStyleValue(const Length& length) | 
					
						
							|  |  |  |         : StyleValue(Type::Length) | 
					
						
							|  |  |  |         , m_length(length) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:55:22 +02:00
										 |  |  |     Length m_length; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-07-08 07:14:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class InitialStyleValue final : public StyleValue { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static NonnullRefPtr<InitialStyleValue> create() { return adopt(*new InitialStyleValue); } | 
					
						
							|  |  |  |     virtual ~InitialStyleValue() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     String to_string() const override { return "initial"; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     InitialStyleValue() | 
					
						
							|  |  |  |         : StyleValue(Type::Initial) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class InheritStyleValue final : public StyleValue { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static NonnullRefPtr<InheritStyleValue> create() { return adopt(*new InheritStyleValue); } | 
					
						
							|  |  |  |     virtual ~InheritStyleValue() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     String to_string() const override { return "inherit"; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     InheritStyleValue() | 
					
						
							|  |  |  |         : StyleValue(Type::Inherit) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; |