[LFC][BFC] Fix block level formatting root inflow box height computation
https://bugs.webkit.org/show_bug.cgi?id=203085
<rdar://problem/56372306>

Reviewed by Antti Koivisto.

Section 10.6.7 (https://www.w3.org/TR/CSS22/visudet.html#root-height) defines the height computation for block level formatting context roots.
We already use it for floats, out-of-flow and block level boxes when overflow computes to not "visible".
This patch makes generic in-flow non-replaced BFC roots (e.g. principal block container box for <table>) compute their heights according to 10.6.7.

* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index b022774..e13f884 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
+2019-10-18  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][BFC] Fix block level formatting root inflow box height computation
+        https://bugs.webkit.org/show_bug.cgi?id=203085
+        <rdar://problem/56372306>
+
+        Reviewed by Antti Koivisto.
+
+        Section 10.6.7 (https://www.w3.org/TR/CSS22/visudet.html#root-height) defines the height computation for block level formatting context roots.
+        We already use it for floats, out-of-flow and block level boxes when overflow computes to not "visible".
+        This patch makes generic in-flow non-replaced BFC roots (e.g. principal block container box for <table>) compute their heights according to 10.6.7.
+
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
+
 2019-10-17  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Clipboard API] Support navigator.clipboard.read()
diff --git a/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp b/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
index 54f7e6f..ef688af 100644
--- a/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
+++ b/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
@@ -100,6 +100,10 @@
         return { 0, nonCollapsedMargin };
     };
 
+    // 10.6.7 'Auto' heights for block formatting context roots
+    auto isAutoHeight = !usedValues.height && !computedContentHeight(layoutBox);
+    if (isAutoHeight && layoutBox.establishesBlockFormattingContext())
+        usedValues.height = contentHeightForFormattingContextRoot(layoutBox);
     auto contentHeightAndMargin = compute();
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> height(" << contentHeightAndMargin.contentHeight << "px) margin(" << contentHeightAndMargin.nonCollapsedMargin.before << "px, " << contentHeightAndMargin.nonCollapsedMargin.after << "px) -> layoutBox(" << &layoutBox << ")");
     return contentHeightAndMargin;