Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / css_length.h
blobae787105af13e2c717605caaf135990935984c71
1 #ifndef LH_CSS_LENGTH_H
2 #define LH_CSS_LENGTH_H
4 #include "types.h"
6 namespace litehtml
8 class css_length
10 union
12 float m_value;
13 int m_predef;
15 css_units m_units;
16 bool m_is_predefined;
17 public:
18 css_length();
19 css_length(float val, css_units units = css_units_px);
20 css_length& operator=(float val);
22 bool is_predefined() const;
23 void predef(int val);
24 int predef() const;
25 static css_length predef_value(int val = 0);
26 void set_value(float val, css_units units);
27 float val() const;
28 css_units units() const;
29 int calc_percent(int width) const;
30 void fromString(const string& str, const string& predefs = "", int defValue = 0);
31 static css_length from_string(const string& str, const string& predefs = "", int defValue = 0);
32 string to_string() const;
35 using length_vector = std::vector<css_length>;
37 // css_length inlines
39 inline css_length::css_length()
41 m_value = 0;
42 m_predef = 0;
43 m_units = css_units_none;
44 m_is_predefined = false;
47 inline css_length::css_length(float val, css_units units)
49 m_value = val;
50 m_units = units;
51 m_is_predefined = false;
54 inline css_length& css_length::operator=(float val)
56 m_value = val;
57 m_units = css_units_px;
58 m_is_predefined = false;
59 return *this;
62 inline bool css_length::is_predefined() const
64 return m_is_predefined;
67 inline void css_length::predef(int val)
69 m_predef = val;
70 m_is_predefined = true;
73 inline int css_length::predef() const
75 if(m_is_predefined)
77 return m_predef;
79 return 0;
82 inline void css_length::set_value(float val, css_units units)
84 m_value = val;
85 m_is_predefined = false;
86 m_units = units;
89 inline float css_length::val() const
91 if(!m_is_predefined)
93 return m_value;
95 return 0;
98 inline css_units css_length::units() const
100 return m_units;
103 inline int css_length::calc_percent(int width) const
105 if(!is_predefined())
107 if(units() == css_units_percentage)
109 return (int) ((double) width * (double) m_value / 100.0);
110 } else
112 return (int) val();
115 return 0;
119 #endif // LH_CSS_LENGTH_H