[LFC][BFC] Add support for percentage height in quirks mode.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2018 15:46:38 +0000 (15:46 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Nov 2018 15:46:38 +0000 (15:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191232

Reviewed by Antti Koivisto.

Source/WebCore:

In quirks mode, we go and travers the containing block chain to find a block level
box with fixed height value to resolve the percentage value.

Test: fast/block/basic/quirk-mode-percent-height.html

* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::computedHeightValue):
* layout/Verification.cpp:
(WebCore::Layout::LayoutState::verifyAndOutputMismatchingLayoutTree const):

Tools:

* LayoutReloaded/misc/LFC-passing-tests.txt:

LayoutTests:

* fast/block/basic/quirk-mode-percent-height-expected.txt: Added.
* fast/block/basic/quirk-mode-percent-height.html: Added.
* platform/ios/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237783 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/block/basic/quirk-mode-percent-height-expected.txt [new file with mode: 0644]
LayoutTests/fast/block/basic/quirk-mode-percent-height.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContextGeometry.cpp
Tools/ChangeLog
Tools/LayoutReloaded/misc/LFC-passing-tests.txt

index e0afd9d..090c927 100644 (file)
@@ -1,5 +1,16 @@
 2018-11-04  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][BFC] Add support for percentage height in quirks mode.
+        https://bugs.webkit.org/show_bug.cgi?id=191232
+
+        Reviewed by Antti Koivisto.
+
+        * fast/block/basic/quirk-mode-percent-height-expected.txt: Added.
+        * fast/block/basic/quirk-mode-percent-height.html: Added.
+        * platform/ios/TestExpectations:
+
+2018-11-04  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][BCF] Add support for block level non-replaced inflow height percentage
         https://bugs.webkit.org/show_bug.cgi?id=191229
 
diff --git a/LayoutTests/fast/block/basic/quirk-mode-percent-height-expected.txt b/LayoutTests/fast/block/basic/quirk-mode-percent-height-expected.txt
new file mode 100644 (file)
index 0000000..3764f7a
--- /dev/null
@@ -0,0 +1,24 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+layer at (8,8) size 202x296 clip at (9,9) size 200x294 scrollWidth 300
+  RenderBlock {DIV} at (0,0) size 202x296 [border: (1px solid #008000)]
+    RenderBlock {DIV} at (1,1) size 300x294
+      RenderBlock {DIV} at (0,0) size 202x294 [border: (1px solid #FF0000)]
+        RenderText {#text} at (1,1) size 182x72
+          text run at (1,1) width 175: "This nested div has percent"
+          text run at (1,19) width 177: "height value and the closest"
+          text run at (1,37) width 182: "block level containing block"
+          text run at (1,55) width 97: "box is the ICB."
+layer at (8,304) size 202x202 clip at (9,305) size 200x200 scrollWidth 300
+  RenderBlock {DIV} at (0,296) size 202x202 [border: (1px solid #008000)]
+    RenderBlock {DIV} at (1,1) size 300x102
+      RenderBlock {DIV} at (0,0) size 202x102 [border: (1px solid #FF0000)]
+        RenderText {#text} at (1,1) size 182x90
+          text run at (1,1) width 175: "This nested div has percent"
+          text run at (1,19) width 177: "height value and the closest"
+          text run at (1,37) width 182: "block level containing block"
+          text run at (1,55) width 168: "box is 2 containing blocks"
+          text run at (1,73) width 37: "away."
diff --git a/LayoutTests/fast/block/basic/quirk-mode-percent-height.html b/LayoutTests/fast/block/basic/quirk-mode-percent-height.html
new file mode 100644 (file)
index 0000000..fd75952
--- /dev/null
@@ -0,0 +1,23 @@
+<style>
+.top {
+       border: 1px solid green;
+       width: 200px;
+       overflow: hidden;
+}
+
+.main {
+       width: 300px;
+}
+
+.nested {
+       border: 1px solid red;
+       display: block;
+       height: 50%;
+       width: 200px;
+}
+
+</style>
+
+<div class=top><div class=main><div class=nested>This nested div has percent height value and the closest block level containing block box is the ICB.</div></div></div>
+
+<div class=top style="height: 200px"><div class=main><div class=nested>This nested div has percent height value and the closest block level containing block box is 2 containing blocks away.</div></div></div>
index c81f0a2..c0a4d3a 100644 (file)
@@ -3117,6 +3117,7 @@ fast/inline/simple-inline-block.html [ Failure ]
 fast/inline/simple-shrink-to-fit-inline-block.html [ Failure ]
 fast/block/basic/height-percentage-simple.html [ Failure ]
 fast/block/basic/child-block-level-box-with-height-percent.html [ Failure ]
+fast/block/basic/quirk-mode-percent-height.html [ Failure ]
 
 # Datalist
 webkit.org/b/186714 fast/forms/datalist/datalist-textinput-keydown.html [ Skip ]
index a0c5884..b37e4dd 100644 (file)
@@ -1,5 +1,22 @@
 2018-11-04  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][BFC] Add support for percentage height in quirks mode.
+        https://bugs.webkit.org/show_bug.cgi?id=191232
+
+        Reviewed by Antti Koivisto.
+
+        In quirks mode, we go and travers the containing block chain to find a block level
+        box with fixed height value to resolve the percentage value.
+
+        Test: fast/block/basic/quirk-mode-percent-height.html
+
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::computedHeightValue):
+        * layout/Verification.cpp:
+        (WebCore::Layout::LayoutState::verifyAndOutputMismatchingLayoutTree const):
+
+2018-11-04  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][BCF] Add support for block level non-replaced inflow height percentage
         https://bugs.webkit.org/show_bug.cgi?id=191229
 
index dca9c08..8080343 100644 (file)
@@ -68,12 +68,44 @@ std::optional<LayoutUnit> FormattingContext::Geometry::computedHeightValue(const
         return { height.value() };
 
     std::optional<LayoutUnit> containingBlockHeightValue;
-    auto containingBlockHeight = layoutBox.containingBlock()->style().logicalHeight();
-    if (containingBlockHeight.isFixed())
-        containingBlockHeightValue = { containingBlockHeight.value() };
-    else if (layoutBox.isOutOfFlowPositioned()) {
-        // Containing block's height is already computed.
+    if (layoutBox.isOutOfFlowPositioned()) {
+        // Containing block's height is already computed since we layout the out-of-flow boxes as the last step.
         containingBlockHeightValue = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).height();
+    } else {
+        auto computedHeightValueForQuirksMode = [&]() -> LayoutUnit {
+            // In quirks mode, we go and travers the containing block chain to find a block level box with fixed height value, even if it means leaving
+            // the current formatting context. FIXME: surely we need to do some tricks here when block direction support is added.
+            auto* containingBlock = layoutBox.containingBlock();
+            LayoutUnit bodyAndDocumentVerticalMarginsPaddingsAndBorders;
+            while (containingBlock) {
+                auto containingBlockHeight = containingBlock->style().logicalHeight();
+                if (containingBlockHeight.isFixed())
+                    return containingBlockHeight.value() - bodyAndDocumentVerticalMarginsPaddingsAndBorders;
+
+                // If the only fixed value box we find is the ICB, then ignore the body and the document (vertical) margin, padding and border. So much quirkiness.
+                // -and it's totally insane because now we freely travel across formatting context boundaries and computed margins are nonexistent.
+                if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
+                    auto& displayBox = layoutState.displayBoxForLayoutBox(*containingBlock);
+
+                    auto verticalMargins = computedNonCollapsedVerticalMarginValue(layoutState, *containingBlock);
+                    auto verticalPaddings = displayBox.paddingTop().value_or(0) + displayBox.paddingBottom().value_or(0);
+                    auto verticalBorders = displayBox.borderTop() + displayBox.borderBottom();
+                    bodyAndDocumentVerticalMarginsPaddingsAndBorders += verticalMargins.top + verticalMargins.bottom + verticalPaddings + verticalBorders;
+                }
+
+                containingBlock = containingBlock->containingBlock();
+            }
+            // Initial containing block has to have a height.
+            return layoutState.displayBoxForLayoutBox(layoutBox.initialContainingBlock()).contentBox().height() - bodyAndDocumentVerticalMarginsPaddingsAndBorders;
+        };
+
+        if (layoutState.inQuirksMode())
+            containingBlockHeightValue = computedHeightValueForQuirksMode();
+        else {
+            auto containingBlockHeight = layoutBox.containingBlock()->style().logicalHeight();
+            if (containingBlockHeight.isFixed())
+                containingBlockHeightValue = { containingBlockHeight.value() };
+        }
     }
 
     if (!containingBlockHeightValue)
index 2e03a0d..aec4a17 100644 (file)
@@ -1,5 +1,14 @@
 2018-11-04  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][BFC] Add support for percentage height in quirks mode.
+        https://bugs.webkit.org/show_bug.cgi?id=191232
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
+2018-11-04  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][BCF] Add support for block level non-replaced inflow height percentage
         https://bugs.webkit.org/show_bug.cgi?id=191229
 
index d848e16..95ed618 100644 (file)
@@ -71,3 +71,4 @@ fast/inline/simple-inline-block.html
 fast/inline/simple-shrink-to-fit-inline-block.html
 fast/block/basic/height-percentage-simple.html
 fast/block/basic/child-block-level-box-with-height-percent.html
+fast/block/basic/quirk-mode-percent-height.html