Browse Source

Move build box outside of individual formatting contexts

Instead, pass in the box directly in a generalized fashion.

Should be equivalent.
Michael Ragazzon 5 months ago
parent
commit
e5492585db

+ 4 - 9
Source/Core/Layout/BlockFormattingContext.cpp

@@ -112,7 +112,7 @@ static OuterDisplayType GetOuterDisplayType(Style::Display display)
 	return OuterDisplayType::Invalid;
 	return OuterDisplayType::Invalid;
 }
 }
 
 
-UniquePtr<LayoutBox> BlockFormattingContext::Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box)
+UniquePtr<LayoutBox> BlockFormattingContext::Format(ContainerBox* parent_container, Element* element, Vector2f containing_block, const Box& box)
 {
 {
 	RMLUI_ASSERT(parent_container && element);
 	RMLUI_ASSERT(parent_container && element);
 
 
@@ -122,14 +122,6 @@ UniquePtr<LayoutBox> BlockFormattingContext::Format(ContainerBox* parent_contain
 	RMLUI_ZoneName(name.c_str(), name.size());
 	RMLUI_ZoneName(name.c_str(), name.size());
 #endif
 #endif
 
 
-	const Vector2f containing_block = parent_container->GetContainingBlockSize(element->GetPosition());
-
-	Box box;
-	if (override_initial_box)
-		box = *override_initial_box;
-	else
-		LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::ShrinkableBlock, &parent_container->GetFormattingMode());
-
 	float min_height, max_height;
 	float min_height, max_height;
 	LayoutDetails::GetDefiniteMinMaxHeight(min_height, max_height, element->GetComputedValues(), box, containing_block.y);
 	LayoutDetails::GetDefiniteMinMaxHeight(min_height, max_height, element->GetComputedValues(), box, containing_block.y);
 
 
@@ -221,6 +213,9 @@ bool BlockFormattingContext::FormatBlockContainerChild(BlockContainer* parent_co
 	RMLUI_ZoneName(name.c_str(), name.size());
 	RMLUI_ZoneName(name.c_str(), name.size());
 #endif
 #endif
 
 
+	if (element->GetId() == "outer")
+		int x = 0;
+
 	// Check for special formatting tags.
 	// Check for special formatting tags.
 	if (element->GetTagName() == "br")
 	if (element->GetTagName() == "br")
 	{
 	{

+ 1 - 1
Source/Core/Layout/BlockFormattingContext.h

@@ -51,7 +51,7 @@ class LayoutBox;
 */
 */
 class BlockFormattingContext final : public FormattingContext {
 class BlockFormattingContext final : public FormattingContext {
 public:
 public:
-	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box);
+	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, Vector2f containing_block, const Box& box);
 
 
 private:
 private:
 	// Format the element as a block box, including its children.
 	// Format the element as a block box, including its children.

+ 4 - 4
Source/Core/Layout/ContainerBox.cpp

@@ -304,8 +304,8 @@ String RootBox::DebugDumpTree(int depth) const
 	return String(depth * 2, ' ') + "RootBox";
 	return String(depth * 2, ' ') + "RootBox";
 }
 }
 
 
-FlexContainer::FlexContainer(Element* element, ContainerBox* parent_container) :
-	ContainerBox(Type::FlexContainer, element, parent_container, parent_container->GetFormattingMode())
+FlexContainer::FlexContainer(Element* element, ContainerBox* parent_container, const Box& box) :
+	ContainerBox(Type::FlexContainer, element, parent_container, parent_container->GetFormattingMode()), box(box)
 {
 {
 	RMLUI_ASSERT(element);
 	RMLUI_ASSERT(element);
 }
 }
@@ -333,8 +333,8 @@ String FlexContainer::DebugDumpTree(int depth) const
 	return String(depth * 2, ' ') + "FlexContainer" + " | " + LayoutDetails::GetDebugElementName(element);
 	return String(depth * 2, ' ') + "FlexContainer" + " | " + LayoutDetails::GetDebugElementName(element);
 }
 }
 
 
-TableWrapper::TableWrapper(Element* element, ContainerBox* parent_container) :
-	ContainerBox(Type::TableWrapper, element, parent_container, parent_container->GetFormattingMode())
+TableWrapper::TableWrapper(Element* element, ContainerBox* parent_container, const Box& box) :
+	ContainerBox(Type::TableWrapper, element, parent_container, parent_container->GetFormattingMode()), box(box)
 {
 {
 	RMLUI_ASSERT(element);
 	RMLUI_ASSERT(element);
 }
 }

+ 2 - 2
Source/Core/Layout/ContainerBox.h

@@ -158,7 +158,7 @@ private:
 */
 */
 class FlexContainer final : public ContainerBox {
 class FlexContainer final : public ContainerBox {
 public:
 public:
-	FlexContainer(Element* element, ContainerBox* parent_container);
+	FlexContainer(Element* element, ContainerBox* parent_container, const Box& box);
 
 
 	// Submits the formatted box to the flex container element, and propagates any uncaught overflow to this box.
 	// Submits the formatted box to the flex container element, and propagates any uncaught overflow to this box.
 	// @returns True if it succeeds, otherwise false if it needs to be formatted again because scrollbars were enabled.
 	// @returns True if it succeeds, otherwise false if it needs to be formatted again because scrollbars were enabled.
@@ -182,7 +182,7 @@ private:
 */
 */
 class TableWrapper final : public ContainerBox {
 class TableWrapper final : public ContainerBox {
 public:
 public:
-	TableWrapper(Element* element, ContainerBox* parent_container);
+	TableWrapper(Element* element, ContainerBox* parent_container, const Box& initial_box);
 
 
 	// Submits the formatted box to the table element, and propagates any uncaught overflow to this box.
 	// Submits the formatted box to the table element, and propagates any uncaught overflow to this box.
 	void Close(const Vector2f content_overflow_size, const Box& box, float element_baseline);
 	void Close(const Vector2f content_overflow_size, const Box& box, float element_baseline);

+ 5 - 10
Source/Core/Layout/FlexFormattingContext.cpp

@@ -40,26 +40,21 @@
 
 
 namespace Rml {
 namespace Rml {
 
 
-UniquePtr<LayoutBox> FlexFormattingContext::Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box)
+UniquePtr<LayoutBox> FlexFormattingContext::Format(ContainerBox* parent_container, Element* element, Vector2f containing_block,
+	const Box& initial_box)
 {
 {
 	RMLUI_ZoneScopedC(0xAFAF4F);
 	RMLUI_ZoneScopedC(0xAFAF4F);
-	auto flex_container_box = MakeUnique<FlexContainer>(element, parent_container);
+	auto flex_container_box = MakeUnique<FlexContainer>(element, parent_container, initial_box);
 
 
 	ElementScroll* element_scroll = element->GetElementScroll();
 	ElementScroll* element_scroll = element->GetElementScroll();
 	const ComputedValues& computed = element->GetComputedValues();
 	const ComputedValues& computed = element->GetComputedValues();
 
 
-	const Vector2f containing_block = parent_container->GetContainingBlockSize(element->GetPosition());
 	const FormattingMode::Constraint formatting_constraint = parent_container->GetFormattingMode().constraint;
 	const FormattingMode::Constraint formatting_constraint = parent_container->GetFormattingMode().constraint;
 	RMLUI_ASSERT(containing_block.x >= 0.f || formatting_constraint == FormattingMode::Constraint::MaxContent);
 	RMLUI_ASSERT(containing_block.x >= 0.f || formatting_constraint == FormattingMode::Constraint::MaxContent);
 
 
-	// Build the initial box as specified by the flex's style, as if it was a normal block element.
+	// if (formatting_constraint == FormattingMode::Constraint::MaxContent)
+	// 	LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::UnalignedBlock);
 	Box& box = flex_container_box->GetBox();
 	Box& box = flex_container_box->GetBox();
-	if (override_initial_box)
-		box = *override_initial_box;
-	else if (formatting_constraint == FormattingMode::Constraint::MaxContent)
-		LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::UnalignedBlock);
-	else
-		LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::ShrinkableBlock, &parent_container->GetFormattingMode());
 
 
 	// Start with any auto-scrollbars off.
 	// Start with any auto-scrollbars off.
 	flex_container_box->ResetScrollbars(box);
 	flex_container_box->ResetScrollbars(box);

+ 1 - 1
Source/Core/Layout/FlexFormattingContext.h

@@ -45,7 +45,7 @@ struct FormattingMode;
 class FlexFormattingContext final : public FormattingContext {
 class FlexFormattingContext final : public FormattingContext {
 public:
 public:
 	/// Formats a flex container element and its flex items according to flexbox layout rules.
 	/// Formats a flex container element and its flex items according to flexbox layout rules.
-	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box);
+	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, Vector2f containing_block, const Box& initial_box);
 
 
 private:
 private:
 	FlexFormattingContext() = default;
 	FlexFormattingContext() = default;

+ 19 - 4
Source/Core/Layout/FormattingContext.cpp

@@ -77,6 +77,9 @@ UniquePtr<LayoutBox> FormattingContext::FormatIndependent(ContainerBox* parent_c
 	if (type == FormattingContextType::None)
 	if (type == FormattingContextType::None)
 		type = default_context;
 		type = default_context;
 
 
+	if (element->GetId() == "outer")
+		int x = 0;
+
 #ifdef RMLUI_DEBUG
 #ifdef RMLUI_DEBUG
 	auto* debug_tracker = FormatIndependentDebugTracker::GetIf();
 	auto* debug_tracker = FormatIndependentDebugTracker::GetIf();
 	FormatIndependentDebugTracker::Entry* tracker_entry = nullptr;
 	FormatIndependentDebugTracker::Entry* tracker_entry = nullptr;
@@ -123,14 +126,26 @@ UniquePtr<LayoutBox> FormattingContext::FormatIndependent(ContainerBox* parent_c
 
 
 	if (!layout_box)
 	if (!layout_box)
 	{
 	{
+		const Vector2f containing_block = parent_container->GetContainingBlockSize(element->GetPosition());
+		Box box;
+		if (override_initial_box)
+			box = *override_initial_box;
+
+		else if (formatting_mode.constraint == FormattingMode::Constraint::MaxContent && type == FormattingContextType::Flex)
+			LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::UnalignedBlock);
+		else
+			LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::ShrinkableBlock, &parent_container->GetFormattingMode());
+
 		switch (type)
 		switch (type)
 		{
 		{
-		case FormattingContextType::Block: layout_box = BlockFormattingContext::Format(parent_container, element, override_initial_box); break;
-		case FormattingContextType::Table: layout_box = TableFormattingContext::Format(parent_container, element, override_initial_box); break;
-		case FormattingContextType::Flex: layout_box = FlexFormattingContext::Format(parent_container, element, override_initial_box); break;
-		case FormattingContextType::Replaced: layout_box = ReplacedFormattingContext::Format(parent_container, element, override_initial_box); break;
+		case FormattingContextType::Block: layout_box = BlockFormattingContext::Format(parent_container, element, containing_block, box); break;
+		case FormattingContextType::Table: layout_box = TableFormattingContext::Format(parent_container, element, containing_block, box); break;
+		case FormattingContextType::Flex: layout_box = FlexFormattingContext::Format(parent_container, element, containing_block, box); break;
+		case FormattingContextType::Replaced: layout_box = ReplacedFormattingContext::Format(parent_container, element, box); break;
 		case FormattingContextType::None: break;
 		case FormattingContextType::None: break;
 		}
 		}
+
+		// TODO: If MaxContent constraint, and containing block = -1, -1, store resulting size as max-content size.
 	}
 	}
 
 
 	if (layout_box && formatting_mode.constraint == FormattingMode::Constraint::None)
 	if (layout_box && formatting_mode.constraint == FormattingMode::Constraint::None)

+ 7 - 0
Source/Core/Layout/LayoutDetails.cpp

@@ -246,6 +246,13 @@ float LayoutDetails::GetShrinkToFitWidth(Element* element, Vector2f containing_b
 	LayoutNode* layout_node = element->GetLayoutNode();
 	LayoutNode* layout_node = element->GetLayoutNode();
 	float shrink_to_fit_width;
 	float shrink_to_fit_width;
 
 
+	if (element->GetId() == "nested")
+		int x = 0;
+
+	// TODO: The shrink-to-fit width is only cached for every other nested flexbox during the initial
+	// GetShrinkToFitWidth. I.e. the first .outer flexbox below #nested is formatted outside of this function. Even
+	// though in principle I believe we should be able to store its formatted width. Maybe move this caching into
+	// FormatIndependent somehow?
 	if (Optional<float> cached_width = layout_node->GetMaxContentWidthIfCached())
 	if (Optional<float> cached_width = layout_node->GetMaxContentWidthIfCached())
 	{
 	{
 		shrink_to_fit_width = *cached_width;
 		shrink_to_fit_width = *cached_width;

+ 4 - 12
Source/Core/Layout/ReplacedFormattingContext.cpp

@@ -35,20 +35,12 @@
 
 
 namespace Rml {
 namespace Rml {
 
 
-UniquePtr<LayoutBox> ReplacedFormattingContext::Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box)
+UniquePtr<LayoutBox> ReplacedFormattingContext::Format(ContainerBox* parent_container, Element* element, const Box& box)
 {
 {
 	RMLUI_ASSERT(element->IsReplaced());
 	RMLUI_ASSERT(element->IsReplaced());
 
 
-	// Replaced elements provide their own rendering, we just set their box here and notify them that the element has been sized.
-	auto replaced_box = MakeUnique<ReplacedBox>(element);
-	Box& box = replaced_box->GetBox();
-	if (override_initial_box)
-		box = *override_initial_box;
-	else
-	{
-		const Vector2f containing_block = parent_container->GetContainingBlockSize(element->GetPosition());
-		LayoutDetails::BuildBox(box, containing_block, element, BuildBoxMode::ShrinkableBlock, &parent_container->GetFormattingMode());
-	}
+	// Replaced elements provide their own rendering, we just notify them that the element has been sized.
+	auto replaced_box = MakeUnique<ReplacedBox>(element, box);
 
 
 	// Submit the box and notify the element.
 	// Submit the box and notify the element.
 	replaced_box->Close();
 	replaced_box->Close();
@@ -59,7 +51,7 @@ UniquePtr<LayoutBox> ReplacedFormattingContext::Format(ContainerBox* parent_cont
 	if (element->HasChildNodes())
 	if (element->HasChildNodes())
 	{
 	{
 		RootBox root(box, parent_container->GetFormattingMode());
 		RootBox root(box, parent_container->GetFormattingMode());
-		BlockFormattingContext::Format(&root, element, &box);
+		BlockFormattingContext::Format(&root, element, box.GetSize(), box);
 	}
 	}
 
 
 	return replaced_box;
 	return replaced_box;

+ 3 - 5
Source/Core/Layout/ReplacedFormattingContext.h

@@ -38,20 +38,18 @@ namespace Rml {
 /*
 /*
     A formatting context that handles replaced elements.
     A formatting context that handles replaced elements.
 
 
-    Replaced elements normally take care of their own layouting, so this is only responsible for setting thei box
-    dimensions and notifying the element.
+    Replaced elements normally take care of their own layouting, so this is only responsible for notifying the element.
 */
 */
 class ReplacedFormattingContext final : public FormattingContext {
 class ReplacedFormattingContext final : public FormattingContext {
 public:
 public:
-	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box);
+	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box& box);
 };
 };
 
 
 class ReplacedBox : public LayoutBox {
 class ReplacedBox : public LayoutBox {
 public:
 public:
-	ReplacedBox(Element* element) : LayoutBox(Type::Replaced), element(element) {}
+	ReplacedBox(Element* element, const Box& box) : LayoutBox(Type::Replaced), element(element), box(box) {}
 
 
 	void Close();
 	void Close();
-	Box& GetBox() { return box; }
 
 
 	const Box* GetIfBox() const override { return &box; }
 	const Box* GetIfBox() const override { return &box; }
 	String DebugDumpTree(int depth) const override;
 	String DebugDumpTree(int depth) const override;

+ 5 - 10
Source/Core/Layout/TableFormattingContext.cpp

@@ -39,9 +39,12 @@
 
 
 namespace Rml {
 namespace Rml {
 
 
-UniquePtr<LayoutBox> TableFormattingContext::Format(ContainerBox* parent_container, Element* element_table, const Box* override_initial_box)
+UniquePtr<LayoutBox> TableFormattingContext::Format(ContainerBox* parent_container, Element* element_table, Vector2f containing_block,
+	const Box& initial_box)
 {
 {
-	auto table_wrapper_box = MakeUnique<TableWrapper>(element_table, parent_container);
+	RMLUI_ASSERT(containing_block.x >= 0.f || parent_container->GetFormattingMode().constraint == FormattingMode::Constraint::MaxContent);
+
+	auto table_wrapper_box = MakeUnique<TableWrapper>(element_table, parent_container, initial_box);
 	if (table_wrapper_box->IsScrollContainer())
 	if (table_wrapper_box->IsScrollContainer())
 	{
 	{
 		Log::Message(Log::LT_WARNING, "Table elements can only have 'overflow' property values of 'visible'. Table will not be formatted: %s.",
 		Log::Message(Log::LT_WARNING, "Table elements can only have 'overflow' property values of 'visible'. Table will not be formatted: %s.",
@@ -49,16 +52,8 @@ UniquePtr<LayoutBox> TableFormattingContext::Format(ContainerBox* parent_contain
 		return table_wrapper_box;
 		return table_wrapper_box;
 	}
 	}
 
 
-	const Vector2f containing_block = parent_container->GetContainingBlockSize(element_table->GetPosition());
-	RMLUI_ASSERT(containing_block.x >= 0.f || parent_container->GetFormattingMode().constraint == FormattingMode::Constraint::MaxContent);
 	const ComputedValues& computed_table = element_table->GetComputedValues();
 	const ComputedValues& computed_table = element_table->GetComputedValues();
-
-	// Build the initial box as specified by the table's style, as if it was a normal block element.
 	Box& box = table_wrapper_box->GetBox();
 	Box& box = table_wrapper_box->GetBox();
-	if (override_initial_box)
-		box = *override_initial_box;
-	else
-		LayoutDetails::BuildBox(box, containing_block, element_table, BuildBoxMode::ShrinkableBlock, &parent_container->GetFormattingMode());
 
 
 	TableFormattingContext context;
 	TableFormattingContext context;
 	context.element_table = element_table;
 	context.element_table = element_table;

+ 1 - 1
Source/Core/Layout/TableFormattingContext.h

@@ -46,7 +46,7 @@ using TrackBoxList = Vector<TrackBox>;
 */
 */
 class TableFormattingContext final : public FormattingContext {
 class TableFormattingContext final : public FormattingContext {
 public:
 public:
-	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box);
+	static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, Vector2f containing_block, const Box& box);
 
 
 private:
 private:
 	TableFormattingContext() = default;
 	TableFormattingContext() = default;

+ 3 - 37
Tests/Data/VisualTests/flex_shrink_to_fit_01.rml

@@ -39,49 +39,15 @@
 </head>
 </head>
 
 
 <body>
 <body>
-<div class="shrink-to-fit">
-	Before
-	<div class="outer">
-		<div class="inner">Flex</div>
-	</div>
-	After
-</div>
 
 
-<div class="shrink-to-fit right">
+<div id="shrink-to-fit" class="shrink-to-fit right">
 	Before
 	Before
-	<div class="outer" style="display: inline-flex">
-		<div class="inner">Inline-flex</div>
+	<div id="outer" class="outer" style="display: inline-flex">
+		<div id="inner" class="inner">Inline-flex</div>
 	</div>
 	</div>
 	After
 	After
 </div>
 </div>
 
 
-<div class="shrink-to-fit"  style="display: flex; flex-direction: column">
-	<div style="padding: 42px; background: blue; border: 5px #00ffff">
-		<div style="display: flex; background: green; padding: 10px; border: 5px #ff00ff">
-			<div style="width: 10px; height: 10px; background: red; border: 5px #ffff00"></div>
-		</div>
-	</div>
-</div>
-
-<div class="shrink-to-fit row-align-start" style="width: 130px; height: 130px">
-	<div style="border: 5px yellow">
-		<div style="border: 5px red; width: 100px; height: 100px">
-			<div style="border: 5px green">
-				<div style="border: 5px blue; width: 50px; height: 50px;"></div>
-			</div>
-		</div>
-	</div>
-</div>
-
-<div class="shrink-to-fit right column-align-end" style="width: 130px; height: 130px">
-	<div style="border: 5px yellow">
-		<div style="border: 5px red; width: 100px; height: 100px;">
-			<div style="border: 5px green">
-				<div style="border: 5px blue; width: 50px; height: 50px;"></div>
-			</div>
-		</div>
-	</div>
-</div>
 
 
 <handle size_target="#document"/>
 <handle size_target="#document"/>
 </body>
 </body>

+ 15 - 16
Tests/Source/Benchmarks/Flexbox.cpp

@@ -47,7 +47,7 @@ static const String rml_flexbox_basic_document = R"(
 		header, article { display: block; }
 		header, article { display: block; }
 		h1 { font-size: 1.5em; }
 		h1 { font-size: 1.5em; }
 		h2 { font-size: 1.3em; }
 		h2 { font-size: 1.3em; }
-		
+
 		header {
 		header {
 			background-color: #9777d9;
 			background-color: #9777d9;
 			border: 5dp #666;
 			border: 5dp #666;
@@ -71,7 +71,7 @@ static const String rml_flexbox_basic_document = R"(
 			text-align: center;
 			text-align: center;
 			background-color: #eb6e14;
 			background-color: #eb6e14;
 			margin: -10dp -10dp 0;
 			margin: -10dp -10dp 0;
-			padding: 10dp 0; 
+			padding: 10dp 0;
 		}
 		}
 	</style>
 	</style>
 </head>
 </head>
@@ -89,7 +89,7 @@ static const String rml_flexbox_basic_document_fast = R"(
 		header, article { display: block; }
 		header, article { display: block; }
 		h1 { font-size: 1.5em; }
 		h1 { font-size: 1.5em; }
 		h2 { font-size: 1.3em; }
 		h2 { font-size: 1.3em; }
-		
+
 		header {
 		header {
 			background-color: #9777d9;
 			background-color: #9777d9;
 			border: 5dp #666;
 			border: 5dp #666;
@@ -117,7 +117,7 @@ static const String rml_flexbox_basic_document_fast = R"(
 			text-align: center;
 			text-align: center;
 			background-color: #eb6e14;
 			background-color: #eb6e14;
 			margin: -10dp -10dp 0;
 			margin: -10dp -10dp 0;
-			padding: 10dp 0; 
+			padding: 10dp 0;
 		}
 		}
 	</style>
 	</style>
 </head>
 </head>
@@ -135,7 +135,7 @@ static const String rml_flexbox_basic_document_float_reference = R"(
 		header, article { display: block; }
 		header, article { display: block; }
 		h1 { font-size: 1.5em; }
 		h1 { font-size: 1.5em; }
 		h2 { font-size: 1.3em; }
 		h2 { font-size: 1.3em; }
-		
+
 		header {
 		header {
 			background-color: #9777d9;
 			background-color: #9777d9;
 			border: 5dp #666;
 			border: 5dp #666;
@@ -162,7 +162,7 @@ static const String rml_flexbox_basic_document_float_reference = R"(
 			text-align: center;
 			text-align: center;
 			background-color: #eb6e14;
 			background-color: #eb6e14;
 			margin: -10dp -10dp 0;
 			margin: -10dp -10dp 0;
-			padding: 10dp 0; 
+			padding: 10dp 0;
 		}
 		}
 	</style>
 	</style>
 </head>
 </head>
@@ -602,7 +602,7 @@ static const String rml_flexbox_shrink_to_fit = R"(
 	</style>
 	</style>
 </head>
 </head>
 <body>
 <body>
-<div id="basic" class="shrink-to-fit">
+<div id="basic" class="shrink-to-fit" style="display: none">
 	Before
 	Before
 	<div class="outer">
 	<div class="outer">
 		<div class="inner">Flex</div>
 		<div class="inner">Flex</div>
@@ -611,15 +611,9 @@ static const String rml_flexbox_shrink_to_fit = R"(
 </div>
 </div>
 <div id="nested" class="shrink-to-fit">
 <div id="nested" class="shrink-to-fit">
 	Before
 	Before
-	<div class="outer">
-		<div class="inner">
-			<div class="outer">
-				<div class="inner">
-					<div class="outer">
-						<div class="inner">Flex</div>
-					</div>
-				</div>
-			</div>
+	<div class="outer" id="outer">
+		<div class="inner" id="inner">
+			Flex
 		</div>
 		</div>
 	</div>
 	</div>
 	After
 	After
@@ -644,6 +638,11 @@ TEST_CASE("flexbox.shrink-to-fit")
 	document->Show();
 	document->Show();
 	TestsShell::RenderLoop();
 	TestsShell::RenderLoop();
 
 
+	{
+		document->Close();
+		return;
+	}
+
 	basic->SetProperty(PropertyId::Display, Style::Display::None);
 	basic->SetProperty(PropertyId::Display, Style::Display::None);
 	nested->SetProperty(PropertyId::Display, Style::Display::None);
 	nested->SetProperty(PropertyId::Display, Style::Display::None);