<!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>[230318] trunk/Tools</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/230318">230318</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2018-04-05 19:12:26 -0700 (Thu, 05 Apr 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[LayoutReloaded] Move floating box to the next line when needed
https://bugs.webkit.org/show_bug.cgi?id=184349

Reviewed by Antti Koivisto.

* LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
(InlineFormattingContext.prototype.layout):
(InlineFormattingContext.prototype._handleContent):
(InlineFormattingContext.prototype._handleText):
(InlineFormattingContext.prototype._handleFloatingBox):
(InlineFormattingContext.prototype._mapFloatingHorizontalPosition):
(InlineFormattingContext):
(InlineFormattingContext.prototype._handleFloatingBoxes): Deleted.
(InlineFormattingContext.prototype._floatingBoxes): Deleted.
* LayoutReloaded/FormattingContext/InlineFormatting/Line.js:
(Line.prototype.addTextLineBox):
(Line.prototype.addFloatingBox):
(Line):
* LayoutReloaded/Utils.js:
(LayoutRect.prototype.moveHorizontally):
(LayoutRect.prototype.moveVertically):
* LayoutReloaded/test/index.html:
* LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsLayoutReloadedFormattingContextInlineFormattingInlineFormattingContextjs">trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js</a></li>
<li><a href="#trunkToolsLayoutReloadedFormattingContextInlineFormattingLinejs">trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/Line.js</a></li>
<li><a href="#trunkToolsLayoutReloadedUtilsjs">trunk/Tools/LayoutReloaded/Utils.js</a></li>
<li><a href="#trunkToolsLayoutReloadedtestindexhtml">trunk/Tools/LayoutReloaded/test/index.html</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsLayoutReloadedtestinlinewithfloatswhentheydontfithtml">trunk/Tools/LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (230317 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2018-04-06 01:29:26 UTC (rev 230317)
+++ trunk/Tools/ChangeLog       2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2018-04-05  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutReloaded] Move floating box to the next line when needed
+        https://bugs.webkit.org/show_bug.cgi?id=184349
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
+        (InlineFormattingContext.prototype.layout):
+        (InlineFormattingContext.prototype._handleContent):
+        (InlineFormattingContext.prototype._handleText):
+        (InlineFormattingContext.prototype._handleFloatingBox):
+        (InlineFormattingContext.prototype._mapFloatingHorizontalPosition):
+        (InlineFormattingContext):
+        (InlineFormattingContext.prototype._handleFloatingBoxes): Deleted.
+        (InlineFormattingContext.prototype._floatingBoxes): Deleted.
+        * LayoutReloaded/FormattingContext/InlineFormatting/Line.js:
+        (Line.prototype.addTextLineBox):
+        (Line.prototype.addFloatingBox):
+        (Line):
+        * LayoutReloaded/Utils.js:
+        (LayoutRect.prototype.moveHorizontally):
+        (LayoutRect.prototype.moveVertically):
+        * LayoutReloaded/test/index.html:
+        * LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html: Added.
+
</ins><span class="cx"> 2018-04-05  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Process Swap on Navigation causes many webpages to hang due to attempted process swap for iframe navigations.
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedFormattingContextInlineFormattingInlineFormattingContextjs"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js (230317 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js 2018-04-06 01:29:26 UTC (rev 230317)
+++ trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js    2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -37,10 +37,7 @@
</span><span class="cx">         // This is a post-order tree traversal layout.
</span><span class="cx">         // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child.
</span><span class="cx">         this.m_line = this._createNewLine();
</span><del>-        // Collect floating boxes and layout them first.
-        this._handleFloatingBoxes();
-        //
-        this._addToLayoutQueue(this.formattingRoot().firstInFlowChild());
</del><ins>+        this._addToLayoutQueue(this.formattingRoot().firstInFlowOrFloatChild());
</ins><span class="cx">         while (this._descendantNeedsLayout()) {
</span><span class="cx">             // Travers down on the descendants until we find a leaf node.
</span><span class="cx">             while (true) {
</span><span class="lines">@@ -49,18 +46,17 @@
</span><span class="cx">                     this.layoutState().layout(layoutBox);
</span><span class="cx">                     break;
</span><span class="cx">                 }
</span><del>-                if (!layoutBox.isContainer() || !layoutBox.hasChild())
</del><ins>+                if (!layoutBox.isContainer() || !layoutBox.hasInFlowOrFloatChild())
</ins><span class="cx">                     break;
</span><del>-                this._addToLayoutQueue(layoutBox.firstInFlowChild());
</del><ins>+                this._addToLayoutQueue(layoutBox.firstInFlowOrFloatChild());
</ins><span class="cx">             }
</span><span class="cx">             while (this._descendantNeedsLayout()) {
</span><span class="cx">                 let layoutBox = this._nextInLayoutQueue();
</span><del>-                if (layoutBox instanceof Layout.InlineBox)
-                    this._handleInlineBox(layoutBox);
</del><ins>+                this._handleContent(layoutBox);
</ins><span class="cx">                 // We are done with laying out this box.
</span><span class="cx">                 this._removeFromLayoutQueue(layoutBox);
</span><del>-                if (layoutBox.nextInFlowSibling()) {
-                    this._addToLayoutQueue(layoutBox.nextInFlowSibling());
</del><ins>+                if (layoutBox.nextInFlowOrFloatSibling()) {
+                    this._addToLayoutQueue(layoutBox.nextInFlowOrFloatSibling());
</ins><span class="cx">                     break;
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="lines">@@ -69,6 +65,18 @@
</span><span class="cx">         this._commitLine();
</span><span class="cx">    }
</span><span class="cx"> 
</span><ins>+    _handleContent(layoutBox) {
+        if (layoutBox instanceof Layout.InlineBox) {
+            this._handleInlineBox(layoutBox);
+            return;
+        }
+        if (layoutBox.isFloatingPositioned()) {
+            this._handleFloatingBox(layoutBox);
+            return;
+        }
+        ASSERT_NOT_REACHED();
+    }
+
</ins><span class="cx">     _handleInlineBox(inlineBox) {
</span><span class="cx">         if (inlineBox.text())
</span><span class="cx">             return this._handleText(inlineBox);
</span><span class="lines">@@ -85,25 +93,22 @@
</span><span class="cx">             for (let run of textRuns)
</span><span class="cx">                 this._line().addTextLineBox(run.startPosition, run.endPosition, new LayoutSize(run.width, Utils.textHeight(inlineBox)));
</span><span class="cx">             text = text.slice(textRuns[textRuns.length - 1].endPosition, text.length);
</span><del>-            this._commitLine();
</del><ins>+            // Commit the line unless we run out of content.
+            if (text.length)
+                this._commitLine();
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _handleFloatingBoxes() {
-        let floatingBoxes = this._floatingBoxes();
-        for (let floatingBox of floatingBoxes) {
-            this._addToLayoutQueue(floatingBox);
-            this._handleFloatingBox(floatingBox);
-            this._removeFromLayoutQueue(floatingBox);
-        }
-    }
-
</del><span class="cx">     _handleFloatingBox(floatingBox) {
</span><del>-        this.layoutState().layout(floatingBox);
</del><span class="cx">         this._computeFloatingWidth(floatingBox);
</span><span class="cx">         this._computeFloatingHeight(floatingBox);
</span><ins>+        let displayFloatingBox = this.displayBox(floatingBox);
+        if (displayFloatingBox.width() > this._line().availableWidth())
+            this._commitLine();
+        // Position this float statically first, the floating context will figure it out the final position.
+        displayFloatingBox.setTopLeft(this._line().rect().topLeft());
</ins><span class="cx">         this.floatingContext().computePosition(floatingBox);
</span><del>-        this._line().addFloatingBox(this.displayBox(floatingBox).size());
</del><ins>+        this._line().addFloatingBox(displayFloatingBox.size());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _commitLine() {
</span><span class="lines">@@ -164,33 +169,5 @@
</span><span class="cx">             return root.contentBox().left();
</span><span class="cx">         return horizontalPosition - rootLeft;
</span><span class="cx">      }
</span><del>-
-    _floatingBoxes() {
-        ASSERT(this.formattingRoot().firstChild());
-        // FIXME: This is highly inefficient but will do for now.
-        let floatingBoxes = new Array();
-        let stack = new Array();
-        stack.push(this.formattingRoot().firstChild());
-        while (stack.length) {
-            while (true) {
-                let box = stack[stack.length - 1];
-                if (box.isFloatingPositioned())
-                    floatingBoxes.push(box);
-                if (box.establishesFormattingContext())
-                    break;
-                if (!box.isContainer() || !box.hasChild())
-                    break;
-                stack.push(box.firstChild());
-            }
-            while (stack.length) {
-                let box = stack.pop();
-                if (box.nextSibling()) {
-                    stack.push(box.nextSibling());
-                    break;
-                }
-            }
-        }
-        return floatingBoxes;
-    }
</del><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedFormattingContextInlineFormattingLinejs"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/Line.js (230317 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/Line.js    2018-04-06 01:29:26 UTC (rev 230317)
+++ trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/Line.js       2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     addTextLineBox(startPosition, endPosition, size) {
</span><ins>+        ASSERT(size.width() <= this.m_availableWidth);
</ins><span class="cx">         this.m_availableWidth -= size.width();
</span><span class="cx">         // TODO: use the actual height instead of the line height.
</span><span class="cx">         let lineBoxRect = new LayoutRect(this.rect().topRight(), new LayoutSize(size.width(), this.rect().height()));
</span><span class="lines">@@ -55,8 +56,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     addFloatingBox(size) {
</span><del>-        // TODO: Add missing cases.
</del><ins>+        ASSERT(size.width() <= this.m_availableWidth);
+        // Push non-floating boxes to the right.
</ins><span class="cx">         this.m_availableWidth -= size.width();
</span><del>-        this.m_lineRect.moveBy(new LayoutSize(size.width(), 0));
</del><ins>+        for (let lineBox of this.m_lineBoxes)
+            lineBox.lineBoxRect.moveHorizontally(size.width());
+        this.m_lineRect.moveHorizontally(size.width());
</ins><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedUtilsjs"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutReloaded/Utils.js (230317 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/Utils.js      2018-04-06 01:29:26 UTC (rev 230317)
+++ trunk/Tools/LayoutReloaded/Utils.js 2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -207,7 +207,15 @@
</span><span class="cx">     moveBy(distance) {
</span><span class="cx">         this.m_topLeft.moveBy(distance);
</span><span class="cx">     }
</span><del>-    
</del><ins>+
+    moveHorizontally(distance) {
+        this.m_topLeft.shiftLeft(distance);
+    }
+
+    moveVertically(distance) {
+        this.m_topLeft.shiftTop(distance);
+    }
+
</ins><span class="cx">     isEmpty() {
</span><span class="cx">         return this.m_size.isEmpty();
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedtestindexhtml"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutReloaded/test/index.html (230317 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/test/index.html       2018-04-06 01:29:26 UTC (rev 230317)
+++ trunk/Tools/LayoutReloaded/test/index.html  2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -69,7 +69,8 @@
</span><span class="cx">     "inline-formatting-context-with-floats2.html",
</span><span class="cx">     "float-is-inside-inline-formatting-context-simple.html",
</span><span class="cx">     "multiple-left-floats-on-line-simple.html",
</span><del>-    "multiple-left-floats-on-line-from-parent-formatting-context.html"
</del><ins>+    "multiple-left-floats-on-line-from-parent-formatting-context.html",
+    "inline-with-floats-when-they-dont-fit.html"
</ins><span class="cx"> ];
</span><span class="cx"> 
</span><span class="cx"> let debugThis = [];
</span></span></pre></div>
<a id="trunkToolsLayoutReloadedtestinlinewithfloatswhentheydontfithtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html (0 => 230318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html                               (rev 0)
+++ trunk/Tools/LayoutReloaded/test/inline-with-floats-when-they-dont-fit.html  2018-04-06 02:12:26 UTC (rev 230318)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<div style="width: 100px; height: 100px;">foobar<div style="float: left; width: 20px; height: 20px;"></div><div style="float: left; width: 60px; height: 20px;"></div></div>
+</body>
+</html>
</ins></span></pre>
</div>
</div>

</body>
</html>