mirror of
https://github.com/servo/servo.git
synced 2025-09-23 13:20:11 +01:00
layout: Add style to ConstraintSpace
and IndefiniteContainingBlock
(#39229)
They only had the writing mode, now they will have the entire computed style. This is needed for #39230. Testing: Not needed, no behavior change Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
dfdcba88d4
commit
9e9bd80bba
10 changed files with 44 additions and 62 deletions
|
@ -2050,7 +2050,7 @@ impl FlexItemBox {
|
|||
let flex_axis = config.flex_axis;
|
||||
let style = self.style();
|
||||
let cross_axis_is_item_block_axis = cross_axis_is_item_block_axis(
|
||||
containing_block.writing_mode.is_horizontal(),
|
||||
containing_block.style.writing_mode.is_horizontal(),
|
||||
style.writing_mode.is_horizontal(),
|
||||
flex_axis,
|
||||
);
|
||||
|
@ -2180,7 +2180,7 @@ impl FlexItemBox {
|
|||
// The main axis is the inline axis, so we can get the content size from the normal
|
||||
// preferred widths calculation.
|
||||
let constraint_space =
|
||||
ConstraintSpace::new(cross_size, style.writing_mode, preferred_aspect_ratio);
|
||||
ConstraintSpace::new(cross_size, style, preferred_aspect_ratio);
|
||||
let content_sizes = flex_item
|
||||
.inline_content_sizes(layout_context, &constraint_space)
|
||||
.sizes;
|
||||
|
@ -2586,9 +2586,8 @@ impl FlexItemBox {
|
|||
block_size: SizeConstraint,
|
||||
preferred_aspect_ratio: Option<AspectRatio>,
|
||||
) -> ContentSizes {
|
||||
let writing_mode = self.independent_formatting_context.style().writing_mode;
|
||||
let constraint_space =
|
||||
ConstraintSpace::new(block_size, writing_mode, preferred_aspect_ratio);
|
||||
let style = self.independent_formatting_context.style();
|
||||
let constraint_space = ConstraintSpace::new(block_size, style, preferred_aspect_ratio);
|
||||
self.independent_formatting_context
|
||||
.inline_content_sizes(flex_context.layout_context, &constraint_space)
|
||||
.sizes
|
||||
|
|
|
@ -2349,7 +2349,7 @@ impl ComputeInlineContentSizes for InlineFormattingContext {
|
|||
/// A struct which takes care of computing [`ContentSizes`] for an [`InlineFormattingContext`].
|
||||
struct ContentSizesComputation<'layout_data> {
|
||||
layout_context: &'layout_data LayoutContext<'layout_data>,
|
||||
constraint_space: &'layout_data ConstraintSpace,
|
||||
constraint_space: &'layout_data ConstraintSpace<'layout_data>,
|
||||
paragraph: ContentSizes,
|
||||
current_line: ContentSizes,
|
||||
/// Size for whitespace pending to be added to this line.
|
||||
|
@ -2394,7 +2394,7 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
|
|||
// https://drafts.csswg.org/css-sizing-3/#min-percentage-contribution
|
||||
let inline_box = inline_box.borrow();
|
||||
let zero = Au::zero();
|
||||
let writing_mode = self.constraint_space.writing_mode;
|
||||
let writing_mode = self.constraint_space.style.writing_mode;
|
||||
let layout_style = inline_box.layout_style();
|
||||
let padding = layout_style
|
||||
.padding(writing_mode)
|
||||
|
|
|
@ -238,7 +238,7 @@ impl BlockLevelBox {
|
|||
let get_inline_content_sizes = || {
|
||||
let constraint_space = ConstraintSpace::new(
|
||||
tentative_block_size,
|
||||
style.writing_mode,
|
||||
style,
|
||||
None, /* TODO: support preferred aspect ratios on non-replaced boxes */
|
||||
);
|
||||
self.inline_content_sizes(layout_context, &constraint_space)
|
||||
|
@ -508,16 +508,11 @@ fn compute_inline_content_sizes_for_block_level_boxes(
|
|||
false, /* auto_block_size_stretches_to_containing_block */
|
||||
);
|
||||
let style = &float_box.contents.style();
|
||||
let container_writing_mode = containing_block.style.writing_mode;
|
||||
Some((
|
||||
inline_content_sizes_result,
|
||||
FloatSide::from_style_and_container_writing_mode(
|
||||
style,
|
||||
containing_block.writing_mode,
|
||||
),
|
||||
Clear::from_style_and_container_writing_mode(
|
||||
style,
|
||||
containing_block.writing_mode,
|
||||
),
|
||||
FloatSide::from_style_and_container_writing_mode(style, container_writing_mode),
|
||||
Clear::from_style_and_container_writing_mode(style, container_writing_mode),
|
||||
))
|
||||
},
|
||||
BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => {
|
||||
|
@ -551,7 +546,7 @@ fn compute_inline_content_sizes_for_block_level_boxes(
|
|||
None,
|
||||
Clear::from_style_and_container_writing_mode(
|
||||
independent.style(),
|
||||
containing_block.writing_mode,
|
||||
containing_block.style.writing_mode,
|
||||
),
|
||||
))
|
||||
},
|
||||
|
@ -1373,11 +1368,8 @@ impl IndependentFormattingContext {
|
|||
|
||||
// With the tentative block size we can compute the inline min/max-content sizes.
|
||||
let get_inline_content_sizes = || {
|
||||
let constraint_space = ConstraintSpace::new(
|
||||
tentative_block_size,
|
||||
style.writing_mode,
|
||||
preferred_aspect_ratio,
|
||||
);
|
||||
let constraint_space =
|
||||
ConstraintSpace::new(tentative_block_size, style, preferred_aspect_ratio);
|
||||
self.inline_content_sizes(layout_context, &constraint_space)
|
||||
.sizes
|
||||
};
|
||||
|
@ -1681,7 +1673,6 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
|
|||
} = layout_style.content_box_sizes_and_padding_border_margin(&containing_block.into());
|
||||
|
||||
let pbm_sums = pbm.sums_auto_is_zero(ignore_block_margins_for_stretch);
|
||||
let writing_mode = style.writing_mode;
|
||||
let available_inline_size = Au::zero().max(containing_block.size.inline - pbm_sums.inline);
|
||||
let available_block_size = containing_block
|
||||
.size
|
||||
|
@ -1721,7 +1712,7 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
|
|||
let get_inline_content_sizes = || {
|
||||
get_inline_content_sizes(&ConstraintSpace::new(
|
||||
tentative_block_size,
|
||||
writing_mode,
|
||||
style,
|
||||
preferred_aspect_ratio,
|
||||
))
|
||||
};
|
||||
|
@ -2238,7 +2229,6 @@ impl IndependentFormattingContext {
|
|||
containing_block: &ContainingBlock,
|
||||
) -> IndependentFloatOrAtomicLayoutResult {
|
||||
let style = self.style();
|
||||
let writing_mode = style.writing_mode;
|
||||
let container_writing_mode = containing_block.style.writing_mode;
|
||||
let layout_style = self.layout_style();
|
||||
let content_box_sizes_and_pbm =
|
||||
|
@ -2277,7 +2267,7 @@ impl IndependentFormattingContext {
|
|||
|
||||
let get_content_size = || {
|
||||
let constraint_space =
|
||||
ConstraintSpace::new(tentative_block_size, writing_mode, preferred_aspect_ratio);
|
||||
ConstraintSpace::new(tentative_block_size, style, preferred_aspect_ratio);
|
||||
self.inline_content_sizes(layout_context, &constraint_space)
|
||||
.sizes
|
||||
};
|
||||
|
@ -2300,7 +2290,7 @@ impl IndependentFormattingContext {
|
|||
};
|
||||
assert_eq!(
|
||||
container_writing_mode.is_horizontal(),
|
||||
writing_mode.is_horizontal(),
|
||||
style.writing_mode.is_horizontal(),
|
||||
"Mixed horizontal and vertical writing modes are not supported yet"
|
||||
);
|
||||
|
||||
|
|
|
@ -58,74 +58,70 @@ pub(crate) type SharedStyle = ArcRefCell<ServoArc<ComputedValues>>;
|
|||
|
||||
/// Represents the set of constraints that we use when computing the min-content
|
||||
/// and max-content inline sizes of an element.
|
||||
pub(crate) struct ConstraintSpace {
|
||||
pub(crate) struct ConstraintSpace<'a> {
|
||||
pub block_size: SizeConstraint,
|
||||
pub writing_mode: WritingMode,
|
||||
pub style: &'a ComputedValues,
|
||||
pub preferred_aspect_ratio: Option<AspectRatio>,
|
||||
}
|
||||
|
||||
impl ConstraintSpace {
|
||||
impl<'a> ConstraintSpace<'a> {
|
||||
fn new(
|
||||
block_size: SizeConstraint,
|
||||
writing_mode: WritingMode,
|
||||
style: &'a ComputedValues,
|
||||
preferred_aspect_ratio: Option<AspectRatio>,
|
||||
) -> Self {
|
||||
Self {
|
||||
block_size,
|
||||
writing_mode,
|
||||
style,
|
||||
preferred_aspect_ratio,
|
||||
}
|
||||
}
|
||||
|
||||
fn new_for_style_and_ratio(
|
||||
style: &ComputedValues,
|
||||
style: &'a ComputedValues,
|
||||
preferred_aspect_ratio: Option<AspectRatio>,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
SizeConstraint::default(),
|
||||
style.writing_mode,
|
||||
preferred_aspect_ratio,
|
||||
)
|
||||
Self::new(SizeConstraint::default(), style, preferred_aspect_ratio)
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of [`ContainingBlock`] that allows an indefinite inline size.
|
||||
/// Useful for code that is shared for both layout (where we know the inline size
|
||||
/// of the containing block) and intrinsic sizing (where we don't know it).
|
||||
pub(crate) struct IndefiniteContainingBlock {
|
||||
pub(crate) struct IndefiniteContainingBlock<'a> {
|
||||
pub size: LogicalVec2<Option<Au>>,
|
||||
pub writing_mode: WritingMode,
|
||||
pub style: &'a ComputedValues,
|
||||
}
|
||||
|
||||
impl From<&ConstraintSpace> for IndefiniteContainingBlock {
|
||||
fn from(constraint_space: &ConstraintSpace) -> Self {
|
||||
impl<'a> From<&ConstraintSpace<'a>> for IndefiniteContainingBlock<'a> {
|
||||
fn from(constraint_space: &ConstraintSpace<'a>) -> Self {
|
||||
Self {
|
||||
size: LogicalVec2 {
|
||||
inline: None,
|
||||
block: constraint_space.block_size.to_definite(),
|
||||
},
|
||||
writing_mode: constraint_space.writing_mode,
|
||||
style: constraint_space.style,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'_ ContainingBlock<'a>> for IndefiniteContainingBlock {
|
||||
impl<'a> From<&'_ ContainingBlock<'a>> for IndefiniteContainingBlock<'a> {
|
||||
fn from(containing_block: &ContainingBlock<'a>) -> Self {
|
||||
Self {
|
||||
size: LogicalVec2 {
|
||||
inline: Some(containing_block.size.inline),
|
||||
block: containing_block.size.block.to_definite(),
|
||||
},
|
||||
writing_mode: containing_block.style.writing_mode,
|
||||
style: containing_block.style,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'_ DefiniteContainingBlock<'a>> for IndefiniteContainingBlock {
|
||||
impl<'a> From<&'_ DefiniteContainingBlock<'a>> for IndefiniteContainingBlock<'a> {
|
||||
fn from(containing_block: &DefiniteContainingBlock<'a>) -> Self {
|
||||
Self {
|
||||
size: containing_block.size.map(|v| Some(*v)),
|
||||
writing_mode: containing_block.style.writing_mode,
|
||||
style: containing_block.style,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -532,11 +532,8 @@ impl HoistedAbsolutelyPositionedBox {
|
|||
// The inline axis can be fully resolved, computing intrinsic sizes using the
|
||||
// extrinsic block size.
|
||||
let get_inline_content_size = || {
|
||||
let constraint_space = ConstraintSpace::new(
|
||||
tentative_block_size,
|
||||
style.writing_mode,
|
||||
preferred_aspect_ratio,
|
||||
);
|
||||
let constraint_space =
|
||||
ConstraintSpace::new(tentative_block_size, &style, preferred_aspect_ratio);
|
||||
context
|
||||
.inline_content_sizes(layout_context, &constraint_space)
|
||||
.sizes
|
||||
|
|
|
@ -546,7 +546,7 @@ impl ComputeInlineContentSizes for ReplacedContents {
|
|||
Direction::Inline,
|
||||
constraint_space.preferred_aspect_ratio,
|
||||
&|| constraint_space.block_size,
|
||||
&|| self.fallback_inline_size(constraint_space.writing_mode),
|
||||
&|| self.fallback_inline_size(constraint_space.style.writing_mode),
|
||||
);
|
||||
InlineContentSizesResult {
|
||||
sizes: inline_content_size.into(),
|
||||
|
|
|
@ -175,14 +175,14 @@ pub(crate) fn outer_inline(
|
|||
available_block_size,
|
||||
)
|
||||
};
|
||||
ConstraintSpace::new(block_size, style.writing_mode, aspect_ratio)
|
||||
ConstraintSpace::new(block_size, style, aspect_ratio)
|
||||
} else {
|
||||
// This assumes that there is no preferred aspect ratio, or that there is no
|
||||
// block size constraint to be transferred so the ratio is irrelevant.
|
||||
// We only get into here for anonymous blocks, for which the assumption holds.
|
||||
ConstraintSpace::new(
|
||||
containing_block.size.block.into(),
|
||||
containing_block.writing_mode,
|
||||
containing_block.style,
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
@ -246,13 +246,14 @@ pub(crate) fn outer_inline(
|
|||
// We need a comment here to avoid breaking `./mach test-tidy`.
|
||||
matches!(size, Size::Numeric(numeric) if numeric.has_percentage())
|
||||
};
|
||||
let writing_mode = containing_block.style.writing_mode;
|
||||
if content_box_sizes.inline.preferred.is_initial() &&
|
||||
has_percentage(style.box_size(containing_block.writing_mode).inline)
|
||||
has_percentage(style.box_size(writing_mode).inline)
|
||||
{
|
||||
preferred_min_content = Au::zero();
|
||||
}
|
||||
if content_box_sizes.inline.max.is_initial() &&
|
||||
has_percentage(style.max_box_size(containing_block.writing_mode).inline)
|
||||
has_percentage(style.max_box_size(writing_mode).inline)
|
||||
{
|
||||
max_min_content = Some(Au::zero());
|
||||
}
|
||||
|
|
|
@ -1092,7 +1092,7 @@ impl LayoutStyle<'_> {
|
|||
// we instead resolve indefinite percentages against zero.
|
||||
let containing_block_size_or_zero =
|
||||
containing_block.size.map(|value| value.unwrap_or_default());
|
||||
let writing_mode = containing_block.writing_mode;
|
||||
let writing_mode = containing_block.style.writing_mode;
|
||||
let pbm = self.padding_border_margin_with_writing_mode_and_containing_block_inline_size(
|
||||
writing_mode,
|
||||
containing_block_size_or_zero.inline,
|
||||
|
|
|
@ -709,7 +709,7 @@ impl<'a> TableLayout<'a> {
|
|||
fn compute_caption_minimum_inline_size(&self, layout_context: &LayoutContext) -> Au {
|
||||
let containing_block = IndefiniteContainingBlock {
|
||||
size: LogicalVec2::default(),
|
||||
writing_mode: self.table.style.writing_mode,
|
||||
style: &self.table.style,
|
||||
};
|
||||
self.table
|
||||
.captions
|
||||
|
@ -2709,7 +2709,7 @@ impl ComputeInlineContentSizes for Table {
|
|||
layout_context: &LayoutContext,
|
||||
constraint_space: &ConstraintSpace,
|
||||
) -> InlineContentSizesResult {
|
||||
let writing_mode = constraint_space.writing_mode;
|
||||
let writing_mode = constraint_space.style.writing_mode;
|
||||
let mut layout = TableLayout::new(self);
|
||||
layout.compute_border_collapse(writing_mode);
|
||||
layout.pbm = self
|
||||
|
|
|
@ -128,7 +128,6 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> {
|
|||
// TODO: re-evaluate sizing constraint conversions in light of recent layout changes
|
||||
let containing_block = &self.content_box_size_override;
|
||||
let style = independent_context.style();
|
||||
let writing_mode = style.writing_mode;
|
||||
|
||||
// Adjust known_dimensions from border box to content box
|
||||
let pbm = independent_context
|
||||
|
@ -160,7 +159,7 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> {
|
|||
let inline_size = content_box_known_dimensions.width.unwrap_or_else(|| {
|
||||
let constraint_space = ConstraintSpace {
|
||||
block_size: tentative_block_size,
|
||||
writing_mode,
|
||||
style,
|
||||
preferred_aspect_ratio,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue