[LayoutReloaded] Move move functions to the base class from BlockFormattingContext
https://bugs.webkit.org/show_bug.cgi?id=183719

Reviewed by Antti Koivisto.

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext):
(BlockFormattingContext.prototype.layout):
(BlockFormattingContext.prototype._shrinkToFitWidth):
(BlockFormattingContext.prototype._toAbsolutePosition): Deleted.
(BlockFormattingContext.prototype._needsLayout): Deleted.
(BlockFormattingContext.prototype._addToLayoutQueue): Deleted.
(BlockFormattingContext.prototype._nextInLayoutQueue): Deleted.
(BlockFormattingContext.prototype._removeFromLayoutQueue): Deleted.
(BlockFormattingContext.prototype._createDisplayBox): Deleted.
(BlockFormattingContext.prototype._toDisplayBox): Deleted.
(BlockFormattingContext.prototype._toLayoutBox): Deleted.
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext):
(FormattingContext.prototype._toAbsolutePosition):
(FormattingContext.prototype._descendantNeedsLayout):
(FormattingContext.prototype._addToLayoutQueue):
(FormattingContext.prototype._nextInLayoutQueue):
(FormattingContext.prototype._removeFromLayoutQueue):
(FormattingContext.prototype._createDisplayBox):
(FormattingContext.prototype._toDisplayBox):
(FormattingContext.prototype._toLayoutBox):
* LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
(InlineFormattingContext.prototype.layout):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@229692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js b/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
index 04e0508..2d2ba60 100644
--- a/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
+++ b/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
@@ -27,9 +27,6 @@
         super(root);
         // New block formatting context always establishes a new floating context.
         this.m_floatingContext = new FloatingContext(this);
-        this.m_displayToLayout = new Map();
-        this.m_layoutToDisplay = new Map();
-        this.m_layoutStack = new Array();
     }
 
     layout(layoutContext) {
@@ -46,7 +43,7 @@
         // 2. Compute static position and width as we travers down
         // 3. As we climb back on the tree, compute height and finialize position
         // (Any subtrees with new formatting contexts need to layout synchronously)
-        while (this._needsLayout()) {
+        while (this._descendantNeedsLayout()) {
             // Travers down on the descendants until we find a leaf node.
             while (true) {
                 let layoutBox = this._nextInLayoutQueue();
@@ -62,7 +59,7 @@
             }
 
             // Climb back on the ancestors and compute height/final position.
-            while (this._needsLayout()) {
+            while (this._descendantNeedsLayout()) {
                 // All inflow descendants (if there are any) are laid out by now. Let's compute the box's height.
                 let layoutBox = this._nextInLayoutQueue();
                 this.computeHeight(layoutBox);
@@ -331,59 +328,4 @@
         }
         return width;
     }
-
-    _toAbsolutePosition(layoutBox) {
-        // We should never need to go beyond the root container.
-        let containingBlock = layoutBox.containingBlock();
-        ASSERT(containingBlock == this.rootContainer() || Utils.isDescendantOf(containingBlock, this.rootContainer()));
-        let topLeft = layoutBox.rect().topLeft();
-        let ascendant = layoutBox.parent();
-        while (ascendant && ascendant != containingBlock) {
-            topLeft.moveBy(ascendant.rect().topLeft());
-            ascendant = ascendant.parent();
-        }
-        return new LayoutRect(topLeft, layoutBox.rect().size());
-    }
-
-    _needsLayout() {
-        return this.m_layoutStack.length;
-    }
-
-    _addToLayoutQueue(layoutBox) {
-        // Initialize the corresponding display box.
-        this._createDisplayBox(layoutBox);
-        this.m_layoutStack.push(layoutBox);
-    }
-
-    _nextInLayoutQueue() {
-        ASSERT(this.m_layoutStack.length);
-        return this.m_layoutStack[this.m_layoutStack.length - 1];
-    }
-
-    _removeFromLayoutQueue(layoutBox) {
-        // With the current layout logic, the layoutBox should be at the top (this.m_layoutStack.pop() should do).
-        ASSERT(this.m_layoutStack.length);
-        ASSERT(this.m_layoutStack[this.m_layoutStack.length - 1] == layoutBox);
-        this.m_layoutStack.splice(this.m_layoutStack.indexOf(layoutBox), 1);
-    }
-
-    _createDisplayBox(layoutBox) {
-        let displayBox = new Display.Box(layoutBox.node());
-        this.m_displayToLayout.set(displayBox, layoutBox);
-        this.m_layoutToDisplay.set(layoutBox, displayBox);
-        // This is temporary.
-        layoutBox.setDisplayBox(displayBox);
-    }
-
-    _toDisplayBox(layoutBox) {
-        ASSERT(layoutBox);
-        ASSERT(this.m_layoutToDisplay.has(layoutBox));
-        return this.m_layoutToDisplay.get(layout);
-    }
-
-    _toLayoutBox(displayBox) {
-        ASSERT(displayBox);
-        ASSERT(this.m_displayToLayout.has(displayBox));
-        return this.m_displayToLayout.get(layout);
-    }
 }
diff --git a/Tools/LayoutReloaded/FormattingContext/FormattingContext.js b/Tools/LayoutReloaded/FormattingContext/FormattingContext.js
index 7a7cad8..e9251f6 100644
--- a/Tools/LayoutReloaded/FormattingContext/FormattingContext.js
+++ b/Tools/LayoutReloaded/FormattingContext/FormattingContext.js
@@ -27,6 +27,9 @@
     constructor(rootContainer) {
         this.m_rootContainer = rootContainer;
         this.m_floatingContext = null;
+        this.m_displayToLayout = new Map();
+        this.m_layoutToDisplay = new Map();
+        this.m_layoutStack = new Array();
     }
 
     rootContainer() {
@@ -89,4 +92,59 @@
         absoluteRect.moveBy(contentBox.topLeft());
         return absoluteRect;
     }
+
+    _toAbsolutePosition(layoutBox) {
+        // We should never need to go beyond the root container.
+        let containingBlock = layoutBox.containingBlock();
+        ASSERT(containingBlock == this.rootContainer() || Utils.isDescendantOf(containingBlock, this.rootContainer()));
+        let topLeft = layoutBox.rect().topLeft();
+        let ascendant = layoutBox.parent();
+        while (ascendant && ascendant != containingBlock) {
+            topLeft.moveBy(ascendant.rect().topLeft());
+            ascendant = ascendant.parent();
+        }
+        return new LayoutRect(topLeft, layoutBox.rect().size());
+    }
+
+    _descendantNeedsLayout() {
+        return this.m_layoutStack.length;
+    }
+
+    _addToLayoutQueue(layoutBox) {
+        // Initialize the corresponding display box.
+        this._createDisplayBox(layoutBox);
+        this.m_layoutStack.push(layoutBox);
+    }
+
+    _nextInLayoutQueue() {
+        ASSERT(this.m_layoutStack.length);
+        return this.m_layoutStack[this.m_layoutStack.length - 1];
+    }
+
+    _removeFromLayoutQueue(layoutBox) {
+        // With the current layout logic, the layoutBox should be at the top (this.m_layoutStack.pop() should do).
+        ASSERT(this.m_layoutStack.length);
+        ASSERT(this.m_layoutStack[this.m_layoutStack.length - 1] == layoutBox);
+        this.m_layoutStack.splice(this.m_layoutStack.indexOf(layoutBox), 1);
+    }
+
+    _createDisplayBox(layoutBox) {
+        let displayBox = new Display.Box(layoutBox.node());
+        this.m_displayToLayout.set(displayBox, layoutBox);
+        this.m_layoutToDisplay.set(layoutBox, displayBox);
+        // This is temporary.
+        layoutBox.setDisplayBox(displayBox);
+    }
+
+    _toDisplayBox(layoutBox) {
+        ASSERT(layoutBox);
+        ASSERT(this.m_layoutToDisplay.has(layoutBox));
+        return this.m_layoutToDisplay.get(layout);
+    }
+
+    _toLayoutBox(displayBox) {
+        ASSERT(displayBox);
+        ASSERT(this.m_displayToLayout.has(displayBox));
+        return this.m_displayToLayout.get(layout);
+    }
 }
diff --git a/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js b/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
index 41a36b9..c6e0036 100644
--- a/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
+++ b/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
@@ -45,26 +45,27 @@
         if (!this.rootContainer().firstChild())
             return;
         // This is a post-order tree traversal layout.
-        let layoutStack = new Array();
         // 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.
-        layoutStack.push(this.rootContainer().firstChild());
+        this._addToLayoutQueue(this.rootContainer().firstChild());
         while (layoutStack.length) {
             // Travers down on the descendants until we find a leaf node.
             while (true) {
-                let layoutBox = layoutStack[layoutStack.length - 1];
+                let layoutBox = this._nextInLayoutQueue();
                 if (layoutBox.establishesFormattingContext()) {
                     layoutContext.layoutFormattingContext(layoutBox.establishedFormattingContext());
                     break;
                 }
                 if (!layoutBox.isContainer() || !layoutBox.hasChild())
                     break;
-                layoutStack.push(box.firstChild());
+                this._addToLayoutQueue(layoutBox.firstChild());
             }
             while (layoutStack.length) {
-                let layoutBox = layoutStack.pop();
+                let layoutBox = this._nextInLayoutQueue();
                 this._handleInlineBox(layoutBox);
+                // We are done with laying out this box.
+                this._removeFromLayoutQueue(layoutBox);
                 if (layoutBox.nextSibling()) {
-                    layoutStack.push(layoutBox.nextSibling());
+                    this._addToLayoutQueue(layoutBox.nextSibling());
                     break;
                 }
             }