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 289c153

Browse filesBrowse files
committed
flex: bug in processing box-sizing in flex items (litehtml#295)
1 parent 54d830f commit 289c153
Copy full SHA for 289c153

File tree

Expand file treeCollapse file tree

5 files changed

+69
-2
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+69
-2
lines changed

‎include/litehtml/render_item.h

Copy file name to clipboardExpand all lines: include/litehtml/render_item.h
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,52 @@ namespace litehtml
222222
return content_offset_top() + content_offset_bottom();
223223
}
224224

225+
int render_offset_left() const
226+
{
227+
if(css().get_box_sizing() == box_sizing_content_box)
228+
{
229+
return m_margins.left + m_borders.left + m_padding.left;
230+
}
231+
return m_margins.left;
232+
}
233+
234+
int render_offset_right() const
235+
{
236+
if(css().get_box_sizing() == box_sizing_content_box)
237+
{
238+
return m_margins.right + m_borders.right + m_padding.right;
239+
}
240+
return m_margins.right;
241+
}
242+
243+
int render_offset_width() const
244+
{
245+
return render_offset_left() + render_offset_right();
246+
}
247+
248+
int render_offset_top() const
249+
{
250+
if(css().get_box_sizing() == box_sizing_content_box)
251+
{
252+
return m_margins.top + m_borders.top + m_padding.top;
253+
}
254+
return m_margins.top;
255+
}
256+
257+
int render_offset_bottom() const
258+
{
259+
if(css().get_box_sizing() == box_sizing_content_box)
260+
{
261+
return m_margins.bottom + m_borders.bottom + m_padding.bottom;
262+
}
263+
return m_margins.bottom;
264+
}
265+
266+
int render_offset_height() const
267+
{
268+
return render_offset_top() + render_offset_bottom();
269+
}
270+
225271
int box_sizing_left() const
226272
{
227273
if(css().get_box_sizing() == box_sizing_border_box)

‎src/flex_item.cpp

Copy file name to clipboardExpand all lines: src/flex_item.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void litehtml::flex_item_row_direction::direction_specific_init(const litehtml::
170170
{
171171
case flex_basis_auto:
172172
base_size = el->css().get_width().calc_percent(self_size.render_width) +
173-
el->content_offset_width();
173+
el->render_offset_width();
174174
break;
175175
case flex_basis_fit_content:
176176
case flex_basis_content:

‎src/flex_line.cpp

Copy file name to clipboardExpand all lines: src/flex_line.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void litehtml::flex_line::init(int container_main_size, bool fit_container, bool
261261
{
262262
item->el->render(0,
263263
0,
264-
self_size.new_width(item->main_size - item->el->content_offset_width(), containing_block_context::size_mode_exact_width), fmt_ctx, false);
264+
self_size.new_width(item->main_size - item->el->render_offset_width(), containing_block_context::size_mode_exact_width), fmt_ctx, false);
265265

266266
if((item->align & 0xFF) == flex_align_items_baseline)
267267
{

‎test/render/flex-box-sizing.htm

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<style>
4+
* {
5+
margin: 0px;
6+
box-sizing: border-box;
7+
}
8+
</style>
9+
</head>
10+
<body>
11+
<div style="background-color: red; padding: 32px; height: 300px; width: 300px; display: flex; overflow: hidden;">
12+
<div style="background-color:yellow; padding:32px; flex: 1; display: flex; overflow: hidden;">
13+
<div style="background-color:green; padding:32px; flex: 1; display: flex; overflow: hidden;">
14+
<div style="background-color:white; display: flex; flex: 1; justify-content: center; align-items: center">
15+
<div>ciao</div>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
</body>
21+
</html>

‎test/render/flex-box-sizing.htm.png

Copy file name to clipboard
338 Bytes
Loading

0 commit comments

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