<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[234878] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/234878">234878</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2018-08-14 19:59:51 -0700 (Tue, 14 Aug 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[LFC][Floating] Add support for negative clearance.
https://bugs.webkit.org/show_bug.cgi?id=188555

Reviewed by Simon Fraser.

Source/WebCore:

1. Compute clearance to avoid float(s) (border box needs to avoid floats)
2. Reset vertical margins to non-collapsed values.
4. Adjust clearance with the new margins.
5. Take the adjusted clearance and move the box vertically if needed.

Test: fast/block/block-only/margin-collapse-with-clearance.html

* layout/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
* layout/FloatingState.cpp:
(WebCore::Layout::FloatingState::FloatItem::FloatItem):
* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::mapBoxToAncestor):
(WebCore::Layout::FormattingContext::mapTopLeftToAncestor):
(WebCore::Layout::FormattingContext::mapCoordinateToAncestor):
(WebCore::Layout::FormattingContext::mapToAncestor): Deleted.
* layout/FormattingContext.h:
* layout/LayoutUnits.h:
(WebCore::Layout::Position::Position):
(WebCore::Layout::Position::moveBy):
* layout/displaytree/DisplayBox.h:

Tools:

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

LayoutTests:

* fast/block/block-only/margin-collapse-with-clearance-expected.txt: Added.
* fast/block/block-only/margin-collapse-with-clearance.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorelayoutFloatingContextcpp">trunk/Source/WebCore/layout/FloatingContext.cpp</a></li>
<li><a href="#trunkSourceWebCorelayoutFloatingStatecpp">trunk/Source/WebCore/layout/FloatingState.cpp</a></li>
<li><a href="#trunkSourceWebCorelayoutFormattingContextcpp">trunk/Source/WebCore/layout/FormattingContext.cpp</a></li>
<li><a href="#trunkSourceWebCorelayoutFormattingContexth">trunk/Source/WebCore/layout/FormattingContext.h</a></li>
<li><a href="#trunkSourceWebCorelayoutLayoutUnitsh">trunk/Source/WebCore/layout/LayoutUnits.h</a></li>
<li><a href="#trunkSourceWebCorelayoutdisplaytreeDisplayBoxh">trunk/Source/WebCore/layout/displaytree/DisplayBox.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsLayoutReloadedmiscLFCpassingteststxt">trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastblockblockonlymargincollapsewithclearanceexpectedtxt">trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastblockblockonlymargincollapsewithclearancehtml">trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/LayoutTests/ChangeLog 2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2018-08-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][Floating] Add support for negative clearance.
+        https://bugs.webkit.org/show_bug.cgi?id=188555
+
+        Reviewed by Simon Fraser.
+
+        * fast/block/block-only/margin-collapse-with-clearance-expected.txt: Added.
+        * fast/block/block-only/margin-collapse-with-clearance.html: Added.
+
</ins><span class="cx"> 2018-08-14  Ansh Shukla  <ansh_shukla@apple.com>
</span><span class="cx"> 
</span><span class="cx">         NSURLAuthenticationMethodOAuth challenges are surfaced to clients in -didReceiveAuthenticationChallenge as NSURLAuthenticationMethodDefault
</span></span></pre></div>
<a id="trunkLayoutTestsfastblockblockonlymargincollapsewithclearanceexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance-expected.txt (0 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance-expected.txt                              (rev 0)
+++ trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance-expected.txt 2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x450
+  RenderBlock {HTML} at (0,0) size 800x450
+    RenderBody {BODY} at (8,8) size 784x434
+      RenderBlock {DIV} at (0,0) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (1,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,45) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,62) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (449,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,45) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,124) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,43) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,186) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (1,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (449,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,45) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,248) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (1,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,45) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,310) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (449,23) size 52x22 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,45) size 12x12 [border: (1px solid #000000)]
+      RenderBlock {DIV} at (0,372) size 502x62 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,1) size 12x12 [border: (1px solid #000000)]
+        RenderBlock (floating) {DIV} at (1,23) size 52x7 [border: (1px solid #000000)]
+        RenderBlock {DIV} at (1,30) size 12x12 [border: (1px solid #000000)]
</ins></span></pre></div>
<a id="trunkLayoutTestsfastblockblockonlymargincollapsewithclearancehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance.html (0 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance.html                              (rev 0)
+++ trunk/LayoutTests/fast/block/block-only/margin-collapse-with-clearance.html 2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -0,0 +1,47 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<style>
+div {
+       border: 1px solid black;
+}
+</style>
+</head>
+<body>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: left; width: 50px; height: 20px;"></div>
+       <div style="clear: left; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: right; width: 50px; height: 20px;"></div>
+       <div style="clear: right; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="clear: both; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: left; width: 50px; height: 20px;"></div>
+       <div style="float: right; width: 50px; height: 20px;"></div>
+       <div style="clear: both; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: left; width: 50px; height: 20px;"></div>
+       <div style="clear: both; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: right; width: 50px; height: 20px;"></div>
+       <div style="clear: both; width: 10px; height: 10px; margin-top: 30px"></div>
+</div>
+<div style="width: 500px; height: 60px;">
+       <div style="width: 10px; height: 10px; margin-bottom: 10px"></div>
+       <div style="float: left; width: 50px; height: 5px;"></div>
+       <div style="clear: left; width: 10px; height: 10px; margin-top: 10px"></div>
+</div>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/ChangeLog      2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2018-08-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][Floating] Add support for negative clearance.
+        https://bugs.webkit.org/show_bug.cgi?id=188555
+
+        Reviewed by Simon Fraser.
+
+        1. Compute clearance to avoid float(s) (border box needs to avoid floats)
+        2. Reset vertical margins to non-collapsed values.
+        4. Adjust clearance with the new margins.
+        5. Take the adjusted clearance and move the box vertically if needed.
+
+        Test: fast/block/block-only/margin-collapse-with-clearance.html
+
+        * layout/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
+        * layout/FloatingState.cpp:
+        (WebCore::Layout::FloatingState::FloatItem::FloatItem):
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::mapBoxToAncestor):
+        (WebCore::Layout::FormattingContext::mapTopLeftToAncestor):
+        (WebCore::Layout::FormattingContext::mapCoordinateToAncestor):
+        (WebCore::Layout::FormattingContext::mapToAncestor): Deleted.
+        * layout/FormattingContext.h:
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::Position::Position):
+        (WebCore::Layout::Position::moveBy):
+        * layout/displaytree/DisplayBox.h:
+
</ins><span class="cx"> 2018-08-14  Fujii Hironori  <Hironori.Fujii@sony.com>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r234859.
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutFloatingContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/FloatingContext.cpp (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/FloatingContext.cpp  2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/FloatingContext.cpp     2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -150,13 +150,40 @@
</span><span class="cx">         // 1. The amount necessary to place the border edge of the block even with the bottom outer edge of the lowest float that is to be cleared.
</span><span class="cx">         // 2. The amount necessary to place the top border edge of the block at its hypothetical position.
</span><span class="cx"> 
</span><del>-        auto absoluteDisplayBox = FormattingContext::mapToAncestor(layoutContext(), layoutBox, downcast<Container>(m_floatingState.root()));
-        if (floatBottom <= absoluteDisplayBox.rectWithMargin().top())
</del><ins>+        auto& layoutContext = this->layoutContext();
+        auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
+        auto rootRelativeTop = FormattingContext::mapTopLeftToAncestor(layoutContext, layoutBox, downcast<Container>(m_floatingState.root())).y;
+        auto clearance = *floatBottom - rootRelativeTop;
+        if (clearance <= 0)
</ins><span class="cx">             return { };
</span><span class="cx"> 
</span><ins>+        // Clearance inhibits margin collapsing. Let's reset the relevant adjoining margins.
+        if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling()) {
+            auto& previousInFlowDisplayBox = *layoutContext.displayBoxForLayoutBox(*previousInFlowSibling);
+
+            // Since the previous inflow sibling has already been laid out, its margin is collapsed by now.
+            ASSERT(!previousInFlowDisplayBox.marginBottom());
+            auto collapsedMargin = displayBox.marginTop();
+
+            // Reset previous bottom and current top margins to non-collapsing.
+            previousInFlowDisplayBox.setVerticalMargin({ previousInFlowDisplayBox.marginTop(), previousInFlowDisplayBox.nonCollapsedMarginBottom() });
+            displayBox.setVerticalMargin({ displayBox.nonCollapsedMarginTop(), displayBox.marginBottom() });
+
+            auto nonCollapsedMargin = previousInFlowDisplayBox.marginBottom() + displayBox.marginTop();
+            auto marginOffset = nonCollapsedMargin - collapsedMargin;
+            // Move the box to the position where it would be with non-collapsed margins.
+            rootRelativeTop += marginOffset;
+
+            // Having negative clearance is also normal. It just means that the box with the non-collapsed margins is now lower than it needs to be.
+            clearance -= marginOffset;
+        }
+        // Now adjust the box's position with the clearance.
+        rootRelativeTop += clearance;
+        ASSERT(*floatBottom == rootRelativeTop);
+
</ins><span class="cx">         // The return vertical position is in the containing block's coordinate system.
</span><del>-        auto* containingBlockDisplayBox = layoutContext().displayBoxForLayoutBox(*layoutBox.containingBlock());
-        return *floatBottom - containingBlockDisplayBox->top();
</del><ins>+        auto containingBlockRootRelativeTop = FormattingContext::mapTopLeftToAncestor(layoutContext, *layoutBox.containingBlock(), downcast<Container>(m_floatingState.root())).y;
+        return rootRelativeTop - containingBlockRootRelativeTop;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     auto clear = layoutBox.style().clear();
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutFloatingStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/FloatingState.cpp (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/FloatingState.cpp    2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/FloatingState.cpp       2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -41,8 +41,8 @@
</span><span class="cx"> FloatingState::FloatItem::FloatItem(const Box& layoutBox, const FloatingState& floatingState)
</span><span class="cx">     : m_layoutBox(makeWeakPtr(const_cast<Box&>(layoutBox)))
</span><span class="cx">     , m_containingBlock(makeWeakPtr(const_cast<Container&>(*layoutBox.containingBlock())))
</span><del>-    , m_absoluteDisplayBox(FormattingContext::mapToAncestor(floatingState.layoutContext(), layoutBox, downcast<Container>(floatingState.root())))
-    , m_containingBlockAbsoluteDisplayBox(FormattingContext::mapToAncestor(floatingState.layoutContext(), *m_containingBlock, downcast<Container>(floatingState.root())))
</del><ins>+    , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(floatingState.layoutContext(), layoutBox, downcast<Container>(floatingState.root())))
+    , m_containingBlockAbsoluteDisplayBox(FormattingContext::mapBoxToAncestor(floatingState.layoutContext(), *m_containingBlock, downcast<Container>(floatingState.root())))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutFormattingContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/FormattingContext.cpp        2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp   2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -142,7 +142,7 @@
</span><span class="cx">     LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutContext << " root: " << &root());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Display::Box FormattingContext::mapToAncestor(const LayoutContext& layoutContext, const Box& layoutBox, const Container& ancestor)
</del><ins>+Display::Box FormattingContext::mapBoxToAncestor(const LayoutContext& layoutContext, const Box& layoutBox, const Container& ancestor)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(layoutBox.isDescendantOf(ancestor));
</span><span class="cx"> 
</span><span class="lines">@@ -164,6 +164,27 @@
</span><span class="cx">     return mappedDisplayBox;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Position FormattingContext::mapTopLeftToAncestor(const LayoutContext& layoutContext, const Box& layoutBox, const Container& ancestor)
+{
+    ASSERT(layoutBox.isDescendantOf(ancestor));
+    return mapCoordinateToAncestor(layoutContext, layoutContext.displayBoxForLayoutBox(layoutBox)->topLeft(), *layoutBox.containingBlock(), ancestor);
+}
+
+Position FormattingContext::mapCoordinateToAncestor(const LayoutContext& layoutContext, Position position, const Container& containingBlock, const Container& ancestor)
+{
+    auto mappedPosition = position;
+    auto* container = &containingBlock;
+    for (; container && container != &ancestor; container = container->containingBlock())
+        mappedPosition.moveBy(layoutContext.displayBoxForLayoutBox(*container)->topLeft());
+
+    if (!container) {
+        ASSERT_NOT_REACHED();
+        return position;
+    }
+
+    return mappedPosition;
+}
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> void FormattingContext::validateGeometryConstraintsAfterLayout(const LayoutContext& layoutContext) const
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutFormattingContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/FormattingContext.h (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/FormattingContext.h  2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/FormattingContext.h     2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -59,7 +59,9 @@
</span><span class="cx">     };
</span><span class="cx">     virtual InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutContext&, const Box&) const = 0;
</span><span class="cx"> 
</span><del>-    static Display::Box mapToAncestor(const LayoutContext&, const Box&, const Container& ancestor);
</del><ins>+    static Display::Box mapBoxToAncestor(const LayoutContext&, const Box&, const Container& ancestor);
+    static Position mapTopLeftToAncestor(const LayoutContext&, const Box&, const Container& ancestor);
+    static Position mapCoordinateToAncestor(const LayoutContext&, Position, const Container& containingBlock, const Container& ancestor);
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     struct LayoutPair {
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutLayoutUnitsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/LayoutUnits.h (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/LayoutUnits.h        2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/LayoutUnits.h   2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -38,9 +38,32 @@
</span><span class="cx">     // FIXME: Use LayoutUnit<Horizontal> to avoid top/left vs. x/y confusion.
</span><span class="cx">     LayoutUnit x; // left
</span><span class="cx">     LayoutUnit y; // top
</span><ins>+
+    Position() = default;
+    Position(LayoutUnit, LayoutUnit);
+    Position(LayoutPoint);
+    void moveBy(LayoutPoint);
</ins><span class="cx">     operator LayoutPoint() const { return { x, y }; }
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+inline Position::Position(LayoutPoint point)
+    : x(point.x())
+    , y(point.y())
+{
+}
+
+inline Position::Position(LayoutUnit x, LayoutUnit y)
+    : x(x)
+    , y(y)
+{
+}
+
+inline void Position::moveBy(LayoutPoint offset)
+{
+    x += offset.x();
+    y += offset.y();
+}
+
</ins><span class="cx"> // Margin, border, padding
</span><span class="cx"> struct HorizontalEdges {
</span><span class="cx">     LayoutUnit left;
</span></span></pre></div>
<a id="trunkSourceWebCorelayoutdisplaytreeDisplayBoxh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h     2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h        2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> namespace Layout {
</span><span class="cx"> class BlockFormattingContext;
</span><span class="cx"> class FormattingContext;
</span><ins>+class FloatingContext;
</ins><span class="cx"> class LayoutContext;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -48,6 +49,7 @@
</span><span class="cx"> public:
</span><span class="cx">     friend class Layout::BlockFormattingContext;
</span><span class="cx">     friend class Layout::FormattingContext;
</span><ins>+    friend class Layout::FloatingContext;
</ins><span class="cx">     friend class Layout::LayoutContext;
</span><span class="cx"> 
</span><span class="cx">     Box(const Box&);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Tools/ChangeLog       2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2018-08-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][Floating] Add support for negative clearance.
+        https://bugs.webkit.org/show_bug.cgi?id=188555
+
+        Reviewed by Simon Fraser.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
</ins><span class="cx"> 2018-08-14 Sihui Liu <sihui_liu@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Crash in WebKit::filterPreloadHSTSEntry via NetworkProcess::getHostNamesWithHSTSCache
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedmiscLFCpassingteststxt"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt (234877 => 234878)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt    2018-08-15 02:42:59 UTC (rev 234877)
+++ trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt       2018-08-15 02:59:51 UTC (rev 234878)
</span><span class="lines">@@ -49,3 +49,4 @@
</span><span class="cx"> fast/block/block-only/floating-and-next-previous-inflow-with-margin.html
</span><span class="cx"> fast/block/block-only/floating-left-and-right-with-clearance.html
</span><span class="cx"> fast/block/block-only/float-and-siblings-with-margins.html
</span><ins>+fast/block/block-only/margin-collapse-with-clearance.html
</ins></span></pre>
</div>
</div>

</body>
</html>