Skip to content

LibWeb: Various layout logic simplifications - #11057

Merged
kalenikaliaksandr merged 12 commits into
LadybirdBrowser:masterfrom
gmta:libweb-layout-simplifications
Aug 9, 2026
Merged

LibWeb: Various layout logic simplifications#11057
kalenikaliaksandr merged 12 commits into
LadybirdBrowser:masterfrom
gmta:libweb-layout-simplifications

Conversation

@gmta

@gmta gmta commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

No functional changes.

@gmta gmta changed the title LibWeb: Various simplifications LibWeb: Various layout logic simplifications Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09e80ff2-97a3-4b40-9a5f-966684b26355

📥 Commits

Reviewing files that changed from the base of the PR and between a7ea61b and 2713875.

📒 Files selected for processing (1)
  • Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Libraries/LibWeb/Rust/src/layout/abspos_engine.rs

📝 Walkthrough

Walkthrough

This PR refactors Rust layout sizing and formatting contexts. It removes unused used_mut accessors and updates state writes through used. It adds shared intrinsic-sizing, block-size clamping, absolute-positioned block-axis, flex-axis, grid-axis, and nested SVG input helpers. It simplifies float placement and text chunk commits through PendingChunk. It also centralizes grid axis access and subgrid line naming.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description states that the changes make no functional changes, which matches the layout refactoring and simplification described in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gmta
gmta force-pushed the libweb-layout-simplifications branch from a7ea61b to 256586e Compare August 9, 2026 15:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Libraries/LibWeb/Rust/src/layout/abspos_engine.rs (1)

1287-1304: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Dead local variables kept only for a comment.

containing_block_inline_size and containing_block_block_size are computed and then discarded via let _ = (...), with a comment explaining they document a basis distinction. Since neither value participates in any computation on this path, consider removing the variables and folding the note into a plain comment instead of keeping unused bindings alive.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/Rust/src/layout/abspos_engine.rs` around lines 1287 - 1304,
Remove the unused containing_block_inline_size and containing_block_block_size
bindings and the let _ discard in the affected layout method. Preserve the
basis-distinction note as a plain comment near the resolved solution values,
without retaining dead locals.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Libraries/LibWeb/Rust/src/layout/abspos_engine.rs`:
- Around line 1287-1304: Remove the unused containing_block_inline_size and
containing_block_block_size bindings and the let _ discard in the affected
layout method. Preserve the basis-distinction note as a plain comment near the
resolved solution values, without retaining dead locals.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c49f1310-4167-467e-a508-3bfd47aff5ce

📥 Commits

Reviewing files that changed from the base of the PR and between b826ab7 and a7ea61b.

📒 Files selected for processing (9)
  • Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
  • Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/line_builder.rs
  • Libraries/LibWeb/Rust/src/layout/sizing_context.rs
  • Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/text_chunker.rs
💤 Files with no reviewable changes (1)
  • Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs

@gmta
gmta force-pushed the libweb-layout-simplifications branch 2 times, most recently from 9ab40a6 to 2713875 Compare August 9, 2026 15:20
gmta added 12 commits August 9, 2026 17:24
Every one of `used_mut()`, `item_used_mut()` and `container_used_mut()`
took `&self` and returned the same `&UsedValues` as its non-`_mut`
counterpart, so the name promised a mutable borrow that Rust never
handed out. They are leftovers from the C++ layout code, where the
distinction was real. Remove the aliases and call the plain accessors
instead.
Nearly every per-axis accessor the flex formatting context owns had to
spell out a whole `if self.main_axis_is_horizontal()` block just to
pick between an inline-axis and a block-axis value. Add `select_main()`
and `select_cross()`, plus their `SizingAxis` variants, and route those
accessors through them so each one states which pair of values it
chooses between.
`solve_non_replaced_block_once()` kept the block axis unknowns in five
separate locals, so its `solve_for` closure could not capture them and
every call site had to re-pass all of them by hand. Collect them into a
`BlockAxisSolution` that the closure takes by value, which also lets
the caller thread one value around instead of destructuring a
five-tuple three times.
`next_chunk()` commits chunks from eight different places, and each one
had to restate the same `try_commit_chunk()` call in full because the
chunk start, font, text type and pending tab break were all loose
locals. Bundle them into a `PendingChunk` and add a helper that commits
everything up to the cursor, leaving the varying `can_break_after` as
the only thing a call site has to say.
Laying out a nested viewport and laying out a mask or clip resource
both built the same `LayoutInput` literal. Move it into a
`nested_layout_input()` helper.
Both places where an auto margin stops being honoured — an over-wide
box, and a box with an automatic inline size — zeroed `margin_left` and
`margin_right` and cleared their auto flags with the same code. Give
that step a name and call it twice.
`place_float()` had two exits from its band search, and each one built
the same `FloatPlacement` with the same nested left/right offset
expression. Turn the search into a single `continue` and fall through
to one construction site.
Computing a replaced element's inline size and computing its block size
opened the same way, substituting `auto` for whichever of `width` and
`height` has to be treated as automatic. Name that step and call it
from both.
Resolving a used block size clamped it against `min-height` and
`max-height` the same way whether or not the size is treated as
automatic. Move the clamp into one helper.
The four min/max-content size calculators all ended the same way:
consult the measurement cache, set up a `MeasurementState` under the
matching size constraint, lay the box out and store the result. Move
those tails into one helper per axis, keyed on the cache kind, and drop
the hand-written `LayoutInput` literals in favour of
`LayoutInput::new()` now that both agree on every field.
Adopting a parent grid area's names into a subgrid pushed the same
`LineName` four times over, once per axis and edge, differing only in
which raw name and which end it records. Loop over the two edges in a
helper instead.
Almost everything the grid formatting context reads is stored once per
axis, so it spelled out an `if axis.is_column()` block to pick between
the two all over the file. Add `Axis::select()` along with
`sizing_axis()` and `opposite()`, and give the repeatedly selected
pairs — track lines, explicit line counts, content alignment and
container padding — accessors of their own. `outer_edges()` now sums
the two margin box edge helpers rather than restating them.
@gmta
gmta force-pushed the libweb-layout-simplifications branch from 2713875 to cd3843a Compare August 9, 2026 15:24
@gmta
gmta enabled auto-merge (rebase) August 9, 2026 15:28
@kalenikaliaksandr
kalenikaliaksandr merged commit 6bbff37 into LadybirdBrowser:master Aug 9, 2026
18 of 22 checks passed
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