Initial commit of litehtml_viewer
[claws.git] / src / plugins / litehtml_viewer / litehtml / style.h
1 #pragma once\r
2 #include "attributes.h"\r
3 #include <string>\r
4 \r
5 namespace litehtml\r
6 {\r
7         class property_value\r
8         {\r
9         public:\r
10                 tstring m_value;\r
11                 bool                    m_important;\r
12 \r
13                 property_value()\r
14                 {\r
15                         m_important = false;\r
16                 }\r
17                 property_value(const tchar_t* val, bool imp)\r
18                 {\r
19                         m_important = imp;\r
20                         m_value         = val;\r
21                 }\r
22                 property_value(const property_value& val)\r
23                 {\r
24                         m_value         = val.m_value;\r
25                         m_important     = val.m_important;\r
26                 }\r
27 \r
28                 property_value& operator=(const property_value& val)\r
29                 {\r
30                         m_value         = val.m_value;\r
31                         m_important     = val.m_important;\r
32                         return *this;\r
33                 }\r
34         };\r
35 \r
36         typedef std::map<tstring, property_value>       props_map;\r
37 \r
38         class style\r
39         {\r
40         public:\r
41                 typedef std::shared_ptr<style>          ptr;\r
42                 typedef std::vector<style::ptr>         vector;\r
43         private:\r
44                 props_map                       m_properties;\r
45                 static string_map       m_valid_values;\r
46         public:\r
47                 style();\r
48                 style(const style& val);\r
49                 virtual ~style();\r
50 \r
51                 void operator=(const style& val)\r
52                 {\r
53                         m_properties = val.m_properties;\r
54                 }\r
55 \r
56                 void add(const tchar_t* txt, const tchar_t* baseurl)\r
57                 {\r
58                         parse(txt, baseurl);\r
59                 }\r
60 \r
61                 void add_property(const tchar_t* name, const tchar_t* val, const tchar_t* baseurl, bool important);\r
62 \r
63                 const tchar_t* get_property(const tchar_t* name) const\r
64                 {\r
65                         if(name)\r
66                         {\r
67                                 props_map::const_iterator f = m_properties.find(name);\r
68                                 if(f != m_properties.end())\r
69                                 {\r
70                                         return f->second.m_value.c_str();\r
71                                 }\r
72                         }\r
73                         return 0;\r
74                 }\r
75 \r
76                 void combine(const litehtml::style& src);\r
77                 void clear()\r
78                 {\r
79                         m_properties.clear();\r
80                 }\r
81 \r
82         private:\r
83                 void parse_property(const tstring& txt, const tchar_t* baseurl);\r
84                 void parse(const tchar_t* txt, const tchar_t* baseurl);\r
85                 void parse_short_border(const tstring& prefix, const tstring& val, bool important);\r
86                 void parse_short_background(const tstring& val, const tchar_t* baseurl, bool important);\r
87                 void parse_short_font(const tstring& val, bool important);\r
88                 void add_parsed_property(const tstring& name, const tstring& val, bool important);\r
89                 void remove_property(const tstring& name, bool important);\r
90         };\r
91 }