From b289f97a65f352471a3416f375276dc5e7abfacf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 15 Oct 2022 13:46:15 +0200 Subject: [PATCH] LibWeb: Split intrinsic heights cache by definite available widths As it turns out, we sometimes query the intrinsic height of a box before having fully resolved and/or constrained its containing block. Because of this, we may enter intrinsic sizing with different amounts of available width for the same box. To accommodate this scenario, we now allow caching of multiple intrinsic heights, separated by the amount of available width provided as input. --- Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 4 ++-- Userland/Libraries/LibWeb/Layout/LayoutState.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 0f1532d9fb..dfac2822d3 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1183,7 +1183,7 @@ float FormattingContext::calculate_min_content_height(Layout::Box const& box, Av auto& root_state = m_state.m_root; auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (available_width.is_definite()) { - cache_slot = &cache.min_content_height_with_definite_available_width; + cache_slot = &cache.min_content_height_with_definite_available_width.ensure(available_width.to_px()); } else if (available_width.is_min_content()) { cache_slot = &cache.min_content_height_with_min_content_available_width; } else if (available_width.is_max_content()) { @@ -1228,7 +1228,7 @@ float FormattingContext::calculate_max_content_height(Layout::Box const& box, Av auto& root_state = m_state.m_root; auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (available_width.is_definite()) { - cache_slot = &cache.max_content_height_with_definite_available_width; + cache_slot = &cache.max_content_height_with_definite_available_width.ensure(available_width.to_px()); } else if (available_width.is_min_content()) { cache_slot = &cache.max_content_height_with_min_content_available_width; } else if (available_width.is_max_content()) { diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index a85eae6e5e..ec1071e390 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -162,9 +162,9 @@ struct LayoutState { Optional max_content_width; // NOTE: Since intrinsic heights depend on the amount of available width, we have to cache - // three separate results, depending on the available width at the time of calculation. - Optional min_content_height_with_definite_available_width; - Optional max_content_height_with_definite_available_width; + // three separate kinds of results, depending on the available width at the time of calculation. + HashMap> min_content_height_with_definite_available_width; + HashMap> max_content_height_with_definite_available_width; Optional min_content_height_with_min_content_available_width; Optional max_content_height_with_min_content_available_width; Optional min_content_height_with_max_content_available_width;