Skip to content

LibWeb: Move NodeFacts into node_facts.rs - #11056

Merged
kalenikaliaksandr merged 1 commit into
LadybirdBrowser:masterfrom
kalenikaliaksandr:libweb-move-node-facts
Aug 9, 2026
Merged

LibWeb: Move NodeFacts into node_facts.rs#11056
kalenikaliaksandr merged 1 commit into
LadybirdBrowser:masterfrom
kalenikaliaksandr:libweb-move-node-facts

Conversation

@kalenikaliaksandr

Copy link
Copy Markdown
Member

This pure code reorganization moves NodeFacts and its implementation from layout_state.rs to node_facts.rs, alongside the existing node fact helper functions.

This pure code reorganization moves NodeFacts and its implementation
from layout_state.rs to node_facts.rs, alongside the existing node fact
helper functions.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change moves the pass-scoped NodeFacts abstraction from layout_state.rs into a dedicated node_facts.rs module. The new façade retains layout-node access and adds queries for classification, positioning, flow participation, list markers, replaced content, sizing, containment, display, SVG, table, viewport, and document state. LayoutState continues to hold pending absolute-position child declarations.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description accurately states that NodeFacts moved from layout_state.rs to node_facts.rs as a code reorganization.
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.

@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.

Actionable comments posted: 1

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

492-526: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add unit tests for the marker traversal.

list_item_marker is a hand-rolled descend-and-ascend walk with three exit paths. The existing node_facts_tests module covers only node_can_have_children. Cover at least: an outside marker as a direct child, an inside marker below one anonymous wrapper, a nested authored list item that must not be entered, and a list item with no marker.

The traversal needs a NodeFacts instance, so the tests need arena-backed fixtures rather than the plain NodeData values the current tests use. Do you want me to draft those fixtures and tests?

🤖 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/node_facts.rs` around lines 492 - 526, Add
arena-backed fixtures in the node_facts_tests module to construct NodeFacts and
exercise list_item_marker. Cover a direct outside marker, an inside marker
beneath one anonymous wrapper, a nested authored list item that must not be
traversed, and a list item without any marker; assert the returned node for each
case, including Node::INVALID where appropriate.
🤖 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.

Inline comments:
In `@Libraries/LibWeb/Rust/src/layout/node_facts.rs`:
- Around line 176-180: Make the fields of NodeFacts accessible to
LayoutState::node_facts by marking state, callbacks, and node pub(crate), or add
a pub(crate) NodeFacts::new constructor and update LayoutState::node_facts to
use it.

---

Nitpick comments:
In `@Libraries/LibWeb/Rust/src/layout/node_facts.rs`:
- Around line 492-526: Add arena-backed fixtures in the node_facts_tests module
to construct NodeFacts and exercise list_item_marker. Cover a direct outside
marker, an inside marker beneath one anonymous wrapper, a nested authored list
item that must not be traversed, and a list item without any marker; assert the
returned node for each case, including Node::INVALID where appropriate.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86100d83-aa1a-4e97-9d7b-64ab368802cd

📥 Commits

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

📒 Files selected for processing (2)
  • Libraries/LibWeb/Rust/src/layout/layout_state.rs
  • Libraries/LibWeb/Rust/src/layout/node_facts.rs
💤 Files with no reviewable changes (1)
  • Libraries/LibWeb/Rust/src/layout/layout_state.rs

Comment on lines +176 to +180
pub(crate) struct NodeFacts<'pass> {
state: &'pass LayoutState,
callbacks: &'pass FfiLayoutFcCallbacks,
node: Node,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate the module declarations and every NodeFacts construction site.
fd -t f 'mod.rs|layout.rs' Libraries/LibWeb/Rust/src --exec rg -n 'mod (node_facts|layout_state)' {} +

# Struct literal / constructor uses outside node_facts.rs
rg -nP --type=rust -C4 'NodeFacts\s*\{' Libraries/LibWeb/Rust/src

# Field declaration visibility in the new module
ast-grep run --pattern 'pub(crate) struct NodeFacts<$_> { $$$ }' --lang rust Libraries/LibWeb/Rust/src/layout/node_facts.rs

Repository: LadybirdBrowser/ladybird

Length of output: 1329


🏁 Script executed:

#!/bin/bash
set -u

printf 'Module declarations:\n'
rg -n --type=rust '^\s*mod\s+(node_facts|layout_state)\s*;' Libraries/LibWeb/Rust/src || true
rg -n --type=rust '^\s*mod\s+(node_facts|layout_state)\s*;' Libraries/LibWeb/Rust/src/layout.rs 2>/dev/null || true

printf '\nNodeFacts construction/constructor usage:\n'
rg -n --type=rust -C3 'NodeFacts\s*\{|\bNodeFacts::|node_facts\s*:' Libraries/LibWeb/Rust/src || true

printf '\nRelevant file headers/imports:\n'
sed -n '1,80p' Libraries/LibWeb/Rust/src/layout/layout_state.rs
printf '\n---\n'
sed -n '160,185p' Libraries/LibWeb/Rust/src/layout/node_facts.rs

Repository: LadybirdBrowser/ladybird

Length of output: 4590


🏁 Script executed:

#!/bin/bash
set -u

find Libraries/LibWeb/Rust/src -maxdepth 1 -type d -print | sort
printf '\nRoot Rust files:\n'
find Libraries/LibWeb/Rust/src -maxdepth 1 -type f -print | sort

printf '\nlayout/layout_state.rs module boundary around declarations:\n'
rg -n --type=rust '^(mod node_facts|mod layout_state|pub mod node_facts|pub mod layout_state)' Libraries/LibWeb/Rust/src/layout -g '*.rs' || true

printf '\nImports/usages of NodeFacts in layout_state.rs:\n'
rg -n --type=rust -C3 'NodeFacts|layout_state' Libraries/LibWeb/Rust/src/layout/layout_state.rs || true

printf '\nImports/usages of NodeFacts from node_facts module in layout state path:\n'
rg -n --type=rust -C3 'use .*node_facts|NodeFacts' Libraries/LibWeb/Rust/src/layout/layout_state.rs Libraries/LibWeb/Rust/src/layout/node_facts.rs | sed -n '1,220p'

Repository: LadybirdBrowser/ladybird

Length of output: 2567


🌐 Web query:

Rust reference field visibility E0451 private fields struct literal outside defining module

💡 Result:

In Rust, the compiler error E0451 occurs when you attempt to instantiate a struct using struct literal syntax outside of the module where the struct is defined, if that struct contains any private fields [1][2]. This behavior is a fundamental part of Rust's encapsulation and privacy system [3][4]. By default, struct fields are private, meaning they are only accessible within the module that defines the struct (and its descendants) [3][4]. To use struct literal syntax (e.g., MyStruct { field1: val }) to create an instance, all fields of the struct must be visible in the scope where the instantiation occurs [3][5]. If even one field is private, the compiler prohibits direct construction via literals to prevent external code from bypassing the encapsulation intended by the module author [1][4]. To resolve this error, you generally have two options: 1. Make all fields public: If the struct is intended to be a simple data container, you can prefix the fields with the pub keyword (e.g., pub field1: T) [1][2][4]. 2. Provide a public constructor function: Keep the fields private to maintain encapsulation and define a public associated function (often named new) within an impl block for the struct to handle initialization [1][2][4]. Since private fields cannot be accessed or initialized externally, they are effectively hidden from outside code, ensuring that the struct's internal state can only be modified or viewed through public methods defined within the same module [3][4]. While there have been community discussions regarding potential future features—such as opt-in mechanisms to allow initialization of private fields without a constructor [6]—these are not currently part of the language. Top results: [1][3][4]

Citations:


Make the NodeFacts fields reachable from layout_state.

LayoutState::node_facts constructs NodeFacts with fields in the sibling layout_state module. Since the fields are private to node_facts, NodeFacts { state: self, callbacks, node } is not accessible there after the move.

Add pub(crate) to the fields, or expose a NodeFacts::new(...) constructor from this module and call it from LayoutState::node_facts.

🤖 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/node_facts.rs` around lines 176 - 180, Make
the fields of NodeFacts accessible to LayoutState::node_facts by marking state,
callbacks, and node pub(crate), or add a pub(crate) NodeFacts::new constructor
and update LayoutState::node_facts to use it.

@kalenikaliaksandr
kalenikaliaksandr merged commit bbdccfb into LadybirdBrowser:master Aug 9, 2026
14 of 15 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.

1 participant