aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2024-11-25 17:17:54 +0100
committerGitHub <noreply@github.com>2024-11-25 16:17:54 +0000
commitba061ec2b0ef7124a5e64ec11a406cbc45cac02f (patch)
treea37476cdaffdbeaf0c03f02c8e2c6b4fb7b4f5ce /components/layout_2020
parentc9e3d3e25e37068cff5164d83dfa906a7d74f528 (diff)
downloadservo-ba061ec2b0ef7124a5e64ec11a406cbc45cac02f.tar.gz
servo-ba061ec2b0ef7124a5e64ec11a406cbc45cac02f.zip
Refine logic for laying out flex item in column layout after #34346 (#34372)
- Clamp the stretch size to not be negative when the sum of padding, borders and margins exceed the available space. This avoids a 2nd layout. - Avoid computing the inline content sizes if the result isn't needed. - Instead of clamping both the min-content and max-content sizes to be between the min and max constraints, just compute the fit-content size first, and then clamp. Then `ContentSizes::map()` can be removed. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/layout_2020')
-rw-r--r--components/layout_2020/flexbox/layout.rs33
-rw-r--r--components/layout_2020/sizing.rs7
2 files changed, 15 insertions, 25 deletions
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 2b699d75ab7..65d6c7e1554 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -1882,12 +1882,20 @@ impl FlexItem<'_> {
} else {
(
cross_size.auto_is(|| {
+ let style = self.box_.style();
+ let stretch_size =
+ Au::zero().max(containing_block.inline_size - self.pbm_auto_is_zero.cross);
+ if flex_context
+ .config
+ .item_with_auto_cross_size_stretches_to_container_size(style, &self.margin)
+ {
+ return stretch_size;
+ }
let constraint_space = ConstraintSpace::new(
SizeConstraint::Definite(used_main_size),
item_writing_mode,
);
- let content_contributions = self
- .box_
+ self.box_
.independent_formatting_context
.inline_content_sizes(
flex_context.layout_context,
@@ -1895,22 +1903,11 @@ impl FlexItem<'_> {
&containing_block.into(),
)
.sizes
- .map(|size| {
- size.clamp_between_extremums(
- self.content_min_size.cross,
- self.content_max_size.cross,
- )
- });
- let stretch_size = containing_block.inline_size - self.pbm_auto_is_zero.cross;
- let style = self.box_.style();
- if flex_context
- .config
- .item_with_auto_cross_size_stretches_to_container_size(style, &self.margin)
- {
- stretch_size
- } else {
- content_contributions.shrink_to_fit(stretch_size)
- }
+ .shrink_to_fit(stretch_size)
+ .clamp_between_extremums(
+ self.content_min_size.cross,
+ self.content_max_size.cross,
+ )
}),
// The main size of a flex item is considered to be definite if its flex basis is definite
// or the flex container has a definite main size.
diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs
index f7b691dbcde..8e1c467d196 100644
--- a/components/layout_2020/sizing.rs
+++ b/components/layout_2020/sizing.rs
@@ -40,13 +40,6 @@ pub(crate) struct ContentSizes {
/// <https://drafts.csswg.org/css-sizing/#intrinsic-sizes>
impl ContentSizes {
- pub fn map(&self, f: impl Fn(Au) -> Au) -> Self {
- Self {
- min_content: f(self.min_content),
- max_content: f(self.max_content),
- }
- }
-
pub fn max(&self, other: Self) -> Self {
Self {
min_content: self.min_content.max(other.min_content),