Skip to content

Truly independent web browser

LibWeb: Build style groups from typed value handles and payloads

Andreas Klinge3fbb45cffad
diff --git a/Libraries/LibWeb/Rust/Cargo.toml b/Libraries/LibWeb/Rust/Cargo.toml
index 09719e80481..97c3bc5d573 100644
--- a/Libraries/LibWeb/Rust/Cargo.toml
+++ b/Libraries/LibWeb/Rust/Cargo.toml
@@ -24,7 +24,7 @@ liburl_rust = { path = "../../LibURL/Rust", default-features = false }
libweb_html_tokenizer = { path = "../HTML/Parser/Rust" }
rustc-demangle = "0.1"
serde_json = { version = "1", features = ["float_roundtrip", "preserve_order"] }
-smallvec = "1.15.1"
+smallvec = { version = "1.15.1", features = ["const_generics"] }
[build-dependencies]
cbindgen = "0.29"
diff --git a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs b/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
index 0b8a0ca29b4..903ec875d5b 100644
--- a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
+++ b/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
@@ -81,7 +81,18 @@ impl FfiAnimatedOverlayEntry {
}
pub(crate) fn value(&self) -> &StyleValueData {
- unsafe { &*self.value.cast() }
+ self.value_handle().data()
+ }
+
+ /// The entry's value as the handle that owns it.
+ pub(crate) fn value_handle(&self) -> &RetainedStyleValueData {
+ const {
+ assert!(size_of::<RetainedStyleValueData>() == size_of::<*const c_void>());
+ assert!(align_of::<RetainedStyleValueData>() == align_of::<*const c_void>());
+ }
+ // SAFETY: `value` owns one strong reference while the entry is stored, which is exactly what a
+ // RetainedStyleValueData holds, and that repr(C) type is a single pointer of the same layout.
+ unsafe { &*std::ptr::from_ref(&self.value).cast::<RetainedStyleValueData>() }
}
pub(crate) fn value_pointer(&self) -> *const StyleValueData {
diff --git a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
index 67f26a29a32..39e79f52325 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
@@ -1315,29 +1315,37 @@ impl ComputedLonghandTable {
property_id: u16,
with_animations: bool,
) -> FfiEffectiveLonghandValue {
+ let (value, source) = self.effective_value_handle(overlay, property_id, with_animations);
+ FfiEffectiveLonghandValue {
+ value: value.pointer().cast(),
+ source,
+ }
+ }
+
+ /// The handle `effective_value` reads the longhand's value from, and which source it is.
+ pub(crate) fn effective_value_handle<'a>(
+ &'a self,
+ overlay: Option<&'a AnimatedOverlay>,
+ property_id: u16,
+ with_animations: bool,
+ ) -> (&'a RetainedStyleValueData, u8) {
if with_animations
&& let Some(overlay) = overlay
&& let Some(entry) = overlay.get(property_id)
&& overlay_wins(entry, self.is_important(property_id))
{
- return FfiEffectiveLonghandValue {
- value: entry.value,
- source: EFFECTIVE_LONGHAND_SOURCE_OVERLAY,
- };
+ return (entry.value_handle(), EFFECTIVE_LONGHAND_SOURCE_OVERLAY);
}
if !self.is_evaluated(property_id)
&& let Some(value) = self.inheritance_dependent_value(property_id)
&& retained_value_depends_on_current_color(value)
{
- return FfiEffectiveLonghandValue {
- value: value.pointer().cast(),
- source: EFFECTIVE_LONGHAND_SOURCE_SPECIFIED,
- };
- }
- FfiEffectiveLonghandValue {
- value: self.storage.slot(Self::slot_index(property_id)).0.pointer().cast(),
- source: EFFECTIVE_LONGHAND_SOURCE_TABLE,
+ return (value, EFFECTIVE_LONGHAND_SOURCE_SPECIFIED);
}
+ (
+ self.storage.slot(Self::slot_index(property_id)).0,
+ EFFECTIVE_LONGHAND_SOURCE_TABLE,
+ )
}
pub(crate) fn freeze(&mut self) {
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rs
index 0443e5d8858..f09b2dcd34b 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs
@@ -23,7 +23,6 @@
//! reference counted or freed.
use std::alloc::{Layout, alloc, dealloc};
-use std::any::TypeId;
use std::ffi::c_void;
use std::hash::Hasher;
use std::sync::OnceLock;
@@ -48,7 +47,7 @@ pub use crate::css::computed_value_types::{
};
use crate::css::retained_fly_string::{RetainedUtf16FlyString, RetainedUtf16FlyStringList};
use crate::css::style::fast_hash::{FastHasher, fast_hasher};
-use crate::css::style_value::StyleValueData;
+use crate::css::style_value::{RetainedStyleValueData, StyleValueData};
use crate::css::style_value::{retained_list_drop, retained_list_partial_eq};
use crate::css::table_group_builder::group_index;
@@ -78,9 +77,10 @@ impl ComputedStyleValueHandle {
}
}
- pub(crate) fn retained(data: *const crate::css::style_value::StyleValueData) -> Self {
+ /// Another reference to the value `handle` holds, empty for an empty handle.
+ pub(crate) fn from_retained(handle: &RetainedStyleValueData) -> Self {
Self {
- pointer: unsafe { crate::css::style_value::retain_style_value(data) }.cast(),
+ pointer: handle.clone().into_pointer().cast(),
}
}
@@ -1672,39 +1672,198 @@ fn allocate_payload(group: StyleGroup, initial_refcount: usize) -> *mut c_void {
}
}
+/// A style group's payload type, which knows the index of its group.
+pub(crate) trait StyleGroupPayload: 'static {
+ const GROUP_INDEX: usize;
+}
+
+macro_rules! impl_style_group_payload {
+ ($($type:ty => $index:ident),+ $(,)?) => {
+ $(impl StyleGroupPayload for $type {
+ const GROUP_INDEX: usize = group_index::$index;
+ })+
+ };
+}
+
+impl_style_group_payload!(
+ InheritedTableValues => INHERITED_TABLE,
+ InheritedListValues => INHERITED_LIST,
+ InheritedUIValues => INHERITED_UI,
+ InheritedSVGValues => INHERITED_SVG,
+ InheritedTextValues => INHERITED_TEXT,
+ InheritedBoxValues => INHERITED_BOX,
+ FontValues => FONT,
+ AnimationValues => ANIMATION,
+ SVGResetValues => SVG_RESET,
+ GridValues => GRID,
+ AnchorValues => ANCHOR,
+ EffectsValues => EFFECTS,
+ MaskValues => MASK,
+ TextResetValues => TEXT_RESET,
+ ContentValues => CONTENT,
+ TransformValues => TRANSFORM,
+ BackgroundValues => BACKGROUND,
+ BorderValues => BORDER,
+ AlignmentValues => ALIGNMENT,
+ MiscResetValues => MISC_RESET,
+ SizingValues => SIZING,
+ SurroundValues => SURROUND,
+ BoxValues => BOX,
+);
+
/// Verifies that `T` is the payload type of `group_index`, so typed payload views of the group's
/// default and freshly allocated payloads are sound.
-fn assert_group_payload_type<T: 'static>(group_index: usize) {
- let payload_type = with_style_group_type!(style_group(group_index), Payload => TypeId::of::<Payload>());
- assert!(payload_type == TypeId::of::<T>(), "style group payload type mismatch");
+fn assert_group_payload_type<T: StyleGroupPayload>(group_index: usize) {
+ assert_eq!(group_index, T::GROUP_INDEX, "style group payload type mismatch");
}
-/// The payload a built group value can share instead of allocating its own: the parent's payload,
-/// retained for the caller, or the group's default payload, when either holds the same values.
-///
-/// # Safety
-/// `parent_payload` must be null or a live payload of the group at `group_index`.
-unsafe fn share_group_payload<T: PartialEq + 'static>(
+/// A live payload of the style group at `group_index`, borrowed for `'a`.
+#[derive(Clone, Copy)]
+pub(crate) struct GroupPayloadRef<'a> {
+ group_index: usize,
+ pointer: std::ptr::NonNull<c_void>,
+ payload: std::marker::PhantomData<&'a c_void>,
+}
+
+impl<'a> GroupPayloadRef<'a> {
+ /// The payload `pointer` names, or `None` for a null pointer.
+ ///
+ /// # Safety
+ /// A non-null `pointer` must be a payload of the group at `group_index` that stays live and
+ /// unmodified for `'a`.
+ pub(crate) unsafe fn new(group_index: usize, pointer: *const c_void) -> Option<Self> {
+ assert!(group_index < group_index::COUNT);
+ Some(Self {
+ group_index,
+ pointer: std::ptr::NonNull::new(pointer.cast_mut())?,
+ payload: std::marker::PhantomData,
+ })
+ }
+
+ /// The group's immortal default payload.
+ pub(crate) fn default_payload(group_index: usize) -> GroupPayloadRef<'static> {
+ // SAFETY: Default payloads are leaked, so they stay live and unmodified forever.
+ unsafe { GroupPayloadRef::new(group_index, default_group_payload(group_index)) }
+ .expect("a style group has a default payload")
+ }
+
+ pub(crate) fn as_ptr(self) -> *const c_void {
+ self.pointer.as_ptr().cast_const()
+ }
+
+ /// The payload as its group's type, which must be `T`.
+ fn values<T: StyleGroupPayload>(self) -> &'a T {
+ assert_group_payload_type::<T>(self.group_index);
+ // SAFETY: The payload is live for 'a and its group's type is `T`.
+ unsafe { payload_ref::<T>(self.as_ptr()) }
+ }
+
+ /// Whether `other`, a payload of the same group, holds the same values.
+ fn equals(self, other: GroupPayloadRef<'_>) -> bool {
+ assert_eq!(self.group_index, other.group_index);
+ // SAFETY: Both payloads are live payloads of the group.
+ unsafe { payloads_equal(style_group(self.group_index), self.as_ptr(), other.as_ptr()) }
+ }
+
+ /// The payload, with one more reference for the caller.
+ fn retained(self) -> *const c_void {
+ retain_group_payload(self.group_index, self.as_ptr());
+ self.as_ptr()
+ }
+}
+
+/// A freshly allocated payload of one group, which holds the payload's one reference and frees it unless published.
+struct ScratchPayload {
+ group_index: usize,
+ pointer: *mut c_void,
+}
+
+impl ScratchPayload {
+ fn new_default(group_index: usize) -> Self {
+ let group = style_group(group_index);
+ let pointer = allocate_payload(group, 1);
+ // SAFETY: The payload was just allocated with the layout of the group's type.
+ unsafe { default_construct(group, pointer) };
+ Self { group_index, pointer }
+ }
+
+ fn apply_pokes(&mut self, pokes: &[GroupFieldPoke<'_>]) {
+ // SAFETY: The pokes come from the group's registered descriptors, whose offsets name fields of the right
+ // type in the group's payload, and nothing else references the scratch payload yet.
+ unsafe { apply_group_field_pokes(self.pointer, pokes) };
+ }
+
+ /// The payload as its group's type, which must be `T`.
+ fn values_mut<T: StyleGroupPayload>(&mut self) -> &mut T {
+ assert_group_payload_type::<T>(self.group_index);
+ // SAFETY: The scratch payload is a live payload of type `T` that only this guard references.
+ unsafe { &mut *self.pointer.cast::<T>() }
+ }
+
+ fn as_ref(&self) -> GroupPayloadRef<'_> {
+ // SAFETY: The scratch payload is live while the guard is, and nothing modifies it while borrowed.
+ unsafe { GroupPayloadRef::new(self.group_index, self.pointer) }.expect("allocation never returns null")
+ }
+
+ /// Hands the payload and its one reference to the caller.
+ fn publish(self) -> *const c_void {
+ let pointer = self.pointer.cast_const();
+ std::mem::forget(self);
+ pointer
+ }
+}
+
+impl Drop for ScratchPayload {
+ fn drop(&mut self) {
+ // SAFETY: The scratch payload was never published, so this guard holds its only reference.
+ unsafe { free_scratch_payload(style_group(self.group_index), self.pointer) };
+ }
+}
+
+/// The payload a build of the group at `group_index` can share instead of publishing its own: the parent's payload,
+/// retained for the caller, or the group's default payload, whichever `matches` first.
+fn share_matching_group_payload(
+ group_index: usize,
+ parent: Option<GroupPayloadRef<'_>>,
+ matches: impl Fn(GroupPayloadRef<'_>) -> bool,
+) -> Option<*const c_void> {
+ if let Some(parent) = parent {
+ assert_eq!(parent.group_index, group_index);
+ if matches(parent) {
+ return Some(parent.retained());
+ }
+ }
+ let default_payload = GroupPayloadRef::default_payload(group_index);
+ matches(default_payload).then(|| default_payload.as_ptr())
+}
+
+/// The payload `built` can share instead of being published.
+fn share_equal_group_payload(built: GroupPayloadRef<'_>, parent: Option<GroupPayloadRef<'_>>) -> Option<*const c_void> {
+ share_matching_group_payload(built.group_index, parent, |candidate| built.equals(candidate))
+}
+
+/// The payload a built group value can share instead of allocating its own.
+fn share_group_payload<T: StyleGroupPayload + PartialEq>(
group_index: usize,
built: &T,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> Option<*const c_void> {
assert_group_payload_type::<T>(group_index);
- // SAFETY: The caller guarantees that a non-null parent payload is live, and its type is `T`.
- if !parent_payload.is_null() && built == unsafe { payload_ref::<T>(parent_payload) } {
- retain_group_payload(group_index, parent_payload);
- return Some(parent_payload);
- }
- let default_payload = default_group_payload(group_index);
- // SAFETY: The default payload is immortal and immutable, and its type is `T`.
- if built == unsafe { payload_ref::<T>(default_payload) } {
- return Some(default_payload);
- }
- None
+ share_matching_group_payload(group_index, parent, |candidate| built == candidate.values::<T>())
+}
+
+/// The payload a built group value shares, or else a fresh payload holding it. Either carries one reference for the
+/// caller.
+fn share_or_publish_group_payload<T: StyleGroupPayload + PartialEq>(
+ group_index: usize,
+ built: T,
+ parent: Option<GroupPayloadRef<'_>>,
+) -> *const c_void {
+ share_group_payload(group_index, &built, parent).unwrap_or_else(|| publish_group_payload(group_index, built))
}
/// Moves a built group value into a fresh payload that carries one reference for the caller.
-fn publish_group_payload<T: 'static>(group_index: usize, built: T) -> *const c_void {
+fn publish_group_payload<T: StyleGroupPayload>(group_index: usize, built: T) -> *const c_void {
assert_group_payload_type::<T>(group_index);
let payload = allocate_payload(style_group(group_index), 1);
// SAFETY: The payload was just allocated with the layout of the group's type, which is `T`.
@@ -2179,8 +2338,8 @@ pub(crate) fn computed_group_output_mask(property: u16) -> Option<u32> {
/// One gathered value for the generic group builder: the computed value's
/// data, plus the resolved raw color for color-kind fields.
-pub(crate) struct GroupValueEntry {
- pub(crate) data: *const c_void,
+pub(crate) struct GroupValueEntry<'a> {
+ pub(crate) data: &'a RetainedStyleValueData,
pub(crate) resolved_color: u32,
pub(crate) has_resolved_color: bool,
pub(crate) resolved_number: f64,
@@ -2188,59 +2347,31 @@ pub(crate) struct GroupValueEntry {
}
/// One decoded write into a scratch payload, at an offset into it.
-enum GroupFieldPoke {
+#[derive(Clone, Copy)]
+enum GroupFieldPoke<'a> {
U8(usize, u8),
F32(usize, f32),
F64(usize, f64),
I32(usize, i32),
U64(usize, u64),
U32(usize, u32),
- Data(usize, *const crate::css::style_value::StyleValueData),
+ Data(usize, &'a RetainedStyleValueData),
}
pub(crate) const MAX_GROUP_FIELD_COUNT: usize = 48;
-struct GroupFieldPokes {
- entries: [std::mem::MaybeUninit<GroupFieldPoke>; MAX_GROUP_FIELD_COUNT],
- len: usize,
-}
-
-impl GroupFieldPokes {
- fn new() -> Self {
- Self {
- entries: [const { std::mem::MaybeUninit::uninit() }; MAX_GROUP_FIELD_COUNT],
- len: 0,
- }
- }
-
- fn push(&mut self, poke: GroupFieldPoke) {
- assert!(
- self.len < self.entries.len(),
- "a computed style group has too many fields"
- );
- self.entries[self.len].write(poke);
- self.len += 1;
- }
-}
-
-impl std::ops::Deref for GroupFieldPokes {
- type Target = [GroupFieldPoke];
-
- fn deref(&self) -> &Self::Target {
- // SAFETY: push initializes every entry below len and GroupFieldPoke has no drop glue.
- unsafe { std::slice::from_raw_parts(self.entries.as_ptr().cast(), self.len) }
- }
-}
+/// The pokes of one group, which has at most `MAX_GROUP_FIELD_COUNT` fields.
+type GroupFieldPokes<'a> = smallvec::SmallVec<[GroupFieldPoke<'a>; MAX_GROUP_FIELD_COUNT]>;
/// Decodes one group's gathered values against its descriptors into scratch
/// pokes. Constraint descriptors (the Require kinds) fail the decode when the
/// value diverges and constraints are enforced. A Rust group builder that
/// completes complex members itself skips those constraints.
-fn decode_group_field_pokes(
+fn decode_group_field_pokes<'a>(
descriptors: &[GroupFieldDescriptor],
- values: &[GroupValueEntry],
+ values: &[GroupValueEntry<'a>],
enforce_constraints: bool,
-) -> Option<GroupFieldPokes> {
+) -> Option<GroupFieldPokes<'a>> {
use crate::css::style_compute::px_length_unit;
use crate::css::style_value::StyleValueData;
use GroupFieldKind as Kind;
@@ -2249,7 +2380,7 @@ fn decode_group_field_pokes(
assert!(values.len() <= MAX_GROUP_FIELD_COUNT);
let mut pokes = GroupFieldPokes::new();
for (descriptor, value) in descriptors.iter().zip(values) {
- let data = unsafe { (value.data as *const StyleValueData).as_ref() }?;
+ let data = value.data.optional_data()?;
let offset = descriptor.offset;
let resolved_number = || value.has_resolved_number.then_some(value.resolved_number);
match descriptor.kind {
@@ -2326,7 +2457,7 @@ fn decode_group_field_pokes(
Kind::ResolvedF32 => pokes.push(Poke::F32(offset, resolved_number()? as f32)),
Kind::ResolvedF64 => pokes.push(Poke::F64(offset, resolved_number()?)),
Kind::ResolvedU8 => pokes.push(Poke::U8(offset, resolved_number()? as u8)),
- Kind::RetainedData => pokes.push(Poke::Data(offset, value.data.cast())),
+ Kind::RetainedData => pokes.push(Poke::Data(offset, value.data)),
Kind::KeywordEqualsBool(keyword) => {
let is_keyword =
matches!(data, StyleValueData::Keyword { keyword: value_keyword } if *value_keyword == keyword);
@@ -2352,7 +2483,8 @@ fn decode_group_field_pokes(
}
}
Kind::RequireInitialValue => {
- if value.data != crate::css::style_compute::initial_value_data(descriptor.property_id).cast() {
+ if value.data.pointer() != crate::css::style_compute::initial_value_data(descriptor.property_id).cast()
+ {
return None;
}
}
@@ -2382,8 +2514,7 @@ unsafe fn apply_group_field_pokes(scratch: *mut c_void, pokes: &[GroupFieldPoke]
Poke::U32(offset, value) => *(base.add(offset) as *mut u32) = value,
Poke::Data(offset, data) => {
// The slot's constructor default is null, so nothing is released.
- let retained = crate::css::style_value::retain_style_value(data);
- *(base.add(offset) as *mut *const StyleValueData) = retained;
+ *(base.add(offset) as *mut *const StyleValueData) = data.clone().into_pointer();
}
}
}
@@ -2408,15 +2539,10 @@ unsafe fn free_scratch_payload(group: StyleGroup, scratch: *mut c_void) {
/// population path when any value cannot be decoded or a constraint fails),
/// default-constructs a scratch payload, pokes the simple fields, and shares
/// the parent or default payload when the result compares equal.
-///
-/// # Safety
-/// `values` must hold one valid data entry per registered descriptor
-/// of the group, in registration order; `parent_payload` must be a valid
-/// payload of the group or null.
-pub(crate) unsafe fn build_style_group(
+pub(crate) fn build_style_group(
group_index: usize,
- values: &[GroupValueEntry],
- parent_payload: *const c_void,
+ values: &[GroupValueEntry<'_>],
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let build_or_reuse_group_payload = || {
let descriptors = group_field_descriptors(group_index);
@@ -2425,39 +2551,16 @@ pub(crate) unsafe fn build_style_group(
}
let pokes = decode_group_field_pokes(descriptors, values, true)?;
- let group = style_group(group_index);
-
// A group whose descriptors are all satisfied constraints would
// scratch-build an exact copy of the default payload, so skip the
// allocation and share directly.
if pokes.is_empty() {
- let default_payload = default_group_payload(group_index);
- if !parent_payload.is_null() && unsafe { payloads_equal(group, parent_payload, default_payload) } {
- retain_group_payload(group_index, parent_payload);
- return Some(parent_payload);
- }
- return Some(default_payload);
- }
-
- let scratch = allocate_payload(group, 1);
- // SAFETY: The scratch payload was allocated for this group's layout,
- // and every poke offset comes from offsetof on the C++ side.
- unsafe {
- default_construct(group, scratch);
- apply_group_field_pokes(scratch, &pokes);
+ return Some(share_default_group_payload(group_index, parent));
}
- if !parent_payload.is_null() && unsafe { payloads_equal(group, scratch, parent_payload) } {
- unsafe { free_scratch_payload(group, scratch) };
- retain_group_payload(group_index, parent_payload);
- return Some(parent_payload);
- }
- let default_payload = default_group_payload(group_index);
- if unsafe { payloads_equal(group, scratch, default_payload) } {
- unsafe { free_scratch_payload(group, scratch) };
- return Some(default_payload);
- }
- Some(scratch as *const c_void)
+ let mut scratch = ScratchPayload::new_default(group_index);
+ scratch.apply_pokes(&pokes);
+ Some(share_equal_group_payload(scratch.as_ref(), parent).unwrap_or_else(|| scratch.publish()))
};
build_or_reuse_group_payload().unwrap_or(std::ptr::null())
}
@@ -2465,59 +2568,29 @@ pub(crate) unsafe fn build_style_group(
/// Shares one group's immortal default payload - or the parent payload when
/// it equals the default, keeping the identity - for a build whose inputs are
/// all initial values.
-///
-/// # Safety
-/// `parent_payload` must be a valid payload of the group or null.
-pub(crate) unsafe fn share_default_group_payload(group_index: usize, parent_payload: *const c_void) -> *const c_void {
- let group = style_group(group_index);
- let default_payload = default_group_payload(group_index);
- if !parent_payload.is_null() && unsafe { payloads_equal(group, parent_payload, default_payload) } {
- retain_group_payload(group_index, parent_payload);
- return parent_payload;
- }
- default_payload
+pub(crate) fn share_default_group_payload(group_index: usize, parent: Option<GroupPayloadRef<'_>>) -> *const c_void {
+ let default_payload = GroupPayloadRef::default_payload(group_index);
+ share_matching_group_payload(group_index, parent, |candidate| candidate.equals(default_payload))
+ .expect("the default payload equals itself")
}
/// Builds a Rust-native group whose descriptor-backed fields are completed by
/// a Rust closure before the normal parent/default sharing checks.
-///
-/// # Safety
-/// `values` must hold one valid data entry per registered descriptor of the
-/// group in registration order, and `parent_payload` must be a valid payload
-/// of the group or null. The closure must cast the payload to the registered
-/// Rust-native type only.
-pub(crate) unsafe fn build_group_payload_with_rust_fill(
+pub(crate) fn build_group_payload_with_rust_fill<T: StyleGroupPayload>(
group_index: usize,
- values: &[GroupValueEntry],
- fill: impl FnOnce(*mut c_void),
- parent_payload: *const c_void,
+ values: &[GroupValueEntry<'_>],
+ fill: impl FnOnce(&mut T),
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let descriptors = group_field_descriptors(group_index);
assert_eq!(descriptors.len(), values.len());
let pokes = decode_group_field_pokes(descriptors, values, false)
.expect("computed values decode for every non-constraint descriptor");
- let group = style_group(group_index);
- let scratch = allocate_payload(group, 1);
- // SAFETY: The scratch payload was allocated for this group's Rust-native
- // layout, and every poke offset comes from offsetof on the C++ mirror.
- unsafe {
- default_construct(group, scratch);
- apply_group_field_pokes(scratch, &pokes);
- }
- fill(scratch);
-
- if !parent_payload.is_null() && unsafe { payloads_equal(group, scratch, parent_payload) } {
- unsafe { free_scratch_payload(group, scratch) };
- retain_group_payload(group_index, parent_payload);
- return parent_payload;
- }
- let default_payload = default_group_payload(group_index);
- if unsafe { payloads_equal(group, scratch, default_payload) } {
- unsafe { free_scratch_payload(group, scratch) };
- return default_payload;
- }
- scratch as *const c_void
+ let mut scratch = ScratchPayload::new_default(group_index);
+ scratch.apply_pokes(&pokes);
+ fill(scratch.values_mut::<T>());
+ share_equal_group_payload(scratch.as_ref(), parent).unwrap_or_else(|| scratch.publish())
}
/// Builds an inherited box group payload from the five computed keyword
@@ -2529,23 +2602,19 @@ pub(crate) unsafe fn build_group_payload_with_rust_fill(
/// The returned payload carries one reference for the caller; fresh payloads
/// start at one, shared payloads are retained, and default payloads are
/// intentionally leaked and never counted.
-///
-/// # Safety
-/// The value pointers must be valid StyleValueData or null, and
-/// `parent_payload` a valid inherited box payload or null.
-pub(crate) unsafe fn build_inherited_box_group(
+pub(crate) fn build_inherited_box_group(
group_index: usize,
- visibility: *const c_void,
- direction: *const c_void,
- writing_mode: *const c_void,
- content_visibility: *const c_void,
- image_rendering: *const c_void,
- parent_payload: *const c_void,
+ visibility: &RetainedStyleValueData,
+ direction: &RetainedStyleValueData,
+ writing_mode: &RetainedStyleValueData,
+ content_visibility: &RetainedStyleValueData,
+ image_rendering: &RetainedStyleValueData,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::style_value::StyleValueData;
- let keyword_code = |data: *const c_void, map: fn(u16) -> Option<u8>| -> u8 {
- match unsafe { (data as *const StyleValueData).as_ref() } {
+ let keyword_code = |data: &RetainedStyleValueData, map: fn(u16) -> Option<u8>| -> u8 {
+ match data.optional_data() {
Some(StyleValueData::Keyword { keyword }) => map(*keyword).expect("computed keyword has a supported value"),
_ => panic!("computed inherited box value is not a keyword"),
}
@@ -2561,9 +2630,7 @@ pub(crate) unsafe fn build_inherited_box_group(
image_rendering: keyword_code(image_rendering, crate::css::style_compute::keyword_to_image_rendering),
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<InheritedBoxValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<InheritedBoxValues>(group_index, built, parent)
}
impl ComputedSize {
@@ -2574,19 +2641,18 @@ impl ComputedSize {
}
}
- fn retained(kind: ComputedSizeKind, data: *const crate::css::style_value::StyleValueData) -> Self {
+ fn retained(kind: ComputedSizeKind, data: &RetainedStyleValueData) -> Self {
Self {
kind,
- value: ComputedStyleValueHandle::retained(data),
+ value: ComputedStyleValueHandle::from_retained(data),
}
}
- pub(crate) fn from_data(data: *const c_void) -> Self {
+ pub(crate) fn from_data(data: &RetainedStyleValueData) -> Self {
use crate::css::css_enums::keyword;
use crate::css::style_value::StyleValueData;
- let data = data.cast::<StyleValueData>();
- match unsafe { data.as_ref() } {
+ match data.optional_data() {
Some(StyleValueData::Keyword { keyword: value }) if *value == keyword::AUTO => {
Self::keyword(ComputedSizeKind::Auto)
}
@@ -2602,9 +2668,7 @@ impl ComputedSize {
Some(StyleValueData::Keyword { keyword: value }) if *value == keyword::NONE => {
Self::keyword(ComputedSizeKind::None)
}
- Some(StyleValueData::Function { value, .. }) => {
- Self::retained(ComputedSizeKind::FitContent, value.pointer())
- }
+ Some(StyleValueData::Function { value, .. }) => Self::retained(ComputedSizeKind::FitContent, value),
Some(StyleValueData::Calculated { .. }) => Self::retained(ComputedSizeKind::Calculated, data),
Some(StyleValueData::Percentage { .. }) => Self::retained(ComputedSizeKind::Percentage, data),
Some(StyleValueData::Length { .. }) => Self::retained(ComputedSizeKind::Length, data),
@@ -2629,12 +2693,12 @@ impl SizingValues {
}
impl ComputedFlexBasis {
- fn from_data(data: *const c_void) -> Self {
+ fn from_data(data: &RetainedStyleValueData) -> Self {
use crate::css::css_enums::keyword;
use crate::css::style_value::StyleValueData;
let is_content = matches!(
- unsafe { data.cast::<StyleValueData>().as_ref() },
+ data.optional_data(),
Some(StyleValueData::Keyword { keyword }) if *keyword == keyword::CONTENT
);
Self {
@@ -2649,13 +2713,12 @@ impl ComputedFlexBasis {
}
impl ComputedGap {
- fn from_data(data: *const c_void) -> Self {
+ fn from_data(data: &RetainedStyleValueData) -> Self {
use crate::css::css_enums::keyword;
use crate::css::style_value::StyleValueData;
- let data = data.cast::<StyleValueData>();
let is_normal = matches!(
- unsafe { data.as_ref() },
+ data.optional_data(),
Some(StyleValueData::Keyword { keyword }) if *keyword == keyword::NORMAL
);
Self {
@@ -2663,7 +2726,7 @@ impl ComputedGap {
value: if is_normal {
ComputedStyleValueHandle::empty()
} else {
- ComputedStyleValueHandle::retained(data)
+ ComputedStyleValueHandle::from_retained(data)
},
}
}
@@ -2720,13 +2783,12 @@ impl ComputedLengthPercentageOrAuto {
}
}
- pub(crate) fn from_data(data: *const c_void) -> Self {
+ pub(crate) fn from_data(data: &RetainedStyleValueData) -> Self {
use crate::css::css_enums::keyword;
use crate::css::style_value::StyleValueData;
- let data = data.cast::<StyleValueData>();
let is_auto = matches!(
- unsafe { data.as_ref() },
+ data.optional_data(),
Some(StyleValueData::Keyword { keyword }) if *keyword == keyword::AUTO
);
Self {
@@ -2734,23 +2796,22 @@ impl ComputedLengthPercentageOrAuto {
value: if is_auto {
ComputedStyleValueHandle::empty()
} else {
- ComputedStyleValueHandle::retained(data)
+ ComputedStyleValueHandle::from_retained(data)
},
}
}
- fn from_length_box_data(data: *const c_void, default_is_auto: bool) -> Self {
+ fn from_length_box_data(data: &RetainedStyleValueData, default_is_auto: bool) -> Self {
use crate::css::css_enums::keyword;
use crate::css::style_value::StyleValueData;
- let data = data.cast::<StyleValueData>();
- match unsafe { data.as_ref() } {
+ match data.optional_data() {
Some(StyleValueData::Keyword { keyword: value }) if *value == keyword::AUTO => Self::auto(),
Some(
StyleValueData::Length { .. } | StyleValueData::Percentage { .. } | StyleValueData::Calculated { .. },
) => Self {
is_auto: false,
- value: ComputedStyleValueHandle::retained(data),
+ value: ComputedStyleValueHandle::from_retained(data),
},
_ if default_is_auto => Self::auto(),
_ => Self::zero(),
@@ -2783,10 +2844,10 @@ impl ComputedLengthBox {
}
pub(crate) fn from_data(
- top: *const c_void,
- right: *const c_void,
- bottom: *const c_void,
- left: *const c_void,
+ top: &RetainedStyleValueData,
+ right: &RetainedStyleValueData,
+ bottom: &RetainedStyleValueData,
+ left: &RetainedStyleValueData,
default_is_auto: bool,
) -> Self {
Self {
@@ -2968,8 +3029,9 @@ impl EffectsValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
let auto_edge = ComputedClipEdge {
is_auto: true,
value: 0.0,
@@ -3063,8 +3125,9 @@ impl InheritedSVGValues {
use crate::css::css_enums;
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
let color_interpolation = |keyword| {
css_enums::keyword_to_color_interpolation(keyword)
.expect("an initial color-interpolation keyword maps to its enum")
@@ -3151,8 +3214,9 @@ impl AnimationValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
animation_name: initial(property_id::ANIMATION_NAME),
animation_composition: initial(property_id::ANIMATION_COMPOSITION),
@@ -3184,8 +3248,9 @@ impl MaskValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
mask_image: initial(property_id::MASK_IMAGE),
mask_type: initial(property_id::MASK_TYPE),
@@ -3205,8 +3270,9 @@ impl BackgroundValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
background_color: 0,
background_color_style_value: initial(property_id::BACKGROUND_COLOR),
@@ -3231,8 +3297,9 @@ impl BorderValues {
use crate::css::css_pixels::CssPixels;
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
let side = || ComputedBorderSide {
color: 0,
line_style: 0,
@@ -3273,8 +3340,9 @@ impl ContentValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
content: initial(property_id::CONTENT),
counter_increment: initial(property_id::COUNTER_INCREMENT),
@@ -3351,8 +3419,9 @@ impl InheritedListValues {
fn initial() -> Self {
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
list_style_type: initial(property_id::LIST_STYLE_TYPE),
list_style_position: 1,
@@ -3388,8 +3457,9 @@ impl MiscResetValues {
use crate::css::css_pixels::CssPixels;
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
outline_offset_style_value: initial(property_id::OUTLINE_OFFSET),
scroll_margin: ComputedLengthBox::zero(),
@@ -3440,8 +3510,9 @@ impl FontValues {
use crate::css::css_pixels::CssPixels;
use crate::css::property_metadata::property_id;
- let initial =
- |property| ComputedStyleValueHandle::retained(crate::css::style_compute::initial_value_data(property));
+ let initial = |property| {
+ ComputedStyleValueHandle::from_retained(crate::css::style_compute::initial_value_handle(property))
+ };
Self {
font_size: CssPixels::from_integer(16),
line_height_used: CssPixels::from_raw(0),
@@ -3486,35 +3557,31 @@ impl FontValues {
/// The returned payload carries one reference for the caller; fresh payloads
/// start at one, shared payloads are retained, and default payloads are
/// intentionally leaked and never counted.
-///
-/// # Safety
-/// The value pointers must identify valid StyleValueData, and
-/// `parent_payload` must identify an alignment payload or be null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn rust_build_alignment_group(
+pub(crate) fn rust_build_alignment_group(
group_index: usize,
- webkit_box_orient: *const c_void,
- flex_direction: *const c_void,
- flex_wrap: *const c_void,
- flex_basis: *const c_void,
+ webkit_box_orient: &RetainedStyleValueData,
+ flex_direction: &RetainedStyleValueData,
+ flex_wrap: &RetainedStyleValueData,
+ flex_basis: &RetainedStyleValueData,
flex_grow: f64,
flex_shrink: f64,
order: i32,
- align_content: *const c_void,
- align_items: *const c_void,
- align_self: *const c_void,
- justify_content: *const c_void,
- justify_items: *const c_void,
- justify_self: *const c_void,
- column_gap: *const c_void,
- row_gap: *const c_void,
- parent_payload: *const c_void,
+ align_content: &RetainedStyleValueData,
+ align_items: &RetainedStyleValueData,
+ align_self: &RetainedStyleValueData,
+ justify_content: &RetainedStyleValueData,
+ justify_items: &RetainedStyleValueData,
+ justify_self: &RetainedStyleValueData,
+ column_gap: &RetainedStyleValueData,
+ row_gap: &RetainedStyleValueData,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::style_value::StyleValueData;
let build_or_reuse_group_payload = || {
- let keyword_code = |data: *const c_void, map: fn(u16) -> Option<u8>| -> Option<u8> {
- match unsafe { data.cast::<StyleValueData>().as_ref() } {
+ let keyword_code = |data: &RetainedStyleValueData, map: fn(u16) -> Option<u8>| -> Option<u8> {
+ match data.optional_data() {
Some(StyleValueData::Keyword { keyword }) => map(*keyword),
_ => None,
}
@@ -3537,11 +3604,11 @@ pub(crate) unsafe fn rust_build_alignment_group(
row_gap: ComputedGap::from_data(row_gap),
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- Some(
- unsafe { share_group_payload::<AlignmentValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built)),
- )
+ Some(share_or_publish_group_payload::<AlignmentValues>(
+ group_index,
+ built,
+ parent,
+ ))
};
build_or_reuse_group_payload().unwrap_or(std::ptr::null())
}
@@ -3551,51 +3618,33 @@ pub(crate) unsafe fn rust_build_alignment_group(
/// The returned payload carries one reference for the caller; fresh payloads
/// start at one, shared payloads are retained, and default payloads are
/// intentionally leaked and never counted.
-///
-/// # Safety
-/// `parent_payload` must identify an SVG reset payload or be null.
-pub(crate) unsafe fn build_svg_reset_group_payload(
+pub(crate) fn build_svg_reset_group_payload(
group_index: usize,
built: SVGResetValues,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- abort_on_panic(|| {
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<SVGResetValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
- })
+ abort_on_panic(|| share_or_publish_group_payload::<SVGResetValues>(group_index, built, parent))
}
/// Builds the complete text-decoration reset group from its lowered values.
-///
-/// # Safety
-/// `text_decoration_lines` must address `text_decoration_line_count` valid
-/// enum codes, a non-null thickness must identify valid StyleValueData, and
-/// `parent_payload` must identify a text reset payload or be null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn rust_build_text_reset_group(
+pub(crate) fn rust_build_text_reset_group(
group_index: usize,
- text_decoration_lines: *const u8,
- text_decoration_line_count: usize,
+ lines: &[u8],
text_decoration_thickness_kind: u8,
- text_decoration_thickness: *const c_void,
+ text_decoration_thickness: &RetainedStyleValueData,
text_decoration_style: u8,
text_decoration_color: u32,
white_space_trim_discard_before: bool,
white_space_trim_discard_after: bool,
white_space_trim_discard_inner: bool,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let lines = if text_decoration_line_count == 0 {
- &[]
- } else {
- unsafe { std::slice::from_raw_parts(text_decoration_lines, text_decoration_line_count) }
- };
let built = TextResetValues {
text_decoration_lines: RetainedTextDecorationLineList::from_vec(lines.to_vec()),
text_decoration_thickness_kind,
text_decoration_thickness: if text_decoration_thickness_kind == 2 {
- ComputedStyleValueHandle::retained(text_decoration_thickness.cast())
+ ComputedStyleValueHandle::from_retained(text_decoration_thickness)
} else {
ComputedStyleValueHandle::empty()
},
@@ -3606,44 +3655,37 @@ pub(crate) unsafe fn rust_build_text_reset_group(
white_space_trim_discard_inner,
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<TextResetValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<TextResetValues>(group_index, built, parent)
}
/// Builds the complete surround group from the physical inset, margin, and
/// padding properties. Anchor insets retain their original value separately
/// while exposing auto through the length-box facade, matching layout's
/// existing representation.
-///
-/// # Safety
-/// Each value pointer must address valid StyleValueData, and `parent_payload`
-/// must be a valid surround payload or null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn rust_build_surround_group(
+pub(crate) fn rust_build_surround_group(
group_index: usize,
- top: *const c_void,
- right: *const c_void,
- bottom: *const c_void,
- left: *const c_void,
- margin_top: *const c_void,
- margin_right: *const c_void,
- margin_bottom: *const c_void,
- margin_left: *const c_void,
- padding_top: *const c_void,
- padding_right: *const c_void,
- padding_bottom: *const c_void,
- padding_left: *const c_void,
- position_anchor: *const c_void,
- parent_payload: *const c_void,
+ top: &RetainedStyleValueData,
+ right: &RetainedStyleValueData,
+ bottom: &RetainedStyleValueData,
+ left: &RetainedStyleValueData,
+ margin_top: &RetainedStyleValueData,
+ margin_right: &RetainedStyleValueData,
+ margin_bottom: &RetainedStyleValueData,
+ margin_left: &RetainedStyleValueData,
+ padding_top: &RetainedStyleValueData,
+ padding_right: &RetainedStyleValueData,
+ padding_bottom: &RetainedStyleValueData,
+ padding_left: &RetainedStyleValueData,
+ position_anchor: Option<&RetainedStyleValueData>,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::style_value::StyleValueData;
let build_or_reuse_group_payload = || {
- let anchor = |data: *const c_void| {
- let data = data.cast::<StyleValueData>();
- if matches!(unsafe { data.as_ref() }, Some(StyleValueData::Anchor { .. })) {
- ComputedStyleValueHandle::retained(data)
+ let anchor = |data: &RetainedStyleValueData| {
+ if matches!(data.optional_data(), Some(StyleValueData::Anchor { .. })) {
+ ComputedStyleValueHandle::from_retained(data)
} else {
ComputedStyleValueHandle::empty()
}
@@ -3658,17 +3700,13 @@ pub(crate) unsafe fn rust_build_surround_group(
right_anchor_inset_wrapper: ComputedStyleValueHandle::empty(),
bottom_anchor_inset_wrapper: ComputedStyleValueHandle::empty(),
left_anchor_inset_wrapper: ComputedStyleValueHandle::empty(),
- position_anchor: if position_anchor.is_null() {
- ComputedStyleValueHandle::empty()
- } else {
- ComputedStyleValueHandle::retained(position_anchor.cast())
- },
+ position_anchor: position_anchor
+ .map_or_else(ComputedStyleValueHandle::empty, ComputedStyleValueHandle::from_retained),
margin: ComputedLengthBox::from_data(margin_top, margin_right, margin_bottom, margin_left, false),
padding: ComputedLengthBox::from_data(padding_top, padding_right, padding_bottom, padding_left, false),
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- if let Some(shared) = unsafe { share_group_payload::<SurroundValues>(group_index, &built, parent_payload) } {
+ if let Some(shared) = share_group_payload::<SurroundValues>(group_index, &built, parent) {
return Some(shared);
}
@@ -3703,39 +3741,22 @@ pub(crate) unsafe fn rust_build_surround_group(
/// The returned payload carries one reference for the caller; fresh payloads
/// start at one, shared payloads are retained, and default payloads are
/// intentionally leaked and never counted.
-///
-/// # Safety
-/// `values` must point at a fully initialized box payload whose ownership
-/// transfers to this call, and `parent_payload` must be a valid box payload
-/// or null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn rust_build_box_group(
+pub(crate) fn rust_build_box_group(
group_index: usize,
- values: *const BoxValues,
- parent_payload: *const c_void,
+ built: BoxValues,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let built = unsafe { values.read() };
-
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<BoxValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<BoxValues>(group_index, built, parent)
}
-/// # Safety
-/// `values` must point at a fully initialized grid payload whose ownership
-/// transfers to this call, and `parent_payload` must be a valid grid payload
-/// or null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn rust_build_grid_group(
+pub(crate) fn rust_build_grid_group(
group_index: usize,
- values: *const GridValues,
- parent_payload: *const c_void,
+ built: GridValues,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let built = unsafe { values.read() };
-
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<GridValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<GridValues>(group_index, built, parent)
}
pub(crate) fn copy_grid_placements(source: &GridValues, target: &mut GridValues) {
@@ -3771,20 +3792,16 @@ pub(crate) fn copy_grid_placements(source: &GridValues, target: &mut GridValues)
/// sizing functions are already constrained to fit-content() by parsing, so
/// the function payload can be consumed without inspecting or copying its
/// interned name.
-///
-/// # Safety
-/// Each value pointer must address valid StyleValueData, and `parent_payload`
-/// must be a valid sizing payload or null.
#[allow(clippy::too_many_arguments)]
-pub(crate) unsafe fn build_sizing_group(
+pub(crate) fn build_sizing_group(
group_index: usize,
- width: *const c_void,
- min_width: *const c_void,
- max_width: *const c_void,
- height: *const c_void,
- min_height: *const c_void,
- max_height: *const c_void,
- parent_payload: *const c_void,
+ width: &RetainedStyleValueData,
+ min_width: &RetainedStyleValueData,
+ max_width: &RetainedStyleValueData,
+ height: &RetainedStyleValueData,
+ min_height: &RetainedStyleValueData,
+ max_height: &RetainedStyleValueData,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let built = SizingValues {
width: ComputedSize::from_data(width),
@@ -3795,30 +3812,24 @@ pub(crate) unsafe fn build_sizing_group(
max_height: ComputedSize::from_data(max_height),
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<SizingValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<SizingValues>(group_index, built, parent)
}
/// Builds an inherited table group payload from the computed values, with the
/// same sharing rules as the inherited box builder. Computed border-spacing
/// is a pair of absolute pixel lengths.
-///
-/// # Safety
-/// The value pointers must be valid StyleValueData or null, and
-/// `parent_payload` a valid inherited table payload or null.
-pub(crate) unsafe fn build_inherited_table_group(
+pub(crate) fn build_inherited_table_group(
group_index: usize,
- border_collapse: *const c_void,
- caption_side: *const c_void,
- empty_cells: *const c_void,
- border_spacing: *const c_void,
- parent_payload: *const c_void,
+ border_collapse: &RetainedStyleValueData,
+ caption_side: &RetainedStyleValueData,
+ empty_cells: &RetainedStyleValueData,
+ border_spacing: &RetainedStyleValueData,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::style_value::StyleValueData;
- let keyword_code = |data: *const c_void, map: fn(u16) -> Option<u8>| -> u8 {
- match unsafe { (data as *const StyleValueData).as_ref() } {
+ let keyword_code = |data: &RetainedStyleValueData, map: fn(u16) -> Option<u8>| -> u8 {
+ match data.optional_data() {
Some(StyleValueData::Keyword { keyword }) => map(*keyword).expect("computed keyword has a supported value"),
_ => panic!("computed inherited table value is not a keyword"),
}
@@ -3831,7 +3842,7 @@ pub(crate) unsafe fn build_inherited_table_group(
_ => panic!("computed border-spacing component is not an absolute pixel length"),
}
};
- let components = match unsafe { (border_spacing as *const StyleValueData).as_ref() } {
+ let components = match border_spacing.optional_data() {
Some(StyleValueData::ValueList { values, .. }) if values.as_slice().len() == 2 => values.as_slice(),
_ => panic!("computed border-spacing is not a pair"),
};
@@ -3843,9 +3854,7 @@ pub(crate) unsafe fn build_inherited_table_group(
border_spacing_vertical: spacing_component(components[1].data()),
};
- // SAFETY: The caller guarantees that `parent_payload` is null or a live payload of this group.
- unsafe { share_group_payload::<InheritedTableValues>(group_index, &built, parent_payload) }
- .unwrap_or_else(|| publish_group_payload(group_index, built))
+ share_or_publish_group_payload::<InheritedTableValues>(group_index, built, parent)
}
/// Layout of the inherited table style value group.
@@ -3894,6 +3903,13 @@ impl InheritedBoxValues {
mod tests {
use super::*;
+ #[test]
+ fn every_payload_type_names_the_group_it_is_dispatched_for() {
+ for (group_index, &group) in STYLE_GROUPS.iter().enumerate() {
+ with_style_group_type!(group, Payload => assert_eq!(Payload::GROUP_INDEX, group_index));
+ }
+ }
+
#[test]
fn field_descriptors_belong_to_the_group_properties_json_declares() {
for group in 0..group_index::COUNT {
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 473bca6bab1..8c7d4a658e6 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -1911,7 +1911,7 @@ pub(crate) unsafe fn intern_document_style(
use crate::css::table_group_builder::{assemble_group_from_table, assembly_color_inputs, group_index};
let color_inputs = assembly_color_inputs(table, length);
let payloads: [*const c_void; group_index::COUNT] = std::array::from_fn(|group| unsafe {
- assemble_group_from_table(table, group, Some(font), std::ptr::null(), color_inputs, length)
+ assemble_group_from_table(table, group, Some(font), None, color_inputs, length)
});
let delta = unsafe {
publish_computed_groups(
diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rs
index fedacd6514f..92a04d12da3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs
@@ -1649,7 +1649,7 @@ impl ComputedGroupSets {
crate::css::table_group_builder::rebuild_group_for_inherited_current_color(
table,
group,
- old_payload.as_ptr(),
+ crate::css::computed_values::GroupPayloadRef::new(group, old_payload.as_ptr()),
inherited_text.color,
inherited_ui.color_scheme,
)
@@ -1799,7 +1799,7 @@ impl ComputedGroupSets {
&table,
group,
font,
- old_payload.as_ptr(),
+ crate::css::computed_values::GroupPayloadRef::new(group, old_payload.as_ptr()),
color_inputs,
length,
)
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index 0ae502227b8..81373478dc9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -2344,7 +2344,7 @@ impl RetainedState {
&*table,
group,
Some(font),
- parent_payload.as_ptr(),
+ crate::css::computed_values::GroupPayloadRef::new(group, parent_payload.as_ptr()),
color_inputs,
length,
)
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 9f5a5ec9406..0076a46a1c0 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2560,7 +2560,11 @@ pub(crate) fn initial_value(property_id: u16) -> Option<&'static crate::css::sty
}
pub(crate) fn initial_value_data(property_id: u16) -> *const crate::css::style_value::StyleValueData {
- initial_value_table().values[longhand_index(property_id)].pointer()
+ initial_value_handle(property_id).pointer()
+}
+
+pub(crate) fn initial_value_handle(property_id: u16) -> &'static crate::css::style_value::RetainedStyleValueData {
+ &initial_value_table().values[longhand_index(property_id)]
}
fn initial_value_dependencies(property_id: u16) -> ExternalValueDependencies {
diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rs
index 8f55904ebf3..a3713b8f0e7 100644
--- a/Libraries/LibWeb/Rust/src/css/style_value.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs
@@ -464,6 +464,13 @@ impl RetainedStyleValueData {
unsafe { Self::from_retained_optional_pointer(pointer) }
}
+ /// Releases the handle's reference to the caller as a raw pointer, null for an empty handle.
+ pub(crate) fn into_pointer(self) -> *const StyleValueData {
+ let pointer = self.pointer();
+ std::mem::forget(self);
+ pointer
+ }
+
/// Converts the retained reference into an Arc, transferring the strong reference.
pub(crate) fn into_arc(self) -> std::sync::Arc<StyleValueData> {
let pointer = self.pointer();
@@ -3286,13 +3293,21 @@ pub unsafe extern "C" fn rust_style_value_release(value: *const StyleValueData)
/// `first` and `second` must be null or point at live `StyleValueData` allocated by this module.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_style_value_equals(first: *const StyleValueData, second: *const StyleValueData) -> bool {
- if std::ptr::eq(first, second) {
- return true;
- }
- if first.is_null() || second.is_null() {
- return false;
+ optional_style_values_equal(unsafe { first.as_ref() }, unsafe { second.as_ref() })
+}
+
+/// `rust_style_value_equals` for two handles.
+pub(crate) fn retained_style_values_equal(first: &RetainedStyleValueData, second: &RetainedStyleValueData) -> bool {
+ optional_style_values_equal(first.optional_data(), second.optional_data())
+}
+
+/// Two absent values are equal, and an absent value equals no present one.
+fn optional_style_values_equal(first: Option<&StyleValueData>, second: Option<&StyleValueData>) -> bool {
+ match (first, second) {
+ (None, None) => true,
+ (Some(first), Some(second)) => style_values_equal(first, second),
+ _ => false,
}
- style_values_equal(unsafe { &*first }, unsafe { &*second })
}
fn style_values_equal(first: &StyleValueData, second: &StyleValueData) -> bool {
diff --git a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs b/Libraries/LibWeb/Rust/src/css/table_group_builder.rs
index 385d700d2c6..65e16d26683 100644
--- a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs
+++ b/Libraries/LibWeb/Rust/src/css/table_group_builder.rs
@@ -37,15 +37,16 @@ use crate::css::computed_value_types::{
RetainedPositionTryFallbackList, RetainedWillChangePropertyList, SVGResetValues, TransformValues,
};
use crate::css::computed_values::{
- GroupFieldKind, GroupValueEntry, MAX_GROUP_FIELD_COUNT, build_inherited_box_group, build_inherited_table_group,
- build_sizing_group, build_style_group, build_svg_reset_group_payload, group_field_descriptors,
- rust_build_alignment_group, rust_build_grid_group, rust_build_surround_group, rust_build_text_reset_group,
+ GroupFieldKind, GroupPayloadRef, GroupValueEntry, MAX_GROUP_FIELD_COUNT, build_inherited_box_group,
+ build_inherited_table_group, build_sizing_group, build_style_group, build_svg_reset_group_payload,
+ group_field_descriptors, rust_build_alignment_group, rust_build_grid_group, rust_build_surround_group,
+ rust_build_text_reset_group,
};
use crate::css::css_enums::keyword;
use crate::css::css_pixels::CssPixels;
use crate::css::property_metadata::property_id;
use crate::css::retained_fly_string::{RetainedUtf16FlyString, RetainedUtf16FlyStringList};
-use crate::css::style_value::{GridTrackEntryKind, RetainedGridTrackEntry, StyleValueData};
+use crate::css::style_value::{GridTrackEntryKind, RetainedGridTrackEntry, RetainedStyleValueData, StyleValueData};
/// Mirror of the C++ StyleGroupIndex numbering; ComputedValues.cpp
/// static-asserts these values against the enum, and the entry point asserts
@@ -117,49 +118,18 @@ struct EffectiveValues<'a> {
animated_overlay: Option<&'a AnimatedOverlay>,
}
-struct GroupValueEntries {
- entries: [std::mem::MaybeUninit<GroupValueEntry>; MAX_GROUP_FIELD_COUNT],
- len: usize,
-}
-
-impl GroupValueEntries {
- fn new() -> Self {
- Self {
- entries: [const { std::mem::MaybeUninit::uninit() }; MAX_GROUP_FIELD_COUNT],
- len: 0,
- }
- }
-
- fn push(&mut self, entry: GroupValueEntry) {
- assert!(
- self.len < self.entries.len(),
- "a computed style group has too many fields"
- );
- self.entries[self.len].write(entry);
- self.len += 1;
- }
-}
-
-impl std::ops::Deref for GroupValueEntries {
- type Target = [GroupValueEntry];
-
- fn deref(&self) -> &Self::Target {
- // SAFETY: push initializes every entry below len and GroupValueEntry has no drop glue.
- unsafe { std::slice::from_raw_parts(self.entries.as_ptr().cast(), self.len) }
- }
-}
+/// The gathered entries of one group, which has at most `MAX_GROUP_FIELD_COUNT` fields.
+type GroupValueEntries<'a> = smallvec::SmallVec<[GroupValueEntry<'a>; MAX_GROUP_FIELD_COUNT]>;
-impl EffectiveValues<'_> {
- fn pointer(&self, property_id: u16) -> *const c_void {
+impl<'a> EffectiveValues<'a> {
+ fn handle(&self, property_id: u16) -> &'a RetainedStyleValueData {
self.table
- .effective_value(self.animated_overlay, property_id, true)
- .value
+ .effective_value_handle(self.animated_overlay, property_id, true)
+ .0
}
- fn value(&self, property_id: u16) -> Option<&StyleValueData> {
- // SAFETY: Table slots retain their data and override pointers borrow
- // values the caller keeps alive across the build.
- unsafe { self.pointer(property_id).cast::<StyleValueData>().as_ref() }
+ fn value(&self, property_id: u16) -> Option<&'a StyleValueData> {
+ self.handle(property_id).optional_data()
}
}
@@ -210,20 +180,20 @@ fn resolved_wrapped_number(data: &StyleValueData) -> Option<f64> {
/// Gathers one group's descriptor entries from the table, resolving the
/// color and number sidecars the descriptor kinds ask for.
-fn gather_group_entries(
+fn gather_group_entries<'a>(
group_index: usize,
- values: &EffectiveValues,
+ values: &EffectiveValues<'a>,
input: &ColorResolutionInput,
used_color_scheme: u8,
-) -> Option<GroupValueEntries> {
+) -> Option<GroupValueEntries<'a>> {
let descriptors = group_field_descriptors(group_index);
assert!(descriptors.len() <= MAX_GROUP_FIELD_COUNT);
let mut entries = GroupValueEntries::new();
for descriptor in descriptors {
- let data = values.value(descriptor.property_id)?;
- let data_pointer = std::ptr::from_ref(data).cast::<c_void>();
+ let handle = values.handle(descriptor.property_id);
+ let data = handle.optional_data()?;
let mut entry = GroupValueEntry {
- data: data_pointer,
+ data: handle,
resolved_color: 0,
has_resolved_color: false,
resolved_number: 0.0,
@@ -256,83 +226,73 @@ fn gather_group_entries(
/// Builds one descriptor-driven group through `build_style_group`,
/// gathering the entries from the table instead of a marshalled span.
-unsafe fn build_generic_group(
+fn build_generic_group(
group_index: usize,
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index, values, input, used_color_scheme) else {
return std::ptr::null();
};
- // SAFETY: The entries hold live value data gathered above and the caller
- // warrants the parent payload.
- unsafe { build_style_group(group_index, &entries, parent_payload) }
+ build_style_group(group_index, &entries, parent)
}
-unsafe fn build_surround_group(values: &EffectiveValues, parent_payload: *const c_void) -> *const c_void {
+fn build_surround_group(values: &EffectiveValues, parent: Option<GroupPayloadRef<'_>>) -> *const c_void {
let position_anchor = match values.value(property_id::POSITION_ANCHOR) {
- Some(StyleValueData::CustomIdent { .. }) => values.pointer(property_id::POSITION_ANCHOR),
- _ => std::ptr::null(),
+ Some(StyleValueData::CustomIdent { .. }) => Some(values.handle(property_id::POSITION_ANCHOR)),
+ _ => None,
};
- // SAFETY: Every pointer names live value data from the table and the
- // caller warrants the parent payload.
- unsafe {
- rust_build_surround_group(
- group_index::SURROUND,
- values.pointer(property_id::TOP),
- values.pointer(property_id::RIGHT),
- values.pointer(property_id::BOTTOM),
- values.pointer(property_id::LEFT),
- values.pointer(property_id::MARGIN_TOP),
- values.pointer(property_id::MARGIN_RIGHT),
- values.pointer(property_id::MARGIN_BOTTOM),
- values.pointer(property_id::MARGIN_LEFT),
- values.pointer(property_id::PADDING_TOP),
- values.pointer(property_id::PADDING_RIGHT),
- values.pointer(property_id::PADDING_BOTTOM),
- values.pointer(property_id::PADDING_LEFT),
- position_anchor,
- parent_payload,
- )
- }
+ rust_build_surround_group(
+ group_index::SURROUND,
+ values.handle(property_id::TOP),
+ values.handle(property_id::RIGHT),
+ values.handle(property_id::BOTTOM),
+ values.handle(property_id::LEFT),
+ values.handle(property_id::MARGIN_TOP),
+ values.handle(property_id::MARGIN_RIGHT),
+ values.handle(property_id::MARGIN_BOTTOM),
+ values.handle(property_id::MARGIN_LEFT),
+ values.handle(property_id::PADDING_TOP),
+ values.handle(property_id::PADDING_RIGHT),
+ values.handle(property_id::PADDING_BOTTOM),
+ values.handle(property_id::PADDING_LEFT),
+ position_anchor,
+ parent,
+ )
}
-unsafe fn build_alignment_group(values: &EffectiveValues, parent_payload: *const c_void) -> *const c_void {
+fn build_alignment_group(values: &EffectiveValues, parent: Option<GroupPayloadRef<'_>>) -> *const c_void {
let number = |property: u16| required_number(values.value(property).expect("the table holds the flex factor"));
let flex_grow = number(property_id::FLEX_GROW);
let flex_shrink = number(property_id::FLEX_SHRINK);
let order = required_integer(values.value(property_id::ORDER).expect("the table holds order"));
- // SAFETY: Every pointer names live value data from the table and the
- // caller warrants the parent payload.
- unsafe {
- rust_build_alignment_group(
- group_index::ALIGNMENT,
- values.pointer(property_id::_WEBKIT_BOX_ORIENT),
- values.pointer(property_id::FLEX_DIRECTION),
- values.pointer(property_id::FLEX_WRAP),
- values.pointer(property_id::FLEX_BASIS),
- flex_grow,
- flex_shrink,
- order,
- values.pointer(property_id::ALIGN_CONTENT),
- values.pointer(property_id::ALIGN_ITEMS),
- values.pointer(property_id::ALIGN_SELF),
- values.pointer(property_id::JUSTIFY_CONTENT),
- values.pointer(property_id::JUSTIFY_ITEMS),
- values.pointer(property_id::JUSTIFY_SELF),
- values.pointer(property_id::COLUMN_GAP),
- values.pointer(property_id::ROW_GAP),
- parent_payload,
- )
- }
+ rust_build_alignment_group(
+ group_index::ALIGNMENT,
+ values.handle(property_id::_WEBKIT_BOX_ORIENT),
+ values.handle(property_id::FLEX_DIRECTION),
+ values.handle(property_id::FLEX_WRAP),
+ values.handle(property_id::FLEX_BASIS),
+ flex_grow,
+ flex_shrink,
+ order,
+ values.handle(property_id::ALIGN_CONTENT),
+ values.handle(property_id::ALIGN_ITEMS),
+ values.handle(property_id::ALIGN_SELF),
+ values.handle(property_id::JUSTIFY_CONTENT),
+ values.handle(property_id::JUSTIFY_ITEMS),
+ values.handle(property_id::JUSTIFY_SELF),
+ values.handle(property_id::COLUMN_GAP),
+ values.handle(property_id::ROW_GAP),
+ parent,
+ )
}
-unsafe fn build_svg_reset_group(
+fn build_svg_reset_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let color = |property: u16| {
packed_color(
@@ -347,14 +307,14 @@ unsafe fn build_svg_reset_group(
resolved_wrapped_number(values.value(property).expect("the table holds the computed opacity"))
.expect("a computed SVG reset opacity resolves")
};
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
let built = SVGResetValues {
cx: retained(property_id::CX),
cy: retained(property_id::CY),
d: retained(property_id::D),
r: retained(property_id::R),
- rx: ComputedLengthPercentageOrAuto::from_data(values.pointer(property_id::RX)),
- ry: ComputedLengthPercentageOrAuto::from_data(values.pointer(property_id::RY)),
+ rx: ComputedLengthPercentageOrAuto::from_data(values.handle(property_id::RX)),
+ ry: ComputedLengthPercentageOrAuto::from_data(values.handle(property_id::RY)),
x: retained(property_id::X),
y: retained(property_id::Y),
stop_color: color(property_id::STOP_COLOR),
@@ -367,8 +327,7 @@ unsafe fn build_svg_reset_group(
crate::css::css_enums::keyword_to_vector_effect,
),
};
- // SAFETY: The caller warrants the parent payload.
- unsafe { build_svg_reset_group_payload(group_index::SVG_RESET, built, parent_payload) }
+ build_svg_reset_group_payload(group_index::SVG_RESET, built, parent)
}
/// The name table, name-index spans, track entries and named areas one grid
@@ -425,7 +384,8 @@ fn auto_grid_track_breadth() -> ComputedGridTrackBreadth {
/// GridSize lowering: flex values - including calc that resolves to flex -
/// carry their fr factor, everything else maps through the shared computed
/// size representation.
-fn grid_track_breadth(data: &StyleValueData) -> ComputedGridTrackBreadth {
+fn grid_track_breadth(handle: &RetainedStyleValueData) -> ComputedGridTrackBreadth {
+ let data = handle.data();
let flex_factor = match data {
StyleValueData::Flex { value, unit } => {
Some(value * crate::css::calc::FLEX_UNIT_CANONICAL_RATIOS[*unit as usize])
@@ -440,7 +400,7 @@ fn grid_track_breadth(data: &StyleValueData) -> ComputedGridTrackBreadth {
size: ComputedSize::keyword(ComputedSizeKind::Auto),
};
}
- let size = ComputedSize::from_data(std::ptr::from_ref(data).cast());
+ let size = ComputedSize::from_data(handle);
assert!(size.kind != ComputedSizeKind::None, "a grid size cannot be none");
ComputedGridTrackBreadth {
is_flex: false,
@@ -511,14 +471,14 @@ fn build_grid_track_list(
entry.name_index_count = arena.name_indices.len() - name_index_start;
}
GridTrackEntryKind::Size => {
- let size = grid_track_breadth(source.size_value.data());
+ let size = grid_track_breadth(&source.size_value);
let entry = &mut arena.entries[entry_index as usize];
entry.kind = ComputedGridTrackEntryKind::TrackSize as u8;
entry.size = size;
}
GridTrackEntryKind::MinMax => {
- let min_size = grid_track_breadth(source.min_value.data());
- let max_size = grid_track_breadth(source.max_value.data());
+ let min_size = grid_track_breadth(&source.min_value);
+ let max_size = grid_track_breadth(&source.max_value);
let entry = &mut arena.entries[entry_index as usize];
entry.kind = ComputedGridTrackEntryKind::MinMax as u8;
entry.min_size = min_size;
@@ -603,7 +563,7 @@ fn build_grid_placement(data: &StyleValueData, arena: &mut GridGroupArena) -> Op
/// Builds the grid group payload from the table's computed track lists,
/// template areas and placements, in the C++ marshalled build's interning
/// order so the arena layout stays deterministic.
-unsafe fn build_grid_group(values: &EffectiveValues, parent_payload: *const c_void) -> *const c_void {
+fn build_grid_group(values: &EffectiveValues, parent: Option<GroupPayloadRef<'_>>) -> *const c_void {
// An all-initial grid shares the immortal default payload directly, with
// its empty style value handles, exactly as the descriptor constraints
// used to. A value is initial by what it holds, so that equal tables build
@@ -619,15 +579,14 @@ unsafe fn build_grid_group(values: &EffectiveValues, parent_payload: *const c_vo
property_id::GRID_ROW_START,
property_id::GRID_ROW_END,
];
- let all_initial = GRID_PROPERTIES.iter().all(|property| unsafe {
- crate::css::style_value::rust_style_value_equals(
- values.pointer(*property).cast(),
- crate::css::style_compute::initial_value_data(*property).cast(),
+ let all_initial = GRID_PROPERTIES.iter().all(|property| {
+ crate::css::style_value::retained_style_values_equal(
+ values.handle(*property),
+ crate::css::style_compute::initial_value_handle(*property),
)
});
if all_initial {
- // SAFETY: The caller warrants the parent payload.
- return unsafe { crate::css::computed_values::share_default_group_payload(group_index::GRID, parent_payload) };
+ return crate::css::computed_values::share_default_group_payload(group_index::GRID, parent);
}
let mut arena = GridGroupArena::new();
@@ -691,11 +650,7 @@ unsafe fn build_grid_group(values: &EffectiveValues, parent_payload: *const c_vo
return std::ptr::null();
};
- let retained_slot = |property: u16| {
- // SAFETY: Table slots and override values are live style value data
- // across the build.
- ComputedStyleValueHandle::retained(values.pointer(property).cast())
- };
+ let retained_slot = |property: u16| ComputedStyleValueHandle::from_retained(values.handle(property));
let built = GridValues {
names: RetainedUtf16FlyStringList::from_retained_strings(arena.names),
name_indices: RetainedGridNameIndexList::from_vec(arena.name_indices),
@@ -719,11 +674,7 @@ unsafe fn build_grid_group(values: &EffectiveValues, parent_payload: *const c_vo
grid_row_start_style_value: retained_slot(property_id::GRID_ROW_START),
grid_row_end_style_value: retained_slot(property_id::GRID_ROW_END),
};
- // SAFETY: The built payload is fully initialized; the builder assumes
- // ownership of it, so the local value must not drop.
- let payload = unsafe { rust_build_grid_group(group_index::GRID, &raw const built, parent_payload) };
- std::mem::forget(built);
- payload
+ rust_build_grid_group(group_index::GRID, built, parent)
}
// --- Transform and effects lowering ---------------------------------------
@@ -1214,7 +1165,7 @@ fn lower_transformation(data: &StyleValueData) -> ComputedResolvedTransform {
}
let value = &values[index];
if axis_needs_reference_box(index) {
- return (0.0, ComputedStyleValueHandle::retained(value.pointer()));
+ return (0.0, ComputedStyleValueHandle::from_retained(value));
}
(
length_to_css_pixels(value.data()).to_float(),
@@ -1261,11 +1212,11 @@ fn lower_transformation(data: &StyleValueData) -> ComputedResolvedTransform {
/// Builds the complete transform payload in Rust, including paint-ready
/// matrices and retained computed-value handles.
-unsafe fn build_transform_group(
+fn build_transform_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::TRANSFORM, values, input, used_color_scheme) else {
return std::ptr::null();
@@ -1273,7 +1224,7 @@ unsafe fn build_transform_group(
let retained = |property: u16| -> ComputedStyleValueHandle {
match values.value(property) {
- Some(_) => ComputedStyleValueHandle::retained(values.pointer(property).cast()),
+ Some(_) => ComputedStyleValueHandle::from_retained(values.handle(property)),
None => ComputedStyleValueHandle::empty(),
}
};
@@ -1309,9 +1260,9 @@ unsafe fn build_transform_group(
Some(StyleValueData::ValueList { values: list, .. }) if list.as_slice().len() == 3 => {
let offsets = list.as_slice();
(
- ComputedStyleValueHandle::retained(offsets[0].pointer()),
- ComputedStyleValueHandle::retained(offsets[1].pointer()),
- ComputedStyleValueHandle::retained(offsets[2].pointer()),
+ ComputedStyleValueHandle::from_retained(&offsets[0]),
+ ComputedStyleValueHandle::from_retained(&offsets[1]),
+ ComputedStyleValueHandle::from_retained(&offsets[2]),
)
}
_ => unreachable!("computed transform-origin is a three-value list"),
@@ -1330,19 +1281,16 @@ unsafe fn build_transform_group(
let StyleValueData::Edge { offset, .. } = edge.data() else {
unreachable!("computed position component is an edge value");
};
- ComputedStyleValueHandle::retained(offset.pointer())
+ ComputedStyleValueHandle::from_retained(offset)
};
let perspective_origin_x = position_offset(edge_x);
let perspective_origin_y = position_offset(edge_y);
- // SAFETY: The closure casts the scratch payload to its registered
- // Rust-native type and the caller warrants the parent payload.
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::TRANSFORM,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<TransformValues>();
+ |payload: &mut TransformValues| {
payload.transformations = transform_list;
payload.resolved_transforms = RetainedComputedResolvedTransformList::from_vec(resolved);
payload.transform_origin_x = transform_origin_x;
@@ -1356,7 +1304,7 @@ unsafe fn build_transform_group(
payload.perspective_origin_x = perspective_origin_x;
payload.perspective_origin_y = perspective_origin_y;
},
- parent_payload,
+ parent,
)
}
}
@@ -1444,7 +1392,7 @@ fn lower_filter_operations(
StyleValueData::Url { .. } => {
operations.push(ComputedFilterOperation {
kind: FILTER_KIND_URL,
- url_value: ComputedStyleValueHandle::retained(value.pointer()),
+ url_value: ComputedStyleValueHandle::from_retained(value),
..empty_operation()
});
}
@@ -1516,7 +1464,7 @@ fn lower_filter_operations(
}
(
operations,
- ComputedStyleValueHandle::retained(values.pointer(property).cast()),
+ ComputedStyleValueHandle::from_retained(values.handle(property)),
)
}
@@ -1585,11 +1533,11 @@ fn lower_clip_edge(data: &StyleValueData) -> ComputedClipEdge {
}
/// Builds the complete effects payload in Rust.
-unsafe fn build_effects_group(
+fn build_effects_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::EFFECTS, values, input, used_color_scheme) else {
return std::ptr::null();
@@ -1630,32 +1578,31 @@ unsafe fn build_effects_group(
filter_list: backdrop_list,
operations: RetainedComputedFilterOperationList::from_vec(backdrop_operations),
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::EFFECTS,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<EffectsValues>();
+ |payload: &mut EffectsValues| {
payload.filter = filter;
payload.backdrop_filter = backdrop_filter;
payload.box_shadows = RetainedComputedShadowList::from_vec(shadows);
payload.clip_is_rect = clip_is_rect;
payload.clip_edges = clip_edges;
payload.opacity_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::OPACITY).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::OPACITY));
payload.filter_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::FILTER).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::FILTER));
payload.backdrop_filter_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::BACKDROP_FILTER).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::BACKDROP_FILTER));
payload.mix_blend_mode_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::MIX_BLEND_MODE).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::MIX_BLEND_MODE));
payload.isolation_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::ISOLATION).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::ISOLATION));
payload.box_shadow_style_value =
- ComputedStyleValueHandle::retained(values.pointer(property_id::BOX_SHADOW).cast());
- payload.clip_style_value = ComputedStyleValueHandle::retained(values.pointer(property_id::CLIP).cast());
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::BOX_SHADOW));
+ payload.clip_style_value = ComputedStyleValueHandle::from_retained(values.handle(property_id::CLIP));
},
- parent_payload,
+ parent,
)
}
}
@@ -1667,13 +1614,11 @@ unsafe fn build_effects_group(
// wrapper-backed members travel as retained canonical handles.
/// The comma-separated computed items of a repeatable-list property: the
-/// list's element pointers, or the single value itself.
-fn repeatable_item_pointers(values: &EffectiveValues, property: u16) -> Vec<*const c_void> {
+/// list's elements, or the single value itself.
+fn repeatable_items<'a>(values: &EffectiveValues<'a>, property: u16) -> Vec<&'a RetainedStyleValueData> {
match values.value(property) {
- Some(StyleValueData::ValueList { values: list, .. }) => {
- list.as_slice().iter().map(|value| value.pointer().cast()).collect()
- }
- _ => vec![values.pointer(property)],
+ Some(StyleValueData::ValueList { values: list, .. }) => list.as_slice().iter().collect(),
+ _ => vec![values.handle(property)],
}
}
@@ -1698,16 +1643,16 @@ fn border_radius_is_initial(data: &StyleValueData) -> bool {
}
/// Builds the background group from retained canonical computed values.
-unsafe fn build_background_group(
+fn build_background_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::BACKGROUND, values, input, used_color_scheme) else {
return std::ptr::null();
};
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
let background_color = resolved_color(
input,
property_id::BACKGROUND_COLOR,
@@ -1716,20 +1661,18 @@ unsafe fn build_background_group(
.expect("background-color has a computed value"),
)
.expect("a computed background-color resolves in Rust");
- let image_items = repeatable_item_pointers(values, property_id::BACKGROUND_IMAGE);
- let clip_items = repeatable_item_pointers(values, property_id::BACKGROUND_CLIP);
- let final_clip_pointer = clip_items[(image_items.len() - 1) % clip_items.len()];
- let final_clip = unsafe { &*final_clip_pointer.cast::<StyleValueData>() };
+ let image_items = repeatable_items(values, property_id::BACKGROUND_IMAGE);
+ let clip_items = repeatable_items(values, property_id::BACKGROUND_CLIP);
+ let final_clip = clip_items[(image_items.len() - 1) % clip_items.len()].data();
let background_color_clip = keyword_of(final_clip)
.and_then(crate::css::css_enums::keyword_to_background_box)
.expect("a computed background-clip keyword maps to its enum");
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::BACKGROUND,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<BackgroundValues>();
+ |payload: &mut BackgroundValues| {
payload.background_color = background_color;
payload.background_color_style_value = retained(property_id::BACKGROUND_COLOR);
payload.background_color_clip = background_color_clip;
@@ -1743,28 +1686,27 @@ unsafe fn build_background_group(
payload.background_repeat = retained(property_id::BACKGROUND_REPEAT);
payload.background_size = retained(property_id::BACKGROUND_SIZE);
},
- parent_payload,
+ parent,
)
}
}
/// Builds the mask group from retained canonical computed values.
-unsafe fn build_mask_group(
+fn build_mask_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::MASK, values, input, used_color_scheme) else {
return std::ptr::null();
};
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
- unsafe {
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::MASK,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<MaskValues>();
+ |payload: &mut MaskValues| {
payload.mask_image = retained(property_id::MASK_IMAGE);
payload.mask_type = retained(property_id::MASK_TYPE);
payload.clip_path = retained(property_id::CLIP_PATH);
@@ -1776,27 +1718,27 @@ unsafe fn build_mask_group(
payload.mask_size = retained(property_id::MASK_SIZE);
payload.mask_composite = retained(property_id::MASK_COMPOSITE);
},
- parent_payload,
+ parent,
)
}
}
/// Builds the border group from layout-facing side facts and retained
/// canonical values for the C++ presentation views.
-unsafe fn build_border_group(
+fn build_border_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let generic = unsafe { build_generic_group(group_index::BORDER, values, input, used_color_scheme, parent_payload) };
+ let generic = build_generic_group(group_index::BORDER, values, input, used_color_scheme, parent);
if !generic.is_null() {
return generic;
}
let Some(entries) = gather_group_entries(group_index::BORDER, values, input, used_color_scheme) else {
return std::ptr::null();
};
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
let has_noninitial_border_radii = [
property_id::BORDER_BOTTOM_LEFT_RADIUS,
property_id::BORDER_BOTTOM_RIGHT_RADIUS,
@@ -1836,12 +1778,11 @@ unsafe fn build_border_group(
}
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::BORDER,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<BorderValues>();
+ |payload: &mut BorderValues| {
payload.border_left = side(
property_id::BORDER_LEFT_STYLE,
property_id::BORDER_LEFT_WIDTH,
@@ -1897,7 +1838,7 @@ unsafe fn build_border_group(
payload.border_image_outset = retained(property_id::BORDER_IMAGE_OUTSET);
payload.border_image_repeat = retained(property_id::BORDER_IMAGE_REPEAT);
},
- parent_payload,
+ parent,
)
}
}
@@ -1921,7 +1862,7 @@ fn lower_svg_paint(values: &EffectiveValues, property: u16, input: &ColorResolut
StyleValueData::ValueList { values: list, .. } if list.as_slice().len() == 2 => {
let components = list.as_slice();
paint.kind = SVG_PAINT_URL;
- paint.url = ComputedStyleValueHandle::retained(components[0].pointer());
+ paint.url = ComputedStyleValueHandle::from_retained(&components[0]);
match components[1].data() {
StyleValueData::EmptyOptional => paint,
StyleValueData::Keyword { keyword: code } if *code == keyword::NONE => paint,
@@ -1958,16 +1899,16 @@ fn lower_svg_length_percentage_or_number(values: &EffectiveValues, property: u16
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
Some(number) => ComputedStyleValueHandle::length(number),
- None => ComputedStyleValueHandle::retained(values.pointer(property).cast()),
+ None => ComputedStyleValueHandle::from_retained(values.handle(property)),
}
}
/// Builds the complete inherited SVG payload in Rust.
-unsafe fn build_inherited_svg_group(
+fn build_inherited_svg_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::INHERITED_SVG, values, input, used_color_scheme) else {
return std::ptr::null();
@@ -1995,7 +1936,7 @@ unsafe fn build_inherited_svg_group(
None => ComputedSvgDash {
is_number: false,
number: 0.0,
- value: ComputedStyleValueHandle::retained(item.pointer()),
+ value: ComputedStyleValueHandle::from_retained(item),
},
});
}
@@ -2046,12 +1987,11 @@ unsafe fn build_inherited_svg_group(
.and_then(keyword_of)
.and_then(crate::css::css_enums::keyword_to_baseline_metric);
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::INHERITED_SVG,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<InheritedSVGValues>();
+ |payload: &mut InheritedSVGValues| {
payload.fill = lower_svg_paint(values, property_id::FILL, input);
payload.stroke = lower_svg_paint(values, property_id::STROKE, input);
payload.stroke_dasharray = RetainedComputedSvgDashList::from_vec(dashes);
@@ -2064,28 +2004,20 @@ unsafe fn build_inherited_svg_group(
payload.has_dominant_baseline = dominant_baseline.is_some();
payload.dominant_baseline = dominant_baseline.unwrap_or(0);
},
- parent_payload,
+ parent,
)
}
}
/// Builds the inherited list group from canonical values without leaving
/// Rust. Counter-style scope resolution remains a consumer-side operation.
-unsafe fn build_inherited_list_group(
+fn build_inherited_list_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let generic = unsafe {
- build_generic_group(
- group_index::INHERITED_LIST,
- values,
- input,
- used_color_scheme,
- parent_payload,
- )
- };
+ let generic = build_generic_group(group_index::INHERITED_LIST, values, input, used_color_scheme, parent);
if !generic.is_null() {
return generic;
}
@@ -2093,13 +2025,12 @@ unsafe fn build_inherited_list_group(
return std::ptr::null();
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::INHERITED_LIST,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<InheritedListValues>();
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ |payload: &mut InheritedListValues| {
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
payload.list_style_type = retained(property_id::LIST_STYLE_TYPE);
payload.list_style_position = values
.value(property_id::LIST_STYLE_POSITION)
@@ -2109,20 +2040,19 @@ unsafe fn build_inherited_list_group(
payload.list_style_image = retained(property_id::LIST_STYLE_IMAGE);
payload.quotes = retained(property_id::QUOTES);
},
- parent_payload,
+ parent,
)
}
}
/// Builds the content group from its canonical values without leaving Rust.
-unsafe fn build_content_group(
+fn build_content_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let generic =
- unsafe { build_generic_group(group_index::CONTENT, values, input, used_color_scheme, parent_payload) };
+ let generic = build_generic_group(group_index::CONTENT, values, input, used_color_scheme, parent);
if !generic.is_null() {
return generic;
}
@@ -2130,19 +2060,18 @@ unsafe fn build_content_group(
return std::ptr::null();
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::CONTENT,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<ContentValues>();
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ |payload: &mut ContentValues| {
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
payload.content = retained(property_id::CONTENT);
payload.counter_increment = retained(property_id::COUNTER_INCREMENT);
payload.counter_reset = retained(property_id::COUNTER_RESET);
payload.counter_set = retained(property_id::COUNTER_SET);
},
- parent_payload,
+ parent,
)
}
}
@@ -2150,11 +2079,11 @@ unsafe fn build_content_group(
// --- Inherited UI, inherited text and misc lowering -------------------------
/// Builds the complete inherited UI payload in Rust.
-unsafe fn build_inherited_ui_group(
+fn build_inherited_ui_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::INHERITED_UI, values, input, used_color_scheme) else {
return std::ptr::null();
@@ -2176,10 +2105,10 @@ unsafe fn build_inherited_ui_group(
// The cursor list, with the extractor's rules: unmappable keywords are
// skipped, and an empty result is the predefined auto cursor.
let mut cursors: Vec<ComputedCursor> = Vec::new();
- let mut push_cursor = |data: &StyleValueData, pointer: *const c_void| match data {
+ let mut push_cursor = |data: &StyleValueData, handle: &RetainedStyleValueData| match data {
StyleValueData::Cursor { .. } => cursors.push(ComputedCursor {
is_cursor_value: true,
- cursor: ComputedStyleValueHandle::retained(pointer.cast()),
+ cursor: ComputedStyleValueHandle::from_retained(handle),
predefined: 0,
}),
_ => {
@@ -2195,10 +2124,10 @@ unsafe fn build_inherited_ui_group(
match values.value(property_id::CURSOR) {
Some(StyleValueData::ValueList { values: list, .. }) => {
for item in list.as_slice() {
- push_cursor(item.data(), item.pointer().cast());
+ push_cursor(item.data(), item);
}
}
- Some(data) => push_cursor(data, values.pointer(property_id::CURSOR)),
+ Some(data) => push_cursor(data, values.handle(property_id::CURSOR)),
None => {}
}
if cursors.is_empty() {
@@ -2238,12 +2167,11 @@ unsafe fn build_inherited_ui_group(
schemes.as_slice().iter().map(|name| name.to_fly_string()).collect(),
);
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::INHERITED_UI,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<InheritedUIValues>();
+ |payload: &mut InheritedUIValues| {
payload.caret_color = caret_color;
payload.accent_color = accent_color;
payload.cursor = RetainedComputedCursorList::from_vec(cursors);
@@ -2251,7 +2179,7 @@ unsafe fn build_inherited_ui_group(
payload.color_schemes = color_schemes;
payload.color_scheme_only = *only;
},
- parent_payload,
+ parent,
)
}
}
@@ -2279,11 +2207,11 @@ fn font_relative_length_to_css_pixels(data: &StyleValueData, input: &ColorResolu
}
/// Builds the complete inherited text payload in Rust.
-unsafe fn build_inherited_text_group(
+fn build_inherited_text_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::INHERITED_TEXT, values, input, used_color_scheme) else {
return std::ptr::null();
@@ -2342,12 +2270,11 @@ unsafe fn build_inherited_text_group(
font_relative_length_to_css_pixels(underline_offset_data, input)
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::INHERITED_TEXT,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<InheritedTextValues>();
+ |payload: &mut InheritedTextValues| {
payload.text_shadow = RetainedComputedShadowList::from_vec(text_shadows);
payload.text_underline_position = ComputedTextUnderlinePosition {
horizontal: *horizontal,
@@ -2359,11 +2286,11 @@ unsafe fn build_inherited_text_group(
value: if underline_offset_is_auto {
ComputedStyleValueHandle::empty()
} else {
- ComputedStyleValueHandle::retained(values.pointer(property_id::TEXT_UNDERLINE_OFFSET).cast())
+ ComputedStyleValueHandle::from_retained(values.handle(property_id::TEXT_UNDERLINE_OFFSET))
},
};
payload.text_indent = ComputedTextIndent {
- length_percentage: ComputedStyleValueHandle::retained(length_percentage.pointer()),
+ length_percentage: ComputedStyleValueHandle::from_retained(length_percentage),
each_line: *each_line,
hanging: *hanging,
};
@@ -2373,32 +2300,24 @@ unsafe fn build_inherited_text_group(
payload.word_spacing = word_spacing;
payload.letter_spacing = letter_spacing;
},
- parent_payload,
+ parent,
)
}
}
/// Builds the misc reset group entirely from Rust-owned canonical values.
-unsafe fn build_misc_reset_group(
+fn build_misc_reset_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let implicit_will_change = values
.animated_overlay
.map_or(&[][..], |overlay| overlay.implicit_will_change.as_slice());
if implicit_will_change.is_empty() {
- let generic = unsafe {
- build_generic_group(
- group_index::MISC_RESET,
- values,
- input,
- used_color_scheme,
- parent_payload,
- )
- };
+ let generic = build_generic_group(group_index::MISC_RESET, values, input, used_color_scheme, parent);
if !generic.is_null() {
return generic;
}
@@ -2469,7 +2388,7 @@ unsafe fn build_misc_reset_group(
let StyleValueData::Edge { offset, .. } = edge.data() else {
unreachable!("a computed position component is an edge value");
};
- ComputedStyleValueHandle::retained(offset.pointer())
+ ComputedStyleValueHandle::from_retained(offset)
};
let Some(StyleValueData::ScrollbarGutter {
@@ -2541,27 +2460,26 @@ unsafe fn build_misc_reset_group(
.expect("a computed outline-color resolves in the Rust color context"),
);
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::MISC_RESET,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<MiscResetValues>();
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ |payload: &mut MiscResetValues| {
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
payload.outline_offset_style_value = retained(property_id::OUTLINE_OFFSET);
payload.outline_offset = outline_offset;
payload.scroll_margin = ComputedLengthBox::from_data(
- values.pointer(property_id::SCROLL_MARGIN_TOP),
- values.pointer(property_id::SCROLL_MARGIN_RIGHT),
- values.pointer(property_id::SCROLL_MARGIN_BOTTOM),
- values.pointer(property_id::SCROLL_MARGIN_LEFT),
+ values.handle(property_id::SCROLL_MARGIN_TOP),
+ values.handle(property_id::SCROLL_MARGIN_RIGHT),
+ values.handle(property_id::SCROLL_MARGIN_BOTTOM),
+ values.handle(property_id::SCROLL_MARGIN_LEFT),
false,
);
payload.scroll_padding = ComputedLengthBox::from_data(
- values.pointer(property_id::SCROLL_PADDING_TOP),
- values.pointer(property_id::SCROLL_PADDING_RIGHT),
- values.pointer(property_id::SCROLL_PADDING_BOTTOM),
- values.pointer(property_id::SCROLL_PADDING_LEFT),
+ values.handle(property_id::SCROLL_PADDING_TOP),
+ values.handle(property_id::SCROLL_PADDING_RIGHT),
+ values.handle(property_id::SCROLL_PADDING_BOTTOM),
+ values.handle(property_id::SCROLL_PADDING_LEFT),
true,
);
payload.overflow_clip_margin = ComputedOverflowClipMargin {
@@ -2572,7 +2490,7 @@ unsafe fn build_misc_reset_group(
};
payload.appearance = normalized_appearance;
payload.computed_appearance = computed_appearance;
- payload.column_height = ComputedSize::from_data(values.pointer(property_id::COLUMN_HEIGHT));
+ payload.column_height = ComputedSize::from_data(values.handle(property_id::COLUMN_HEIGHT));
payload.outline_color = outline_color;
payload.object_position_x = position_offset(edge_x);
payload.object_position_y = position_offset(edge_y);
@@ -2587,7 +2505,7 @@ unsafe fn build_misc_reset_group(
payload.will_change = retained(property_id::WILL_CHANGE);
payload.implicit_will_change = RetainedWillChangePropertyList::from_vec(implicit_will_change.to_vec());
},
- parent_payload,
+ parent,
)
}
}
@@ -2597,10 +2515,10 @@ unsafe fn build_misc_reset_group(
const SEPARATOR_COMMA: u8 = 1;
/// Builds the complete text reset group in Rust.
-unsafe fn build_text_reset_group(
+fn build_text_reset_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let mut text_decoration_lines: Vec<u8> = Vec::new();
match values.value(property_id::TEXT_DECORATION_LINE) {
@@ -2617,10 +2535,12 @@ unsafe fn build_text_reset_group(
_ => unreachable!("a computed text-decoration-line is none or a value list"),
}
- let (thickness_kind, thickness_value) = match values.value(property_id::TEXT_DECORATION_THICKNESS) {
- Some(StyleValueData::Keyword { keyword: code }) if *code == keyword::AUTO => (0u8, std::ptr::null()),
- Some(StyleValueData::Keyword { keyword: code }) if *code == keyword::FROM_FONT => (1u8, std::ptr::null()),
- Some(_) => (2u8, values.pointer(property_id::TEXT_DECORATION_THICKNESS)),
+ // The builder reads the thickness value only for the length kind.
+ let thickness_value = values.handle(property_id::TEXT_DECORATION_THICKNESS);
+ let thickness_kind = match thickness_value.optional_data() {
+ Some(StyleValueData::Keyword { keyword: code }) if *code == keyword::AUTO => 0u8,
+ Some(StyleValueData::Keyword { keyword: code }) if *code == keyword::FROM_FONT => 1u8,
+ Some(_) => 2u8,
None => unreachable!("the table holds text-decoration-thickness"),
};
@@ -2659,23 +2579,18 @@ unsafe fn build_text_reset_group(
.expect("a computed text-decoration-color resolves in the Rust color context"),
);
- // SAFETY: The list and value pointers remain live through the call and
- // the caller warrants the parent payload.
- unsafe {
- rust_build_text_reset_group(
- group_index::TEXT_RESET,
- text_decoration_lines.as_ptr(),
- text_decoration_lines.len(),
- thickness_kind,
- thickness_value,
- text_decoration_style,
- text_decoration_color,
- discard_before,
- discard_after,
- discard_inner,
- parent_payload,
- )
- }
+ rust_build_text_reset_group(
+ group_index::TEXT_RESET,
+ &text_decoration_lines,
+ thickness_kind,
+ thickness_value,
+ text_decoration_style,
+ text_decoration_color,
+ discard_before,
+ discard_after,
+ discard_inner,
+ parent,
+ )
}
/// The C++ PositionArea codes a value's keywords map to, fanning out a value
@@ -2699,13 +2614,13 @@ fn position_area_codes(data: &StyleValueData) -> Vec<u8> {
}
/// Builds the complete anchor-positioning payload in Rust.
-unsafe fn build_anchor_group(
+fn build_anchor_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
- let generic = unsafe { build_generic_group(group_index::ANCHOR, values, input, used_color_scheme, parent_payload) };
+ let generic = build_generic_group(group_index::ANCHOR, values, input, used_color_scheme, parent);
if !generic.is_null() {
return generic;
}
@@ -2863,14 +2778,12 @@ unsafe fn build_anchor_group(
position_visibility_anchors_visible: anchors_visible,
position_visibility_no_overflow: no_overflow,
};
- unsafe {
- crate::css::computed_values::build_group_payload_with_rust_fill(
- group_index::ANCHOR,
- &entries,
- |payload| *payload.cast::<AnchorValues>() = built,
- parent_payload,
- )
- }
+ crate::css::computed_values::build_group_payload_with_rust_fill(
+ group_index::ANCHOR,
+ &entries,
+ |payload: &mut AnchorValues| *payload = built,
+ parent,
+ )
}
/// The keyword code of a slot that must hold an enum keyword.
@@ -2908,10 +2821,10 @@ fn required_number(data: &StyleValueData) -> f64 {
/// transformation happened at compute time, so the display slot already
/// holds the transformed value; only the pre-transformation display is a
/// C++-side member and arrives through the build inputs.
-unsafe fn build_box_group(
+fn build_box_group(
values: &EffectiveValues,
display_before_transformation_raw: u32,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::computed_value_types::{
BoxValues, ComputedAspectRatio, ComputedContainIntrinsicSize, ComputedVerticalAlign,
@@ -2953,7 +2866,7 @@ unsafe fn build_box_group(
Some(_) => ComputedVerticalAlign {
is_keyword: false,
keyword: 0,
- value: ComputedStyleValueHandle::retained(values.pointer(property_id::VERTICAL_ALIGN).cast()),
+ value: ComputedStyleValueHandle::from_retained(values.handle(property_id::VERTICAL_ALIGN)),
},
None => unreachable!("the table holds vertical-align"),
};
@@ -3130,7 +3043,7 @@ unsafe fn build_box_group(
_ => unreachable!("a computed container-name is none or custom idents"),
}
- let built = std::mem::ManuallyDrop::new(BoxValues {
+ let built = BoxValues {
display,
display_before_box_type_transformation: crate::css::display::FfiDisplay::from_raw(
display_before_transformation_raw,
@@ -3147,7 +3060,7 @@ unsafe fn build_box_group(
table_layout: required_keyword_code(values, property_id::TABLE_LAYOUT, keyword_to_table_layout),
grid_auto_flow_row: grid_auto_flow.0,
grid_auto_flow_dense: grid_auto_flow.1,
- column_width: ComputedSize::from_data(values.pointer(property_id::COLUMN_WIDTH)),
+ column_width: ComputedSize::from_data(values.handle(property_id::COLUMN_WIDTH)),
column_count_has_value: column_count.is_some(),
column_count: column_count.unwrap_or(0),
continue_: required_keyword_code(values, property_id::CONTINUE, keyword_to_continue_value),
@@ -3171,13 +3084,8 @@ unsafe fn build_box_group(
is_inline_size_container,
is_scroll_state_container,
container_name: RetainedUtf16FlyStringList::from_retained_strings(container_names),
- });
- // SAFETY: The payload value is fully materialized and ownership of its
- // retained references transfers to the builder; the caller warrants the
- // parent payload.
- unsafe {
- crate::css::computed_values::rust_build_box_group(group_index::BOX, (&raw const built).cast(), parent_payload)
- }
+ };
+ crate::css::computed_values::rust_build_box_group(group_index::BOX, built, parent)
}
/// Builds the inherited font group from canonical Rust longhands and the
@@ -3185,13 +3093,13 @@ unsafe fn build_box_group(
unsafe fn build_font_group(
values: &EffectiveValues,
inputs: &FfiFontGroupBuildInputs,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
use crate::css::css_pixels::CssPixels;
assert!(!inputs.first_available_font.is_null());
assert!(!inputs.font_cascade_list.is_null());
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
let built = FontValues {
font_size: CssPixels::from_raw(inputs.font_size_raw),
line_height_used: CssPixels::from_raw(inputs.line_height_used_raw),
@@ -3232,29 +3140,27 @@ unsafe fn build_font_group(
math_depth_value: retained(property_id::MATH_DEPTH),
font_size_value: retained(property_id::FONT_SIZE),
};
- unsafe {
- crate::css::computed_values::build_group_payload_with_rust_fill(
- group_index::FONT,
- &[],
- |payload| *payload.cast::<FontValues>() = built,
- parent_payload,
- )
- }
+ crate::css::computed_values::build_group_payload_with_rust_fill(
+ group_index::FONT,
+ &[],
+ |payload: &mut FontValues| *payload = built,
+ parent,
+ )
}
/// Builds the animation group from the canonical Rust longhand values.
-unsafe fn build_animation_group(
+fn build_animation_group(
values: &EffectiveValues,
input: &ColorResolutionInput,
used_color_scheme: u8,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> *const c_void {
let Some(entries) = gather_group_entries(group_index::ANIMATION, values, input, used_color_scheme) else {
return std::ptr::null();
};
- let retained = |property| ComputedStyleValueHandle::retained(values.pointer(property).cast());
+ let retained = |property| ComputedStyleValueHandle::from_retained(values.handle(property));
let is_single_zero_time = |property| {
- let value = unsafe { &*values.pointer(property).cast::<StyleValueData>() };
+ let value = values.handle(property).data();
let StyleValueData::ValueList { values, .. } = value else {
return false;
};
@@ -3263,12 +3169,11 @@ unsafe fn build_animation_group(
};
matches!(item.data(), StyleValueData::Time { value, .. } if *value == 0.0)
};
- unsafe {
+ {
crate::css::computed_values::build_group_payload_with_rust_fill(
group_index::ANIMATION,
&entries,
- |payload| {
- let payload = &mut *payload.cast::<AnimationValues>();
+ |payload: &mut AnimationValues| {
payload.animation_name = retained(property_id::ANIMATION_NAME);
payload.animation_composition = retained(property_id::ANIMATION_COMPOSITION);
payload.animation_delay = retained(property_id::ANIMATION_DELAY);
@@ -3294,7 +3199,7 @@ unsafe fn build_animation_group(
is_single_zero_time(property_id::TRANSITION_DELAY)
&& is_single_zero_time(property_id::TRANSITION_DURATION);
},
- parent_payload,
+ parent,
)
}
}
@@ -3302,17 +3207,17 @@ unsafe fn build_animation_group(
/// Rebuilds the font group from the table and the platform font inputs the engine resolved.
///
/// # Safety
-/// `table` must be a valid frozen table and `parent_payload` a valid font payload or null.
+/// `table` must be a valid frozen table and `parent` a valid font payload or null.
pub(crate) unsafe fn rebuild_font_group_from_table(
table: &ComputedLonghandTable,
inputs: &FfiFontGroupBuildInputs,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
) -> Option<*const c_void> {
let values = EffectiveValues {
table,
animated_overlay: None,
};
- let payload = unsafe { build_font_group(&values, inputs, parent_payload) };
+ let payload = unsafe { build_font_group(&values, inputs, parent) };
(!payload.is_null()).then_some(payload)
}
@@ -3367,27 +3272,20 @@ pub(crate) fn assembly_color_inputs(
/// anyway publishes the group's defaults rather than no record.
///
/// # Safety
-/// `table` must be a valid frozen table and `parent_payload` a valid payload of the group or null.
+/// `table` must be a valid frozen table and `parent` a valid payload of the group or null.
pub(crate) unsafe fn assemble_group_from_table(
table: &ComputedLonghandTable,
group: usize,
font: Option<&FfiFontGroupBuildInputs>,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
(used_color_scheme, current_color): (u8, u32),
length: &crate::css::style_compute::FfiLengthResolutionContext,
) -> *const c_void {
let payload = unsafe {
if group == group_index::FONT {
- font.and_then(|font| rebuild_font_group_from_table(table, font, parent_payload))
+ font.and_then(|font| rebuild_font_group_from_table(table, font, parent))
} else {
- rebuild_group_from_table(
- table,
- group,
- parent_payload,
- current_color,
- used_color_scheme,
- Some(length),
- )
+ rebuild_group_from_table(table, group, parent, current_color, used_color_scheme, Some(length))
}
};
payload.unwrap_or_else(|| {
@@ -3398,10 +3296,10 @@ pub(crate) unsafe fn assemble_group_from_table(
/// Rebuilds one non-inherited group whose specified values read the newly
/// inherited `color`. These groups need no DOM, layout, or font input.
-pub(crate) unsafe fn rebuild_group_for_inherited_current_color(
+pub(crate) fn rebuild_group_for_inherited_current_color(
table: &ComputedLonghandTable,
group: usize,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
current_color: u32,
used_color_scheme: u8,
) -> Option<*const c_void> {
@@ -3416,16 +3314,16 @@ pub(crate) unsafe fn rebuild_group_for_inherited_current_color(
) {
return None;
}
- unsafe { rebuild_group_from_table(table, group, parent_payload, current_color, used_color_scheme, None) }
+ rebuild_group_from_table(table, group, parent, current_color, used_color_scheme, None)
}
/// Rebuilds one of the groups whose payload is a function of the longhand table, the element's
-/// own `color` and its used color scheme alone. `parent_payload` is the group's previous payload,
+/// own `color` and its used color scheme alone. `parent` is the group's previous payload,
/// returned retained when the rebuilt values equal it.
-pub(crate) unsafe fn rebuild_group_from_table(
+pub(crate) fn rebuild_group_from_table(
table: &ComputedLonghandTable,
group: usize,
- parent_payload: *const c_void,
+ parent: Option<GroupPayloadRef<'_>>,
current_color: u32,
used_color_scheme: u8,
length: Option<&crate::css::style_compute::FfiLengthResolutionContext>,
@@ -3446,64 +3344,56 @@ pub(crate) unsafe fn rebuild_group_from_table(
length,
channels: None,
};
- let payload = unsafe {
- match group {
- // The font group needs platform font resources the table does not hold.
- group_index::FONT => return None,
- group_index::BOX => {
- build_box_group(&values, table.display_before_box_type_transformation(), parent_payload)
- }
- group_index::INHERITED_TABLE => build_inherited_table_group(
- group,
- values.pointer(property_id::BORDER_COLLAPSE),
- values.pointer(property_id::CAPTION_SIDE),
- values.pointer(property_id::EMPTY_CELLS),
- values.pointer(property_id::BORDER_SPACING),
- parent_payload,
- ),
- group_index::INHERITED_BOX => build_inherited_box_group(
- group,
- values.pointer(property_id::VISIBILITY),
- values.pointer(property_id::DIRECTION),
- values.pointer(property_id::WRITING_MODE),
- values.pointer(property_id::CONTENT_VISIBILITY),
- values.pointer(property_id::IMAGE_RENDERING),
- parent_payload,
- ),
- group_index::SIZING => build_sizing_group(
- group,
- values.pointer(property_id::WIDTH),
- values.pointer(property_id::MIN_WIDTH),
- values.pointer(property_id::MAX_WIDTH),
- values.pointer(property_id::HEIGHT),
- values.pointer(property_id::MIN_HEIGHT),
- values.pointer(property_id::MAX_HEIGHT),
- parent_payload,
- ),
- group_index::SURROUND => build_surround_group(&values, parent_payload),
- group_index::ANIMATION => build_animation_group(&values, &input, used_color_scheme, parent_payload),
- group_index::ANCHOR => build_anchor_group(&values, &input, used_color_scheme, parent_payload),
- group_index::TEXT_RESET => build_text_reset_group(&values, &input, parent_payload),
- group_index::ALIGNMENT => build_alignment_group(&values, parent_payload),
- group_index::SVG_RESET => build_svg_reset_group(&values, &input, parent_payload),
- group_index::GRID => build_grid_group(&values, parent_payload),
- group_index::TRANSFORM => build_transform_group(&values, &input, used_color_scheme, parent_payload),
- group_index::EFFECTS => build_effects_group(&values, &input, used_color_scheme, parent_payload),
- group_index::INHERITED_UI => build_inherited_ui_group(&values, &input, used_color_scheme, parent_payload),
- group_index::INHERITED_TEXT => {
- build_inherited_text_group(&values, &input, used_color_scheme, parent_payload)
- }
- group_index::MISC_RESET => build_misc_reset_group(&values, &input, used_color_scheme, parent_payload),
- group_index::INHERITED_SVG => build_inherited_svg_group(&values, &input, used_color_scheme, parent_payload),
- group_index::INHERITED_LIST => {
- build_inherited_list_group(&values, &input, used_color_scheme, parent_payload)
- }
- group_index::CONTENT => build_content_group(&values, &input, used_color_scheme, parent_payload),
- group_index::MASK => build_mask_group(&values, &input, used_color_scheme, parent_payload),
- group_index::BACKGROUND => build_background_group(&values, &input, used_color_scheme, parent_payload),
- group_index::BORDER => build_border_group(&values, &input, used_color_scheme, parent_payload),
- _ => return None,
- }
+ let payload = match group {
+ // The font group needs platform font resources the table does not hold.
+ group_index::FONT => return None,
+ group_index::BOX => build_box_group(&values, table.display_before_box_type_transformation(), parent),
+ group_index::INHERITED_TABLE => build_inherited_table_group(
+ group,
+ values.handle(property_id::BORDER_COLLAPSE),
+ values.handle(property_id::CAPTION_SIDE),
+ values.handle(property_id::EMPTY_CELLS),
+ values.handle(property_id::BORDER_SPACING),
+ parent,
+ ),
+ group_index::INHERITED_BOX => build_inherited_box_group(
+ group,
+ values.handle(property_id::VISIBILITY),
+ values.handle(property_id::DIRECTION),
+ values.handle(property_id::WRITING_MODE),
+ values.handle(property_id::CONTENT_VISIBILITY),
+ values.handle(property_id::IMAGE_RENDERING),
+ parent,
+ ),
+ group_index::SIZING => build_sizing_group(
+ group,
+ values.handle(property_id::WIDTH),
+ values.handle(property_id::MIN_WIDTH),
+ values.handle(property_id::MAX_WIDTH),
+ values.handle(property_id::HEIGHT),
+ values.handle(property_id::MIN_HEIGHT),
+ values.handle(property_id::MAX_HEIGHT),
+ parent,
+ ),
+ group_index::SURROUND => build_surround_group(&values, parent),
+ group_index::ANIMATION => build_animation_group(&values, &input, used_color_scheme, parent),
+ group_index::ANCHOR => build_anchor_group(&values, &input, used_color_scheme, parent),
+ group_index::TEXT_RESET => build_text_reset_group(&values, &input, parent),
+ group_index::ALIGNMENT => build_alignment_group(&values, parent),
+ group_index::SVG_RESET => build_svg_reset_group(&values, &input, parent),
+ group_index::GRID => build_grid_group(&values, parent),
+ group_index::TRANSFORM => build_transform_group(&values, &input, used_color_scheme, parent),
+ group_index::EFFECTS => build_effects_group(&values, &input, used_color_scheme, parent),
+ group_index::INHERITED_UI => build_inherited_ui_group(&values, &input, used_color_scheme, parent),
+ group_index::INHERITED_TEXT => build_inherited_text_group(&values, &input, used_color_scheme, parent),
+ group_index::MISC_RESET => build_misc_reset_group(&values, &input, used_color_scheme, parent),
+ group_index::INHERITED_SVG => build_inherited_svg_group(&values, &input, used_color_scheme, parent),
+ group_index::INHERITED_LIST => build_inherited_list_group(&values, &input, used_color_scheme, parent),
+ group_index::CONTENT => build_content_group(&values, &input, used_color_scheme, parent),
+ group_index::MASK => build_mask_group(&values, &input, used_color_scheme, parent),
+ group_index::BACKGROUND => build_background_group(&values, &input, used_color_scheme, parent),
+ group_index::BORDER => build_border_group(&values, &input, used_color_scheme, parent),
+ _ => return None,
};
(!payload.is_null()).then_some(payload)
}
@@ -3531,80 +3421,70 @@ pub(crate) unsafe fn build_group_payloads_from_table(
if (groups_to_apply >> group) & 1 == 0 {
continue;
}
- let parent_payload = std::ptr::null();
+ let parent = None;
// SAFETY: Gathered pointers name live table or override data.
let payload = unsafe {
match group {
group_index::FONT => build_font_group(
&values,
inputs.font.expect("an applied font group has platform font inputs"),
- parent_payload,
+ parent,
),
- group_index::BOX => {
- build_box_group(&values, inputs.box_display_before_transformation_raw, parent_payload)
- }
+ group_index::BOX => build_box_group(&values, inputs.box_display_before_transformation_raw, parent),
group_index::INHERITED_TABLE => build_inherited_table_group(
group,
- values.pointer(property_id::BORDER_COLLAPSE),
- values.pointer(property_id::CAPTION_SIDE),
- values.pointer(property_id::EMPTY_CELLS),
- values.pointer(property_id::BORDER_SPACING),
- parent_payload,
+ values.handle(property_id::BORDER_COLLAPSE),
+ values.handle(property_id::CAPTION_SIDE),
+ values.handle(property_id::EMPTY_CELLS),
+ values.handle(property_id::BORDER_SPACING),
+ parent,
),
group_index::INHERITED_BOX => build_inherited_box_group(
group,
- values.pointer(property_id::VISIBILITY),
- values.pointer(property_id::DIRECTION),
- values.pointer(property_id::WRITING_MODE),
- values.pointer(property_id::CONTENT_VISIBILITY),
- values.pointer(property_id::IMAGE_RENDERING),
- parent_payload,
+ values.handle(property_id::VISIBILITY),
+ values.handle(property_id::DIRECTION),
+ values.handle(property_id::WRITING_MODE),
+ values.handle(property_id::CONTENT_VISIBILITY),
+ values.handle(property_id::IMAGE_RENDERING),
+ parent,
),
group_index::SIZING => build_sizing_group(
group,
- values.pointer(property_id::WIDTH),
- values.pointer(property_id::MIN_WIDTH),
- values.pointer(property_id::MAX_WIDTH),
- values.pointer(property_id::HEIGHT),
- values.pointer(property_id::MIN_HEIGHT),
- values.pointer(property_id::MAX_HEIGHT),
- parent_payload,
+ values.handle(property_id::WIDTH),
+ values.handle(property_id::MIN_WIDTH),
+ values.handle(property_id::MAX_WIDTH),
+ values.handle(property_id::HEIGHT),
+ values.handle(property_id::MIN_HEIGHT),
+ values.handle(property_id::MAX_HEIGHT),
+ parent,
),
- group_index::SURROUND => build_surround_group(&values, parent_payload),
- group_index::ANIMATION => {
- build_animation_group(&values, &input, inputs.used_color_scheme, parent_payload)
- }
- group_index::ANCHOR => build_anchor_group(&values, &input, inputs.used_color_scheme, parent_payload),
- group_index::TEXT_RESET => build_text_reset_group(&values, &input, parent_payload),
- group_index::ALIGNMENT => build_alignment_group(&values, parent_payload),
- group_index::SVG_RESET => build_svg_reset_group(&values, &input, parent_payload),
- group_index::GRID => build_grid_group(&values, parent_payload),
- group_index::TRANSFORM => {
- build_transform_group(&values, &input, inputs.used_color_scheme, parent_payload)
- }
- group_index::EFFECTS => build_effects_group(&values, &input, inputs.used_color_scheme, parent_payload),
+ group_index::SURROUND => build_surround_group(&values, parent),
+ group_index::ANIMATION => build_animation_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::ANCHOR => build_anchor_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::TEXT_RESET => build_text_reset_group(&values, &input, parent),
+ group_index::ALIGNMENT => build_alignment_group(&values, parent),
+ group_index::SVG_RESET => build_svg_reset_group(&values, &input, parent),
+ group_index::GRID => build_grid_group(&values, parent),
+ group_index::TRANSFORM => build_transform_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::EFFECTS => build_effects_group(&values, &input, inputs.used_color_scheme, parent),
group_index::INHERITED_UI => {
- build_inherited_ui_group(&values, &input, inputs.used_color_scheme, parent_payload)
+ build_inherited_ui_group(&values, &input, inputs.used_color_scheme, parent)
}
group_index::INHERITED_TEXT => {
- build_inherited_text_group(&values, &input, inputs.used_color_scheme, parent_payload)
- }
- group_index::MISC_RESET => {
- build_misc_reset_group(&values, &input, inputs.used_color_scheme, parent_payload)
+ build_inherited_text_group(&values, &input, inputs.used_color_scheme, parent)
}
+ group_index::MISC_RESET => build_misc_reset_group(&values, &input, inputs.used_color_scheme, parent),
group_index::INHERITED_SVG => {
- build_inherited_svg_group(&values, &input, inputs.used_color_scheme, parent_payload)
+ build_inherited_svg_group(&values, &input, inputs.used_color_scheme, parent)
}
group_index::INHERITED_LIST => {
- build_inherited_list_group(&values, &input, inputs.used_color_scheme, parent_payload)
- }
- group_index::CONTENT => build_content_group(&values, &input, inputs.used_color_scheme, parent_payload),
- group_index::BACKGROUND => {
- build_background_group(&values, &input, inputs.used_color_scheme, parent_payload)
+ build_inherited_list_group(&values, &input, inputs.used_color_scheme, parent)
}
- group_index::MASK => build_mask_group(&values, &input, inputs.used_color_scheme, parent_payload),
- group_index::BORDER => build_border_group(&values, &input, inputs.used_color_scheme, parent_payload),
- _ => build_generic_group(group, &values, &input, inputs.used_color_scheme, parent_payload),
+ group_index::CONTENT => build_content_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::BACKGROUND => build_background_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::MASK => build_mask_group(&values, &input, inputs.used_color_scheme, parent),
+ group_index::BORDER => build_border_group(&values, &input, inputs.used_color_scheme, parent),
+ _ => build_generic_group(group, &values, &input, inputs.used_color_scheme, parent),
}
};
assert!(!payload.is_null(), "computed group build returned null");