Never resolve margin-left:auto to a negative amount (#30065)

With direction:ltr (and we don't support direction:rtl yet), the rules
from https://drafts.csswg.org/css2/#blockwidth imply that margin-left
shouldn't resolve auto to a negative amount.

This aligns Servo with Gecko and Blink. WebKit may resolve to a negative
amount in some cases.
This commit is contained in:
Oriol Brufau 2023-08-03 11:21:22 +02:00 committed by GitHub
parent 1296ddf273
commit d90e3078a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 158 additions and 6 deletions

View file

@ -1142,12 +1142,15 @@ fn solve_inline_margins_for_in_flow_block_level(
pbm: &PaddingBorderMargin,
inline_size: Length,
) -> (Length, Length) {
let available = containing_block.inline_size - pbm.padding_border_sums.inline - inline_size;
match (pbm.margin.inline_start, pbm.margin.inline_end) {
(LengthOrAuto::Auto, LengthOrAuto::Auto) => (available / 2., available / 2.),
(LengthOrAuto::Auto, LengthOrAuto::LengthPercentage(end)) => (available - end, end),
(LengthOrAuto::LengthPercentage(start), _) => (start, available - start),
}
let free_space = containing_block.inline_size - pbm.padding_border_sums.inline - inline_size;
let margin_inline_start = match (pbm.margin.inline_start, pbm.margin.inline_end) {
(LengthOrAuto::Auto, LengthOrAuto::Auto) => Length::zero().max(free_space / 2.),
(LengthOrAuto::Auto, LengthOrAuto::LengthPercentage(end)) => {
Length::zero().max(free_space - end)
},
(LengthOrAuto::LengthPercentage(start), _) => start,
};
(margin_inline_start, free_space - margin_inline_start)
}
/// State that we maintain when placing blocks.