mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
LibWeb: Move get_pixel_{width,height} helpers into FFC class
This commit is contained in:
parent
60ac258a48
commit
a4d7dc40bf
2 changed files with 21 additions and 16 deletions
|
@ -27,19 +27,19 @@ template<typename T>
|
|||
return ::max(min, ::min(value, max));
|
||||
}
|
||||
|
||||
static float get_pixel_width(LayoutState const& state, Box const& box, Optional<CSS::LengthPercentage> const& length_percentage)
|
||||
float FlexFormattingContext::get_pixel_width(Box const& box, Optional<CSS::LengthPercentage> const& length_percentage) const
|
||||
{
|
||||
if (!length_percentage.has_value())
|
||||
return 0;
|
||||
auto inner_width = CSS::Length::make_px(state.get(*box.containing_block()).content_width());
|
||||
auto inner_width = CSS::Length::make_px(containing_block_width_for(box));
|
||||
return length_percentage->resolved(box, inner_width).to_px(box);
|
||||
}
|
||||
|
||||
static float get_pixel_height(LayoutState const& state, Box const& box, Optional<CSS::LengthPercentage> const& length_percentage)
|
||||
float FlexFormattingContext::get_pixel_height(Box const& box, Optional<CSS::LengthPercentage> const& length_percentage) const
|
||||
{
|
||||
if (!length_percentage.has_value())
|
||||
return 0;
|
||||
auto inner_height = CSS::Length::make_px(state.get(*box.containing_block()).content_height());
|
||||
auto inner_height = CSS::Length::make_px(containing_block_height_for(box));
|
||||
return length_percentage->resolved(box, inner_height).to_px(box);
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,8 @@ float FlexFormattingContext::resolved_definite_cross_size(Box const& box) const
|
|||
return specified_cross_size(flex_container());
|
||||
if (cross_value.is_length())
|
||||
return specified_cross_size(box);
|
||||
return cross_value.resolved(box, CSS::Length::make_px(specified_cross_size(flex_container()))).to_px(box);
|
||||
auto containing_block_size = !is_row_layout() ? containing_block_width_for(box) : containing_block_height_for(box);
|
||||
return cross_value.resolved(box, CSS::Length::make_px(containing_block_size)).to_px(box);
|
||||
}
|
||||
|
||||
float FlexFormattingContext::resolved_definite_main_size(Box const& box) const
|
||||
|
@ -349,7 +350,8 @@ float FlexFormattingContext::resolved_definite_main_size(Box const& box) const
|
|||
return specified_main_size(flex_container());
|
||||
if (main_value.is_length())
|
||||
return specified_main_size(box);
|
||||
return main_value.resolved(box, CSS::Length::make_px(specified_main_size(flex_container()))).to_px(box);
|
||||
auto containing_block_size = is_row_layout() ? containing_block_width_for(box) : containing_block_height_for(box);
|
||||
return main_value.resolved(box, CSS::Length::make_px(containing_block_size)).to_px(box);
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::has_main_min_size(Box const& box) const
|
||||
|
@ -380,15 +382,15 @@ float FlexFormattingContext::specified_main_size_of_child_box(Box const& child_b
|
|||
float FlexFormattingContext::specified_main_min_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? get_pixel_width(m_state, box, box.computed_values().min_width())
|
||||
: get_pixel_height(m_state, box, box.computed_values().min_height());
|
||||
? get_pixel_width(box, box.computed_values().min_width())
|
||||
: get_pixel_height(box, box.computed_values().min_height());
|
||||
}
|
||||
|
||||
float FlexFormattingContext::specified_cross_min_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? get_pixel_height(m_state, box, box.computed_values().min_height())
|
||||
: get_pixel_width(m_state, box, box.computed_values().min_width());
|
||||
? get_pixel_height(box, box.computed_values().min_height())
|
||||
: get_pixel_width(box, box.computed_values().min_width());
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::has_main_max_size(Box const& box) const
|
||||
|
@ -406,15 +408,15 @@ bool FlexFormattingContext::has_cross_max_size(Box const& box) const
|
|||
float FlexFormattingContext::specified_main_max_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? get_pixel_width(m_state, box, box.computed_values().max_width())
|
||||
: get_pixel_height(m_state, box, box.computed_values().max_height());
|
||||
? get_pixel_width(box, box.computed_values().max_width())
|
||||
: get_pixel_height(box, box.computed_values().max_height());
|
||||
}
|
||||
|
||||
float FlexFormattingContext::specified_cross_max_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? get_pixel_height(m_state, box, box.computed_values().max_height())
|
||||
: get_pixel_width(m_state, box, box.computed_values().max_width());
|
||||
? get_pixel_height(box, box.computed_values().max_height())
|
||||
: get_pixel_width(box, box.computed_values().max_width());
|
||||
}
|
||||
|
||||
float FlexFormattingContext::calculated_main_size(Box const& box) const
|
||||
|
@ -659,8 +661,8 @@ void FlexFormattingContext::determine_flex_base_size_and_hypothetical_main_size(
|
|||
// A. If the item has a definite used flex basis, that’s the flex base size.
|
||||
if (flex_item.used_flex_basis_is_definite) {
|
||||
if (is_row_layout())
|
||||
return get_pixel_width(m_state, child_box, flex_item.used_flex_basis.length_percentage.value());
|
||||
return get_pixel_height(m_state, child_box, flex_item.used_flex_basis.length_percentage.value());
|
||||
return get_pixel_width(child_box, flex_item.used_flex_basis.length_percentage.value());
|
||||
return get_pixel_height(child_box, flex_item.used_flex_basis.length_percentage.value());
|
||||
}
|
||||
|
||||
// B. If the flex item has ...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue