Repository: servo/servo
File: components/layout/replaced.rs (Rust)

Code before:
                    },
                },
                LayoutImageCacheResult::Pending | LayoutImageCacheResult::LoadError => return None,
            };

            return Some(Self {
                kind: ReplacedContentKind::Image(image, false /* showing_broken_image_icon */),
                natural_size: NaturalSizes::from_width_and_height(width, height),
                base_fragment_info: node.into(),
            });
        }
        None
    }

    pub fn from_image(
        element: ServoThreadSafeLayoutNode<'_>,
        context: &LayoutContext,
        image: &ComputedImage,
    ) -> Option<Self> {
        match image {
            ComputedImage::Url(image_url) => Self::from_image_url(element, context, image_url),
            _ => None, // TODO
        }
    }

    pub fn zero_sized_invalid_image(node: ServoThreadSafeLayoutNode<'_>) -> Self {
        Self {
            kind: ReplacedContentKind::Image(None, false /* showing_broken_image_icon */),
            natural_size: NaturalSizes::from_width_and_height(0., 0.),
            base_fragment_info: node.into(),
        }
    }

    #[inline]
    fn is_broken_image(&self) -> bool {
        matches!(self.kind, ReplacedContentKind::Image(_, true))
    }

    #[inline]
    fn content_size(
        &self,
        axis: Direction,
        preferred_aspect_ratio: Option<AspectRatio>,
        get_size_in_opposite_axis: &dyn Fn() -> SizeConstraint,
        get_fallback_size: &dyn Fn() -> Au,
    ) -> Au {
        let Some(ratio) = preferred_aspect_ratio else {
            return get_fallback_size();
        };
        let transfer = |size| ratio.compute_dependent_size(axis, size);
        match get_size_in_opposite_axis() {

Review comment (suggestion):
```suggestion
    pub(crate) fn zero_sized_invalid_image(node: ServoThreadSafeLayoutNode<'_>) -> Self {
```

Code after:
            ratio,
        };

        let svg_source = match svg_data.source {
            None => {
                // The SVGSVGElement is not yet serialized, so we add it to a list
                // and hand it over to script to peform the serialization.
                context
                    .image_resolver
                    .queue_svg_element_for_serialization(node);
                return None;
            },
            Some(Err(_)) => {
                // Don't attempt to serialize if previous attempt had errored.
                return None;
            },
            Some(Ok(svg_source)) => svg_source,
        };

        let result = context
            .image_resolver
            .get_cached_image_for_url(
                node.opaque(),
                svg_source,
                LayoutImageDestination::BoxTreeConstruction,
            )
            .ok();

        let vector_image = result.map(|result| match result {
            Image::Vector(mut vector_image) => {
                vector_image.svg_id = Some(svg_data.svg_id);
                vector_image
            },
            _ => unreachable!("SVG element can't contain a raster image."),
        });

        Some((ReplacedContentKind::SVGElement(vector_image), natural_size))
    }

    fn from_content_property(
        node: ServoThreadSafeLayoutNode<'_>,
        context: &LayoutContext,
    ) -> Option<Self> {
        // If the `content` property is a single image URL, non-replaced boxes
        // and images get replaced with the given image.
        if let Content::Items(GenericContentItems { items, .. }) =
            node.style(&context.style_context).clone_content()
        {
            if let [GenericContentItem::Image(image)] = items.as_slice() {
                // Invalid images are treated as zero-sized.
                return Some(