1 #ifndef LITEHTML_FLEX_ITEM_H
2 #define LITEHTML_FLEX_ITEM_H
5 #include "formatting_context.h"
12 * Base class for flex item
17 std::shared_ptr
<render_item
> el
;
20 def_value
<int> max_size
;
24 int scaled_flex_shrink_factor
;
28 def_value
<int> auto_margin_main_start
;
29 def_value
<int> auto_margin_main_end
;
30 bool auto_margin_cross_start
;
31 bool auto_margin_cross_end
;
32 flex_align_items align
;
34 explicit flex_item(std::shared_ptr
<render_item
> &_el
) :
36 align(flex_align_items_auto
),
46 scaled_flex_shrink_factor(0),
47 auto_margin_main_start(0),
48 auto_margin_main_end(0),
49 auto_margin_cross_start(false),
50 auto_margin_cross_end(false)
53 virtual ~flex_item() = default;
55 bool operator<(const flex_item
& b
) const
57 if(order
< b
.order
) return true;
58 if(order
== b
.order
) return src_order
< b
.src_order
;
61 void init(const litehtml::containing_block_context
&self_size
,
62 litehtml::formatting_context
*fmt_ctx
, flex_align_items align_items
);
63 virtual void apply_main_auto_margins() = 0;
64 virtual bool apply_cross_auto_margins(int cross_size
) = 0;
65 virtual void set_main_position(int pos
) = 0;
66 virtual void set_cross_position(int pos
) = 0;
67 virtual int get_el_main_size() = 0;
68 virtual int get_el_cross_size() = 0;
70 void place(flex_line
&ln
, int main_pos
,
71 const containing_block_context
&self_size
,
72 formatting_context
*fmt_ctx
);
73 int get_last_baseline(baseline::_baseline_type type
) const;
74 int get_first_baseline(baseline::_baseline_type type
) const;
77 virtual void direction_specific_init(const litehtml::containing_block_context
&self_size
,
78 litehtml::formatting_context
*fmt_ctx
) = 0;
79 virtual void align_stretch(flex_line
&ln
, const containing_block_context
&self_size
,
80 formatting_context
*fmt_ctx
) = 0;
81 virtual void align_baseline(flex_line
&ln
,
82 const containing_block_context
&self_size
,
83 formatting_context
*fmt_ctx
) = 0;
87 * Flex item with "flex-direction: row" or " flex-direction: row-reverse"
89 class flex_item_row_direction
: public flex_item
92 explicit flex_item_row_direction(std::shared_ptr
<render_item
> &_el
) : flex_item(_el
) {}
94 void apply_main_auto_margins() override
;
95 bool apply_cross_auto_margins(int cross_size
) override
;
96 void set_main_position(int pos
) override
;
97 void set_cross_position(int pos
) override
;
98 int get_el_main_size() override
;
99 int get_el_cross_size() override
;
102 void direction_specific_init(const litehtml::containing_block_context
&self_size
,
103 litehtml::formatting_context
*fmt_ctx
) override
;
104 void align_stretch(flex_line
&ln
, const containing_block_context
&self_size
,
105 formatting_context
*fmt_ctx
) override
;
106 void align_baseline(flex_line
&ln
,
107 const containing_block_context
&self_size
,
108 formatting_context
*fmt_ctx
) override
;
112 * Flex item with "flex-direction: column" or " flex-direction: column-reverse"
114 class flex_item_column_direction
: public flex_item
117 explicit flex_item_column_direction(std::shared_ptr
<render_item
> &_el
) : flex_item(_el
) {}
119 void apply_main_auto_margins() override
;
120 bool apply_cross_auto_margins(int cross_size
) override
;
121 void set_main_position(int pos
) override
;
122 void set_cross_position(int pos
) override
;
123 int get_el_main_size() override
;
124 int get_el_cross_size() override
;
127 void direction_specific_init(const litehtml::containing_block_context
&self_size
,
128 litehtml::formatting_context
*fmt_ctx
) override
;
129 void align_stretch(flex_line
&ln
, const containing_block_context
&self_size
,
130 formatting_context
*fmt_ctx
) override
;
131 void align_baseline(flex_line
&ln
,
132 const containing_block_context
&self_size
,
133 formatting_context
*fmt_ctx
) override
;
137 #endif //LITEHTML_FLEX_ITEM_H