mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
- 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>
This commit is contained in:
parent
c9e3d3e25e
commit
ba061ec2b0
2 changed files with 15 additions and 25 deletions
|
@ -1882,12 +1882,20 @@ impl FlexItem<'_> {
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
cross_size.auto_is(|| {
|
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(
|
let constraint_space = ConstraintSpace::new(
|
||||||
SizeConstraint::Definite(used_main_size),
|
SizeConstraint::Definite(used_main_size),
|
||||||
item_writing_mode,
|
item_writing_mode,
|
||||||
);
|
);
|
||||||
let content_contributions = self
|
self.box_
|
||||||
.box_
|
|
||||||
.independent_formatting_context
|
.independent_formatting_context
|
||||||
.inline_content_sizes(
|
.inline_content_sizes(
|
||||||
flex_context.layout_context,
|
flex_context.layout_context,
|
||||||
|
@ -1895,22 +1903,11 @@ impl FlexItem<'_> {
|
||||||
&containing_block.into(),
|
&containing_block.into(),
|
||||||
)
|
)
|
||||||
.sizes
|
.sizes
|
||||||
.map(|size| {
|
.shrink_to_fit(stretch_size)
|
||||||
size.clamp_between_extremums(
|
.clamp_between_extremums(
|
||||||
self.content_min_size.cross,
|
self.content_min_size.cross,
|
||||||
self.content_max_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)
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
// The main size of a flex item is considered to be definite if its flex basis is definite
|
// 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.
|
// or the flex container has a definite main size.
|
||||||
|
|
|
@ -40,13 +40,6 @@ pub(crate) struct ContentSizes {
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-sizing/#intrinsic-sizes>
|
/// <https://drafts.csswg.org/css-sizing/#intrinsic-sizes>
|
||||||
impl ContentSizes {
|
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 {
|
pub fn max(&self, other: Self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
min_content: self.min_content.max(other.min_content),
|
min_content: self.min_content.max(other.min_content),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue