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