Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / table.h
blobd738b63ebff57ac4f4ac7bc1c63b6a7fab001078
1 #ifndef LH_TABLE_H
2 #define LH_TABLE_H
4 #include <vector>
5 #include <memory>
6 #include "css_length.h"
8 namespace litehtml
10 class render_item;
12 struct table_row
14 typedef std::vector<table_row> vector;
16 int height;
17 int border_top;
18 int border_bottom;
19 std::shared_ptr<render_item> el_row;
20 int top;
21 int bottom;
22 css_length css_height;
23 int min_height;
25 table_row()
27 min_height = 0;
28 top = 0;
29 bottom = 0;
30 border_bottom = 0;
31 border_top = 0;
32 height = 0;
33 el_row = nullptr;
34 css_height.predef(0);
37 table_row(int h, const std::shared_ptr<render_item>& row);
39 table_row(const table_row& val)
41 min_height = val.min_height;
42 top = val.top;
43 bottom = val.bottom;
44 border_bottom = val.border_bottom;
45 border_top = val.border_top;
46 height = val.height;
47 css_height = val.css_height;
48 el_row = val.el_row;
51 table_row(table_row&& val) noexcept
53 min_height = val.min_height;
54 top = val.top;
55 bottom = val.bottom;
56 border_bottom = val.border_bottom;
57 border_top = val.border_top;
58 height = val.height;
59 css_height = val.css_height;
60 el_row = std::move(val.el_row);
64 struct table_column
66 typedef std::vector<table_column> vector;
68 int min_width;
69 int max_width;
70 int width;
71 css_length css_width;
72 int border_left;
73 int border_right;
74 int left;
75 int right;
77 table_column()
79 left = 0;
80 right = 0;
81 border_left = 0;
82 border_right = 0;
83 min_width = 0;
84 max_width = 0;
85 width = 0;
86 css_width.predef(0);
89 table_column(int min_w, int max_w)
91 left = 0;
92 right = 0;
93 border_left = 0;
94 border_right = 0;
95 max_width = max_w;
96 min_width = min_w;
97 width = 0;
98 css_width.predef(0);
101 table_column(const table_column& val)
103 left = val.left;
104 right = val.right;
105 border_left = val.border_left;
106 border_right = val.border_right;
107 max_width = val.max_width;
108 min_width = val.min_width;
109 width = val.width;
110 css_width = val.css_width;
114 class table_column_accessor
116 public:
117 virtual int& get(table_column& col) = 0;
119 protected:
120 ~table_column_accessor() = default;
123 class table_column_accessor_max_width final : public table_column_accessor
125 public:
126 int& get(table_column& col) override;
129 class table_column_accessor_min_width final : public table_column_accessor
131 public:
132 int& get(table_column& col) override;
135 class table_column_accessor_width final : public table_column_accessor
137 public:
138 int& get(table_column& col) override;
141 struct table_cell
143 std::shared_ptr<render_item> el;
144 int colspan;
145 int rowspan;
146 int min_width;
147 int min_height;
148 int max_width;
149 int max_height;
150 int width;
151 int height;
152 margins borders;
154 table_cell()
156 min_width = 0;
157 min_height = 0;
158 max_width = 0;
159 max_height = 0;
160 width = 0;
161 height = 0;
162 colspan = 1;
163 rowspan = 1;
164 el = nullptr;
167 table_cell(const table_cell& val)
169 el = val.el;
170 colspan = val.colspan;
171 rowspan = val.rowspan;
172 width = val.width;
173 height = val.height;
174 min_width = val.min_width;
175 min_height = val.min_height;
176 max_width = val.max_width;
177 max_height = val.max_height;
178 borders = val.borders;
181 table_cell(table_cell&& val) noexcept
183 el = std::move(val.el);
184 colspan = val.colspan;
185 rowspan = val.rowspan;
186 width = val.width;
187 height = val.height;
188 min_width = val.min_width;
189 min_height = val.min_height;
190 max_width = val.max_width;
191 max_height = val.max_height;
192 borders = val.borders;
196 class table_grid
198 public:
199 typedef std::vector< std::vector<table_cell> > rows;
200 private:
201 int m_rows_count;
202 int m_cols_count;
203 rows m_cells;
204 table_column::vector m_columns;
205 table_row::vector m_rows;
206 std::vector<std::shared_ptr<render_item>> m_captions;
207 int m_top_captions_height;
208 int m_bottom_captions_height;
209 public:
211 table_grid() :
212 m_rows_count(0),
213 m_cols_count(0),
214 m_top_captions_height(0),
215 m_bottom_captions_height(0)
219 void clear();
220 void begin_row(const std::shared_ptr<render_item>& row);
221 void add_cell(const std::shared_ptr<render_item>& el);
222 bool is_rowspanned(int r, int c);
223 void finish();
224 table_cell* cell(int t_col, int t_row);
225 table_column& column(int c) { return m_columns[c]; }
226 table_row& row(int r) { return m_rows[r]; }
227 std::vector<std::shared_ptr<render_item>>& captions() { return m_captions; }
229 int rows_count() const { return m_rows_count; }
230 int cols_count() const { return m_cols_count; }
232 void top_captions_height(int height) { m_top_captions_height = height; }
233 int top_captions_height() const { return m_top_captions_height; }
234 void bottom_captions_height(int height) { m_bottom_captions_height = height; }
235 int bottom_captions_height() const { return m_bottom_captions_height; }
237 void distribute_max_width(int width, int start, int end);
238 void distribute_min_width(int width, int start, int end);
239 void distribute_width(int width, int start, int end);
240 void distribute_width(int width, int start, int end, table_column_accessor* acc);
241 int calc_table_width(int block_width, bool is_auto, int& min_table_width, int& max_table_width);
242 void calc_horizontal_positions(const margins& table_borders, border_collapse bc, int bdr_space_x);
243 void calc_vertical_positions(const margins& table_borders, border_collapse bc, int bdr_space_y);
244 void calc_rows_height(int blockHeight, int borderSpacingY);
248 #endif // LH_TABLE_H