Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / style.h
blobc83876ad6d41bcd91e8ac92a1836815f1289e343
1 #ifndef LH_STYLE_H
2 #define LH_STYLE_H
4 namespace litehtml
6 enum property_type
8 prop_type_invalid, // indicates "not found" condition in style::get_property
9 prop_type_inherit, // "inherit" was specified as the value of this property
11 prop_type_enum_item,
12 prop_type_enum_item_vector,
13 prop_type_length,
14 prop_type_length_vector,
15 prop_type_number,
16 prop_type_color,
17 prop_type_string,
18 prop_type_string_vector,
19 prop_type_size_vector,
21 prop_type_var, // also string, but needs further parsing because of var()
24 class property_value
26 public:
27 property_type m_type;
28 bool m_important;
30 union {
31 int m_enum_item;
32 int_vector m_enum_item_vector;
33 css_length m_length;
34 length_vector m_length_vector;
35 float m_number;
36 web_color m_color;
37 string m_string;
38 string_vector m_string_vector;
39 size_vector m_size_vector;
42 property_value()
43 : m_type(prop_type_invalid)
46 property_value(bool important, property_type type)
47 : m_type(type), m_important(important)
50 property_value(const string& str, bool important, property_type type = prop_type_string)
51 : m_string(str), m_type(type), m_important(important)
54 property_value(const string_vector& vec, bool important)
55 : m_string_vector(vec), m_type(prop_type_string_vector), m_important(important)
58 property_value(const css_length& length, bool important)
59 : m_length(length), m_type(prop_type_length), m_important(important)
62 property_value(const length_vector& vec, bool important)
63 : m_length_vector(vec), m_type(prop_type_length_vector), m_important(important)
66 property_value(float number, bool important)
67 : m_number(number), m_type(prop_type_number), m_important(important)
70 property_value(int enum_item, bool important)
71 : m_enum_item(enum_item), m_type(prop_type_enum_item), m_important(important)
74 property_value(const int_vector& vec, bool important)
75 : m_enum_item_vector(vec), m_type(prop_type_enum_item_vector), m_important(important)
78 property_value(web_color color, bool important)
79 : m_color(color), m_type(prop_type_color), m_important(important)
82 property_value(const size_vector& vec, bool important)
83 : m_size_vector(vec), m_type(prop_type_size_vector), m_important(important)
86 ~property_value()
88 switch (m_type)
90 case prop_type_string:
91 case prop_type_var:
92 m_string.~string();
93 break;
94 case prop_type_string_vector:
95 m_string_vector.~string_vector();
96 break;
97 case prop_type_length:
98 m_length.~css_length();
99 break;
100 case prop_type_length_vector:
101 m_length_vector.~length_vector();
102 break;
103 case prop_type_enum_item_vector:
104 m_enum_item_vector.~int_vector();
105 break;
106 case prop_type_color:
107 m_color.~web_color();
108 break;
109 case prop_type_size_vector:
110 m_size_vector.~size_vector();
111 break;
114 property_value& operator=(const property_value& val)
116 this->~property_value();
118 switch (val.m_type)
120 case prop_type_invalid:
121 new(this) property_value();
122 break;
123 case prop_type_inherit:
124 new(this) property_value(val.m_important, val.m_type);
125 break;
126 case prop_type_string:
127 case prop_type_var:
128 new(this) property_value(val.m_string, val.m_important, val.m_type);
129 break;
130 case prop_type_string_vector:
131 new(this) property_value(val.m_string_vector, val.m_important);
132 break;
133 case prop_type_enum_item:
134 new(this) property_value(val.m_enum_item, val.m_important);
135 break;
136 case prop_type_enum_item_vector:
137 new(this) property_value(val.m_enum_item_vector, val.m_important);
138 break;
139 case prop_type_length:
140 new(this) property_value(val.m_length, val.m_important);
141 break;
142 case prop_type_length_vector:
143 new(this) property_value(val.m_length_vector, val.m_important);
144 break;
145 case prop_type_number:
146 new(this) property_value(val.m_number, val.m_important);
147 break;
148 case prop_type_color:
149 new(this) property_value(val.m_color, val.m_important);
150 break;
151 case prop_type_size_vector:
152 new(this) property_value(val.m_size_vector, val.m_important);
153 break;
156 return *this;
160 typedef std::map<string_id, property_value> props_map;
162 class style
164 public:
165 typedef std::shared_ptr<style> ptr;
166 typedef std::vector<style::ptr> vector;
167 private:
168 props_map m_properties;
169 static std::map<string_id, string> m_valid_values;
170 public:
171 void add(const string& txt, const string& baseurl = "", document_container* container = nullptr)
173 parse(txt, baseurl, container);
176 void add_property(string_id name, const string& val, const string& baseurl = "", bool important = false, document_container* container = nullptr);
178 const property_value& get_property(string_id name) const;
180 void combine(const style& src);
181 void clear()
183 m_properties.clear();
186 void subst_vars(const element* el);
188 private:
189 void parse_property(const string& txt, const string& baseurl, document_container* container);
190 void parse(const string& txt, const string& baseurl, document_container* container);
191 void parse_background(const string& val, const string& baseurl, bool important, document_container* container);
192 bool parse_one_background(const string& val, document_container* container, background& bg);
193 void parse_background_image(const string& val, const string& baseurl, bool important);
194 // parse comma-separated list of keywords
195 void parse_keyword_comma_list(string_id name, const string& val, bool important);
196 void parse_background_position(const string& val, bool important);
197 bool parse_one_background_position(const string& val, css_length& x, css_length& y);
198 void parse_background_size(const string& val, bool important);
199 bool parse_one_background_size(const string& val, css_size& size);
200 void parse_font(const string& val, bool important);
201 void parse_flex(const string& val, bool important);
202 static css_length parse_border_width(const string& str);
203 static void parse_two_lengths(const string& str, css_length len[2]);
204 static int parse_four_lengths(const string& str, css_length len[4]);
205 static void subst_vars_(string& str, const element* el);
207 void add_parsed_property(string_id name, const property_value& propval);
208 void remove_property(string_id name, bool important);
212 #endif // LH_STYLE_H