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

Code before:
        context: &LayoutContext,
        node_and_style_info: &NodeAndStyleInfo,
        display_inside: DisplayInside,
        contents: Contents,
        propagated_data: PropagatedBoxTreeData,
    ) -> Self {
        let mut base_fragment_info: BaseFragmentInfo = node_and_style_info.into();

        let non_replaced_contents = match contents {
            Contents::Replaced(contents) => {
                base_fragment_info.flags.insert(FragmentFlags::IS_REPLACED);
                return Self {
                    base: LayoutBoxBase::new(base_fragment_info, node_and_style_info.style.clone()),
                    contents: IndependentFormattingContextContents::Replaced(contents),
                };
            },
            Contents::Widget(non_replaced_contents) => {
                base_fragment_info.flags.insert(FragmentFlags::IS_WIDGET);
                non_replaced_contents
            },
            Contents::NonReplaced(non_replaced_contents) => non_replaced_contents,
            Contents::ReplacedWithWidget(replaced_contents, non_replaced_contents) => {
                base_fragment_info
                    .flags
                    .insert(FragmentFlags::IS_REPLACED | FragmentFlags::IS_WIDGET);
                // Since the display insdie for video element is always flow, we can continue here.
                let bfc = BlockFormattingContext::construct(
                    context,
                    node_and_style_info,
                    non_replaced_contents,
                    propagated_data,
                    false, /* is_list_item */
                );
                return Self {
                    base: LayoutBoxBase::new(base_fragment_info, node_and_style_info.style.clone()),
                    contents: IndependentFormattingContextContents::ReplacedWithWidget(
                        replaced_contents,
                        bfc,
                    ),
                };
            },
        };
        let contents = match display_inside {
            DisplayInside::Flow { is_list_item } | DisplayInside::FlowRoot { is_list_item } => {
                IndependentFormattingContextContents::Flow(BlockFormattingContext::construct(
                    context,
                    node_and_style_info,
                    non_replaced_contents,
                    propagated_data,
                    is_list_item,
                ))

Review comment (suggestion):
I am suggesting do not use `video` here, because `audio` element also could be replaced element, may be replaced to `media` atleast.

Update: I found below your comment `// For replaced with widget, we use the block formatting context's layout style.` so may be use here smth like if it makes sense `// For replaced with widget, use block formatting context since the display inside is always flow.`

`insdie` -> `inside`

Code after:
        context: &LayoutContext,
        node_and_style_info: &NodeAndStyleInfo,
        display_inside: DisplayInside,
        contents: Contents,
        propagated_data: PropagatedBoxTreeData,
    ) -> Self {
        let mut base_fragment_info: BaseFragmentInfo = node_and_style_info.into();

        let non_replaced_contents = match contents {
            Contents::Replaced(contents) => {
                base_fragment_info.flags.insert(FragmentFlags::IS_REPLACED);
                return Self {
                    base: LayoutBoxBase::new(base_fragment_info, node_and_style_info.style.clone()),
                    contents: IndependentFormattingContextContents::Replaced(contents),
                };
            },
            Contents::ReplacedWithWidget(replaced_contents, non_replaced_contents) => {
                base_fragment_info
                    .flags
                    .insert(FragmentFlags::IS_REPLACED | FragmentFlags::IS_WIDGET);
                // For replaced with widget, use block formatting context since the display inside is always flow.
                let bfc = BlockFormattingContext::construct(
                    context,
                    node_and_style_info,
                    non_replaced_contents,
                    propagated_data,
                    false, /* is_list_item */
                );
                return Self {
                    base: LayoutBoxBase::new(base_fragment_info, node_and_style_info.style.clone()),
                    contents: IndependentFormattingContextContents::ReplacedWithWidget(
                        replaced_contents,
                        bfc,
                    ),
                };
            },
            Contents::Widget(non_replaced_contents) => {
                base_fragment_info.flags.insert(FragmentFlags::IS_WIDGET);
                non_replaced_contents
            },
            Contents::NonReplaced(non_replaced_contents) => non_replaced_contents,
        };
        let contents = match display_inside {
            DisplayInside::Flow { is_list_item } | DisplayInside::FlowRoot { is_list_item } => {
                IndependentFormattingContextContents::Flow(BlockFormattingContext::construct(
                    context,
                    node_and_style_info,
                    non_replaced_contents,
                    propagated_data,
                    is_list_item,
                ))