Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cca0547

Browse filesBrowse files
committed
flexbox: some tests are resolved
1 parent ef70eef commit cca0547
Copy full SHA for cca0547

File tree

Expand file treeCollapse file tree

44 files changed

+246
-225
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

44 files changed

+246
-225
lines changed

‎include/litehtml/render_item.h

Copy file name to clipboardExpand all lines: include/litehtml/render_item.h
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ namespace litehtml
301301
m_element->in_normal_flow() &&
302302
m_element->css().get_float() == float_none &&
303303
m_margins.top >= 0 &&
304+
!is_flex_item() &&
304305
!is_root();
305306
}
306307

@@ -319,6 +320,16 @@ namespace litehtml
319320
return !(m_skip || src_el()->css().get_display() == display_none || src_el()->css().get_visibility() != visibility_visible);
320321
}
321322

323+
bool is_flex_item() const
324+
{
325+
auto par = parent();
326+
if(par && (par->css().get_display() == display_inline_flex || par->css().get_display() == display_flex))
327+
{
328+
return true;
329+
}
330+
return false;
331+
}
332+
322333
int render(int x, int y, const containing_block_context& containing_block_size, formatting_context* fmt_ctx, bool second_pass = false);
323334
void apply_relative_shift(const containing_block_context &containing_block_size);
324335
void calc_outlines( int parent_width );

‎src/flex_item.cpp

Copy file name to clipboardExpand all lines: src/flex_item.cpp
+48-7Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ void litehtml::flex_item_row_direction::direction_specific_init(const litehtml::
121121
{
122122
auto_margin_cross_end = true;
123123
}
124+
def_value<int> content_size(0);
124125
if (el->css().get_min_width().is_predefined())
125126
{
126127
min_size = el->render(0, 0,
127128
self_size.new_width(el->content_offset_width(),
128129
containing_block_context::size_mode_content), fmt_ctx);
130+
content_size = min_size;
129131
} else
130132
{
131133
min_size = el->css().get_min_width().calc_percent(self_size.render_width) +
@@ -160,12 +162,27 @@ void litehtml::flex_item_row_direction::direction_specific_init(const litehtml::
160162
el->content_offset_width();
161163
break;
162164
}
163-
case flex_basis_max_content:
165+
// if width is not predefined, use content size as base size
164166
case flex_basis_fit_content:
165-
base_size = el->render(0, 0, self_size, fmt_ctx);
167+
case flex_basis_content:
168+
base_size = el->render(0, 0, self_size.new_width(self_size.render_width + el->content_offset_width(),
169+
containing_block_context::size_mode_content |
170+
containing_block_context::size_mode_exact_width),
171+
fmt_ctx);
166172
break;
167173
case flex_basis_min_content:
168-
base_size = min_size;
174+
if(content_size.is_default())
175+
{
176+
content_size = el->render(0, 0,
177+
self_size.new_width(el->content_offset_width(),
178+
containing_block_context::size_mode_content),
179+
fmt_ctx);
180+
}
181+
base_size = content_size;
182+
break;
183+
case flex_basis_max_content:
184+
el->render(0, 0, self_size, fmt_ctx);
185+
base_size = el->width();
169186
break;
170187
default:
171188
base_size = 0;
@@ -340,8 +357,20 @@ void litehtml::flex_item_column_direction::direction_specific_init(const litehtm
340357
}
341358
} else
342359
{
343-
base_size = el->css().get_flex_basis().calc_percent(self_size.height) +
344-
el->content_offset_height();
360+
if(el->css().get_flex_basis().units() == css_units_percentage)
361+
{
362+
if(self_size.height.type == containing_block_context::cbc_value_type_absolute)
363+
{
364+
base_size = el->css().get_flex_basis().calc_percent(self_size.height) +
365+
el->content_offset_height();
366+
} else
367+
{
368+
base_size = 0;
369+
}
370+
} else
371+
{
372+
base_size = (int) el->css().get_flex_basis().val() + el->content_offset_height();
373+
}
345374
base_size = std::max(base_size, min_size);
346375
}
347376
}
@@ -429,10 +458,22 @@ void litehtml::flex_item_column_direction::align_baseline(litehtml::flex_line &l
429458
// The fallback alignment for first baseline is start, the one for last baseline is end.
430459
if(align & flex_align_items_last)
431460
{
432-
set_cross_position(ln.cross_start + ln.cross_size - get_el_cross_size());
461+
if(ln.reverse_cross)
462+
{
463+
set_cross_position(ln.cross_start);
464+
} else
465+
{
466+
set_cross_position(ln.cross_start + ln.cross_size - get_el_cross_size());
467+
}
433468
} else
434469
{
435-
set_cross_position(ln.cross_start);
470+
if(!ln.reverse_cross)
471+
{
472+
set_cross_position(ln.cross_start);
473+
} else
474+
{
475+
set_cross_position(ln.cross_start + ln.cross_size - get_el_cross_size());
476+
}
436477
}
437478
}
438479

‎src/render_block.cpp

Copy file name to clipboardExpand all lines: src/render_block.cpp
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ int litehtml::render_item_block::_render(int x, int y, const containing_block_co
226226
}
227227
}
228228

229+
// Fix width with max-width attribute
230+
if(self_size.max_width.type != containing_block_context::cbc_value_type_none)
231+
{
232+
if(m_pos.width > self_size.max_width)
233+
{
234+
m_pos.width = self_size.max_width;
235+
requires_rerender = true;
236+
}
237+
}
238+
229239
// Fix width with min-width attribute
230240
if(self_size.min_width.type != containing_block_context::cbc_value_type_none)
231241
{
@@ -239,16 +249,6 @@ int litehtml::render_item_block::_render(int x, int y, const containing_block_co
239249
m_pos.width = 0;
240250
}
241251

242-
// Fix width with max-width attribute
243-
if(self_size.max_width.type != containing_block_context::cbc_value_type_none)
244-
{
245-
if(m_pos.width > self_size.max_width)
246-
{
247-
m_pos.width = self_size.max_width;
248-
requires_rerender = true;
249-
}
250-
}
251-
252252
// re-render content with new width if required
253253
if (requires_rerender && !second_pass && !is_root())
254254
{

‎src/render_flex.cpp

Copy file name to clipboardExpand all lines: src/render_flex.cpp
-207Lines changed: 0 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -1,213 +1,6 @@
11
#include "html.h"
22
#include "types.h"
33
#include "render_flex.h"
4-
#include <cmath>
5-
6-
namespace litehtml
7-
{
8-
class flex_justify_content_spread
9-
{
10-
flex_justify_content m_type;
11-
int m_num_items;
12-
int m_free_space;
13-
bool m_row_direction;
14-
bool m_reverse;
15-
public:
16-
flex_justify_content_spread(flex_justify_content type, int num_items, int free_space, bool row_direction, bool reverse) :
17-
m_type(type), m_num_items(num_items), m_free_space(0), m_row_direction(row_direction), m_reverse(reverse)
18-
{
19-
set_free_space(free_space);
20-
}
21-
22-
void set_free_space(int free_space)
23-
{
24-
m_free_space = free_space;
25-
switch (m_type)
26-
{
27-
28-
case flex_justify_content_space_between:
29-
// If the leftover free-space is negative or there is only a single flex item on the line, this
30-
// value is identical to flex-start.
31-
if(m_num_items == 1 || m_free_space < 0) m_type = flex_justify_content_flex_start;
32-
break;
33-
case flex_justify_content_space_around:
34-
case flex_justify_content_space_evenly:
35-
// If the leftover free-space is negative or there is only a single flex item on the line, this
36-
// value is identical to center
37-
if(m_num_items == 1 || m_free_space < 0) m_type = flex_justify_content_center;
38-
break;
39-
case flex_justify_content_right:
40-
case flex_justify_content_left:
41-
if(!m_row_direction)
42-
{
43-
m_type = flex_justify_content_start;
44-
}
45-
break;
46-
default:
47-
break;
48-
}
49-
}
50-
51-
int start()
52-
{
53-
switch (m_type)
54-
{
55-
case flex_justify_content_right:
56-
if(!m_reverse)
57-
{
58-
return m_free_space;
59-
}
60-
return 0;
61-
case flex_justify_content_start:
62-
case flex_justify_content_left:
63-
if(m_reverse)
64-
{
65-
return m_free_space;
66-
}
67-
return 0;
68-
case flex_justify_content_flex_end:
69-
case flex_justify_content_end:
70-
return m_free_space;
71-
case flex_justify_content_center:
72-
return m_free_space / 2;
73-
case flex_justify_content_space_between:
74-
case flex_justify_content_space_around:
75-
default:
76-
// using flex-start by default
77-
return 0;
78-
}
79-
}
80-
81-
int before_item()
82-
{
83-
switch (m_type)
84-
{
85-
case flex_justify_content_space_evenly:
86-
return m_free_space / (m_num_items + 1);
87-
case flex_justify_content_space_between:
88-
return 0;
89-
case flex_justify_content_space_around:
90-
return m_free_space / (m_num_items * 2);
91-
default:
92-
return 0;
93-
}
94-
}
95-
96-
int after_item()
97-
{
98-
switch (m_type)
99-
{
100-
case flex_justify_content_space_between:
101-
return m_free_space / (m_num_items - 1);
102-
case flex_justify_content_space_around:
103-
return m_free_space / (m_num_items * 2);
104-
default:
105-
return 0;
106-
}
107-
}
108-
};
109-
110-
class flex_align_content_spread
111-
{
112-
flex_align_content m_type;
113-
int m_num_lines;
114-
int m_free_space;
115-
flex_wrap m_wrap;
116-
public:
117-
flex_align_content_spread(flex_align_content type, flex_wrap wrap, int num_lines, int free_space) :
118-
m_type(type), m_num_lines(num_lines), m_free_space(0), m_wrap(wrap)
119-
{
120-
if(m_wrap == flex_wrap_nowrap)
121-
{
122-
m_type = flex_align_content_stretch;
123-
}
124-
set_free_space(free_space);
125-
}
126-
127-
void set_free_space(int free_space)
128-
{
129-
m_free_space = free_space;
130-
switch (m_type)
131-
{
132-
133-
case flex_align_content_space_between:
134-
// If the leftover free-space is negative or there is only a single flex line in the flex
135-
// container, this value is identical to flex-start.
136-
if(m_num_lines == 1 || m_free_space < 0) m_type = flex_align_content_flex_start;
137-
break;
138-
case flex_align_content_space_around:
139-
// If the leftover free-space is negative this value is identical to center.
140-
if(m_num_lines == 1 || m_free_space < 0) m_type = flex_align_content_center;
141-
break;
142-
default:
143-
break;
144-
}
145-
}
146-
147-
int start()
148-
{
149-
switch (m_type)
150-
{
151-
case flex_align_content_flex_end:
152-
case flex_align_content_end:
153-
return m_free_space;
154-
case flex_align_content_center:
155-
return m_free_space / 2;
156-
case flex_align_content_stretch:
157-
case flex_align_content_space_between:
158-
case flex_align_content_space_around:
159-
default:
160-
// using stretch by default
161-
return 0;
162-
}
163-
}
164-
165-
int add_line_size()
166-
{
167-
switch (m_type)
168-
{
169-
170-
case flex_align_content_flex_start:
171-
case flex_align_content_flex_end:
172-
case flex_align_content_start:
173-
case flex_align_content_end:
174-
case flex_align_content_center:
175-
case flex_align_content_space_between:
176-
case flex_align_content_space_around:
177-
return 0;
178-
case flex_align_content_stretch:
179-
default:
180-
return m_free_space / m_num_lines;
181-
}
182-
}
183-
184-
int before_line()
185-
{
186-
switch (m_type)
187-
{
188-
case flex_align_content_space_between:
189-
return 0;
190-
case flex_align_content_space_around:
191-
return m_free_space / (m_num_lines * 2);
192-
default:
193-
return 0;
194-
}
195-
}
196-
197-
int after_line()
198-
{
199-
switch (m_type)
200-
{
201-
case flex_align_content_space_between:
202-
return m_free_space / (m_num_lines - 1);
203-
case flex_align_content_space_around:
204-
return m_free_space / (m_num_lines * 2);
205-
default:
206-
return 0;
207-
}
208-
}
209-
};
210-
}
2114

2125
int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass, const containing_block_context &self_size, formatting_context* fmt_ctx)
2136
{

‎src/style.cpp

Copy file name to clipboardExpand all lines: src/style.cpp
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,14 @@ void style::add_property(string_id name, const string& val, const string& baseur
540540
break;
541541

542542
case _order_: // <integer>
543-
add_parsed_property(name, property_value(atoi(val.c_str()), important));
543+
{
544+
char* end;
545+
int int_val = (int) strtol(val.c_str(), &end, 10);
546+
if(end[0] == '\0')
547+
{
548+
add_parsed_property(name, property_value(int_val, important));
549+
}
550+
}
544551
break;
545552

546553
default:
675 Bytes
Loading
1.18 KB
Loading
789 Bytes
Loading
851 Bytes
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.