summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-07-21 00:38:05 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-26 01:53:41 +0200
commitdc66a3cad9decf6c12696e91523f6ac743880fbb (patch)
tree2563b30b3e6fa0f455d031456a53e6c04dc32def
parent18b1854aeaae1307c3ff0a356cbfa2e7c01b5933 (diff)
downloadserenity-dc66a3cad9decf6c12696e91523f6ac743880fbb.zip
LibWeb: Simplify flex container main size determination
We had an older incomplete implementation of flex container max-content sizing that we used for unconstrained main size determination. This patch replaces the old implementation with a call to the new max-content sizing code. Note that this isn't a complete implementation of flex container sizing still, but at least we've deduplicated some code.
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp36
1 files changed, 2 insertions, 34 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index 86085ec1ec..f5fd358ad3 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -798,41 +798,9 @@ float FlexFormattingContext::content_based_minimum_size(FlexItem const& item) co
// https://www.w3.org/TR/css-flexbox-1/#algo-main-container
void FlexFormattingContext::determine_main_size_of_flex_container(bool const main_is_constrained, float const main_min_size, float const main_max_size)
{
- // FIXME: This function should make use of our ability to calculate the flex container's
- // intrinsic max-content sizes.
-
+ // FIXME: This needs to be reworked.
if (!main_is_constrained || !m_available_space->main.has_value()) {
- // Uses https://www.w3.org/TR/css-flexbox-1/#intrinsic-main-sizes
- // 9.9.1
- // 1.
- float largest_max_content_flex_fraction = 0;
- for (auto& flex_item : m_flex_items) {
- // FIXME: This needs some serious work.
- float max_content_contribution = calculated_main_size(flex_item.box);
- float max_content_flex_fraction = max_content_contribution - (flex_item.flex_base_size + flex_item.margins.main_before + flex_item.margins.main_after + flex_item.borders.main_before + flex_item.borders.main_after + flex_item.padding.main_before + flex_item.padding.main_after);
- if (max_content_flex_fraction > 0) {
- max_content_flex_fraction /= max(flex_item.box.computed_values().flex_grow(), 1.0f);
- } else {
- max_content_flex_fraction /= flex_item.scaled_flex_shrink_factor;
- }
- flex_item.desired_flex_fraction = max_content_flex_fraction;
-
- if (max_content_flex_fraction > largest_max_content_flex_fraction)
- largest_max_content_flex_fraction = max_content_flex_fraction;
- }
-
- // 2. Omitted
- // 3.
- float result = 0;
- for (auto& flex_item : m_flex_items) {
- auto product = 0;
- if (flex_item.desired_flex_fraction > 0) {
- product = largest_max_content_flex_fraction * flex_item.box.computed_values().flex_grow();
- } else {
- product = largest_max_content_flex_fraction * flex_item.scaled_flex_shrink_factor;
- }
- result += flex_item.flex_base_size + flex_item.margins.main_before + flex_item.margins.main_after + flex_item.borders.main_before + flex_item.borders.main_after + flex_item.padding.main_before + flex_item.padding.main_after + product;
- }
+ auto result = is_row_layout() ? calculate_max_content_width(flex_container()) : calculate_max_content_height(flex_container());
m_available_space->main = css_clamp(result, main_min_size, main_max_size);
}
set_main_size(flex_container(), m_available_space->main.value_or(NumericLimits<float>::max()));