[LayoutReloaded] Move root container ownership to layout state
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2018 03:09:03 +0000 (03:09 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2018 03:09:03 +0000 (03:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184575

Reviewed by Antti Koivisto.

Now the root container is on the associated layout state (ICB only at this point though).

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype.layout):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext.prototype._layoutOutOfFlowDescendants):
* LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
(InlineFormattingContext.prototype._handleInlineBlockContainer):
(InlineFormattingContext.prototype._handleFloatingBox):
* LayoutReloaded/Layout.js:
(layout):
* LayoutReloaded/LayoutState.js:
(LayoutState):
(LayoutState.prototype.formattingContext):
(LayoutState.prototype.establishedFormattingState):
(LayoutState.prototype.formattingStateForBox):
(LayoutState.prototype.needsLayout):
(LayoutState.prototype.displayBox):
(LayoutState.prototype._formattingContext):
(LayoutState.prototype.layout): Deleted.
(LayoutState.prototype.formattingStates): Deleted.
(LayoutState.prototype.initialDisplayBox): Deleted.
* LayoutReloaded/Utils.js:
(Utils._dumpBox):
(Utils._findDisplayBox): Deleted.

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

Tools/ChangeLog
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
Tools/LayoutReloaded/FormattingContext/FormattingContext.js
Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
Tools/LayoutReloaded/Layout.js
Tools/LayoutReloaded/LayoutState.js
Tools/LayoutReloaded/Utils.js

index e8bd6c73239168f70bc4d60813b52b20c74f2b8b..b55a0e9743043c94af67337ee2cb5f600e8802ba 100644 (file)
@@ -1,3 +1,36 @@
+2018-04-12  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutReloaded] Move root container ownership to layout state
+        https://bugs.webkit.org/show_bug.cgi?id=184575
+
+        Reviewed by Antti Koivisto.
+
+        Now the root container is on the associated layout state (ICB only at this point though).
+
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+        (BlockFormattingContext.prototype.layout):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext.prototype._layoutOutOfFlowDescendants):
+        * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
+        (InlineFormattingContext.prototype._handleInlineBlockContainer):
+        (InlineFormattingContext.prototype._handleFloatingBox):
+        * LayoutReloaded/Layout.js:
+        (layout):
+        * LayoutReloaded/LayoutState.js:
+        (LayoutState):
+        (LayoutState.prototype.formattingContext):
+        (LayoutState.prototype.establishedFormattingState):
+        (LayoutState.prototype.formattingStateForBox):
+        (LayoutState.prototype.needsLayout):
+        (LayoutState.prototype.displayBox):
+        (LayoutState.prototype._formattingContext):
+        (LayoutState.prototype.layout): Deleted.
+        (LayoutState.prototype.formattingStates): Deleted.
+        (LayoutState.prototype.initialDisplayBox): Deleted.
+        * LayoutReloaded/Utils.js:
+        (Utils._dumpBox):
+        (Utils._findDisplayBox): Deleted.
+
 2018-04-12  Jonathan Bedard  <jbedard@apple.com>
 
         Fix --build-directory flag for run-webkit-tests
index d12018ac2c6804c48832f014e8a051fb2af45a7e..393a751601c9774a11cef21118ae9acb362b8eb1 100644 (file)
@@ -47,7 +47,7 @@ class BlockFormattingContext extends FormattingContext {
                 this.computeWidth(layoutBox);
                 this._computeStaticPosition(layoutBox);
                 if (layoutBox.establishesFormattingContext()) {
-                    this.layoutState().layout(layoutBox);
+                    this.layoutState().formattingContext(layoutBox).layout();
                     break;
                 }
                 let childToLayout = this._firstInFlowChildWithNeedsLayout(layoutBox);
index 6e224db7750a2401f7f012f56a577d8a2c24d368..f294d7e4113fb57aea7e66a408ec9ce9b71a7ae3 100644 (file)
@@ -173,7 +173,7 @@ class FormattingContext {
         for (let outOfFlowBox of outOfFlowDescendants) {
             this._addToLayoutQueue(outOfFlowBox);
             this._computeOutOfFlowWidth(outOfFlowBox);
-            this.layoutState().layout(outOfFlowBox);
+            this.layoutState().formattingContext(outOfFlowBox).layout();
             this._computeOutOfFlowHeight(outOfFlowBox);
             this._computeOutOfFlowPosition(outOfFlowBox);
             this._removeFromLayoutQueue(outOfFlowBox);
index c2d85cb032bc153a8c5bec94fc60b305cbe2500a..fb7090e2b51852e80996282c2b6be631ac249533 100644 (file)
@@ -81,7 +81,7 @@ class InlineFormattingContext extends FormattingContext {
         // TODO: auto width/height
         this._adjustLineForInlineContainerStart(inlineBlockContainer);
         displayBox.setWidth(Utils.width(inlineBlockContainer) + Utils.computedHorizontalBorderAndPadding(inlineBlockContainer.node()));
-        this.layoutState().layout(inlineBlockContainer);
+        this.layoutState().formattingContext(inlineBlockContainer).layout();
         displayBox.setHeight(Utils.height(inlineBlockContainer) + Utils.computedVerticalBorderAndPadding(inlineBlockContainer.node()));
         this._adjustLineForInlineContainerEnd(inlineBlockContainer);
         this._line().addInlineContainerBox(displayBox.size());
@@ -122,7 +122,7 @@ class InlineFormattingContext extends FormattingContext {
 
     _handleFloatingBox(floatingBox) {
         this._computeFloatingWidth(floatingBox);
-        this.layoutState().layout(floatingBox);
+        this.layoutState().formattingContext(floatingBox).layout();
         this._computeFloatingHeight(floatingBox);
         let displayBox = this.displayBox(floatingBox);
         // Position this float statically first, the floating context will figure it out the final position.
index 343a024645bb7388b5b2e6f886b3db62de9e3909..5d9df098ac0f079f4d677090749dde32c84f9c74 100644 (file)
@@ -28,7 +28,7 @@ function layout(window, viewportSize) {
     let initialContainingBlock = treeBuilder.createTree(window.document, window.renderTreeStructure);
     let displayBox = new Display.Box();
     displayBox.setSize(viewportSize);
-    let layoutState = new LayoutState(displayBox);
-    layoutState.layout(initialContainingBlock);
+    let layoutState = new LayoutState(initialContainingBlock, displayBox);
+    layoutState.formattingContext(initialContainingBlock).layout();
     return Utils.layoutTreeDump(initialContainingBlock, layoutState);
 }
index 365f5f49d819aacae48108bbd6fbe57adba1953e..deb3b3754497213d3e7765edac30a2a1dc6df440 100644 (file)
  */
 
 class LayoutState {
-    constructor(initialDisplayBox) {
-        this.m_formattingStates = new Map();
-        this.m_initialDisplayBox = initialDisplayBox;
-    }
-
-    layout(formattingRoot) {
-        let formattingState = this._createFormattingState(formattingRoot);
-        this.m_formattingStates.set(formattingRoot, formattingState);
-        this.formattingContext(formattingState).layout();
-    }
+    constructor(rootContainer, rootDisplayBox) {
+        ASSERT(rootContainer.establishesFormattingContext());
+        this.m_rootContainer = rootContainer;
+        this.m_rootDisplayBox = rootDisplayBox;
 
-    formattingContext(formattingState) {
-        if (formattingState instanceof BlockFormattingState)
-            return new BlockFormattingContext(formattingState);
-        if (formattingState instanceof InlineFormattingState)
-            return new InlineFormattingContext(formattingState);
-        ASSERT_NOT_REACHED();
-        return null;
+        this.m_formattingStates = new Map();
     }
 
-    formattingStates() {
-        return this.m_formattingStates;
+    formattingContext(formattingRoot) {
+        return this._formattingContext(this.establishedFormattingState(formattingRoot));
     }
 
     establishedFormattingState(formattingRoot) {
         ASSERT(formattingRoot.establishesFormattingContext());
-        return this.m_formattingStates.get(formattingRoot);
+        let formattingState = this.m_formattingStates.get(formattingRoot);
+        if (formattingState)
+            return formattingState;
+        formattingState = this._createFormattingState(formattingRoot);
+        this.m_formattingStates.set(formattingRoot, formattingState);
+        return formattingState;
     }
 
     formattingStateForBox(layoutBox) {
-        for (let formattingEntry of this.formattingStates()) {
+        for (let formattingEntry of this.m_formattingStates) {
             let formattingRoot = formattingEntry[0];
             let formattingState = formattingEntry[1];
             if (FormattingContext.isInFormattingContext(layoutBox, formattingRoot))
@@ -73,7 +66,7 @@ class LayoutState {
     }
 
     needsLayout() {
-        for (let formattingEntry of this.formattingStates()) {
+        for (let formattingEntry of this.m_formattingStates) {
             let formattingState = formattingEntry[1];
             if (formattingState.layoutNeeded())
                 return true;
@@ -82,19 +75,15 @@ class LayoutState {
     }
 
     displayBox(layoutBox) {
-        for (let formattingEntry of this.formattingStates()) {
+        for (let formattingEntry of this.m_formattingStates) {
             let formattingState = formattingEntry[1];
             let displayBox = formattingState.displayBoxes().get(layoutBox);
             if (displayBox)
                 return displayBox;
         }
-        // It must be the ICB.
-        ASSERT(!layoutBox.parent());
-        return this.initialDisplayBox();
-    }
-
-    initialDisplayBox() {
-        return this.m_initialDisplayBox;
+        // It must be the root container.
+        ASSERT(layoutBox == this.m_rootContainer);
+        return this.m_rootDisplayBox;
     }
 
     _createFormattingState(formattingRoot) {
@@ -107,4 +96,12 @@ class LayoutState {
         return null;
     }
 
+    _formattingContext(formattingState) {
+        if (formattingState instanceof BlockFormattingState)
+            return new BlockFormattingContext(formattingState);
+        if (formattingState instanceof InlineFormattingState)
+            return new InlineFormattingContext(formattingState);
+        ASSERT_NOT_REACHED();
+        return null;
+    }
 }
index 00646bf2b080ac3379804e829ac8658ab3c9288f..0f6a8b4a526b1373979f724347522f4fd44a8491 100644 (file)
@@ -553,17 +553,6 @@ class Utils {
         return this._dumpBox(layoutState, initialContainingBlock, 1) + this._dumpTree(layoutState, initialContainingBlock, 2);
     }
 
-    static _findDisplayBox(layoutState, box) {
-        for (let formattingEntry of layoutState.formattingStates()) {
-            let formattingState = formattingEntry[1];
-            let displayBox = formattingState.displayBoxes().get(box);
-            if (displayBox)
-                return displayBox;
-        }
-        ASSERT(!box.parent());
-        return layoutState.initialDisplayBox();
-    }
-
     static _dumpBox(layoutState, box, level) {
         // Skip anonymous boxes for now -This is the case where WebKit does not generate an anon inline container for text content where the text is a direct child
         // of a block container.
@@ -574,7 +563,7 @@ class Utils {
         }
         if (box.name() == "RenderInline") {
             if (box.isInFlowPositioned()) {
-                let displayBox = Utils._findDisplayBox(layoutState, box);
+                let displayBox = layoutState.displayBox(box);
                 let boxRect = displayBox.rect();
                 return indentation + box.node().tagName + " " + box.name() + "  (" + Utils.precisionRoundWithDecimals(boxRect.left()) + ", " + Utils.precisionRoundWithDecimals(boxRect.top()) + ")\n";
             }
@@ -582,7 +571,7 @@ class Utils {
         }
         if (box.isAnonymous())
             return "";
-        let displayBox = Utils._findDisplayBox(layoutState, box);
+        let displayBox = layoutState.displayBox(box);
         let boxRect = displayBox.rect();
         return indentation + (box.node().tagName ? (box.node().tagName + " ") : "")  + box.name() + " at (" + boxRect.left() + "," + boxRect.top() + ") size " + boxRect.width() + "x" + boxRect.height() + "\n";
     }