Obey table cell's box-sizing (#31536)

Instead of assuming `box-sizing: content-box`.
This commit is contained in:
Oriol Brufau 2024-03-08 13:07:42 +01:00 committed by GitHub
parent 49ae9bb442
commit 6b5a5147f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 66 deletions

View file

@ -9,6 +9,7 @@ use log::warn;
use servo_arc::Arc; use servo_arc::Arc;
use style::computed_values::border_collapse::T as BorderCollapse; use style::computed_values::border_collapse::T as BorderCollapse;
use style::logical_geometry::WritingMode; use style::logical_geometry::WritingMode;
use style::properties::longhands::box_sizing::computed_value::T as BoxSizing;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::{ use style::values::computed::{
CSSPixelLength, Length, LengthPercentage as ComputedLengthPercentage, Percentage, CSSPixelLength, Length, LengthPercentage as ComputedLengthPercentage, Percentage,
@ -143,11 +144,24 @@ impl<'a> TableLayout<'a> {
_ => continue, _ => continue,
}; };
let (size, min_size, max_size) = get_sizes_from_style(&cell.style, writing_mode); let padding = cell
.style
.padding(writing_mode)
.percentages_relative_to(Length::zero());
let border = cell.style.border_width(writing_mode);
let padding_border_sums = LogicalVec2 {
inline: (padding.inline_sum() + border.inline_sum()).into(),
block: (padding.block_sum() + border.block_sum()).into(),
};
let (size, min_size, max_size) =
get_outer_sizes_from_style(&cell.style, writing_mode, &padding_border_sums);
let mut inline_content_sizes = cell let mut inline_content_sizes = cell
.contents .contents
.contents .contents
.inline_content_sizes(layout_context, writing_mode); .inline_content_sizes(layout_context, writing_mode);
inline_content_sizes.min_content += padding_border_sums.inline;
inline_content_sizes.max_content += padding_border_sums.inline;
// TODO: the max-content size should never be smaller than the min-content size! // TODO: the max-content size should never be smaller than the min-content size!
inline_content_sizes.max_content = inline_content_sizes inline_content_sizes.max_content = inline_content_sizes
@ -158,11 +172,11 @@ impl<'a> TableLayout<'a> {
get_size_percentage_contribution_from_style(&cell.style, writing_mode); get_size_percentage_contribution_from_style(&cell.style, writing_mode);
// These formulas differ from the spec, but seem to match Gecko and Blink. // These formulas differ from the spec, but seem to match Gecko and Blink.
let mut outer_min_content_width = inline_content_sizes let outer_min_content_width = inline_content_sizes
.min_content .min_content
.min(max_size.inline) .min(max_size.inline)
.max(min_size.inline); .max(min_size.inline);
let mut outer_max_content_width = if self.columns[column_index].constrained { let outer_max_content_width = if self.columns[column_index].constrained {
inline_content_sizes inline_content_sizes
.min_content .min_content
.max(size.inline) .max(size.inline)
@ -177,17 +191,6 @@ impl<'a> TableLayout<'a> {
}; };
assert!(outer_min_content_width <= outer_max_content_width); assert!(outer_min_content_width <= outer_max_content_width);
let padding = cell
.style
.padding(writing_mode)
.percentages_relative_to(Length::zero());
let border = cell.style.border_width(writing_mode);
let inline_padding_border_sum =
Au::from(padding.inline_sum() + border.inline_sum());
outer_min_content_width += inline_padding_border_sum;
outer_max_content_width += inline_padding_border_sum;
let inline_measure = CellOrTrackMeasure { let inline_measure = CellOrTrackMeasure {
content_sizes: ContentSizes { content_sizes: ContentSizes {
min_content: outer_min_content_width, min_content: outer_min_content_width,
@ -203,8 +206,8 @@ impl<'a> TableLayout<'a> {
// TODO: Is it correct to use the block size as the minimum of the `outer min // TODO: Is it correct to use the block size as the minimum of the `outer min
// content height` here? The specification doesn't mention this, but it does cause // content height` here? The specification doesn't mention this, but it does cause
// a test to pass. // a test to pass.
let mut outer_min_content_height = min_size.block.max(size.block); let outer_min_content_height = min_size.block.max(size.block);
let mut outer_max_content_height = if !self.rows[row_index].constrained { let outer_max_content_height = if !self.rows[row_index].constrained {
min_size.block.max(size.block) min_size.block.max(size.block)
} else { } else {
min_size min_size
@ -213,10 +216,6 @@ impl<'a> TableLayout<'a> {
.max(max_size.block.min(size.block)) .max(max_size.block.min(size.block))
}; };
let block_padding_border_sum = Au::from(padding.block_sum() + border.block_sum());
outer_min_content_height += block_padding_border_sum;
outer_max_content_height += block_padding_border_sum;
let block_measure = CellOrTrackMeasure { let block_measure = CellOrTrackMeasure {
content_sizes: ContentSizes { content_sizes: ContentSizes {
min_content: outer_min_content_height, min_content: outer_min_content_height,
@ -1743,7 +1742,8 @@ impl Table {
None => return CellOrTrackMeasure::zero(), None => return CellOrTrackMeasure::zero(),
}; };
let (size, min_size, max_size) = get_sizes_from_style(&column.style, writing_mode); let (size, min_size, max_size) =
get_outer_sizes_from_style(&column.style, writing_mode, &LogicalVec2::zero());
let percentage_contribution = let percentage_contribution =
get_size_percentage_contribution_from_style(&column.style, writing_mode); get_size_percentage_contribution_from_style(&column.style, writing_mode);
@ -1921,40 +1921,34 @@ fn get_size_percentage_contribution_from_style(
} }
} }
fn get_sizes_from_style( fn get_outer_sizes_from_style(
style: &Arc<ComputedValues>, style: &Arc<ComputedValues>,
writing_mode: WritingMode, writing_mode: WritingMode,
padding_border_sums: &LogicalVec2<Au>,
) -> (LogicalVec2<Au>, LogicalVec2<Au>, LogicalVec2<Au>) { ) -> (LogicalVec2<Au>, LogicalVec2<Au>, LogicalVec2<Au>) {
let get_max_size_for_axis = |size: Option<&ComputedLengthPercentage>| { let box_sizing = style.get_position().box_sizing;
size.and_then(|length_percentage| length_percentage.to_length()) let outer_size = |size: LogicalVec2<Au>| match box_sizing {
.map_or(MAX_AU, Au::from) BoxSizing::ContentBox => &size + padding_border_sums,
BoxSizing::BorderBox => LogicalVec2 {
inline: size.inline.max(padding_border_sums.inline),
block: size.block.max(padding_border_sums.block),
},
}; };
let get_size_for_axis = |size: &LengthPercentageOrAuto<'_>| {
let max_size = style.max_box_size(writing_mode);
let max_size = LogicalVec2 {
inline: get_max_size_for_axis(max_size.inline),
block: get_max_size_for_axis(max_size.block),
};
let get_size_for_axis = |size: LengthPercentageOrAuto<'_>| {
size.non_auto() size.non_auto()
.and_then(|size| size.to_length()) .and_then(|size| size.to_length())
.map_or_else(Au::zero, Au::from) .map_or_else(Au::zero, Au::from)
}; };
let get_max_size_for_axis = |size: &Option<&ComputedLengthPercentage>| {
let min_size = style.min_box_size(writing_mode); size.and_then(|length_percentage| length_percentage.to_length())
let min_size = LogicalVec2 { .map_or(MAX_AU, Au::from)
inline: get_size_for_axis(min_size.inline),
block: get_size_for_axis(min_size.block),
}; };
let size = style.box_size(writing_mode); (
let size = LogicalVec2 { outer_size(style.box_size(writing_mode).map(get_size_for_axis)),
inline: get_size_for_axis(size.inline), outer_size(style.min_box_size(writing_mode).map(get_size_for_axis)),
block: get_size_for_axis(size.block), outer_size(style.max_box_size(writing_mode).map(get_max_size_for_axis)),
}; )
(size, min_size, max_size)
} }
struct RowspanToDistribute<'a> { struct RowspanToDistribute<'a> {

View file

@ -2,8 +2,5 @@
[table 1] [table 1]
expected: FAIL expected: FAIL
[table 2]
expected: FAIL
[table 3] [table 3]
expected: FAIL expected: FAIL

View file

@ -5,12 +5,6 @@
[table 2] [table 2]
expected: FAIL expected: FAIL
[table 6]
expected: FAIL
[table 8]
expected: FAIL
[table 9] [table 9]
expected: FAIL expected: FAIL
@ -19,6 +13,3 @@
[table 11] [table 11]
expected: FAIL expected: FAIL
[table 14]
expected: FAIL

View file

@ -5,14 +5,5 @@
[table 9] [table 9]
expected: FAIL expected: FAIL
[table 5]
expected: FAIL
[table 6]
expected: FAIL
[table 7]
expected: FAIL
[table 10] [table 10]
expected: FAIL expected: FAIL