layout: Make a new ContainingBlockSize type (#34565)

This might make caching these values a bit easier in the future.
Correcting the visibility of `ContainingBlock` also exposed some new
rustc and clippy warnings that are fixed here.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-11 15:40:04 +01:00 committed by GitHub
parent 064569ff3c
commit f1b8d49e77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 192 additions and 158 deletions

View file

@ -42,7 +42,10 @@ use crate::sizing::{ContentSizes, InlineContentSizesResult, IntrinsicSizingMode}
use crate::style_ext::{ use crate::style_ext::{
AspectRatio, Clamp, ComputedValuesExt, ContentBoxSizesAndPBMDeprecated, PaddingBorderMargin, AspectRatio, Clamp, ComputedValuesExt, ContentBoxSizesAndPBMDeprecated, PaddingBorderMargin,
}; };
use crate::{ConstraintSpace, ContainingBlock, IndefiniteContainingBlock, SizeConstraint}; use crate::{
ConstraintSpace, ContainingBlock, ContainingBlockSize, IndefiniteContainingBlock,
SizeConstraint,
};
/// Layout parameters and intermediate results about a flex container, /// Layout parameters and intermediate results about a flex container,
/// grouped to avoid passing around many parameters /// grouped to avoid passing around many parameters
@ -126,8 +129,8 @@ struct FlexItemLayoutResult {
impl FlexItemLayoutResult { impl FlexItemLayoutResult {
fn compatible_with_containing_block_size(&self, containing_block: &ContainingBlock) -> bool { fn compatible_with_containing_block_size(&self, containing_block: &ContainingBlock) -> bool {
if containing_block.inline_size == self.containing_block_inline_size && if containing_block.size.inline == self.containing_block_inline_size &&
(containing_block.block_size == self.containing_block_block_size || (containing_block.size.block == self.containing_block_block_size ||
(!self.depends_on_block_constraints && (!self.depends_on_block_constraints &&
!self.has_child_which_depends_on_block_constraints)) !self.has_child_which_depends_on_block_constraints))
{ {
@ -139,8 +142,8 @@ impl FlexItemLayoutResult {
name: "NonReplaced stretch cache miss", name: "NonReplaced stretch cache miss",
cached_inline = ?self.containing_block_inline_size, cached_inline = ?self.containing_block_inline_size,
cached_block = ?self.containing_block_block_size, cached_block = ?self.containing_block_block_size,
required_inline = ?containing_block.inline_size, required_inline = ?containing_block.size.inline,
required_block = ?containing_block.block_size, required_block = ?containing_block.size.block,
depends_on_block_constraints = self.depends_on_block_constraints, depends_on_block_constraints = self.depends_on_block_constraints,
has_child_which_depends_on_block_constraints = self.has_child_which_depends_on_block_constraints, has_child_which_depends_on_block_constraints = self.has_child_which_depends_on_block_constraints,
); );
@ -264,7 +267,7 @@ impl<'a> FlexLineItem<'a> {
fragment_info, fragment_info,
style.clone(), style.clone(),
self.layout_result.fragments, self.layout_result.fragments,
content_rect.to_physical(Some(flex_context.containing_block)), content_rect.as_physical(Some(flex_context.containing_block)),
flex_context flex_context
.sides_to_flow_relative(self.item.padding) .sides_to_flow_relative(self.item.padding)
.to_physical(container_writing_mode), .to_physical(container_writing_mode),
@ -654,8 +657,8 @@ impl FlexContainer {
// https://drafts.csswg.org/css-flexbox/#definite-sizes // https://drafts.csswg.org/css-flexbox/#definite-sizes
container_definite_inner_size: self.config.flex_axis.vec2_to_flex_relative( container_definite_inner_size: self.config.flex_axis.vec2_to_flex_relative(
LogicalVec2 { LogicalVec2 {
inline: Some(containing_block.inline_size), inline: Some(containing_block.size.inline),
block: containing_block.block_size.non_auto(), block: containing_block.size.block.non_auto(),
}, },
), ),
}; };
@ -663,8 +666,8 @@ impl FlexContainer {
// “Determine the main size of the flex container” // “Determine the main size of the flex container”
// https://drafts.csswg.org/css-flexbox/#algo-main-container // https://drafts.csswg.org/css-flexbox/#algo-main-container
let container_main_size = match self.config.flex_axis { let container_main_size = match self.config.flex_axis {
FlexAxis::Row => containing_block.inline_size, FlexAxis::Row => containing_block.size.inline,
FlexAxis::Column => containing_block.block_size.auto_is(|| { FlexAxis::Column => containing_block.size.block.auto_is(|| {
self.main_content_sizes(layout_context, &containing_block.into(), || &flex_context) self.main_content_sizes(layout_context, &containing_block.into(), || &flex_context)
.sizes .sizes
.max_content .max_content
@ -1024,7 +1027,7 @@ impl FlexContainer {
start_corner: LogicalVec2::zero(), start_corner: LogicalVec2::zero(),
size: self.config.flex_axis.vec2_to_flow_relative(container_size), size: self.config.flex_axis.vec2_to_flow_relative(container_size),
} }
.to_physical(Some(containing_block)); .as_physical(Some(containing_block));
let hoisted_box = AbsolutelyPositionedBox::to_hoisted( let hoisted_box = AbsolutelyPositionedBox::to_hoisted(
absolutely_positioned_box, absolutely_positioned_box,
@ -1912,7 +1915,7 @@ impl FlexItem<'_> {
cross_size.auto_is(|| { cross_size.auto_is(|| {
let style = self.box_.style(); let style = self.box_.style();
let stretch_size = let stretch_size =
Au::zero().max(containing_block.inline_size - self.pbm_auto_is_zero.cross); Au::zero().max(containing_block.size.inline - self.pbm_auto_is_zero.cross);
if flex_context if flex_context
.config .config
.item_with_auto_cross_size_stretches_to_container_size(style, &self.margin) .item_with_auto_cross_size_stretches_to_container_size(style, &self.margin)
@ -1988,8 +1991,8 @@ impl FlexItem<'_> {
fragments, fragments,
positioning_context, positioning_context,
content_size: size, content_size: size,
containing_block_inline_size: containing_block.inline_size, containing_block_inline_size: containing_block.size.inline,
containing_block_block_size: containing_block.block_size, containing_block_block_size: containing_block.size.block,
depends_on_block_constraints: false, depends_on_block_constraints: false,
has_child_which_depends_on_block_constraints: false, has_child_which_depends_on_block_constraints: false,
@ -2017,8 +2020,10 @@ impl FlexItem<'_> {
}; };
let item_as_containing_block = ContainingBlock { let item_as_containing_block = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size, inline: inline_size,
block: block_size,
},
style: item_style, style: item_style,
}; };
@ -2095,11 +2100,11 @@ impl FlexItem<'_> {
positioning_context, positioning_context,
baseline_relative_to_margin_box, baseline_relative_to_margin_box,
content_size: LogicalVec2 { content_size: LogicalVec2 {
inline: item_as_containing_block.inline_size, inline: item_as_containing_block.size.inline,
block: content_block_size, block: content_block_size,
}, },
containing_block_inline_size: item_as_containing_block.inline_size, containing_block_inline_size: item_as_containing_block.size.inline,
containing_block_block_size: item_as_containing_block.block_size, containing_block_block_size: item_as_containing_block.size.block,
depends_on_block_constraints, depends_on_block_constraints,
has_child_which_depends_on_block_constraints, has_child_which_depends_on_block_constraints,
}) })
@ -2781,7 +2786,7 @@ impl FlexItemBox {
.inline .inline
.auto_is(|| { .auto_is(|| {
let containing_block_inline_size_minus_pbm = let containing_block_inline_size_minus_pbm =
flex_context.containing_block.inline_size - flex_context.containing_block.size.inline -
padding_border_margin.padding_border_sums.inline - padding_border_margin.padding_border_sums.inline -
padding_border_margin.margin.inline_start.auto_is(Au::zero) - padding_border_margin.margin.inline_start.auto_is(Au::zero) -
padding_border_margin.margin.inline_end.auto_is(Au::zero); padding_border_margin.margin.inline_end.auto_is(Au::zero);
@ -2805,8 +2810,10 @@ impl FlexItemBox {
}) })
.clamp_between_extremums(min_size.inline, max_size.inline); .clamp_between_extremums(min_size.inline, max_size.inline);
let item_as_containing_block = ContainingBlock { let item_as_containing_block = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size: AuOrAuto::Auto, inline: inline_size,
block: AuOrAuto::Auto,
},
style, style,
}; };
let content_block_size = || { let content_block_size = || {
@ -2835,7 +2842,7 @@ impl FlexItemBox {
let content_block_size = layout.content_block_size; let content_block_size = layout.content_block_size;
*self.block_content_size_cache.borrow_mut() = *self.block_content_size_cache.borrow_mut() =
Some(CachedBlockSizeContribution { Some(CachedBlockSizeContribution {
containing_block_inline_size: item_as_containing_block.inline_size, containing_block_inline_size: item_as_containing_block.size.inline,
layout, layout,
positioning_context, positioning_context,
}); });

View file

@ -190,7 +190,7 @@ impl CachedBlockSizeContribution {
&self, &self,
item_as_containing_block: &ContainingBlock, item_as_containing_block: &ContainingBlock,
) -> bool { ) -> bool {
item_as_containing_block.inline_size == self.containing_block_inline_size && item_as_containing_block.size.inline == self.containing_block_inline_size &&
item_as_containing_block.block_size.is_auto() item_as_containing_block.size.block.is_auto()
} }
} }

View file

@ -1190,6 +1190,6 @@ impl SequentialLayoutState {
.size .size
.to_logical(container_writing_mode), .to_logical(container_writing_mode),
} }
.to_physical(Some(containing_block)); .as_physical(Some(containing_block));
} }
} }

View file

@ -28,7 +28,7 @@ use crate::geom::{AuOrAuto, LogicalRect, LogicalVec2, PhysicalRect, ToLogical};
use crate::positioned::{ use crate::positioned::{
relative_adjustement, AbsolutelyPositionedBox, PositioningContext, PositioningContextLength, relative_adjustement, AbsolutelyPositionedBox, PositioningContext, PositioningContextLength,
}; };
use crate::ContainingBlock; use crate::{ContainingBlock, ContainingBlockSize};
pub(super) struct LineMetrics { pub(super) struct LineMetrics {
/// The block offset of the line start in the containing /// The block offset of the line start in the containing
@ -293,7 +293,7 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
// we know the width of the containing inline block. This step converts the logical rectangle // we know the width of the containing inline block. This step converts the logical rectangle
// into a physical one based on the inline formatting context width. // into a physical one based on the inline formatting context width.
if let Some(content_rect) = fragment.content_rect_mut() { if let Some(content_rect) = fragment.content_rect_mut() {
*content_rect = logical_rect.to_physical(Some(self.layout.containing_block)) *content_rect = logical_rect.as_physical(Some(self.layout.containing_block))
} }
fragment fragment
@ -430,8 +430,10 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
let ifc_writing_mode = self.layout.containing_block.style.writing_mode; let ifc_writing_mode = self.layout.containing_block.style.writing_mode;
let inline_box_containing_block = ContainingBlock { let inline_box_containing_block = ContainingBlock {
inline_size: content_rect.size.inline, size: ContainingBlockSize {
block_size: AuOrAuto::Auto, inline: content_rect.size.inline,
block: AuOrAuto::Auto,
},
style: self.layout.containing_block.style, style: self.layout.containing_block.style,
}; };
let fragments = inner_state let fragments = inner_state
@ -447,7 +449,7 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
// We do not know the actual physical position of a logically laid out inline element, until // We do not know the actual physical position of a logically laid out inline element, until
// we know the width of the containing inline block. This step converts the logical rectangle // we know the width of the containing inline block. This step converts the logical rectangle
// into a physical one now that we've computed inline size of the containing inline block above. // into a physical one now that we've computed inline size of the containing inline block above.
*content_rect = logical_rect.to_physical(Some(&inline_box_containing_block)) *content_rect = logical_rect.as_physical(Some(&inline_box_containing_block))
} }
} }
fragment fragment
@ -456,7 +458,7 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
// Previously all the fragment's children were positioned relative to the linebox, // Previously all the fragment's children were positioned relative to the linebox,
// but they need to be made relative to this fragment. // but they need to be made relative to this fragment.
let physical_content_rect = content_rect.to_physical(Some(self.layout.containing_block)); let physical_content_rect = content_rect.as_physical(Some(self.layout.containing_block));
let mut fragment = BoxFragment::new( let mut fragment = BoxFragment::new(
inline_box.base_fragment_info, inline_box.base_fragment_info,
style.clone(), style.clone(),
@ -619,7 +621,7 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
if let Some(mut positioning_context) = atomic.positioning_context { if let Some(mut positioning_context) = atomic.positioning_context {
let physical_rect_as_if_in_root = let physical_rect_as_if_in_root =
content_rect.to_physical(Some(self.layout.containing_block)); content_rect.as_physical(Some(self.layout.containing_block));
positioning_context.adjust_static_position_of_hoisted_fragments_with_offset( positioning_context.adjust_static_position_of_hoisted_fragments_with_offset(
&physical_rect_as_if_in_root.origin.to_vector(), &physical_rect_as_if_in_root.origin.to_vector(),
PositioningContextLength::zero(), PositioningContextLength::zero(),
@ -672,7 +674,7 @@ impl<'layout_data, 'layout> LineItemLayout<'layout_data, 'layout> {
start_corner: initial_start_corner, start_corner: initial_start_corner,
size: LogicalVec2::zero(), size: LogicalVec2::zero(),
} }
.to_physical(Some(self.layout.containing_block)); .as_physical(Some(self.layout.containing_block));
let hoisted_box = AbsolutelyPositionedBox::to_hoisted( let hoisted_box = AbsolutelyPositionedBox::to_hoisted(
absolute.absolutely_positioned_box.clone(), absolute.absolutely_positioned_box.clone(),

View file

@ -905,11 +905,11 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> {
let physical_line_rect = LogicalRect { let physical_line_rect = LogicalRect {
start_corner, start_corner,
size: LogicalVec2 { size: LogicalVec2 {
inline: self.containing_block.inline_size, inline: self.containing_block.size.inline,
block: effective_block_advance.resolve(), block: effective_block_advance.resolve(),
}, },
} }
.to_physical(Some(self.containing_block)); .as_physical(Some(self.containing_block));
self.fragments self.fragments
.push(Fragment::Positioning(PositioningFragment::new_anonymous( .push(Fragment::Positioning(PositioningFragment::new_anonymous(
physical_line_rect, physical_line_rect,
@ -975,7 +975,7 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> {
placement_among_floats.start_corner.inline, placement_among_floats.start_corner.inline,
placement_among_floats.size.inline, placement_among_floats.size.inline,
), ),
None => (Au::zero(), self.containing_block.inline_size), None => (Au::zero(), self.containing_block.size.inline),
}; };
// Properly handling text-indent requires that we do not align the text // Properly handling text-indent requires that we do not align the text
@ -1061,7 +1061,7 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> {
let available_inline_size = match self.current_line.placement_among_floats.get() { let available_inline_size = match self.current_line.placement_among_floats.get() {
Some(placement_among_floats) => placement_among_floats.size.inline, Some(placement_among_floats) => placement_among_floats.size.inline,
None => self.containing_block.inline_size, None => self.containing_block.size.inline,
} - line_inline_size_without_trailing_whitespace; } - line_inline_size_without_trailing_whitespace;
// If this float doesn't fit on the current line or a previous float didn't fit on // If this float doesn't fit on the current line or a previous float didn't fit on
@ -1146,7 +1146,7 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> {
.size .size
} else { } else {
LogicalVec2 { LogicalVec2 {
inline: self.containing_block.inline_size, inline: self.containing_block.size.inline,
block: MAX_AU, block: MAX_AU,
} }
}; };
@ -1179,7 +1179,7 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> {
// If the potential line is larger than the containing block we do not even need to consider // If the potential line is larger than the containing block we do not even need to consider
// floats. We definitely have to do a linebreak. // floats. We definitely have to do a linebreak.
if potential_line_size.inline > self.containing_block.inline_size { if potential_line_size.inline > self.containing_block.size.inline {
return true; return true;
} }
@ -1605,7 +1605,7 @@ impl InlineFormattingContext {
.get_inherited_text() .get_inherited_text()
.text_indent .text_indent
.length .length
.to_used_value(containing_block.inline_size) .to_used_value(containing_block.size.inline)
} else { } else {
Au::zero() Au::zero()
}; };

View file

@ -44,7 +44,10 @@ use crate::sizing::{self, ContentSizes, InlineContentSizesResult};
use crate::style_ext::{ use crate::style_ext::{
Clamp, ComputedValuesExt, ContentBoxSizesAndPBMDeprecated, PaddingBorderMargin, Clamp, ComputedValuesExt, ContentBoxSizesAndPBMDeprecated, PaddingBorderMargin,
}; };
use crate::{ConstraintSpace, ContainingBlock, IndefiniteContainingBlock, SizeConstraint}; use crate::{
ConstraintSpace, ContainingBlock, ContainingBlockSize, IndefiniteContainingBlock,
SizeConstraint,
};
mod construct; mod construct;
pub mod float; pub mod float;
@ -149,7 +152,7 @@ impl BlockLevelBox {
.auto_is(|| { .auto_is(|| {
let margin_inline_start = pbm.margin.inline_start.auto_is(Au::zero); let margin_inline_start = pbm.margin.inline_start.auto_is(Au::zero);
let margin_inline_end = pbm.margin.inline_end.auto_is(Au::zero); let margin_inline_end = pbm.margin.inline_end.auto_is(Au::zero);
containing_block.inline_size - containing_block.size.inline -
pbm.padding_border_sums.inline - pbm.padding_border_sums.inline -
margin_inline_start - margin_inline_start -
margin_inline_end margin_inline_end
@ -160,8 +163,10 @@ impl BlockLevelBox {
.map(|size| size.clamp_between_extremums(min_size.block, max_size.block)); .map(|size| size.clamp_between_extremums(min_size.block, max_size.block));
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size, inline: inline_size,
block: block_size,
},
style, style,
}; };
@ -242,8 +247,10 @@ impl OutsideMarker {
.block_container .block_container
.inline_content_sizes(layout_context, &constraint_space); .inline_content_sizes(layout_context, &constraint_space);
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size: content_sizes.sizes.max_content, size: ContainingBlockSize {
block_size: AuOrAuto::auto(), inline: content_sizes.sizes.max_content,
block: AuOrAuto::auto(),
},
style: &self.marker_style, style: &self.marker_style,
}; };
@ -306,7 +313,7 @@ impl OutsideMarker {
base_fragment_info, base_fragment_info,
self.marker_style.clone(), self.marker_style.clone(),
flow_layout.fragments, flow_layout.fragments,
content_rect.to_physical(Some(containing_block)), content_rect.as_physical(Some(containing_block)),
PhysicalSides::zero(), PhysicalSides::zero(),
PhysicalSides::zero(), PhysicalSides::zero(),
PhysicalSides::zero(), PhysicalSides::zero(),
@ -324,7 +331,7 @@ impl BlockFormattingContext {
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
) -> IndependentLayout { ) -> IndependentLayout {
let mut sequential_layout_state = if self.contains_floats || !layout_context.use_rayon { let mut sequential_layout_state = if self.contains_floats || !layout_context.use_rayon {
Some(SequentialLayoutState::new(containing_block.inline_size)) Some(SequentialLayoutState::new(containing_block.size.inline))
} else { } else {
None None
}; };
@ -792,7 +799,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
} = solve_margins( } = solve_margins(
containing_block, containing_block,
&pbm, &pbm,
containing_block_for_children.inline_size, containing_block_for_children.size.inline,
); );
let computed_block_size = style.content_block_size(); let computed_block_size = style.content_block_size();
@ -867,7 +874,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
block_start: sequential_layout_state.bfc_relative_block_position, block_start: sequential_layout_state.bfc_relative_block_position,
block_start_margins_not_collapsed: sequential_layout_state.current_margin, block_start_margins_not_collapsed: sequential_layout_state.current_margin,
inline_start, inline_start,
inline_end: inline_start + containing_block_for_children.inline_size, inline_end: inline_start + containing_block_for_children.size.inline,
}; };
parent_containing_block_position_info = Some( parent_containing_block_position_info = Some(
sequential_layout_state.replace_containing_block_position_info(new_cb_offsets), sequential_layout_state.replace_containing_block_position_info(new_cb_offsets),
@ -960,7 +967,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
}, },
size: LogicalVec2 { size: LogicalVec2 {
block: block_size, block: block_size,
inline: containing_block_for_children.inline_size, inline: containing_block_for_children.size.inline,
}, },
}; };
@ -974,7 +981,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
base_fragment_info, base_fragment_info,
style.clone(), style.clone(),
flow_layout.fragments, flow_layout.fragments,
content_rect.to_physical(Some(containing_block)), content_rect.as_physical(Some(containing_block)),
pbm.padding.to_physical(containing_block_writing_mode), pbm.padding.to_physical(containing_block_writing_mode),
pbm.border.to_physical(containing_block_writing_mode), pbm.border.to_physical(containing_block_writing_mode),
margin.to_physical(containing_block_writing_mode), margin.to_physical(containing_block_writing_mode),
@ -1034,7 +1041,7 @@ impl IndependentNonReplacedContents {
.block .block
.auto_is(|| layout.content_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, max_box_size.block),
containing_block_for_children.inline_size, containing_block_for_children.size.inline,
), ),
}; };
@ -1069,7 +1076,7 @@ impl IndependentNonReplacedContents {
base_fragment_info, base_fragment_info,
base.style.clone(), base.style.clone(),
layout.fragments, layout.fragments,
content_rect.to_physical(Some(containing_block)), content_rect.as_physical(Some(containing_block)),
pbm.padding.to_physical(containing_block_writing_mode), pbm.padding.to_physical(containing_block_writing_mode),
pbm.border.to_physical(containing_block_writing_mode), pbm.border.to_physical(containing_block_writing_mode),
margin.to_physical(containing_block_writing_mode), margin.to_physical(containing_block_writing_mode),
@ -1136,8 +1143,10 @@ impl IndependentNonReplacedContents {
layout_context, layout_context,
positioning_context, positioning_context,
&ContainingBlock { &ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size, inline: inline_size,
block: block_size,
},
style, style,
}, },
containing_block, containing_block,
@ -1215,8 +1224,10 @@ impl IndependentNonReplacedContents {
layout_context, layout_context,
positioning_context, positioning_context,
&ContainingBlock { &ContainingBlock {
inline_size: proposed_inline_size, size: ContainingBlockSize {
block_size, inline: proposed_inline_size,
block: block_size,
},
style, style,
}, },
containing_block, containing_block,
@ -1337,7 +1348,7 @@ impl IndependentNonReplacedContents {
base_fragment_info, base_fragment_info,
style.clone(), style.clone(),
layout.fragments, layout.fragments,
content_rect.to_physical(Some(containing_block)), content_rect.as_physical(Some(containing_block)),
pbm.padding.to_physical(containing_block_writing_mode), pbm.padding.to_physical(containing_block_writing_mode),
pbm.border.to_physical(containing_block_writing_mode), pbm.border.to_physical(containing_block_writing_mode),
margin.to_physical(containing_block_writing_mode), margin.to_physical(containing_block_writing_mode),
@ -1448,7 +1459,7 @@ impl ReplacedContents {
start_corner, start_corner,
size: content_size, size: content_size,
} }
.to_physical(Some(containing_block)); .as_physical(Some(containing_block));
let mut base_fragment_info = base.base_fragment_info; let mut base_fragment_info = base.base_fragment_info;
if content_box_sizes_and_pbm.depends_on_block_constraints { if content_box_sizes_and_pbm.depends_on_block_constraints {
@ -1507,8 +1518,10 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
// > Anonymous block boxes are ignored when resolving percentage values that would // > Anonymous block boxes are ignored when resolving percentage values that would
// > refer to it: the closest non-anonymous ancestor box is used instead. // > refer to it: the closest non-anonymous ancestor box is used instead.
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size: containing_block.inline_size, size: ContainingBlockSize {
block_size: containing_block.block_size, inline: containing_block.size.inline,
block: containing_block.size.block,
},
style, style,
}; };
// <https://drafts.csswg.org/css2/#anonymous-block-level> // <https://drafts.csswg.org/css2/#anonymous-block-level>
@ -1544,7 +1557,7 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
.auto_is(|| { .auto_is(|| {
let margin_inline_start = pbm.margin.inline_start.auto_is(Au::zero); let margin_inline_start = pbm.margin.inline_start.auto_is(Au::zero);
let margin_inline_end = pbm.margin.inline_end.auto_is(Au::zero); let margin_inline_end = pbm.margin.inline_end.auto_is(Au::zero);
containing_block.inline_size - containing_block.size.inline -
pbm.padding_border_sums.inline - pbm.padding_border_sums.inline -
margin_inline_start - margin_inline_start -
margin_inline_end margin_inline_end
@ -1560,8 +1573,10 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
} }
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size, inline: inline_size,
block: block_size,
},
style, style,
}; };
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows // https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
@ -1649,7 +1664,7 @@ fn solve_inline_margins_for_in_flow_block_level(
pbm: &PaddingBorderMargin, pbm: &PaddingBorderMargin,
inline_size: Au, inline_size: Au,
) -> ((Au, Au), Au) { ) -> ((Au, Au), Au) {
let free_space = containing_block.inline_size - pbm.padding_border_sums.inline - inline_size; let free_space = containing_block.size.inline - pbm.padding_border_sums.inline - inline_size;
let mut justification = Au::zero(); let mut justification = Au::zero();
let inline_margins = match (pbm.margin.inline_start, pbm.margin.inline_end) { let inline_margins = match (pbm.margin.inline_start, pbm.margin.inline_end) {
(AuOrAuto::Auto, AuOrAuto::Auto) => { (AuOrAuto::Auto, AuOrAuto::Auto) => {
@ -1936,7 +1951,7 @@ impl<'container> PlacementState<'container> {
}, },
size: LogicalVec2::zero(), size: LogicalVec2::zero(),
} }
.to_physical(Some(self.containing_block)); .as_physical(Some(self.containing_block));
}, },
Fragment::Float(box_fragment) => { Fragment::Float(box_fragment) => {
let sequential_layout_state = sequential_layout_state let sequential_layout_state = sequential_layout_state
@ -1995,7 +2010,7 @@ fn block_size_is_zero_or_intrinsic(size: &StyleSize, containing_block: &Containi
StyleSize::LengthPercentage(ref lp) => { StyleSize::LengthPercentage(ref lp) => {
// TODO: Should this resolve definite percentages? Blink does it, Gecko and WebKit don't. // TODO: Should this resolve definite percentages? Blink does it, Gecko and WebKit don't.
lp.is_definitely_zero() || lp.is_definitely_zero() ||
(lp.0.has_percentage() && containing_block.block_size.is_auto()) (lp.0.has_percentage() && containing_block.size.block.is_auto())
}, },
StyleSize::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"), StyleSize::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
} }
@ -2055,9 +2070,10 @@ impl IndependentFormattingContext {
IndependentFormattingContextContents::NonReplaced(non_replaced) => { IndependentFormattingContextContents::NonReplaced(non_replaced) => {
let writing_mode = self.style().writing_mode; let writing_mode = self.style().writing_mode;
let available_inline_size = let available_inline_size =
(containing_block.inline_size - pbm_sums.inline_sum()).max(Au::zero()); (containing_block.size.inline - pbm_sums.inline_sum()).max(Au::zero());
let available_block_size = containing_block let available_block_size = containing_block
.block_size .size
.block
.non_auto() .non_auto()
.map(|block_size| (block_size - pbm_sums.block_sum()).max(Au::zero())); .map(|block_size| (block_size - pbm_sums.block_sum()).max(Au::zero()));
let preferred_block_size = content_box_sizes_and_pbm let preferred_block_size = content_box_sizes_and_pbm
@ -2110,8 +2126,10 @@ impl IndependentFormattingContext {
tentative_inline_size.clamp_between_extremums(min_inline_size, max_inline_size); tentative_inline_size.clamp_between_extremums(min_inline_size, max_inline_size);
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size: tentative_block_size.to_auto_or(), inline: inline_size,
block: tentative_block_size.to_auto_or(),
},
style: self.style(), style: self.style(),
}; };
assert_eq!( assert_eq!(

View file

@ -223,31 +223,6 @@ impl<T: Copy + Neg<Output = T>> LogicalVec2<T> {
} }
} }
impl LogicalVec2<Au> {
#[inline]
pub fn to_physical_point(
&self,
containing_block: Option<&ContainingBlock>,
) -> PhysicalPoint<Au> {
let mode = containing_block.map_or_else(WritingMode::horizontal_tb, |containing_block| {
containing_block.style.writing_mode
});
if mode.is_vertical() {
// TODO: Bottom-to-top writing modes are not supported yet.
PhysicalPoint::new(self.block, self.inline)
} else {
let y = self.block;
let x = match containing_block {
Some(containing_block) if !mode.is_bidi_ltr() => {
containing_block.inline_size - self.inline
},
_ => self.inline,
};
PhysicalPoint::new(x, y)
}
}
}
impl<T: Clone> LogicalSides<T> { impl<T: Clone> LogicalSides<T> {
pub fn from_physical(sides: &PhysicalSides<T>, mode: WritingMode) -> Self { pub fn from_physical(sides: &PhysicalSides<T>, mode: WritingMode) -> Self {
// https://drafts.csswg.org/css-writing-modes/#logical-to-physical // https://drafts.csswg.org/css-writing-modes/#logical-to-physical
@ -508,7 +483,10 @@ impl<T> LogicalRect<T> {
} }
impl LogicalRect<Au> { impl LogicalRect<Au> {
pub fn to_physical(&self, containing_block: Option<&ContainingBlock<'_>>) -> PhysicalRect<Au> { pub(crate) fn as_physical(
&self,
containing_block: Option<&ContainingBlock<'_>>,
) -> PhysicalRect<Au> {
let mode = containing_block.map_or_else(WritingMode::horizontal_tb, |containing_block| { let mode = containing_block.map_or_else(WritingMode::horizontal_tb, |containing_block| {
containing_block.style.writing_mode containing_block.style.writing_mode
}); });
@ -524,7 +502,7 @@ impl LogicalRect<Au> {
let y = self.start_corner.block; let y = self.start_corner.block;
let x = match containing_block { let x = match containing_block {
Some(containing_block) if !mode.is_bidi_ltr() => { Some(containing_block) if !mode.is_bidi_ltr() => {
containing_block.inline_size - self.max_inline_position() containing_block.size.inline - self.max_inline_position()
}, },
_ => self.start_corner.inline, _ => self.start_corner.inline,
}; };
@ -605,7 +583,7 @@ impl ToLogicalWithContainingBlock<LogicalVec2<Au>> for PhysicalPoint<Au> {
inline: if writing_mode.is_bidi_ltr() { inline: if writing_mode.is_bidi_ltr() {
self.x self.x
} else { } else {
containing_block.inline_size - self.x containing_block.size.inline - self.x
}, },
block: self.y, block: self.y,
} }
@ -634,7 +612,7 @@ impl ToLogicalWithContainingBlock<LogicalRect<Au>> for PhysicalRect<Au> {
if writing_mode.is_bidi_ltr() { if writing_mode.is_bidi_ltr() {
inline_start = self.origin.x; inline_start = self.origin.x;
} else { } else {
inline_start = containing_block.inline_size - (self.origin.x + self.size.width); inline_start = containing_block.size.inline - (self.origin.x + self.size.width);
} }
} }
LogicalRect { LogicalRect {
@ -760,10 +738,10 @@ impl LogicalVec2<Size<LengthPercentage>> {
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
) -> LogicalVec2<Size<Au>> { ) -> LogicalVec2<Size<Au>> {
self.map_inline_and_block_axes( self.map_inline_and_block_axes(
|inline_size| inline_size.map(|lp| lp.to_used_value(containing_block.inline_size)), |inline_size| inline_size.map(|lp| lp.to_used_value(containing_block.size.inline)),
|block_size| { |block_size| {
block_size block_size
.maybe_map(|lp| lp.maybe_to_used_value(containing_block.block_size.non_auto())) .maybe_map(|lp| lp.maybe_to_used_value(containing_block.size.block.non_auto()))
.unwrap_or_default() .unwrap_or_default()
}, },
) )

View file

@ -32,6 +32,7 @@ use app_units::Au;
pub use flow::BoxTree; pub use flow::BoxTree;
pub use fragment_tree::FragmentTree; pub use fragment_tree::FragmentTree;
use geom::AuOrAuto; use geom::AuOrAuto;
use serde::Serialize;
use style::logical_geometry::WritingMode; use style::logical_geometry::WritingMode;
use style::properties::ComputedValues; use style::properties::ComputedValues;
@ -95,8 +96,8 @@ impl<'a> From<&'_ ContainingBlock<'a>> for IndefiniteContainingBlock {
fn from(containing_block: &ContainingBlock<'a>) -> Self { fn from(containing_block: &ContainingBlock<'a>) -> Self {
Self { Self {
size: LogicalVec2 { size: LogicalVec2 {
inline: AuOrAuto::LengthPercentage(containing_block.inline_size), inline: AuOrAuto::LengthPercentage(containing_block.size.inline),
block: containing_block.block_size, block: containing_block.size.block,
}, },
writing_mode: containing_block.style.writing_mode, writing_mode: containing_block.style.writing_mode,
} }
@ -114,9 +115,14 @@ impl<'a> From<&'_ DefiniteContainingBlock<'a>> for IndefiniteContainingBlock {
} }
} }
pub struct ContainingBlock<'a> { #[derive(Debug, Serialize)]
inline_size: Au, pub(crate) struct ContainingBlockSize {
block_size: AuOrAuto, inline: Au,
block: AuOrAuto,
}
pub(crate) struct ContainingBlock<'a> {
size: ContainingBlockSize,
style: &'a ComputedValues, style: &'a ComputedValues,
} }
@ -128,8 +134,10 @@ struct DefiniteContainingBlock<'a> {
impl<'a> From<&'_ DefiniteContainingBlock<'a>> for ContainingBlock<'a> { impl<'a> From<&'_ DefiniteContainingBlock<'a>> for ContainingBlock<'a> {
fn from(definite: &DefiniteContainingBlock<'a>) -> Self { fn from(definite: &DefiniteContainingBlock<'a>) -> Self {
ContainingBlock { ContainingBlock {
inline_size: definite.size.inline, size: ContainingBlockSize {
block_size: AuOrAuto::LengthPercentage(definite.size.block), inline: definite.size.inline,
block: AuOrAuto::LengthPercentage(definite.size.block),
},
style: definite.style, style: definite.style,
} }
} }

View file

@ -32,7 +32,9 @@ use crate::geom::{
}; };
use crate::sizing::ContentSizes; use crate::sizing::ContentSizes;
use crate::style_ext::{ComputedValuesExt, DisplayInside}; use crate::style_ext::{ComputedValuesExt, DisplayInside};
use crate::{ConstraintSpace, ContainingBlock, DefiniteContainingBlock, SizeConstraint}; use crate::{
ConstraintSpace, ContainingBlock, ContainingBlockSize, DefiniteContainingBlock, SizeConstraint,
};
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub(crate) struct AbsolutelyPositionedBox { pub(crate) struct AbsolutelyPositionedBox {
@ -579,8 +581,10 @@ impl HoistedAbsolutelyPositionedBox {
// https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height // https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height
let inline_size = inline_axis.size.to_definite().unwrap(); let inline_size = inline_axis.size.to_definite().unwrap();
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size: block_axis.size.to_auto_or(), inline: inline_size,
block: block_axis.size.to_auto_or(),
},
style: &style, style: &style,
}; };
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows // https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
@ -664,7 +668,7 @@ impl HoistedAbsolutelyPositionedBox {
context.base_fragment_info(), context.base_fragment_info(),
style, style,
fragments, fragments,
content_rect.to_physical(Some(containing_block)), content_rect.as_physical(Some(containing_block)),
pbm.padding.to_physical(containing_block_writing_mode), pbm.padding.to_physical(containing_block_writing_mode),
pbm.border.to_physical(containing_block_writing_mode), pbm.border.to_physical(containing_block_writing_mode),
margin.to_physical(containing_block_writing_mode), margin.to_physical(containing_block_writing_mode),
@ -1009,8 +1013,8 @@ pub(crate) fn relative_adjustement(
// It's not completely clear what to do with indefinite percentages // It's not completely clear what to do with indefinite percentages
// (https://github.com/w3c/csswg-drafts/issues/9353), so we match // (https://github.com/w3c/csswg-drafts/issues/9353), so we match
// other browsers and treat them as 'auto' offsets. // other browsers and treat them as 'auto' offsets.
let cbis = containing_block.inline_size; let cbis = containing_block.size.inline;
let cbbs = containing_block.block_size; let cbbs = containing_block.size.block;
let box_offsets = style let box_offsets = style
.box_offsets(containing_block.style.writing_mode) .box_offsets(containing_block.style.writing_mode)
.map_inline_and_block_axes( .map_inline_and_block_axes(

View file

@ -521,9 +521,10 @@ impl ReplacedContents {
}; };
// <https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing> // <https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing>
let inline_stretch_size = Au::zero().max(containing_block.inline_size - pbm_sums.inline); let inline_stretch_size = Au::zero().max(containing_block.size.inline - pbm_sums.inline);
let block_stretch_size = containing_block let block_stretch_size = containing_block
.block_size .size
.block
.non_auto() .non_auto()
.map(|block_size| Au::zero().max(block_size - pbm_sums.block)); .map(|block_size| Au::zero().max(block_size - pbm_sums.block));

View file

@ -440,8 +440,8 @@ impl ComputedValuesExt for ComputedValues {
let min_size = self let min_size = self
.min_box_size(containing_block.style.writing_mode) .min_box_size(containing_block.style.writing_mode)
.map_inline_and_block_sizes( .map_inline_and_block_sizes(
|lp| lp.to_used_value(containing_block.inline_size), |lp| lp.to_used_value(containing_block.size.inline),
|lp| lp.to_used_value(containing_block.block_size.auto_is(Au::zero)), |lp| lp.to_used_value(containing_block.size.block.auto_is(Au::zero)),
); );
self.content_min_box_size_for_min_size(min_size, pbm) self.content_min_box_size_for_min_size(min_size, pbm)
} }
@ -571,7 +571,7 @@ impl ComputedValuesExt for ComputedValues {
fn padding_border_margin(&self, containing_block: &ContainingBlock) -> PaddingBorderMargin { fn padding_border_margin(&self, containing_block: &ContainingBlock) -> PaddingBorderMargin {
self.padding_border_margin_with_writing_mode_and_containing_block_inline_size( self.padding_border_margin_with_writing_mode_and_containing_block_inline_size(
containing_block.style.writing_mode, containing_block.style.writing_mode,
containing_block.inline_size, containing_block.size.inline,
) )
} }

View file

@ -39,7 +39,9 @@ use crate::positioned::{relative_adjustement, PositioningContext, PositioningCon
use crate::sizing::{ContentSizes, InlineContentSizesResult}; use crate::sizing::{ContentSizes, InlineContentSizesResult};
use crate::style_ext::{Clamp, ComputedValuesExt, PaddingBorderMargin}; use crate::style_ext::{Clamp, ComputedValuesExt, PaddingBorderMargin};
use crate::table::TableSlotCoordinates; use crate::table::TableSlotCoordinates;
use crate::{ConstraintSpace, ContainingBlock, IndefiniteContainingBlock, WritingMode}; use crate::{
ConstraintSpace, ContainingBlock, ContainingBlockSize, IndefiniteContainingBlock, WritingMode,
};
/// A result of a final or speculative layout of a single cell in /// A result of a final or speculative layout of a single cell in
/// the table. Note that this is only done for slots that are not /// the table. Note that this is only done for slots that are not
@ -807,7 +809,7 @@ impl<'a> TableLayout<'a> {
// * Otherwise, it's the resulting length (with percentages resolved). // * Otherwise, it's the resulting length (with percentages resolved).
// In both cases, it's clamped between min-inline-size and max-inline-size. // In both cases, it's clamped between min-inline-size and max-inline-size.
// This diverges a little from the specification. // This diverges a little from the specification.
let resolved_table_width = containing_block_for_children.inline_size; let resolved_table_width = containing_block_for_children.size.inline;
// https://drafts.csswg.org/css-tables/#used-width-of-table // https://drafts.csswg.org/css-tables/#used-width-of-table
// * If table-root has a computed value for inline-size different than auto: // * If table-root has a computed value for inline-size different than auto:
@ -1233,8 +1235,10 @@ impl<'a> TableLayout<'a> {
total_cell_width = total_cell_width.max(Au::zero()); total_cell_width = total_cell_width.max(Au::zero());
let containing_block_for_children = ContainingBlock { let containing_block_for_children = ContainingBlock {
inline_size: total_cell_width, size: ContainingBlockSize {
block_size: AuOrAuto::Auto, inline: total_cell_width,
block: AuOrAuto::Auto,
},
style: &cell.base.style, style: &cell.base.style,
}; };
@ -1565,7 +1569,7 @@ impl<'a> TableLayout<'a> {
.content_box_size_deprecated(containing_block_for_table, &self.pbm) .content_box_size_deprecated(containing_block_for_table, &self.pbm)
.block .block
{ {
LengthPercentage(_) => containing_block_for_children.block_size, LengthPercentage(_) => containing_block_for_children.size.block,
Auto => style Auto => style
.content_min_box_size_deprecated(containing_block_for_table, &self.pbm) .content_min_box_size_deprecated(containing_block_for_table, &self.pbm)
.block .block
@ -1608,8 +1612,10 @@ impl<'a> TableLayout<'a> {
let context = caption.context.borrow(); let context = caption.context.borrow();
let mut positioning_context = PositioningContext::new_for_style(context.style()); let mut positioning_context = PositioningContext::new_for_style(context.style());
let containing_block = &ContainingBlock { let containing_block = &ContainingBlock {
inline_size: self.table_width + table_pbm.padding_border_sums.inline, size: ContainingBlockSize {
block_size: AuOrAuto::Auto, inline: self.table_width + table_pbm.padding_border_sums.inline,
block: AuOrAuto::Auto,
},
style: &self.table.style, style: &self.table.style,
}; };
@ -1673,8 +1679,10 @@ impl<'a> TableLayout<'a> {
// TODO: This is broken for orthoganol flows, because the inline size of the parent isn't necessarily // TODO: This is broken for orthoganol flows, because the inline size of the parent isn't necessarily
// the inline size of the table. // the inline size of the table.
let containing_block_for_logical_conversion = ContainingBlock { let containing_block_for_logical_conversion = ContainingBlock {
inline_size: self.table_width, size: ContainingBlockSize {
block_size: containing_block_for_table.block_size, inline: self.table_width,
block: containing_block_for_table.size.block,
},
style: containing_block_for_children.style, style: containing_block_for_children.style,
}; };
let table_pbm = self let table_pbm = self
@ -1682,7 +1690,7 @@ impl<'a> TableLayout<'a> {
.style .style
.padding_border_margin_with_writing_mode_and_containing_block_inline_size( .padding_border_margin_with_writing_mode_and_containing_block_inline_size(
table_writing_mode, table_writing_mode,
containing_block_for_table.inline_size, containing_block_for_table.size.inline,
); );
let offset_from_wrapper = -table_pbm.padding - table_pbm.border; let offset_from_wrapper = -table_pbm.padding - table_pbm.border;
let mut current_block_offset = offset_from_wrapper.block_start; let mut current_block_offset = offset_from_wrapper.block_start;
@ -1735,7 +1743,7 @@ impl<'a> TableLayout<'a> {
.size .size
.to_logical(table_writing_mode), .to_logical(table_writing_mode),
} }
.to_physical(Some(&containing_block_for_logical_conversion)); .as_physical(Some(&containing_block_for_logical_conversion));
current_block_offset += caption_fragment current_block_offset += caption_fragment
.margin_rect() .margin_rect()
@ -1785,7 +1793,7 @@ impl<'a> TableLayout<'a> {
.size .size
.to_logical(table_writing_mode), .to_logical(table_writing_mode),
} }
.to_physical(Some(&containing_block_for_logical_conversion)); .as_physical(Some(&containing_block_for_logical_conversion));
current_block_offset += grid_fragment current_block_offset += grid_fragment
.border_rect() .border_rect()
@ -1827,7 +1835,7 @@ impl<'a> TableLayout<'a> {
.size .size
.to_logical(table_writing_mode), .to_logical(table_writing_mode),
} }
.to_physical(Some(&containing_block_for_logical_conversion)); .as_physical(Some(&containing_block_for_logical_conversion));
current_block_offset += caption_fragment current_block_offset += caption_fragment
.margin_rect() .margin_rect()
@ -1883,7 +1891,7 @@ impl<'a> TableLayout<'a> {
block: self.final_table_height, block: self.final_table_height,
}, },
} }
.to_physical(Some(containing_block_for_logical_conversion)); .as_physical(Some(containing_block_for_logical_conversion));
return BoxFragment::new( return BoxFragment::new(
self.table.grid_base_fragment_info, self.table.grid_base_fragment_info,
self.table.grid_style.clone(), self.table.grid_style.clone(),
@ -2008,7 +2016,7 @@ impl<'a> TableLayout<'a> {
block: table_and_track_dimensions.table_rect.max_block_position(), block: table_and_track_dimensions.table_rect.max_block_position(),
}, },
} }
.to_physical(Some(containing_block_for_logical_conversion)); .as_physical(Some(containing_block_for_logical_conversion));
BoxFragment::new( BoxFragment::new(
self.table.grid_base_fragment_info, self.table.grid_base_fragment_info,
self.table.grid_style.clone(), self.table.grid_style.clone(),
@ -2184,7 +2192,7 @@ impl<'a> TableLayout<'a> {
column_group.base_fragment_info, column_group.base_fragment_info,
dimensions dimensions
.get_column_group_rect(column_group) .get_column_group_rect(column_group)
.to_physical(None), .as_physical(None),
column_group.style.clone(), column_group.style.clone(),
))); )));
} }
@ -2193,7 +2201,7 @@ impl<'a> TableLayout<'a> {
for (column_index, column) in self.table.columns.iter().enumerate() { for (column_index, column) in self.table.columns.iter().enumerate() {
fragments.push(Fragment::Positioning(PositioningFragment::new_empty( fragments.push(Fragment::Positioning(PositioningFragment::new_empty(
column.base_fragment_info, column.base_fragment_info,
dimensions.get_column_rect(column_index).to_physical(None), dimensions.get_column_rect(column_index).as_physical(None),
column.style.clone(), column.style.clone(),
))); )));
} }
@ -2299,8 +2307,10 @@ impl<'a> RowFragmentLayout<'a> {
) -> Self { ) -> Self {
let rect = dimensions.get_row_rect(index); let rect = dimensions.get_row_rect(index);
let containing_block = ContainingBlock { let containing_block = ContainingBlock {
inline_size: rect.size.inline, size: ContainingBlockSize {
block_size: AuOrAuto::LengthPercentage(rect.size.inline), inline: rect.size.inline,
block: AuOrAuto::LengthPercentage(rect.size.inline),
},
style: table_style, style: table_style,
}; };
Self { Self {
@ -2333,14 +2343,16 @@ impl<'a> RowFragmentLayout<'a> {
) )
} else { } else {
( (
containing_block_for_logical_conversion.inline_size, containing_block_for_logical_conversion.size.inline,
containing_block_for_logical_conversion.block_size, containing_block_for_logical_conversion.size.block,
) )
}; };
let row_group_containing_block = ContainingBlock { let row_group_containing_block = ContainingBlock {
inline_size, size: ContainingBlockSize {
block_size, inline: inline_size,
block: block_size,
},
style: containing_block_for_logical_conversion.style, style: containing_block_for_logical_conversion.style,
}; };
@ -2348,7 +2360,7 @@ impl<'a> RowFragmentLayout<'a> {
self.row.base_fragment_info, self.row.base_fragment_info,
self.row.style.clone(), self.row.style.clone(),
self.fragments, self.fragments,
self.rect.to_physical(Some(&row_group_containing_block)), self.rect.as_physical(Some(&row_group_containing_block)),
PhysicalSides::zero(), /* padding */ PhysicalSides::zero(), /* padding */
PhysicalSides::zero(), /* border */ PhysicalSides::zero(), /* border */
PhysicalSides::zero(), /* margin */ PhysicalSides::zero(), /* margin */
@ -2414,7 +2426,7 @@ impl RowGroupFragmentLayout {
self.style, self.style,
self.fragments, self.fragments,
self.rect self.rect
.to_physical(Some(containing_block_for_logical_conversion)), .as_physical(Some(containing_block_for_logical_conversion)),
PhysicalSides::zero(), /* padding */ PhysicalSides::zero(), /* padding */
PhysicalSides::zero(), /* border */ PhysicalSides::zero(), /* border */
PhysicalSides::zero(), /* margin */ PhysicalSides::zero(), /* margin */
@ -2802,7 +2814,7 @@ impl TableSlotCell {
block: vertical_align_offset, block: vertical_align_offset,
}; };
let vertical_align_fragment = PositioningFragment::new_anonymous( let vertical_align_fragment = PositioningFragment::new_anonymous(
vertical_align_fragment_rect.to_physical(None), vertical_align_fragment_rect.as_physical(None),
layout.layout.fragments, layout.layout.fragments,
); );
@ -2813,7 +2825,7 @@ impl TableSlotCell {
// TODO(mrobinson): This is correct for absolutes that are direct children of the table // TODO(mrobinson): This is correct for absolutes that are direct children of the table
// cell, but wrong for absolute fragments that are more deeply nested in the hierarchy of // cell, but wrong for absolute fragments that are more deeply nested in the hierarchy of
// fragments. // fragments.
let physical_cell_rect = cell_content_rect.to_physical(Some(containing_block)); let physical_cell_rect = cell_content_rect.as_physical(Some(containing_block));
layout layout
.positioning_context .positioning_context
.adjust_static_position_of_hoisted_fragments_with_offset( .adjust_static_position_of_hoisted_fragments_with_offset(

View file

@ -27,7 +27,7 @@ use crate::geom::{
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext, PositioningContextLength}; use crate::positioned::{AbsolutelyPositionedBox, PositioningContext, PositioningContextLength};
use crate::sizing::{ContentSizes, InlineContentSizesResult}; use crate::sizing::{ContentSizes, InlineContentSizesResult};
use crate::style_ext::ComputedValuesExt; use crate::style_ext::ComputedValuesExt;
use crate::{ConstraintSpace, ContainingBlock}; use crate::{ConstraintSpace, ContainingBlock, ContainingBlockSize};
const DUMMY_NODE_ID: taffy::NodeId = taffy::NodeId::new(u64::MAX); const DUMMY_NODE_ID: taffy::NodeId = taffy::NodeId::new(u64::MAX);
@ -256,8 +256,10 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> {
let maybe_block_size = let maybe_block_size =
option_f32_to_lpa(content_box_known_dimensions.height); option_f32_to_lpa(content_box_known_dimensions.height);
let content_box_size_override = ContainingBlock { let content_box_size_override = ContainingBlock {
inline_size: Au::from_f32_px(inline_size), size: ContainingBlockSize {
block_size: maybe_block_size, inline: Au::from_f32_px(inline_size),
block: maybe_block_size,
},
style, style,
}; };
@ -355,8 +357,10 @@ impl TaffyContainer {
}; };
let containing_block = &ContainingBlock { let containing_block = &ContainingBlock {
inline_size: Au::zero(), size: ContainingBlockSize {
block_size: GenericLengthPercentageOrAuto::Auto, inline: Au::zero(),
block: GenericLengthPercentageOrAuto::Auto,
},
style, style,
}; };
@ -434,17 +438,17 @@ impl TaffyContainer {
let known_dimensions = taffy::Size { let known_dimensions = taffy::Size {
width: Some( width: Some(
(content_box_size_override.inline_size + pbm.padding_border_sums.inline) (content_box_size_override.size.inline + pbm.padding_border_sums.inline)
.to_f32_px(), .to_f32_px(),
), ),
height: auto_or_to_option(content_box_size_override.block_size) height: auto_or_to_option(content_box_size_override.size.block)
.map(Au::to_f32_px) .map(Au::to_f32_px)
.maybe_add(pbm.padding_border_sums.block.to_f32_px()), .maybe_add(pbm.padding_border_sums.block.to_f32_px()),
}; };
let taffy_containing_block = taffy::Size { let taffy_containing_block = taffy::Size {
width: Some(containing_block.inline_size.to_f32_px()), width: Some(containing_block.size.inline.to_f32_px()),
height: auto_or_to_option(containing_block.block_size).map(Au::to_f32_px), height: auto_or_to_option(containing_block.size.block).map(Au::to_f32_px),
}; };
let layout_input = taffy::LayoutInput { let layout_input = taffy::LayoutInput {