Truly independent web browser
LibWeb: Hold the element box kind as its enum
Andreas Kling926cf0e3cfff
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex 5034f14f8fe..85dc7923214 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -2692,8 +2692,9 @@ fn main() -> Result<(), Box<dyn Error>> {.push_str("\nnamespace Web::Layout::RustFFI { enum class FfiFlightBlocker : uint8_t; }");// The host's objects a style reaction is applied through cross as the host's own types, except an element a struct- // holds, which crosses opaque.+ // holds, which crosses opaque. A box kind crosses as the byte of the host's own enum.for (name, cpp_name) in [+ ("ElementBoxKind", "uint8_t"),("HostElement", "Web::DOM::Element"),("HostElementPtr", "void*"),("HostStyleReactionApplication", "Web::CSS::StyleReactionApplication"),diff --git a/Libraries/LibWeb/Rust/src/css/style/boundary.rs b/Libraries/LibWeb/Rust/src/css/style/boundary.rsindex c83daa4a7b7..b3a1c21be35 100644--- a/Libraries/LibWeb/Rust/src/css/style/boundary.rs+++ b/Libraries/LibWeb/Rust/src/css/style/boundary.rs@@ -79,7 +79,7 @@ carried! {StyleAtomID: u32 as "StyleAtomID" = |atom| StyleAtomID(atom);TreeScopeID: u32 as "TreeScopeID" = |tree_scope| TreeScopeID(tree_scope);CascadeLayerID: u32 as "u32" = |layer| CascadeLayerID(layer);- ElementBoxKind: u8 as "u8" = |box_kind| ElementBoxKind::from_raw(box_kind);+ ElementBoxKind: ElementBoxKind as "u8" = |box_kind| box_kind;Option<StyleNodeID>: u32 as "StyleNodeID" = |node| StyleNodeID::from_raw(node);Option<SheetID>: u32 as "SheetID" = |sheet| sheet.checked_sub(1).map(SheetID);[u32; 4]: *const [u32; 4] as "u32 const*" = |values| unsafe { *values };diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex fac21a7fbf6..630a58e6624 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -595,8 +595,8 @@ pub struct FfiElementArrival {/// One plus the element-backed pseudo-element kind the element stands for in its host's/// shadow tree, or zero.pub associated_pseudo_kind_plus_one: u8,- /// The `ElementBoxKind` the element asks for, as its raw byte.- pub box_kind: u8,+ /// The principal box the element asks for.+ pub box_kind: ElementBoxKind,/// The element's `ElementStyleAdjustmentFact` bits: what the box-type transformation and the/// element style adjustments read of the DOM. Mirrors the C++ enum.pub adjustment_facts: u32,@@ -624,7 +624,7 @@ pub(in crate::css::style) fn element_arrival_facts<'a>(states: super::index::StateSet(arrival.states),adjustment_facts: arrival.adjustment_facts,construction_facts: arrival.construction_facts,- box_kind: ElementBoxKind::from_raw(arrival.box_kind),+ box_kind: arrival.box_kind,atoms,custom_state_count: arrival.custom_state_count as usize,class_count: arrival.class_count as usize,@@ -802,9 +802,11 @@ pub mod element_construction_fact {/// Which principal box an element asks for before its computed style has a say. The element's own/// type and state decide this; the tree build resolves it against the computed `display` and-/// `appearance`. Mirrors the C++ `CSS::ElementBoxKind`; it crosses the boundary as its raw byte.-#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]+/// `appearance`. Mirrors the C++ `CSS::ElementBoxKind`, which lists the same kinds in the same+/// order and crosses the boundary as its underlying byte.+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]#[repr(u8)]+#[expect(dead_code, reason = "C++ constructs the variants")]pub enum ElementBoxKind {/// The computed display decides the box on its own.#[default]@@ -847,38 +849,6 @@ impl ElementBoxKind {Self::InputButton | Self::InputCheckBox | Self::InputRadioButton | Self::InputRange | Self::InputText)}-- /// The kind C++ sends as `raw`. The two enums list the same kinds in the same order, which- /// `ElementBoxKind.h` asserts for the last one.- #[must_use]- pub(crate) fn from_raw(raw: u8) -> Self {- match raw {- 0 => Self::FromDisplay,- 1 => Self::NoBox,- 2 => Self::Break,- 3 => Self::FieldSet,- 4 => Self::Legend,- 5 => Self::Audio,- 6 => Self::Video,- 7 => Self::Canvas,- 8 => Self::NavigableContainerViewport,- 9 => Self::TextArea,- 10 => Self::Image,- 11 => Self::SvgGraphics,- 12 => Self::SvgSvg,- 13 => Self::SvgText,- 14 => Self::SvgTextPath,- 15 => Self::SvgForeignObject,- 16 => Self::SvgImage,- 17 => Self::SvgGeometry,- 18 => Self::InputButton,- 19 => Self::InputCheckBox,- 20 => Self::InputRadioButton,- 21 => Self::InputRange,- 22 => Self::InputText,- _ => unreachable!("C++ sent an unknown element box kind {raw}"),- }- }}/// Which element the values of a replaced content input are of. See@@ -2019,7 +1989,7 @@ mod tests {is_slot: false,has_text_content: false,associated_pseudo_kind_plus_one: 0,- box_kind: 0,+ box_kind: ElementBoxKind::FromDisplay,}}diff --git a/Libraries/LibWeb/Rust/src/css/style/element_host_facts.rs b/Libraries/LibWeb/Rust/src/css/style/element_host_facts.rsindex a04d548bb59..ce7ba7eaf69 100644--- a/Libraries/LibWeb/Rust/src/css/style/element_host_facts.rs+++ b/Libraries/LibWeb/Rust/src/css/style/element_host_facts.rs@@ -24,27 +24,18 @@ pub(in crate::css::style) struct HostFactSet {/// The element facts a layout row built for the element records; see/// `bridge::element_construction_fact`.pub(in crate::css::style) construction_facts: u32,- /// The principal box the element asks for, as its raw byte.- box_kind: u8,+ /// The principal box the element asks for.+ pub(in crate::css::style) box_kind: ElementBoxKind,/// One plus the kind of the element-backed pseudo-element of its shadow host the element stands for, or zero/// where it stands for none.pub(in crate::css::style) associated_pseudo_kind_plus_one: u8,}impl HostFactSet {- #[must_use]- pub(in crate::css::style) fn box_kind(&self) -> ElementBoxKind {- ElementBoxKind::from_raw(self.box_kind)- }-#[must_use]pub(in crate::css::style) fn associated_pseudo_kind(&self) -> Option<u8> {self.associated_pseudo_kind_plus_one.checked_sub(1)}-- pub(in crate::css::style) fn set_box_kind(&mut self, box_kind: ElementBoxKind) {- self.box_kind = box_kind as u8;- }}/// The identity of a distinct set of host facts. Identity zero is the empty set.diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rsindex 5753d444e52..6dd8d895aad 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs@@ -1413,7 +1413,7 @@ impl Projection {/// Which principal box the element asks for.#[must_use]pub(in crate::css::style) fn box_kind(&self, node: StyleNodeID) -> super::super::bridge::ElementBoxKind {- self.host_facts(node).box_kind()+ self.host_facts(node).box_kind}/// The element-backed pseudo-element kind of its shadow host the element stands for, as published.diff --git a/Libraries/LibWeb/Rust/src/css/style/projection_writes.rs b/Libraries/LibWeb/Rust/src/css/style/projection_writes.rsindex 0195dd99626..1e558b967ee 100644--- a/Libraries/LibWeb/Rust/src/css/style/projection_writes.rs+++ b/Libraries/LibWeb/Rust/src/css/style/projection_writes.rs@@ -237,7 +237,7 @@ impl ProjectionWrites<'_> {self.projection.edit_host_facts(node, |set| {set.adjustment_facts = arrival.adjustment_facts;set.construction_facts = arrival.construction_facts;- set.set_box_kind(arrival.box_kind);+ set.box_kind = arrival.box_kind;set.associated_pseudo_kind_plus_one = arrival.backing_pseudo_kind_plus_one;});}@@ -259,8 +259,8 @@ impl ProjectionWrites<'_> {/// Record which principal box the element asks for, answering whether that moved.pub(in crate::css::style) fn set_element_box_kind(&mut self, node: StyleNodeID, box_kind: ElementBoxKind) -> bool {self.projection- .edit_host_facts(node, |set| set.set_box_kind(box_kind))- .box_kind()+ .edit_host_facts(node, |set| set.box_kind = box_kind)+ .box_kind!= box_kind}