···462462 return children;
463463 }
464464465465- // Only consider in-flow children for block/inline normalization.
466466- let has_block = children.iter().any(|c| is_in_flow(c) && is_block_level(c));
465465+ // Consider in-flow block children and floated children as "block-level"
466466+ // for normalization purposes. When floats are present alongside inline
467467+ // content, the inline content must be wrapped in anonymous blocks so that
468468+ // `layout_block_children` can lay it out via its inline formatting context.
469469+ let has_block = children
470470+ .iter()
471471+ .any(|c| (is_in_flow(c) && is_block_level(c)) || is_floated(c));
467472 if !has_block {
468473 return children;
469474 }
···54285433 float_right,
54295434 );
54305435 }
54365436+ }
54375437+54385438+ #[test]
54395439+ fn bare_text_alongside_float_is_laid_out() {
54405440+ // When a container has only float children + bare text (no block
54415441+ // siblings), the text should still be wrapped in an anonymous block
54425442+ // and laid out correctly.
54435443+ let mut doc = Document::new();
54445444+ let root = doc.root();
54455445+ let html = doc.create_element("html");
54465446+ let body = doc.create_element("body");
54475447+ let container = doc.create_element("div");
54485448+ let float_elem = doc.create_element("div");
54495449+ let text = doc.create_text("Hello world");
54505450+ doc.append_child(root, html);
54515451+ doc.append_child(html, body);
54525452+ doc.append_child(body, container);
54535453+ doc.append_child(container, float_elem);
54545454+ doc.append_child(container, text);
54555455+ doc.set_attribute(container, "style", "width: 400px;");
54565456+ doc.set_attribute(
54575457+ float_elem,
54585458+ "style",
54595459+ "float: left; width: 100px; height: 50px;",
54605460+ );
54615461+54625462+ let tree = layout_doc(&doc);
54635463+ let body_box = &tree.root.children[0];
54645464+ let container_box = &body_box.children[0];
54655465+54665466+ // The text should be wrapped in an anonymous block and produce text lines.
54675467+ let has_text = container_box.children.iter().any(|c| !c.lines.is_empty());
54685468+ assert!(
54695469+ has_text,
54705470+ "bare text alongside a float should be laid out (found {} children, none with text lines)",
54715471+ container_box.children.len(),
54725472+ );
54315473 }
54325474}