mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Refactor sizing logic for table measures (#33579)
After #33577, `get_outer_sizes_from_style()` is only used for column and cell measures. For these it's expected to ignore sizing keywords like `min-content`, so rename the function to `get_outer_sizes_for_measurement()`. Additionally, both callers need the percentage contribution, so include it in the returned tuple. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
abad89a49c
commit
e0aa288dac
1 changed files with 34 additions and 31 deletions
|
@ -281,10 +281,12 @@ impl<'a> TableLayout<'a> {
|
||||||
block: padding.block_sum() + border.block_sum(),
|
block: padding.block_sum() + border.block_sum(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (size, min_size, max_size, inline_size_is_auto) =
|
let (size, min_size, max_size, inline_size_is_auto, percentage_contribution) =
|
||||||
get_outer_sizes_from_style(&cell.style, writing_mode, &padding_border_sums);
|
get_outer_sizes_for_measurement(
|
||||||
let percentage_contribution =
|
&cell.style,
|
||||||
get_size_percentage_contribution_from_style(&cell.style, writing_mode);
|
writing_mode,
|
||||||
|
&padding_border_sums,
|
||||||
|
);
|
||||||
|
|
||||||
// <https://drafts.csswg.org/css-tables/#in-fixed-mode>
|
// <https://drafts.csswg.org/css-tables/#in-fixed-mode>
|
||||||
// > When a table-root is laid out in fixed mode, the content of its table-cells is ignored
|
// > When a table-root is laid out in fixed mode, the content of its table-cells is ignored
|
||||||
|
@ -2642,10 +2644,8 @@ impl Table {
|
||||||
None => return CellOrTrackMeasure::zero(),
|
None => return CellOrTrackMeasure::zero(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (size, min_size, max_size, _) =
|
let (size, min_size, max_size, _, percentage_contribution) =
|
||||||
get_outer_sizes_from_style(&column.style, writing_mode, &LogicalVec2::zero());
|
get_outer_sizes_for_measurement(&column.style, writing_mode, &LogicalVec2::zero());
|
||||||
let percentage_contribution =
|
|
||||||
get_size_percentage_contribution_from_style(&column.style, writing_mode);
|
|
||||||
|
|
||||||
CellOrTrackMeasure {
|
CellOrTrackMeasure {
|
||||||
content_sizes: ContentSizes {
|
content_sizes: ContentSizes {
|
||||||
|
@ -2676,18 +2676,17 @@ impl Table {
|
||||||
// In the block axis, the min-content and max-content sizes are the same
|
// In the block axis, the min-content and max-content sizes are the same
|
||||||
// (except for new layout boxes like grid and flex containers). Note that
|
// (except for new layout boxes like grid and flex containers). Note that
|
||||||
// other browsers don't seem to use the min and max sizing properties here.
|
// other browsers don't seem to use the min and max sizing properties here.
|
||||||
let size = row
|
let size = row.style.box_size(writing_mode);
|
||||||
.style
|
let max_size = row.style.max_box_size(writing_mode);
|
||||||
.box_size(writing_mode)
|
let percentage_contribution = get_size_percentage_contribution(&size, &max_size);
|
||||||
.block
|
|
||||||
.to_numeric()
|
|
||||||
.and_then(|size| size.to_length())
|
|
||||||
.map_or_else(Au::zero, Au::from);
|
|
||||||
let percentage_contribution =
|
|
||||||
get_size_percentage_contribution_from_style(&row.style, writing_mode);
|
|
||||||
|
|
||||||
CellOrTrackMeasure {
|
CellOrTrackMeasure {
|
||||||
content_sizes: size.into(),
|
content_sizes: size
|
||||||
|
.block
|
||||||
|
.to_numeric()
|
||||||
|
.and_then(|size| size.to_length())
|
||||||
|
.map_or_else(Au::zero, Au::from)
|
||||||
|
.into(),
|
||||||
percentage: percentage_contribution.block,
|
percentage: percentage_contribution.block,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2795,9 +2794,9 @@ impl TableSlotCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_size_percentage_contribution_from_style(
|
fn get_size_percentage_contribution(
|
||||||
style: &Arc<ComputedValues>,
|
size: &LogicalVec2<Size<ComputedLengthPercentage>>,
|
||||||
writing_mode: WritingMode,
|
max_size: &LogicalVec2<Size<ComputedLengthPercentage>>,
|
||||||
) -> LogicalVec2<Percentage> {
|
) -> LogicalVec2<Percentage> {
|
||||||
// From <https://drafts.csswg.org/css-tables/#percentage-contribution>
|
// From <https://drafts.csswg.org/css-tables/#percentage-contribution>
|
||||||
// > The percentage contribution of a table cell, column, or column group is defined
|
// > The percentage contribution of a table cell, column, or column group is defined
|
||||||
|
@ -2806,11 +2805,8 @@ fn get_size_percentage_contribution_from_style(
|
||||||
// > min(percentage width, percentage max-width).
|
// > min(percentage width, percentage max-width).
|
||||||
// > If the computed values are not percentages, then 0% is used for width, and an
|
// > If the computed values are not percentages, then 0% is used for width, and an
|
||||||
// > infinite percentage is used for max-width.
|
// > infinite percentage is used for max-width.
|
||||||
let size = style.box_size(writing_mode);
|
|
||||||
let max_size = style.max_box_size(writing_mode);
|
|
||||||
|
|
||||||
let get_contribution_for_axis =
|
let get_contribution_for_axis =
|
||||||
|size: Size<ComputedLengthPercentage>, max_size: Size<ComputedLengthPercentage>| {
|
|size: &Size<ComputedLengthPercentage>, max_size: &Size<ComputedLengthPercentage>| {
|
||||||
let size_percentage = size
|
let size_percentage = size
|
||||||
.to_numeric()
|
.to_numeric()
|
||||||
.and_then(|length_percentage| length_percentage.to_percentage())
|
.and_then(|length_percentage| length_percentage.to_percentage())
|
||||||
|
@ -2823,16 +2819,22 @@ fn get_size_percentage_contribution_from_style(
|
||||||
};
|
};
|
||||||
|
|
||||||
LogicalVec2 {
|
LogicalVec2 {
|
||||||
inline: get_contribution_for_axis(size.inline, max_size.inline),
|
inline: get_contribution_for_axis(&size.inline, &max_size.inline),
|
||||||
block: get_contribution_for_axis(size.block, max_size.block),
|
block: get_contribution_for_axis(&size.block, &max_size.block),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_outer_sizes_from_style(
|
fn get_outer_sizes_for_measurement(
|
||||||
style: &Arc<ComputedValues>,
|
style: &Arc<ComputedValues>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
padding_border_sums: &LogicalVec2<Au>,
|
padding_border_sums: &LogicalVec2<Au>,
|
||||||
) -> (LogicalVec2<Au>, LogicalVec2<Au>, LogicalVec2<Au>, bool) {
|
) -> (
|
||||||
|
LogicalVec2<Au>,
|
||||||
|
LogicalVec2<Au>,
|
||||||
|
LogicalVec2<Au>,
|
||||||
|
bool,
|
||||||
|
LogicalVec2<Percentage>,
|
||||||
|
) {
|
||||||
let box_sizing = style.get_position().box_sizing;
|
let box_sizing = style.get_position().box_sizing;
|
||||||
let outer_size = |size: LogicalVec2<Au>| match box_sizing {
|
let outer_size = |size: LogicalVec2<Au>| match box_sizing {
|
||||||
BoxSizing::ContentBox => size + *padding_border_sums,
|
BoxSizing::ContentBox => size + *padding_border_sums,
|
||||||
|
@ -2842,7 +2844,8 @@ fn get_outer_sizes_from_style(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let get_size_for_axis = |size: &Size<ComputedLengthPercentage>| {
|
let get_size_for_axis = |size: &Size<ComputedLengthPercentage>| {
|
||||||
// TODO(#32853): This treats all sizing keywords as `auto`.
|
// Note that measures treat all size values other than <length>
|
||||||
|
// as the initial value of the property.
|
||||||
size.to_numeric()
|
size.to_numeric()
|
||||||
.and_then(|length_percentage| length_percentage.to_length())
|
.and_then(|length_percentage| length_percentage.to_length())
|
||||||
.map(Au::from)
|
.map(Au::from)
|
||||||
|
@ -2855,8 +2858,8 @@ fn get_outer_sizes_from_style(
|
||||||
outer_size(size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))),
|
outer_size(size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))),
|
||||||
outer_size(min_size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))),
|
outer_size(min_size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))),
|
||||||
outer_size(max_size.map(|v| get_size_for_axis(v).unwrap_or(MAX_AU))),
|
outer_size(max_size.map(|v| get_size_for_axis(v).unwrap_or(MAX_AU))),
|
||||||
// TODO(#32853): This treats all sizing keywords as `auto`.
|
|
||||||
size.inline.is_keyword(),
|
size.inline.is_keyword(),
|
||||||
|
get_size_percentage_contribution(&size, &max_size),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue