Skip to content

Commit

Permalink
Refactor box size computation
Browse files Browse the repository at this point in the history
in each layout logic, in order to correctly resolve sizing keywords.

This patch adds a new `Sizes` struct which holds the preferred, min and
max sizing values for one axis, and unifies the logic to resolve the
final size into there.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
  • Loading branch information
Loirooriol committed Dec 18, 2024
1 parent ab270f3 commit fbcd6ee
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 343 deletions.
44 changes: 29 additions & 15 deletions components/layout_2020/flexbox/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::formatting_contexts::{
Baselines, IndependentFormattingContextContents, IndependentLayout,
};
use crate::fragment_tree::{BoxFragment, CollapsedBlockMargins, Fragment, FragmentFlags};
use crate::geom::{AuOrAuto, LogicalRect, LogicalSides, LogicalVec2, Size};
use crate::geom::{AuOrAuto, LogicalRect, LogicalSides, LogicalVec2, Size, Sizes};
use crate::positioned::{
relative_adjustement, AbsolutelyPositionedBox, PositioningContext, PositioningContextLength,
};
Expand Down Expand Up @@ -1957,20 +1957,22 @@ impl FlexItem<'_> {
let item_style = independent_formatting_context.style();
match &independent_formatting_context.contents {
IndependentFormattingContextContents::Replaced(replaced) => {
let min_size = flex_axis.vec2_to_flow_relative(self.content_min_size);
let max_size = flex_axis.vec2_to_flow_relative(self.content_max_size);
let size = replaced.used_size_as_if_inline_element_from_content_box_sizes(
containing_block,
item_style,
self.preferred_aspect_ratio,
LogicalVec2 {
inline: Size::Numeric(inline_size),
block: block_size.non_auto().map_or(Size::Initial, Size::Numeric),
},
flex_axis
.vec2_to_flow_relative(self.content_min_size)
.map(|size| Size::Numeric(*size)),
flex_axis
.vec2_to_flow_relative(self.content_max_size)
.map(|size| size.map_or(Size::Initial, Size::Numeric)),
&Sizes::new(
block_size.non_auto().map_or(Size::Initial, Size::Numeric),
Size::Numeric(min_size.block),
max_size.block.map_or(Size::Initial, Size::Numeric),
),
&Sizes::new(
Size::Numeric(inline_size),
Size::Numeric(min_size.inline),
max_size.inline.map_or(Size::Initial, Size::Numeric),
),
flex_axis.vec2_to_flow_relative(self.pbm_auto_is_zero),
);
let hypothetical_cross_size = flex_axis.vec2_to_flex_relative(size).cross;
Expand Down Expand Up @@ -2777,10 +2779,22 @@ impl FlexItemBox {
flex_context.containing_block,
style,
preferred_aspect_ratio,
content_box_size
.map(|size| size.non_auto().map_or(Size::Initial, Size::Numeric)),
min_size.map(|size| Size::Numeric(*size)),
max_size.map(|size| size.map_or(Size::Initial, Size::Numeric)),
&Sizes::new(
content_box_size
.block
.non_auto()
.map_or(Size::Initial, Size::Numeric),
Size::Numeric(min_size.block),
max_size.block.map_or(Size::Initial, Size::Numeric),
),
&Sizes::new(
content_box_size
.inline
.non_auto()
.map_or(Size::Initial, Size::Numeric),
Size::Numeric(min_size.inline),
max_size.inline.map_or(Size::Initial, Size::Numeric),
),
padding_border_margin.padding_border_sums +
padding_border_margin.margin.auto_is(Au::zero).sum(),
)
Expand Down
Loading

0 comments on commit fbcd6ee

Please sign in to comment.