summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-07-18 18:36:52 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-26 01:53:41 +0200
commit69243947d592ec6c60024e4517b0928bf300becc (patch)
treedbeeb37a8fc799d123530b00cea51e35f7f01b05
parent02c59fe8c9362e0d1ea566e114867bac0c814e29 (diff)
downloadserenity-69243947d592ec6c60024e4517b0928bf300becc.zip
LibWeb: Some flex items have definite size after flexing
This patch implements two of the special "definite size" rules from the CSS-FLEXBOX-1 spec. https://drafts.csswg.org/css-flexbox-1/#definite-sizes
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp26
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h2
2 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index d1d0f51095..e7e0a9d0bc 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -414,6 +414,24 @@ void FlexFormattingContext::set_cross_size(Box const& box, float size)
m_state.get_mutable(box).set_content_width(size);
}
+void FlexFormattingContext::set_has_definite_main_size(Box const& box, bool definite)
+{
+ auto& used_values = m_state.get_mutable(box);
+ if (is_row_layout())
+ used_values.set_has_definite_width(definite);
+ else
+ used_values.set_has_definite_height(definite);
+}
+
+void FlexFormattingContext::set_has_definite_cross_size(Box const& box, bool definite)
+{
+ auto& used_values = m_state.get_mutable(box);
+ if (!is_row_layout())
+ used_values.set_has_definite_width(definite);
+ else
+ used_values.set_has_definite_height(definite);
+}
+
void FlexFormattingContext::set_offset(Box const& box, float main_offset, float cross_offset)
{
if (is_row_layout())
@@ -964,6 +982,14 @@ void FlexFormattingContext::resolve_flexible_lengths()
// 6.5.
for (auto& flex_item : flex_line.items) {
flex_item->main_size = flex_item->target_main_size;
+ set_main_size(flex_item->box, flex_item->main_size);
+
+ // https://drafts.csswg.org/css-flexbox-1/#definite-sizes
+ // 1. If the flex container has a definite main size, then the post-flexing main sizes of its flex items are treated as definite.
+ // 2. If a flex-itemโ€™s flex basis is definite, then its post-flexing main size is also definite.
+ if (has_definite_main_size(flex_container()) || flex_item->used_flex_basis.is_definite()) {
+ set_has_definite_main_size(flex_item->box, true);
+ }
}
flex_line.remaining_free_space = calculate_free_space();
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
index b02929f34d..27e30c5988 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
@@ -107,6 +107,8 @@ private:
void set_main_size(Box const&, float size);
void set_cross_size(Box const&, float size);
+ void set_has_definite_main_size(Box const&, bool);
+ void set_has_definite_cross_size(Box const&, bool);
void set_offset(Box const&, float main_offset, float cross_offset);
void set_main_axis_first_margin(FlexItem&, float margin);
void set_main_axis_second_margin(FlexItem&, float margin);