From eadbd44680813a90823b05a7c4a5f51a6d984253 Mon Sep 17 00:00:00 2001 From: Alex Lurye Date: Tue, 2 Jan 2024 13:21:52 +0100 Subject: [PATCH] Fix a bug with handling infinities in the flex formatter --- Source/Core/Layout/FlexFormattingContext.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Core/Layout/FlexFormattingContext.cpp b/Source/Core/Layout/FlexFormattingContext.cpp index f480fe179..6c2487c4c 100644 --- a/Source/Core/Layout/FlexFormattingContext.cpp +++ b/Source/Core/Layout/FlexFormattingContext.cpp @@ -119,16 +119,18 @@ UniquePtr FlexFormattingContext::Format(ContainerBox* parent_containe } Vector2f FlexFormattingContext::GetMaxContentSize(Element *element) { - RootBox root(Vector2f(FLT_MAX, FLT_MAX)); - Vector2f containing_block(FLT_MAX, FLT_MAX); + // A large but finite number is used here, because the flexbox formatting algorithm + // needs to round numbers, and it doesn't support infinities. + Vector2f infinity(10000.0f, 10000.0f); + RootBox root(infinity); auto flex_container_box = MakeUnique(element, &root); FlexFormattingContext context; context.flex_container_box = flex_container_box.get(); context.element_flex = element; - context.flex_available_content_size = Vector2f(-1, -1); - context.flex_content_containing_block = Vector2f(-1, -1); - context.flex_max_size = Vector2f(FLT_MAX, FLT_MAX); + context.flex_available_content_size = infinity; + context.flex_content_containing_block = infinity; + context.flex_max_size = infinity; // Format the flexbox and all its children. Vector2f flex_resulting_content_size, content_overflow_size;