layout: Switch IndependentLayout to use Au instead of Length (#31083)

* use au in layout

* fmt

* review fix
This commit is contained in:
atbrakhi 2024-01-15 15:31:21 +01:00 committed by GitHub
parent efa38c67fe
commit 1b847c3166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 21 deletions

View file

@ -410,7 +410,7 @@ impl FlexContainer {
IndependentLayout {
fragments,
content_block_size,
content_block_size: content_block_size.into(),
last_inflow_baseline_offset: None,
}
}
@ -1111,7 +1111,7 @@ impl<'a> FlexItem<'a> {
let hypothetical_cross_size = self
.content_box_size
.cross
.auto_is(|| content_block_size)
.auto_is(|| content_block_size.into())
.clamp_between_extremums(
self.content_min_size.cross,
self.content_max_size.cross,

View file

@ -930,7 +930,7 @@ impl FloatBox {
inline: inline_size,
block: box_size
.block
.auto_is(|| independent_layout.content_block_size),
.auto_is(|| independent_layout.content_block_size.into()),
};
children = independent_layout.fragments;
},

View file

@ -1949,7 +1949,7 @@ impl IndependentFormattingContext {
// https://drafts.csswg.org/css2/visudet.html#block-root-margin
let tentative_block_size = box_size
.block
.auto_is(|| independent_layout.content_block_size);
.auto_is(|| independent_layout.content_block_size.into());
// https://drafts.csswg.org/css2/visudet.html#min-max-heights
// In this case “applying the rules above again” with a non-auto block-size
@ -1974,7 +1974,9 @@ impl IndependentFormattingContext {
pbm.border,
margin,
None,
independent_layout.last_inflow_baseline_offset,
independent_layout
.last_inflow_baseline_offset
.map(|t| t.into()),
CollapsedBlockMargins::zero(),
)
},

View file

@ -30,7 +30,7 @@ use crate::geom::{LogicalRect, LogicalSides, LogicalVec2};
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext, PositioningContextLength};
use crate::replaced::ReplacedContent;
use crate::sizing::{self, ContentSizes};
use crate::style_ext::{ComputedValuesExt, PaddingBorderMargin};
use crate::style_ext::{Clamp, ComputedValuesExt, PaddingBorderMargin};
use crate::ContainingBlock;
mod construct;
@ -240,10 +240,11 @@ impl BlockFormattingContext {
IndependentLayout {
fragments: flow_layout.fragments,
content_block_size: flow_layout.content_block_size +
content_block_size: (flow_layout.content_block_size +
flow_layout.collapsible_margins_in_children.end.solve() +
clearance.unwrap_or_else(Length::zero),
last_inflow_baseline_offset: flow_layout.last_inflow_baseline_offset,
clearance.unwrap_or_else(Length::zero))
.into(),
last_inflow_baseline_offset: flow_layout.last_inflow_baseline_offset.map(|t| t.into()),
}
}
}
@ -858,7 +859,11 @@ impl NonReplacedFormattingContext {
let block_size = containing_block_for_children.block_size.auto_is(|| {
layout
.content_block_size
.clamp_between_extremums(min_box_size.block, max_box_size.block)
.clamp_between_extremums(
min_box_size.block.into(),
max_box_size.block.map(|t| t.into()),
)
.into()
});
let content_rect = LogicalRect {
@ -882,7 +887,7 @@ impl NonReplacedFormattingContext {
pbm.border,
margin,
None, /* clearance */
layout.last_inflow_baseline_offset,
layout.last_inflow_baseline_offset.map(|t| t.into()),
block_margins_collapsed_with_children,
)
}
@ -939,12 +944,17 @@ impl NonReplacedFormattingContext {
style: &self.style,
},
);
content_size = LogicalVec2 {
inline: inline_size,
block: block_size.auto_is(|| {
layout
.content_block_size
.clamp_between_extremums(min_box_size.block, max_box_size.block)
.clamp_between_extremums(
min_box_size.block.into(),
max_box_size.block.map(|t| t.into()),
)
.into()
}),
};
@ -1002,13 +1012,16 @@ impl NonReplacedFormattingContext {
style: &self.style,
},
);
content_size = LogicalVec2 {
inline: proposed_inline_size,
block: block_size.auto_is(|| {
layout
.content_block_size
.clamp_between_extremums(min_box_size.block, max_box_size.block)
.clamp_between_extremums(
min_box_size.block.into(),
max_box_size.block.map(|t| t.into()),
)
.into()
}),
};
@ -1092,7 +1105,7 @@ impl NonReplacedFormattingContext {
pbm.border,
margin,
clearance,
layout.last_inflow_baseline_offset,
layout.last_inflow_baseline_offset.map(|t| t.into()),
block_margins_collapsed_with_children,
)
}

View file

@ -4,11 +4,11 @@
use std::convert::TryInto;
use app_units::Au;
use serde::Serialize;
use servo_arc::Arc;
use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;
use style::values::computed::Length;
use style::values::specified::text::TextDecorationLine;
use crate::context::LayoutContext;
@ -63,12 +63,12 @@ pub(crate) struct IndependentLayout {
pub fragments: Vec<Fragment>,
/// https://drafts.csswg.org/css2/visudet.html#root-height
pub content_block_size: Length,
pub content_block_size: Au,
/// The offset of the last inflow baseline of this layout in the content area, if
/// there was one. This is used to propagate baselines to the ancestors of `display:
/// inline-block`.
pub last_inflow_baseline_offset: Option<Length>,
pub last_inflow_baseline_offset: Option<Au>,
}
impl IndependentFormattingContext {

View file

@ -622,7 +622,8 @@ impl HoistedAbsolutelyPositionedBox {
&mut positioning_context,
&containing_block_for_children,
);
let block_size = size.auto_is(|| independent_layout.content_block_size);
let block_size =
size.auto_is(|| independent_layout.content_block_size.into());
Result {
content_size: LogicalVec2 {
inline: inline_size,

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use app_units::Au;
use servo_config::pref;
use style::computed_values::mix_blend_mode::T as ComputedMixBlendMode;
use style::computed_values::position::T as ComputedPosition;
@ -626,3 +627,16 @@ fn size_to_length(size: &Size) -> LengthPercentageOrAuto {
Size::Auto => LengthPercentageOrAuto::Auto,
}
}
pub(crate) trait Clamp: Sized {
fn clamp_between_extremums(self, min: Self, max: Option<Self>) -> Self;
}
impl Clamp for Au {
fn clamp_between_extremums(self, min: Self, max: Option<Self>) -> Self {
match max {
Some(max_value) => self.min(max_value).max(min),
None => self.max(min),
}
}
}

View file

@ -7,11 +7,12 @@
mod construct;
use app_units::Au;
pub(crate) use construct::AnonymousTableContent;
pub use construct::TableBuilder;
use euclid::num::Zero;
use euclid::{Point2D, UnknownUnit, Vector2D};
use serde::Serialize;
use style::values::computed::Length;
use super::flow::BlockFormattingContext;
use crate::context::LayoutContext;
@ -39,7 +40,7 @@ impl Table {
) -> IndependentLayout {
IndependentLayout {
fragments: Vec::new(),
content_block_size: Length::new(0.),
content_block_size: Au::zero(),
last_inflow_baseline_offset: None,
}
}