[LFC] Use the used margin values in outOfFlowReplacedVerticalGeometry consistently
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2019 16:13:07 +0000 (16:13 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2019 16:13:07 +0000 (16:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194020

Reviewed by Antti Koivisto.

Source/WebCore:

Check the used margin variables whether we already computed before/after values.

Test: fast/block/block-only/absolute-position-with-margin-auto-simple.html

* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):

Tools:

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

LayoutTests:

* fast/block/block-only/absolute-position-with-margin-auto-simple-expected.html: Added.
* fast/block/block-only/absolute-position-with-margin-auto-simple.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple-expected.html [new file with mode: 0644]
LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContextGeometry.cpp
Tools/ChangeLog
Tools/LayoutReloaded/misc/LFC-passing-tests.txt

index fe34740..be51479 100644 (file)
@@ -1,3 +1,13 @@
+2019-01-30  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Use the used margin values in outOfFlowReplacedVerticalGeometry consistently
+        https://bugs.webkit.org/show_bug.cgi?id=194020
+
+        Reviewed by Antti Koivisto.
+
+        * fast/block/block-only/absolute-position-with-margin-auto-simple-expected.html: Added.
+        * fast/block/block-only/absolute-position-with-margin-auto-simple.html: Added.
+
 2019-01-30  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Support color well on iOS
diff --git a/LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple-expected.html b/LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple-expected.html
new file mode 100644 (file)
index 0000000..bea034a
--- /dev/null
@@ -0,0 +1,9 @@
+<style>
+div {
+    background-color: green;
+    width: 100px;
+    height: 100px;
+}
+</style>
+<div style="position: relative; top: 10px;"></div>
+<div style="position: relative; top: 290px;"></div>
diff --git a/LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple.html b/LayoutTests/fast/block/block-only/absolute-position-with-margin-auto-simple.html
new file mode 100644 (file)
index 0000000..7e2ab87
--- /dev/null
@@ -0,0 +1,15 @@
+<style>
+div {
+    margin-bottom: auto;
+    margin-top: auto;
+    position: absolute;
+    background-color: green;
+    width: 100px;
+}
+</style>
+<div style="height: 500px; width: 500px; background-color: transparent">
+ <div style="top: 10px;"></div>
+ <div style="bottom: 10px;"></div>
+ <div style="top: 10px; height: 100px"></div>
+ <div style="bottom: 10px; height: 100px"></div>
+</div>
\ No newline at end of file
index 46b35f9..1a8fcec 100644 (file)
@@ -1,3 +1,17 @@
+2019-01-30  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Use the used margin values in outOfFlowReplacedVerticalGeometry consistently
+        https://bugs.webkit.org/show_bug.cgi?id=194020
+
+        Reviewed by Antti Koivisto.
+
+        Check the used margin variables whether we already computed before/after values.
+
+        Test: fast/block/block-only/absolute-position-with-margin-auto-simple.html
+
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
+
 2019-01-30  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Support color well on iOS
index 6973160..2f00b55 100644 (file)
@@ -554,7 +554,8 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
     auto isStaticallyPositioned = !top && !bottom;
     auto height = inlineReplacedHeightAndMargin(layoutState, layoutBox, usedHeight).height;
     auto computedVerticalMargin = Geometry::computedVerticalMargin(layoutState, layoutBox);
-    UsedVerticalMargin::NonCollapsedValues usedVerticalMargin; 
+    Optional<LayoutUnit> usedMarginBefore;
+    Optional<LayoutUnit> usedMarginAfter;
     auto paddingTop = displayBox.paddingTop().valueOr(0);
     auto paddingBottom = displayBox.paddingBottom().valueOr(0);
     auto borderTop = displayBox.borderTop();
@@ -567,32 +568,34 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
 
     if (!bottom) {
         // #2
-        usedVerticalMargin = { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
+        usedMarginBefore = computedVerticalMargin.before.valueOr(0);
+        usedMarginAfter = usedMarginBefore;
     }
 
-    if (!computedVerticalMargin.before && !computedVerticalMargin.after) {
+    if (!usedMarginBefore && !usedMarginAfter) {
         // #3
         auto marginBeforeAndAfter = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
-        usedVerticalMargin = { marginBeforeAndAfter / 2, marginBeforeAndAfter / 2 };
+        usedMarginBefore = marginBeforeAndAfter / 2;
+        usedMarginAfter = usedMarginBefore;
     }
 
     // #4
     if (!top)
-        top = containingBlockHeight - (usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom);
+        top = containingBlockHeight - (*usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom);
 
     if (!bottom)
-        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after);
+        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter);
 
-    if (!computedVerticalMargin.before)
-        usedVerticalMargin.before = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom);
+    if (!usedMarginBefore)
+        usedMarginBefore = containingBlockHeight - (*top + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom);
 
-    if (!computedVerticalMargin.after)
-        usedVerticalMargin.after = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
+    if (!usedMarginAfter)
+        usedMarginAfter = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *bottom);
 
     // #5
-    auto boxHeight = *top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after + *bottom;
+    auto boxHeight = *top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter + *bottom;
     if (boxHeight > containingBlockHeight)
-        bottom = containingBlockHeight - (*top + usedVerticalMargin.before + borderTop + paddingTop + height + paddingBottom + borderBottom + usedVerticalMargin.after); 
+        bottom = containingBlockHeight - (*top + *usedMarginBefore + borderTop + paddingTop + height + paddingBottom + borderBottom + *usedMarginAfter); 
 
     // For out-of-flow elements the containing block is formed by the padding edge of the ancestor.
     // At this point the non-statically positioned value is in the coordinate system of the padding box. Let's convert it to border box coordinate system.
@@ -602,8 +605,12 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
         *bottom += containingBlockPaddingVerticalEdge;
     }
 
-    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << height << "px) margin(" << usedVerticalMargin.before << "px, "  << usedVerticalMargin.after << "px) layoutBox(" << &layoutBox << ")");
-    return { *top, *bottom, { height, usedVerticalMargin } };
+    ASSERT(top);
+    ASSERT(bottom);
+    ASSERT(usedMarginBefore);
+    ASSERT(usedMarginAfter);
+    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position][Height][Margin] -> out-of-flow replaced -> top(" << *top << "px) bottom("  << *bottom << "px) height(" << height << "px) margin(" << *usedMarginBefore << "px, "  << *usedMarginAfter << "px) layoutBox(" << &layoutBox << ")");
+    return { *top, *bottom, { height, { *usedMarginBefore, *usedMarginAfter } } };
 }
 
 HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry(const LayoutState& layoutState, const Box& layoutBox, Optional<LayoutUnit> usedWidth)
index 4254270..0175c20 100644 (file)
@@ -1,3 +1,12 @@
+2019-01-30  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Use the used margin values in outOfFlowReplacedVerticalGeometry consistently
+        https://bugs.webkit.org/show_bug.cgi?id=194020
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2019-01-30  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Support color well on iOS
index ffefcca..5d33fbd 100644 (file)
@@ -82,6 +82,7 @@ fast/block/block-only/non-auto-top-bottom-left-right-widht-height-out-of-flow.ht
 fast/block/block-only/non-auto-top-bottom-height-with-margins.html
 fast/block/block-only/non-auto-top-bottom-height-with-auto-margins.html
 fast/block/block-only/abs-pos-with-border-padding-and-float-child-expected.html
+fast/block/block-only/absolute-position-with-margin-auto-simple.html
 fast/block/basic/002.html
 fast/block/basic/003.html
 fast/block/basic/004.html