LibWeb: Various layout logic simplifications - #11057
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR refactors Rust layout sizing and formatting contexts. It removes unused Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
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. Comment |
a7ea61b to
256586e
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Libraries/LibWeb/Rust/src/layout/abspos_engine.rs (1)
1287-1304: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDead local variables kept only for a comment.
containing_block_inline_sizeandcontaining_block_block_sizeare computed and then discarded vialet _ = (...), 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
📒 Files selected for processing (9)
Libraries/LibWeb/Rust/src/layout/abspos_engine.rsLibraries/LibWeb/Rust/src/layout/block_formatting_context.rsLibraries/LibWeb/Rust/src/layout/flex_formatting_context.rsLibraries/LibWeb/Rust/src/layout/grid_formatting_context.rsLibraries/LibWeb/Rust/src/layout/inline_formatting_context.rsLibraries/LibWeb/Rust/src/layout/line_builder.rsLibraries/LibWeb/Rust/src/layout/sizing_context.rsLibraries/LibWeb/Rust/src/layout/svg_formatting_context.rsLibraries/LibWeb/Rust/src/layout/text_chunker.rs
💤 Files with no reviewable changes (1)
- Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
9ab40a6 to
2713875
Compare
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.
2713875 to
cd3843a
Compare
6bbff37
into
LadybirdBrowser:master
No functional changes.