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

Code before:

        let mut child_positioning_context = PositioningContext::default();
        let result = self.layout_without_caching(
            layout_context,
            &mut child_positioning_context,
            containing_block_for_children,
            containing_block,
            preferred_aspect_ratio,
            lazy_block_size,
        );

        *self.base.cached_layout_result.borrow_mut() =
            Some(Box::new(CacheableLayoutResultAndInputs {
                result: result.clone(),
                positioning_context: child_positioning_context.clone(),
                containing_block_for_children_size: containing_block_for_children.size.clone(),
            }));
        positioning_context.append(child_positioning_context);

        result
    }

    #[inline]
    pub(crate) fn layout_style(&self) -> LayoutStyle<'_> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(fc, _) => fc.layout_style(&self.base),
            IndependentFormattingContextContents::Flow(fc) => fc.layout_style(&self.base),
            IndependentFormattingContextContents::Flex(fc) => fc.layout_style(),
            IndependentFormattingContextContents::Grid(fc) => fc.layout_style(),
            IndependentFormattingContextContents::Table(fc) => fc.layout_style(None),
        }
    }

    #[inline]
    pub(crate) fn preferred_aspect_ratio(
        &self,
        padding_border_sums: &LogicalVec2<Au>,
    ) -> Option<AspectRatio> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(replaced, _) => {
                replaced.preferred_aspect_ratio(self.style(), padding_border_sums)
            },
            // TODO: support preferred aspect ratios on non-replaced boxes.
            _ => None,
        }
    }
}

impl ComputeInlineContentSizes for IndependentFormattingContextContents {
    fn compute_inline_content_sizes(
        &self,

Review comment (suggestion):
Nit: `contents` is probably a better name here. This isn't a formatting context.

```suggestion
            IndependentFormattingContextContents::Replaced(contents, _) => contents.layout_style(&self.base),
```

Code after:

        let mut child_positioning_context = PositioningContext::default();
        let result = self.layout_without_caching(
            layout_context,
            &mut child_positioning_context,
            containing_block_for_children,
            containing_block,
            preferred_aspect_ratio,
            lazy_block_size,
        );

        *self.base.cached_layout_result.borrow_mut() =
            Some(Box::new(CacheableLayoutResultAndInputs {
                result: result.clone(),
                positioning_context: child_positioning_context.clone(),
                containing_block_for_children_size: containing_block_for_children.size.clone(),
            }));
        positioning_context.append(child_positioning_context);

        result
    }

    #[inline]
    pub(crate) fn layout_style(&self) -> LayoutStyle<'_> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(replaced, _) => {
                replaced.layout_style(&self.base)
            },
            IndependentFormattingContextContents::Flow(fc) => fc.layout_style(&self.base),
            IndependentFormattingContextContents::Flex(fc) => fc.layout_style(),
            IndependentFormattingContextContents::Grid(fc) => fc.layout_style(),
            IndependentFormattingContextContents::Table(fc) => fc.layout_style(None),
        }
    }

    #[inline]
    pub(crate) fn preferred_aspect_ratio(
        &self,
        padding_border_sums: &LogicalVec2<Au>,
    ) -> Option<AspectRatio> {
        match &self.contents {
            IndependentFormattingContextContents::Replaced(replaced, _) => {
                replaced.preferred_aspect_ratio(self.style(), padding_border_sums)
            },
            // TODO: support preferred aspect ratios on non-replaced boxes.
            _ => None,
        }
    }
}

impl ComputeInlineContentSizes for IndependentFormattingContextContents {