Jelajahi Sumber

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.
Andreas Kling 2 tahun lalu
induk
melakukan
b289f97a65

+ 2 - 2
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()) {

+ 3 - 3
Userland/Libraries/LibWeb/Layout/LayoutState.h

@@ -162,9 +162,9 @@ struct LayoutState {
         Optional<float> 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<float> min_content_height_with_definite_available_width;
-        Optional<float> max_content_height_with_definite_available_width;
+        //       three separate kinds of results, depending on the available width at the time of calculation.
+        HashMap<float, Optional<float>> min_content_height_with_definite_available_width;
+        HashMap<float, Optional<float>> max_content_height_with_definite_available_width;
         Optional<float> min_content_height_with_min_content_available_width;
         Optional<float> max_content_height_with_min_content_available_width;
         Optional<float> min_content_height_with_max_content_available_width;