Переглянути джерело

LibWeb: Use min-height in calculating block box height
Now we use min-height for calculating the height of block boxes.
Besides, now we check if min-height/max-height are percentage values
and don't use them if parent's height isn't explicitly set (CSS 2.1
section 10.7).

Egor Ananyin 4 роки тому
батько
коміт
3ca6d7dd36
1 змінених файлів з 12 додано та 15 видалено
  1. 12 15
      Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

+ 12 - 15
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -314,26 +314,23 @@ void BlockFormattingContext::compute_height(Box& box)
     if (is<ReplacedBox>(box)) {
     if (is<ReplacedBox>(box)) {
         height = compute_height_for_replaced_element(downcast<ReplacedBox>(box));
         height = compute_height_for_replaced_element(downcast<ReplacedBox>(box));
     } else {
     } else {
-        if (box.computed_values().height().is_undefined_or_auto()) {
+        if (box.computed_values().height().is_undefined_or_auto()
+            || (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) {
             height = compute_auto_height_for_block_level_element(box);
             height = compute_auto_height_for_block_level_element(box);
         } else {
         } else {
-            CSS::Length specified_height;
-            if (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute()) {
-                specified_height = CSS::Length::make_auto();
-            } else {
-                specified_height = computed_values.height().resolved_or_auto(box, containing_block.height());
-            }
-
-            auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height());
-            if (!specified_height.is_auto()) {
-                float used_height = specified_height.to_px(box);
-                if (!specified_max_height.is_auto())
-                    used_height = min(used_height, specified_max_height.to_px(box));
-                height = used_height;
-            }
+            height = computed_values.height().resolved_or_auto(box, containing_block.height()).to_px(box);
         }
         }
     }
     }
 
 
+    auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height());
+    if (!specified_max_height.is_auto()
+        && !(computed_values.max_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
+        height = min(height, specified_max_height.to_px(box));
+    auto specified_min_height = computed_values.min_height().resolved_or_auto(box, containing_block.height());
+    if (!specified_min_height.is_auto()
+        && !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
+        height = max(height, specified_min_height.to_px(box));
+
     box.set_height(height);
     box.set_height(height);
 }
 }