Skip to content

Commit

Permalink
unify-abspos-logic
Browse files Browse the repository at this point in the history
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
  • Loading branch information
Loirooriol committed Oct 25, 2024
1 parent f05f1b3 commit 951bca5
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions components/layout_2020/positioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,29 +454,10 @@ impl HoistedAbsolutelyPositionedBox {
let style = context.style().clone();
let containing_block = &containing_block.into();
let pbm = style.padding_border_margin(containing_block);

let (computed_size, computed_min_size, computed_max_size) = match context {
IndependentFormattingContext::Replaced(replaced) => {
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
let content_box_sizes_and_pbm =
style.content_box_sizes_and_padding_border_margin(&containing_block.into());
let used_size = replaced
.contents
.used_size_as_if_inline_element(
containing_block,
&style,
&content_box_sizes_and_pbm.into(),
)
.map(|size| Size::Numeric(*size));
(used_size, Default::default(), Default::default())
},
IndependentFormattingContext::NonReplaced(_) => (
style.content_box_size(containing_block, &pbm),
style.content_min_box_size(containing_block, &pbm),
style.content_max_box_size(containing_block, &pbm),
),
};
let computed_size = style.content_box_size(containing_block, &pbm);
let computed_min_size = style.content_min_box_size(containing_block, &pbm);
let computed_max_size = style.content_max_box_size(containing_block, &pbm);
let is_replaced = matches!(context, IndependentFormattingContext::Replaced(_));

let shared_fragment = self.fragment.borrow();
let static_position_rect = shared_fragment
Expand Down Expand Up @@ -511,6 +492,7 @@ impl HoistedAbsolutelyPositionedBox {
alignment: inline_alignment,
flip_anchor: shared_fragment.original_parent_writing_mode.is_bidi_ltr() !=
containing_block_writing_mode.is_bidi_ltr(),
is_replaced,
};

// When the "static-position rect" doesn't come into play, we re-resolve "align-self"
Expand All @@ -537,6 +519,7 @@ impl HoistedAbsolutelyPositionedBox {
static_position_rect_axis: static_position_rect.get_axis(AxisDirection::Block),
alignment: block_alignment,
flip_anchor: false,
is_replaced,
};

// The block axis can depend on layout results, so we only solve it tentatively,
Expand Down Expand Up @@ -763,6 +746,7 @@ struct AbsoluteAxisSolver<'a> {
static_position_rect_axis: RectAxis,
alignment: AlignFlags,
flip_anchor: bool,
is_replaced: bool,
}

impl<'a> AbsoluteAxisSolver<'a> {
Expand Down Expand Up @@ -856,7 +840,12 @@ impl<'a> AbsoluteAxisSolver<'a> {
let stretch_size = free_space -
self.computed_margin_start.auto_is(Au::zero) -
self.computed_margin_end.auto_is(Au::zero);
let used_size = solve_size(Size::Stretch, stretch_size).unwrap();
let initial_behavior = if self.is_replaced {
Size::FitContent
} else {
Size::Stretch
};
let used_size = solve_size(initial_behavior, stretch_size).unwrap();
free_space -= used_size;
let (margin_start, margin_end) =
match (self.computed_margin_start, self.computed_margin_end) {
Expand Down

0 comments on commit 951bca5

Please sign in to comment.