Skip to content

Improve block absolute auto resolution#922

Closed
AustinMReppert wants to merge 19 commits into
DioxusLabs:mainfrom
AustinMReppert:feature/fix-block-absolute-resolution
Closed

Improve block absolute auto resolution#922
AustinMReppert wants to merge 19 commits into
DioxusLabs:mainfrom
AustinMReppert:feature/fix-block-absolute-resolution

Conversation

@AustinMReppert
Copy link
Copy Markdown

@AustinMReppert AustinMReppert commented Feb 28, 2026

Improve Block Layout for Non-Replaced Absolutely Positioned Elements

Why did you make this PR?

The current block implementation does not closely follow the spec. This leads to many edge cases with the block algorithm. This PR addresses improves the layout for non-replaced elements.

Changes that will affect external library users must update RELEASES.md before they will be merged.

None

Context

Discuss any context that may be needed for reviewers to understand the changes you've made.
This may include related issues, previous discussion, or links to documentation or code.

Feedback wanted

This section is optional. If there are no particularly tricky or controversial changes, you can delete this section.

Which parts of this PR were you unsure about? Which parts were particularly tricky?

Taffy does not have shrink-to-fit, so I just used content-size.

If you're stuck on part of the changes or want feedback early, open a draft PR and list the items that need to be completed here using a checklist.

The following WPT tests should now pass in Blitz. There were no regressed WPT tests. Running against /css

PASS css/CSS2/positioning/absolute-non-replaced-height-013.html
PASS css/CSS2/positioning/absolute-non-replaced-max-height-011.xht
PASS css/CSS2/positioning/absolute-non-replaced-width-025.xht
PASS css/CSS2/positioning/absolute-non-replaced-width-027.xht
PASS css/css-grid/abspos/grid-positioned-items-and-autofit-tracks-004.html
PASS css/css-grid/abspos/grid-positioned-items-and-autofit-tracks-005.html
PASS css/css-grid/abspos/grid-positioned-items-and-autofit-tracks-006.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-005.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-007.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-009.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-010.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-012.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-014.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-015.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-017.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-019.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-020.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-022.html
PASS css/css-grid/alignment/grid-content-distribution-with-collapsed-tracks-024.html
PASS css/css-grid/grid-definition/grid-auto-fill-columns-001.html
PASS css/css-grid/grid-definition/grid-auto-fill-rows-001.html
PASS css/css-grid/grid-definition/grid-auto-fit-columns-001.html
PASS css/css-grid/grid-definition/grid-auto-fit-rows-001.html
PASS css/css-grid/subgrid/parent-repeat-auto-fit-001.html
PASS css/css-grid/subgrid/parent-repeat-auto-fit-002.html
PASS css/css-position/position-absolute-margin-auto-001.html

@AustinMReppert AustinMReppert changed the title Feature/fix block absolute resolution Improve block absolute auto resolution Feb 28, 2026
@nicoburns
Copy link
Copy Markdown
Member

@AustinMReppert Did you mean to write a proper PR description?

Also, was AI used in creating this PR? (AI assisted or even generated PRs are allowed but will be reviewed differently to human-written PRs).

The fixtures can be auto formatted with cargo run -rp format-fixtures (FYI the formatting convention is "no newlines", and "space after semi-colon" in style attributes).

@AustinMReppert
Copy link
Copy Markdown
Author

It was mostly handwritten against the spec. I did use AI to find the original bug and to create some of the test cases. I am hoping to track down #923 before I finish this PR.

@AustinMReppert
Copy link
Copy Markdown
Author

Planning to finish this on the weekend. Still needs to be cleaned up.

@nicoburns
Copy link
Copy Markdown
Member

Feel free to just #[allow] those clippy lints if it keeps the code more symettrical.

Copy link
Copy Markdown
Member

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encourage you do look at the Rect, Size, Point and Line types from https://github.com/DioxusLabs/taffy/blob/main/src/geometry.rs You should be able to write the same code here significantly less verbosely using these types, their traits impls (they impl things like Add and Sub) and their helper methods.

e.g. border.top + padding.top + padding.bottom + border.bottom; might become padding_border.vertical_axis_sum()

Comment thread src/compute/block.rs Outdated
Comment on lines +1312 to +1313
computed_margin_left = margin_left.unwrap_or(0.0);
computed_margin_right = margin_right.unwrap_or(0.0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are already set to these values above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/compute/block.rs Outdated
// Otherwise, set 'auto' values for 'margin-left' and 'margin-right' to 0, and pick the one of the following six rules that applies.
// These are already our initial values chosen above, so no need to do anything.

if left.is_none() && width.is_none() && right.is_some() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-else chain could be a match

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@AustinMReppert AustinMReppert marked this pull request as ready for review April 12, 2026 04:07
@AustinMReppert
Copy link
Copy Markdown
Author

This should be mostly ready. I plan to remove a few of the tests tomorrow morning.

@nicoburns
Copy link
Copy Markdown
Member

The entiretests/generated directory needs to be removed. This is a merge conflict and has been replaced with tests/xml. Otherwise, why do you want to remove tests?

@AustinMReppert
Copy link
Copy Markdown
Author

The entiretests/generated directory needs to be removed. This is a merge conflict and has been replaced with tests/xml. Otherwise, why do you want to remove tests?

I had added a few test scenarios to the initial PR, but they passed even with the old implementation. I don't think they added any value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants