New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
layout: Add initial support for row height distribution #31421
Conversation
🔨 Triggering try run (#8024844911) for Linux WPT |
Test results for linux-wpt-layout-2020 from try job (#8024844911): Flaky unexpected result (16)
Stable unexpected results that are known to be intermittent (13)
Stable unexpected results (11)
|
|
I'm converting this one back into a draft. I think we should simply implement the LayoutNG distribution algorithm outright to avoid the code churn. |
0acbd7d
to
5bb19f4
Compare
🔨 Triggering try run (#8050682843) for Linux WPT |
Test results for linux-wpt-layout-2020 from try job (#8050682843): Flaky unexpected result (17)
Stable unexpected results that are known to be intermittent (11)
|
✨ Try run (#8050682843) succeeded. |
if let Some(percentage_resolution_size) = percentage_resolution_size { | ||
let get_percent_block_size_deficit = |row_index: usize, track_size: Au| { | ||
let size_needed_for_percent = percentage_resolution_size | ||
.scale_by(self.rows[row_index].percent.0 as f32 / 100.); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already a f32
.scale_by(self.rows[row_index].percent.0 as f32 / 100.); | |
.scale_by(self.rows[row_index].percent.0 / 100.); |
let non_empty_rows_all_constrained = non_empty_rows | ||
.iter() | ||
.filter(|index| is_unconstrained(*index)) | ||
.next() | ||
.is_none(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let non_empty_rows_all_constrained = non_empty_rows | |
.iter() | |
.filter(|index| is_unconstrained(*index)) | |
.next() | |
.is_none(); | |
let non_empty_rows_all_constrained = !non_empty_rows.iter().any(is_unconstrained); |
let mut rows_to_grow = &empty_rows; | ||
let unconstrained_empty_rows: Vec<usize> = rows_to_grow | ||
.iter() | ||
.map(|track| *track) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|track| *track) | |
.copied() |
let get_percent_block_size_deficit = |row_index: usize, track_size: Au| { | ||
let size_needed_for_percent = percentage_resolution_size | ||
.scale_by(self.rows[row_index].percent.0 as f32 / 100.); | ||
size_needed_for_percent - track_size.max(Au::zero()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be?
size_needed_for_percent - track_size.max(Au::zero()) | |
(size_needed_for_percent - track_size).max(Au::zero()) |
Or possibly leave it to the callers, since one is already checking > Au::zero()
and doesn't need .max(Au::zero())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this one. I think we do need this in case the sum of the percentages of the rows is greater than 100%.
row_deficit.to_f32_px() / percent_block_size_deficit.to_f32_px(); | ||
let size = percent_distributable_block_size.scale_by(ratio); | ||
track_sizes[track_index] += size; | ||
excess_size -= size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this make excess_size
negative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We calculate the ratio via (row_deficit / total_deficit), but this ratio is multiplied by total_deficit.min(excess_size), so we always take a ratio of excess size.
.auto_is(Length::zero) | ||
.block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to resolve both dimensions:
.auto_is(Length::zero) | |
.block | |
.block | |
.auto_is(Length::zero) |
Also this is not taking min/max-height into account, but we can leave it for the follow-up.
@@ -306,11 +399,11 @@ impl<'a> TableLayout<'a> { | |||
for column_index in 0..self.table.size.width { | |||
let column_measure = &mut column_measures[column_index]; | |||
let final_intrinsic_percentage_width = column_measure | |||
.percentage_width | |||
.percentage | |||
.0 | |||
.min(100. - total_intrinsic_percentage_width); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized that Percentage
is actually 1-based, but we can fix them in a follow-up.
5bb19f4
to
a18cdab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @Loirooriol. I think I've addressed all the issues you raised.
row_deficit.to_f32_px() / percent_block_size_deficit.to_f32_px(); | ||
let size = percent_distributable_block_size.scale_by(ratio); | ||
track_sizes[track_index] += size; | ||
excess_size -= size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. We calculate the ratio via (row_deficit / total_deficit), but this ratio is multiplied by total_deficit.min(excess_size), so we always take a ratio of excess size.
This change adds a version of row height distribution that follows the distribtuion algorithm used for tables in Blink's LayoutNG. This is just an intermediate step toward implementing a distribution algorithm for both rows and columns more similar to Layout NG. The CSS Table 3 specification is often wrong with regard to web compatability, which is why we have abandoned it in favor of the Layout NG algorithm for row height distribution. this work. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
a18cdab
to
b4f605e
Compare
This change adds a version of row height distribution that follows the
distribution algorithm used for tables in Blink's LayoutNG. This is just
an intermediate step toward implementing a distribution algorithm for
both rows and columns more similar to Layout NG.
The CSS Table 3 specification is often wrong with regard to web
compatibility, which is why we have abandoned it in favor of the Layout
NG algorithm for row height distribution.
Co-authored-by: Oriol Brufau obrufau@igalia.com
./mach build -d
does not report any errors./mach test-tidy
does not report any errors