Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb: Use available space to resolve sizes in FFC #2258

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Libraries/LibWeb/Layout/FlexFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace Web::Layout {

CSSPixels FlexFormattingContext::get_pixel_width(Box const& box, CSS::Size const& size) const
{
return calculate_inner_width(box, containing_block_width_as_available_size(box), size);
return calculate_inner_width(box, m_available_space->width, size);
}

CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, CSS::Size const& size) const
{
return calculate_inner_height(box, containing_block_height_as_available_size(box), size);
return calculate_inner_height(box, m_available_space->height, size);
}

FlexFormattingContext::FlexFormattingContext(LayoutState& state, LayoutMode layout_mode, Box const& flex_container, FormattingContext* parent)
Expand All @@ -51,6 +51,8 @@ void FlexFormattingContext::run(AvailableSpace const& available_space)
{
// This implements https://www.w3.org/TR/css-flexbox-1/#layout-algorithm

m_available_space = available_space;

// 1. Generate anonymous flex items
generate_anonymous_flex_items();

Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/Layout/FlexFormattingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class FlexFormattingContext final : public FormattingContext {
AvailableSpace space;
};
Optional<AxisAgnosticAvailableSpace> m_available_space_for_items;
Optional<AvailableSpace> m_available_space;
};

}
28 changes: 0 additions & 28 deletions Libraries/LibWeb/Layout/FormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,34 +1655,6 @@ CSSPixels FormattingContext::containing_block_height_for(NodeWithStyleAndBoxMode
VERIFY_NOT_REACHED();
}

AvailableSize FormattingContext::containing_block_width_as_available_size(NodeWithStyleAndBoxModelMetrics const& node) const
{
auto const& used_values = m_state.get(node);
switch (used_values.width_constraint) {
case SizeConstraint::MinContent:
return AvailableSize::make_min_content();
case SizeConstraint::MaxContent:
return AvailableSize::make_max_content();
case SizeConstraint::None:
return AvailableSize::make_definite(used_values.containing_block_used_values()->content_width());
}
VERIFY_NOT_REACHED();
}

AvailableSize FormattingContext::containing_block_height_as_available_size(NodeWithStyleAndBoxModelMetrics const& node) const
{
auto const& used_values = m_state.get(node);
switch (used_values.height_constraint) {
case SizeConstraint::MinContent:
return AvailableSize::make_min_content();
case SizeConstraint::MaxContent:
return AvailableSize::make_max_content();
case SizeConstraint::None:
return AvailableSize::make_definite(used_values.containing_block_used_values()->content_height());
}
VERIFY_NOT_REACHED();
}

// https://drafts.csswg.org/css-sizing-3/#stretch-fit-size
CSSPixels FormattingContext::calculate_stretch_fit_width(Box const& box, AvailableSize const& available_width) const
{
Expand Down
3 changes: 0 additions & 3 deletions Libraries/LibWeb/Layout/FormattingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ class FormattingContext {
[[nodiscard]] CSSPixels containing_block_width_for(NodeWithStyleAndBoxModelMetrics const&) const;
[[nodiscard]] CSSPixels containing_block_height_for(NodeWithStyleAndBoxModelMetrics const&) const;

[[nodiscard]] AvailableSize containing_block_width_as_available_size(NodeWithStyleAndBoxModelMetrics const&) const;
[[nodiscard]] AvailableSize containing_block_height_as_available_size(NodeWithStyleAndBoxModelMetrics const&) const;

[[nodiscard]] CSSPixels calculate_stretch_fit_width(Box const&, AvailableSize const&) const;
[[nodiscard]] CSSPixels calculate_stretch_fit_height(Box const&, AvailableSize const&) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Rerun

Found 1 tests

1 Fail
1 Pass
Details
Result Test Name MessageFail .flexbox 1
Result Test Name MessagePass .flexbox 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ Rerun

Found 8 tests

7 Pass
1 Fail
8 Pass
Details
Result Test Name MessagePass .flexbox 1
Pass .flexbox 2
Fail .flexbox 3
Pass .flexbox 3
Pass .flexbox 4
Pass .flexbox 5
Pass .flexbox 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ Rerun

Found 8 tests

7 Pass
1 Fail
8 Pass
Details
Result Test Name MessagePass .flexbox 1
Pass .flexbox 2
Fail .flexbox 3
Pass .flexbox 3
Pass .flexbox 4
Pass .flexbox 5
Pass .flexbox 6
Expand Down
Loading