Skip to content

Commit e4eb6d4

Browse files
committed
LibWeb: Add FFC helpers for resolving definite main/cross sizes
Although something has a definite size, we may still have to "resolve" it, since FFC is quite liberal in what it considers to be definite. Let's put that logic in a set of helper functions.
1 parent 5c8e721 commit e4eb6d4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,30 @@ float FlexFormattingContext::specified_cross_size(Box const& box) const
197197
return is_row_layout() ? box_state.content_height : box_state.content_width;
198198
}
199199

200+
float FlexFormattingContext::resolved_definite_cross_size(Box const& box) const
201+
{
202+
if (is_row_layout())
203+
VERIFY(box.has_definite_height());
204+
else
205+
VERIFY(box.has_definite_width());
206+
auto const& cross_value = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
207+
if (cross_value->is_length())
208+
return cross_value->length().to_px(box);
209+
return cross_value->resolved(box, CSS::Length::make_px(specified_cross_size(flex_container()))).to_px(box);
210+
}
211+
212+
float FlexFormattingContext::resolved_definite_main_size(Box const& box) const
213+
{
214+
if (is_row_layout())
215+
VERIFY(box.has_definite_width());
216+
else
217+
VERIFY(box.has_definite_height());
218+
auto const& cross_value = is_row_layout() ? box.computed_values().width() : box.computed_values().height();
219+
if (cross_value->is_length())
220+
return cross_value->length().to_px(box);
221+
return cross_value->resolved(box, CSS::Length::make_px(specified_main_size(flex_container()))).to_px(box);
222+
}
223+
200224
bool FlexFormattingContext::has_main_min_size(Box const& box) const
201225
{
202226
auto value = is_row_layout() ? box.computed_values().min_width() : box.computed_values().min_height();

Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class FlexFormattingContext final : public FormattingContext {
5959
bool has_definite_cross_size(Box const&) const;
6060
float specified_main_size(Box const&) const;
6161
float specified_cross_size(Box const&) const;
62+
float resolved_definite_main_size(Box const&) const;
63+
float resolved_definite_cross_size(Box const&) const;
6264
bool has_main_min_size(Box const&) const;
6365
bool has_cross_min_size(Box const&) const;
6466
float specified_main_max_size(Box const&) const;

0 commit comments

Comments
 (0)