1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibWeb: Expose size calculation of BlockFormattingContext

This is a hack for the FlexFormattingContext
This commit is contained in:
Tobias Christiansen 2021-05-30 21:57:13 +02:00 committed by Ali Mohammad Pur
parent ce7c8e215f
commit c51dbb4372
2 changed files with 20 additions and 11 deletions

View file

@ -296,19 +296,11 @@ static float compute_auto_height_for_block_level_element(const Box& box)
return bottom.value_or(0) - top.value_or(0);
}
void BlockFormattingContext::compute_height(Box& box)
float BlockFormattingContext::compute_theoretical_height(const Box& box)
{
auto& computed_values = box.computed_values();
auto& containing_block = *box.containing_block();
// First, resolve the top/bottom parts of the surrounding box model.
box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().border.top = computed_values.border_top().width;
box.box_model().border.bottom = computed_values.border_bottom().width;
box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
// Then work out what the height is, based on box type and CSS properties.
float height = 0;
if (is<ReplacedBox>(box)) {
@ -330,7 +322,22 @@ void BlockFormattingContext::compute_height(Box& box)
if (!specified_min_height.is_auto()
&& !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
height = max(height, specified_min_height.to_px(box));
return height;
}
void BlockFormattingContext::compute_height(Box& box)
{
auto& computed_values = box.computed_values();
auto& containing_block = *box.containing_block();
// First, resolve the top/bottom parts of the surrounding box model.
box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().border.top = computed_values.border_top().width;
box.box_model().border.bottom = computed_values.border_bottom().width;
box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
auto height = compute_theoretical_height(box);
box.set_height(height);
}