Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / line_box.h
blob43f5d439e9f9cd39da7da5bf6706057b07d19799
1 #ifndef LH_LINE_BOX_H
2 #define LH_LINE_BOX_H
4 #include <vector>
5 #include <memory>
6 #include "os_types.h"
7 #include "types.h"
9 namespace litehtml
11 class render_item;
13 struct line_context
15 int calculatedTop;
16 int top;
17 int left;
18 int right;
20 int width() const
22 return right - left;
24 void fix_top()
26 calculatedTop = top;
30 class line_box_item
32 public:
33 enum element_type
35 type_text_part,
36 type_inline_start,
37 type_inline_continue,
38 type_inline_end
40 protected:
41 std::shared_ptr<render_item> m_element;
42 int m_rendered_min_width;
43 public:
44 explicit line_box_item(const std::shared_ptr<render_item>& element) : m_element(element), m_rendered_min_width(0) {}
45 line_box_item() = default;
46 line_box_item(const line_box_item& el) = default;
47 line_box_item(line_box_item&&) = default;
49 int height() const { return right() - left(); }
50 const std::shared_ptr<render_item>& get_el() const { return m_element; }
51 virtual position& pos();
52 virtual void place_to(int x, int y);
53 virtual int width() const;
54 virtual int top() const;
55 virtual int bottom() const;
56 virtual int right() const;
57 virtual int left() const;
58 virtual element_type get_type() const { return type_text_part; }
59 virtual int get_rendered_min_width() const { return m_rendered_min_width; }
60 virtual void set_rendered_min_width(int min_width) { m_rendered_min_width = min_width; }
63 class lbi_start : public line_box_item
65 protected:
66 position m_pos;
67 public:
68 explicit lbi_start(const std::shared_ptr<render_item>& element);
70 void place_to(int x, int y) override;
71 int width() const override;
72 position& pos() override { return m_pos; }
73 int top() const override;
74 int bottom() const override;
75 int right() const override;
76 int left() const override;
77 element_type get_type() const override { return type_inline_start; }
78 int get_rendered_min_width() const override { return width(); }
81 class lbi_end : public lbi_start
83 public:
84 explicit lbi_end(const std::shared_ptr<render_item>& element);
86 void place_to(int x, int y) override;
87 int right() const override;
88 int left() const override;
89 element_type get_type() const override { return type_inline_end; }
92 class lbi_continue : public lbi_start
94 public:
95 explicit lbi_continue(const std::shared_ptr<render_item>& element);
97 void place_to(int x, int y) override;
98 int right() const override;
99 int left() const override;
100 int width() const override;
101 element_type get_type() const override { return type_inline_continue; }
104 class line_box
106 struct va_context
108 int baseline;
109 font_metrics fm;
111 va_context() : baseline(0) {}
114 int m_top;
115 int m_left;
116 int m_right;
117 int m_height;
118 int m_width;
119 int m_line_height;
120 int m_default_line_height;
121 font_metrics m_font_metrics;
122 int m_baseline;
123 text_align m_text_align;
124 int m_min_width;
125 std::list< std::unique_ptr<line_box_item> > m_items;
126 public:
127 line_box(int top, int left, int right, int line_height, const font_metrics& fm, text_align align) :
128 m_top(top),
129 m_left(left),
130 m_right(right),
131 m_height(0),
132 m_width(0),
133 m_font_metrics(fm),
134 m_default_line_height(line_height),
135 m_baseline(0),
136 m_line_height(0),
137 m_text_align(align),
138 m_min_width(0)
142 int bottom() const { return m_top + height(); }
143 int top() const { return m_top; }
144 int right() const { return m_left + width(); }
145 int left() const { return m_left; }
146 int height() const { return m_height; }
147 int width() const { return m_width; }
148 int line_right() const { return m_right; }
149 int min_width() const { return m_min_width; }
151 void add_item(std::unique_ptr<line_box_item> item);
152 bool can_hold(const std::unique_ptr<line_box_item>& item, white_space ws) const;
153 bool is_empty() const;
154 int baseline() const;
155 int top_margin() const;
156 int bottom_margin() const;
157 void y_shift(int shift);
158 std::list< std::unique_ptr<line_box_item> > finish(bool last_box, const containing_block_context &containing_block_size);
159 std::list< std::unique_ptr<line_box_item> > new_width(int left, int right);
160 std::shared_ptr<render_item> get_last_text_part() const;
161 std::shared_ptr<render_item> get_first_text_part() const;
162 std::list< std::unique_ptr<line_box_item> >& items() { return m_items; }
163 private:
164 bool have_last_space() const;
165 bool is_break_only() const;
166 static int calc_va_baseline(const va_context& current, vertical_align va, const font_metrics& new_font, int top, int bottom);
170 #endif //LH_LINE_BOX_H