Title: [237775] trunk
Revision
237775
Author
[email protected]
Date
2018-11-03 10:57:49 -0700 (Sat, 03 Nov 2018)

Log Message

[LFC][BFC] Resolve percentage height values.
https://bugs.webkit.org/show_bug.cgi?id=191224

Reviewed by Antti Koivisto.

Source/WebCore:

10.5 Content height: the 'height' property
The percentage is calculated with respect to the height of the generated box's containing block.
If the height of the containing block is not specified explicitly (i.e., it depends on content height),
and this element is not absolutely positioned, the used height is calculated as if 'auto' was specified.

https://www.w3.org/TR/CSS22/visudet.html#propdef-height

Test: fast/block/basic/height-percentage-simple.html

* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::isHeightAuto):
(WebCore::Layout::computedHeightValue):
(WebCore::Layout::contentHeightForFormattingContextRoot):
(WebCore::Layout::FormattingContext::Geometry::computedMaxHeight):
(WebCore::Layout::FormattingContext::Geometry::computedMinHeight):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::complicatedCases):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):

Tools:

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

LayoutTests:

* fast/block/basic/height-percentage-simple-expected.txt: Added.
* fast/block/basic/height-percentage-simple.html: Added.
* platform/ios/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237774 => 237775)


--- trunk/LayoutTests/ChangeLog	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/LayoutTests/ChangeLog	2018-11-03 17:57:49 UTC (rev 237775)
@@ -1,3 +1,14 @@
+2018-11-02  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC] Resolve percentage height values.
+        https://bugs.webkit.org/show_bug.cgi?id=191224
+
+        Reviewed by Antti Koivisto.
+
+        * fast/block/basic/height-percentage-simple-expected.txt: Added.
+        * fast/block/basic/height-percentage-simple.html: Added.
+        * platform/ios/TestExpectations:
+
 2018-11-03  Youenn Fablet  <[email protected]>
 
         Refresh WPT webrtc tests

Added: trunk/LayoutTests/fast/block/basic/height-percentage-simple-expected.txt (0 => 237775)


--- trunk/LayoutTests/fast/block/basic/height-percentage-simple-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/block/basic/height-percentage-simple-expected.txt	2018-11-03 17:57:49 UTC (rev 237775)
@@ -0,0 +1,22 @@
+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
+      RenderBlock {DIV} at (0,0) size 300x18
+        RenderText {#text} at (52,0) size 86x18
+          text run at (52,0) width 86: "first line with"
+        RenderBlock (floating) {DIV} at (0,0) size 52x294 [border: (1px solid #FF0000)]
+          RenderText {#text} at (1,1) size 29x18
+            text run at (1,1) width 29: "float"
+        RenderText {#text} at (137,0) size 48x18
+          text run at (137,0) width 48: "content"
+      RenderBlock {DIV} at (0,18) size 784x100
+        RenderText {#text} at (52,19) size 105x18
+          text run at (52,19) width 105: "second line with"
+        RenderBlock {DIV} at (156,0) size 53x52 [border: (1px solid #FF0000)]
+          RenderText {#text} at (1,1) size 37x36
+            text run at (1,1) width 37: "inline"
+            text run at (1,19) width 36: "block"
+        RenderText {#text} at (208,19) size 48x18
+          text run at (208,19) width 48: "content"

Added: trunk/LayoutTests/fast/block/basic/height-percentage-simple.html (0 => 237775)


--- trunk/LayoutTests/fast/block/basic/height-percentage-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/block/basic/height-percentage-simple.html	2018-11-03 17:57:49 UTC (rev 237775)
@@ -0,0 +1,16 @@
+<style>
+#main {
+	width: 300px;
+}
+
+#nested {
+	border: 1px solid red;
+	display: block;
+	height: 50%;
+	width: 50px;
+}
+
+</style>
+
+<div id=main>first line with<div id=nested style="float: left">float</div>content</div>
+<div style="height: 100px">second line with<div id=nested style="display: inline-block">inline block</div>content</div>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (237774 => 237775)


--- trunk/LayoutTests/platform/ios/TestExpectations	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2018-11-03 17:57:49 UTC (rev 237775)
@@ -3115,6 +3115,7 @@
 fast/inline/simple-intruding-floats3.html [ Failure ]
 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 ]
 
 # Datalist
 webkit.org/b/186714 fast/forms/datalist/datalist-textinput-keydown.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (237774 => 237775)


--- trunk/Source/WebCore/ChangeLog	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/Source/WebCore/ChangeLog	2018-11-03 17:57:49 UTC (rev 237775)
@@ -1,3 +1,30 @@
+2018-11-02  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC] Resolve percentage height values.
+        https://bugs.webkit.org/show_bug.cgi?id=191224
+
+        Reviewed by Antti Koivisto.
+
+        10.5 Content height: the 'height' property
+        The percentage is calculated with respect to the height of the generated box's containing block.
+        If the height of the containing block is not specified explicitly (i.e., it depends on content height),
+        and this element is not absolutely positioned, the used height is calculated as if 'auto' was specified.
+
+        https://www.w3.org/TR/CSS22/visudet.html#propdef-height
+
+        Test: fast/block/basic/height-percentage-simple.html
+
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::isHeightAuto):
+        (WebCore::Layout::computedHeightValue):
+        (WebCore::Layout::contentHeightForFormattingContextRoot):
+        (WebCore::Layout::FormattingContext::Geometry::computedMaxHeight):
+        (WebCore::Layout::FormattingContext::Geometry::computedMinHeight):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::complicatedCases):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
+
 2018-11-03  Eric Carlson  <[email protected]>
 
         [MediaStream] enumerateDevices should not expose devices that are not available to getUserMedia

Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (237774 => 237775)


--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp	2018-11-03 17:57:49 UTC (rev 237775)
@@ -35,9 +35,57 @@
 namespace WebCore {
 namespace Layout {
 
+static inline bool isHeightAuto(const Box& layoutBox)
+{
+    // 10.5 Content height: the 'height' property
+    //
+    // The percentage is calculated with respect to the height of the generated box's containing block.
+    // If the height of the containing block is not specified explicitly (i.e., it depends on content height),
+    // and this element is not absolutely positioned, the used height is calculated as if 'auto' was specified.
+
+    auto height = layoutBox.style().logicalHeight();
+    if (height.isAuto())
+        return true;
+
+    if (height.isPercent()) {
+        if (layoutBox.isOutOfFlowPositioned())
+            return false;
+
+        return !layoutBox.containingBlock()->style().logicalHeight().isFixed();
+    }
+
+    return false;
+}
+
+enum class HeightType { Min, Max, Normal };
+static inline std::optional<LayoutUnit> computedHeightValue(const LayoutState& layoutState, const Box& layoutBox, HeightType heightType)
+{
+    auto& style = layoutBox.style();
+    auto height = heightType == HeightType::Normal ? style.logicalHeight() : heightType == HeightType::Min ? style.logicalMinHeight() : style.logicalMaxHeight();
+    if (height.isUndefined() || height.isAuto())
+        return { };
+
+    if (height.isFixed())
+        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.
+        containingBlockHeightValue = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).height();
+    }
+
+    if (!containingBlockHeightValue)
+        return { };
+
+    return valueForLength(height, *containingBlockHeightValue);
+}
+
 static LayoutUnit contentHeightForFormattingContextRoot(const LayoutState& layoutState, const Box& layoutBox)
 {
-    ASSERT(layoutBox.style().logicalHeight().isAuto() && (layoutBox.establishesFormattingContext() || layoutBox.isDocumentBox()));
+    ASSERT(isHeightAuto(layoutBox) && (layoutBox.establishesFormattingContext() || layoutBox.isDocumentBox()));
 
     // 10.6.7 'Auto' heights for block formatting context roots
 
@@ -108,49 +156,14 @@
 // the percentage value is treated as '0' (for 'min-height') or 'none' (for 'max-height').
 std::optional<LayoutUnit> FormattingContext::Geometry::computedMaxHeight(const LayoutState& layoutState, const Box& layoutBox)
 {
-    auto maxHeight = layoutBox.style().logicalMaxHeight();
-    if (maxHeight.isUndefined() || maxHeight.isAuto())
-        return { };
-
-    if (maxHeight.isFixed())
-        return { maxHeight.value() };
-
-    std::optional<LayoutUnit> containingBlockHeightValue;
-    auto height = layoutBox.containingBlock()->style().logicalHeight();
-    if (height.isFixed())
-        containingBlockHeightValue = { height.value() };
-    else if (layoutBox.isOutOfFlowPositioned()) {
-        // Containing block's height is already computed.
-        containingBlockHeightValue = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).height();
-    }
-
-    if (containingBlockHeightValue)
-        return valueForLength(maxHeight, *containingBlockHeightValue);
-
-    return { };
+    return computedHeightValue(layoutState, layoutBox, HeightType::Max);
 }
 
 std::optional<LayoutUnit> FormattingContext::Geometry::computedMinHeight(const LayoutState& layoutState, const Box& layoutBox)
 {
-    auto minHeight = layoutBox.style().logicalMinHeight();
-    if (minHeight.isUndefined() || minHeight.isAuto())
-        return { };
+    if (auto minHeightValue = computedHeightValue(layoutState, layoutBox, HeightType::Min))
+        return minHeightValue;
 
-    if (minHeight.isFixed())
-        return { minHeight.value() };
-
-    std::optional<LayoutUnit> containingBlockHeightValue;
-    auto height = layoutBox.containingBlock()->style().logicalHeight();
-    if (height.isFixed())
-        containingBlockHeightValue = { height.value() };
-    else if (layoutBox.isOutOfFlowPositioned()) {
-        // Containing block's height is already computed.
-        containingBlockHeightValue = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).height();
-    }
-
-    if (containingBlockHeightValue)
-        return valueForLength(minHeight, *containingBlockHeightValue);
-
     return { 0 };
 }
 
@@ -262,7 +275,7 @@
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
-    auto height = computedValueIfNotAuto(usedHeight ? Length { usedHeight.value(), Fixed } : style.logicalHeight(), containingBlockHeight);
+    auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
     auto marginTop = computedValueIfNotAuto(style.marginTop(), containingBlockWidth);
     auto marginBottom = computedValueIfNotAuto(style.marginBottom(), containingBlockWidth);
     auto paddingTop = displayBox.paddingTop().value_or(0);
@@ -675,7 +688,7 @@
     auto& containingBlockDisplayBox = layoutState.displayBoxForLayoutBox(containingBlock);
     auto containingBlockWidth = containingBlockDisplayBox.contentBoxWidth();
 
-    auto height = fixedValue(usedHeight ? Length { usedHeight.value(), Fixed } : style.logicalHeight());
+    auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
     auto marginTop = computedValueIfNotAuto(style.marginTop(), containingBlockWidth);
     auto marginBottom = computedValueIfNotAuto(style.marginBottom(), containingBlockWidth);
 
@@ -684,10 +697,8 @@
     marginBottom = marginBottom.value_or(0);
     // #2
     if (!height) {
-        if (style.logicalHeight().isAuto())
-            height = contentHeightForFormattingContextRoot(layoutState, layoutBox);
-        else
-            ASSERT_NOT_IMPLEMENTED_YET();
+        ASSERT(isHeightAuto(layoutBox));
+        height = contentHeightForFormattingContextRoot(layoutState, layoutBox);
     }
 
     ASSERT(height);
@@ -801,13 +812,10 @@
     auto& style = layoutBox.style();
     auto replaced = layoutBox.replaced();
 
-    auto height = fixedValue(usedHeight ? Length { usedHeight.value(), Fixed } : style.logicalHeight());
-    auto heightIsAuto = !usedHeight && style.logicalHeight().isAuto();
+    auto height = usedHeight ? usedHeight.value() : computedHeightValue(layoutState, layoutBox, HeightType::Normal);
+    auto heightIsAuto = !usedHeight && isHeightAuto(layoutBox);
     auto widthIsAuto = style.logicalWidth().isAuto();
 
-    if (!height && !heightIsAuto)
-        ASSERT_NOT_IMPLEMENTED_YET();
-
     if (heightIsAuto && widthIsAuto && replaced->hasIntrinsicHeight()) {
         // #2
         height = replaced->intrinsicHeight();
@@ -880,10 +888,8 @@
     auto nonComputedMarginRight = computedValueIfNotAuto(style.marginRight(), containingBlockWidth).value_or(0);
     auto width = computedValueIfNotAuto(usedWidth ? Length { usedWidth.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
 
-    auto heightIsAuto = style.logicalHeight().isAuto();
-    auto height = fixedValue(style.logicalHeight());
-    if (!height && !heightIsAuto)
-        ASSERT_NOT_IMPLEMENTED_YET();
+    auto heightIsAuto = isHeightAuto(layoutBox);
+    auto height = computedHeightValue(layoutState, layoutBox, HeightType::Normal);
 
     if (!width && heightIsAuto && replaced->hasIntrinsicWidth()) {
         // #1

Modified: trunk/Tools/ChangeLog (237774 => 237775)


--- trunk/Tools/ChangeLog	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/Tools/ChangeLog	2018-11-03 17:57:49 UTC (rev 237775)
@@ -1,3 +1,12 @@
+2018-11-02  Zalan Bujtas  <[email protected]>
+
+        [LFC][BFC] Resolve percentage height values.
+        https://bugs.webkit.org/show_bug.cgi?id=191224
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2018-11-03  Alex Christensen  <[email protected]>
 
         Mac production builds should sign the network process xpc service with entitlements

Modified: trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt (237774 => 237775)


--- trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt	2018-11-03 15:22:55 UTC (rev 237774)
+++ trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt	2018-11-03 17:57:49 UTC (rev 237775)
@@ -69,3 +69,4 @@
 fast/inline/simple-intruding-floats3.html
 fast/inline/simple-inline-block.html
 fast/inline/simple-shrink-to-fit-inline-block.html
+fast/block/basic/height-percentage-simple.html
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to