1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

LibWeb: Don't re-resolve "auto" flex item sizes after definitizing them

This is rather subtle and points to our architecture around definite
sizes not being exactly right, but...

At some points during flexbox layout, the spec tells us that the sizes
of certain flex items are considered definite from this point on.
We implement this by marking each item's associated UsedValues as
"has-definite-width/height".

However, this breaks code that tries to resolve computed "auto" sizes
by taking the corresponding size from the containing block. The end
result was that the 1st sizing pass in flexbox would find the right size
for an "auto" sized item, but the 2nd pass would override the correct
size with the containing block's content size in that axis instead.

To work around the issue, FFC now remembers when it "definitizes" an
item, and future attempts to resolve an "auto" computed size for that
value will bypass the computed-auto-is-resolved-against-containing-block
step of the algorithm. It's not perfect, and we'll need to think more
about how to really represent these intermediate states relating to
box sizes being definite..
This commit is contained in:
Andreas Kling 2022-09-14 11:43:57 +02:00
parent b8aa6a4453
commit f25203f245
4 changed files with 45 additions and 23 deletions

View file

@ -232,4 +232,26 @@ void LayoutState::UsedValues::set_content_height(float height)
m_content_height = height;
}
float LayoutState::resolved_definite_width(Box const& box) const
{
auto const& computed_value = box.computed_values().width();
if (computed_value.is_auto())
return get(*box.containing_block()).content_width();
if (computed_value.is_length())
return get(box).content_width();
auto containing_block_size = get(*box.containing_block()).content_width();
return computed_value.resolved(box, CSS::Length::make_px(containing_block_size)).to_px(box);
}
float LayoutState::resolved_definite_height(Box const& box) const
{
auto const& computed_value = box.computed_values().height();
if (computed_value.is_auto())
return get(*box.containing_block()).content_height();
if (computed_value.is_length())
return get(box).content_height();
auto containing_block_size = get(*box.containing_block()).content_height();
return computed_value.resolved(box, CSS::Length::make_px(containing_block_size)).to_px(box);
}
}