Skip to content

Commit

Permalink
Fix intrinsic size of scroll containers that have a small explicit fl…
Browse files Browse the repository at this point in the history
…ex-basis (#728)

* Add tests to for issue 696

* Flexbox: prevent content size from affecting intrinsic main size if an
item is a scroll container

* Format fixtures

* Fix clippy lints
  • Loading branch information
nicoburns authored Oct 22, 2024
1 parent 343203d commit 9f1d71c
Show file tree
Hide file tree
Showing 12 changed files with 967 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/compute/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ struct FlexItem {
offset_cross: f32,
}

impl FlexItem {
/// Returns true if the item is a <https://www.w3.org/TR/css-overflow-3/#scroll-container>
fn is_scroll_container(&self) -> bool {
self.overflow.x.is_scroll_container() | self.overflow.y.is_scroll_container()
}
}

/// A line of [`FlexItem`] used for intermediate computation
struct FlexLine<'a> {
/// The slice of items to iterate over during computation of this line
Expand Down Expand Up @@ -975,8 +982,12 @@ fn determine_container_main_size(
pref.min(max).max(min) + item.margin.main_axis_sum(constants.dir)
}
(min, _, max) if max <= min => min + item.margin.main_axis_sum(constants.dir),

// Else compute the min- or -max content size and apply the full formula for computing the
// min- or max- content contributuon
// min- or max- content contribution
_ if item.is_scroll_container() => {
item.flex_basis + item.margin.main_axis_sum(constants.dir)
}
_ => {
// Parent size for child sizing
let cross_axis_parent_size = constants.node_inner_size.cross(dir);
Expand Down
18 changes: 18 additions & 0 deletions test_fixtures/flex/taffy_issue_696.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>
<div id="test-root" style="display: flex; flex-direction: column; width: 200px;">
<div style="display: flex; flex-direction: column; overflow: hidden; min-height: 100px; padding: 20px; flex-basis: 0px;">
<div style="display: flex; height: 200px; flex-shrink: 0;"></div>
</div>
</div>
</body>

</html>
18 changes: 18 additions & 0 deletions test_fixtures/flex/taffy_issue_696_flex_basis_20.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>
<div id="test-root" style="display: flex; flex-direction: column; width: 200px;">
<div style="display: flex; flex-direction: column; overflow: hidden; min-height: 100px; padding: 20px; flex-basis: 20px;">
<div style="display: flex; height: 200px; flex-shrink: 0;"></div>
</div>
</div>
</body>

</html>
18 changes: 18 additions & 0 deletions test_fixtures/flex/taffy_issue_696_min_height.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>
<div id="test-root" style="display: flex; flex-direction: column; width: 200px;">
<div style="display: flex; flex-direction: column; min-height: 100px; padding: 20px; flex-basis: 0px;">
<div style="display: flex; height: 200px; flex-shrink: 0;"></div>
</div>
</div>
</body>

</html>
18 changes: 18 additions & 0 deletions test_fixtures/flex/taffy_issue_696_no_flex_basis.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>
<div id="test-root" style="display: flex; flex-direction: column; width: 200px;">
<div style="display: flex; flex-direction: column; overflow: hidden; min-height: 100px; padding: 20px;">
<div style="display: flex; height: 200px; flex-shrink: 0;"></div>
</div>
</div>
</body>

</html>
18 changes: 18 additions & 0 deletions test_fixtures/flex/taffy_issue_696_overflow_hidden.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
</head>
<body>
<div id="test-root" style="display: flex; flex-direction: column; width: 200px;">
<div style="display: flex; flex-direction: column; overflow: hidden; padding: 20px; flex-basis: 0px;">
<div style="display: flex; height: 200px; flex-shrink: 0;"></div>
</div>
</div>
</body>

</html>
5 changes: 5 additions & 0 deletions tests/generated/flex/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 182 additions & 0 deletions tests/generated/flex/taffy_issue_696.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f1d71c

Please sign in to comment.