layout: Use ServoThreadSafeLayoutNode in more places (#38626)

Use `ServoThreadSafeLayoutNode` in more places in layout rather than
`ServoLayoutNode`. The former is meant to be used during layout, but
layout 2020 was written against the latter. In general, this reduces the
amount of conversion to the thread-safe version in many places in
layout.

In addition, an unused iterator from the `script` crate
`ServoThreadSafeLayoutNodeChildrenIterator` is replaced with the child
iterator from `layout`. The `layout` version must be directly in
`script` now as it uses the dangerous variants of `next_sibling` and
`first_child`, which allow encapsulating the unsafe bits into one
module.

This will ultimately be useful for storing the layout data of
pseudo-element children of pseudo-elements properly.

Testing: This should not change any behavior and thus is covered by
existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-13 16:55:19 +02:00 committed by GitHub
parent 20ad1ce84e
commit ee7c1d9109
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 258 additions and 321 deletions

View file

@ -8,13 +8,13 @@ use data_url::DataUrl;
use embedder_traits::ViewportDetails;
use euclid::{Scale, Size2D};
use layout_api::IFrameSize;
use layout_api::wrapper_traits::ThreadSafeLayoutNode;
use malloc_size_of_derive::MallocSizeOf;
use net_traits::image_cache::{Image, ImageOrMetadataAvailable, UsePlaceholder, VectorImage};
use script::layout_dom::ServoLayoutNode;
use script::layout_dom::ServoThreadSafeLayoutNode;
use servo_arc::Arc as ServoArc;
use style::Zero;
use style::computed_values::object_fit::T as ObjectFit;
use style::dom::TNode;
use style::logical_geometry::{Direction, WritingMode};
use style::properties::ComputedValues;
use style::servo::url::ComputedUrl;
@ -131,7 +131,10 @@ pub(crate) enum ReplacedContentKind {
}
impl ReplacedContents {
pub fn for_element(element: ServoLayoutNode<'_>, context: &LayoutContext) -> Option<Self> {
pub fn for_element(
element: ServoThreadSafeLayoutNode<'_>,
context: &LayoutContext,
) -> Option<Self> {
if let Some(ref data_attribute_string) = element.as_typeless_object_with_data_attribute() {
if let Some(url) = try_to_parse_image_data_url(data_attribute_string) {
return Self::from_image_url(
@ -219,7 +222,7 @@ impl ReplacedContents {
}
pub fn from_image_url(
element: ServoLayoutNode<'_>,
element: ServoThreadSafeLayoutNode<'_>,
context: &LayoutContext,
image_url: &ComputedUrl,
) -> Option<Self> {
@ -255,7 +258,7 @@ impl ReplacedContents {
}
pub fn from_image(
element: ServoLayoutNode<'_>,
element: ServoThreadSafeLayoutNode<'_>,
context: &LayoutContext,
image: &ComputedImage,
) -> Option<Self> {