[LayoutReloaded] Remove left/right width/height getters from Layout.Box
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2018 03:00:26 +0000 (03:00 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2018 03:00:26 +0000 (03:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183734

Reviewed by Antti Koivisto.

...and use Display.Box instead.

* LayoutReloaded/DisplayTree/Box.js:
(Display.Box.prototype.bottomRight):
(Display.Box.prototype.size):
(Display.Box.prototype.height):
(Display.Box.prototype.width):
* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype._computeStaticPosition):
(BlockFormattingContext.prototype._adjustBottomWithFIXME):
(BlockFormattingContext.prototype._computeInFlowPositionedPosition):
(BlockFormattingContext.prototype._computeOutOfFlowPosition):
* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype._positionForClear):
(FloatingContext.prototype._computePositionToAvoidIntrudingFloats):
(FloatingContext.prototype._adjustedFloatingPosition):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext.prototype.absoluteMarginBox):
(FormattingContext.prototype.absoluteBorderBox):
(FormattingContext.prototype.absolutePaddingBox):
(FormattingContext.prototype.absoluteContentBox):
(FormattingContext.prototype._toAbsolutePosition):
(FormattingContext.prototype._toRootAbsolutePosition):
* LayoutReloaded/LayoutTree/Box.js:
(Layout.Box.prototype.rect): Deleted.
(Layout.Box.prototype.topLeft): Deleted.
(Layout.Box.prototype.bottomRight): Deleted.
* LayoutReloaded/Utils.js:
(Utils._dumpBox):
(Utils.mapToContainer): Deleted.

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

Tools/ChangeLog
Tools/LayoutReloaded/DisplayTree/Box.js
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
Tools/LayoutReloaded/FormattingContext/FloatingContext.js
Tools/LayoutReloaded/FormattingContext/FormattingContext.js
Tools/LayoutReloaded/LayoutTree/Box.js
Tools/LayoutReloaded/Utils.js

index a824701..061434e 100644 (file)
@@ -1,5 +1,43 @@
 2018-03-18  Zalan Bujtas  <zalan@apple.com>
 
+        [LayoutReloaded] Remove left/right width/height getters from Layout.Box
+        https://bugs.webkit.org/show_bug.cgi?id=183734
+
+        Reviewed by Antti Koivisto.
+
+        ...and use Display.Box instead.
+
+        * LayoutReloaded/DisplayTree/Box.js:
+        (Display.Box.prototype.bottomRight):
+        (Display.Box.prototype.size):
+        (Display.Box.prototype.height):
+        (Display.Box.prototype.width):
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+        (BlockFormattingContext.prototype._computeStaticPosition):
+        (BlockFormattingContext.prototype._adjustBottomWithFIXME):
+        (BlockFormattingContext.prototype._computeInFlowPositionedPosition):
+        (BlockFormattingContext.prototype._computeOutOfFlowPosition):
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype._positionForClear):
+        (FloatingContext.prototype._computePositionToAvoidIntrudingFloats):
+        (FloatingContext.prototype._adjustedFloatingPosition):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext.prototype.absoluteMarginBox):
+        (FormattingContext.prototype.absoluteBorderBox):
+        (FormattingContext.prototype.absolutePaddingBox):
+        (FormattingContext.prototype.absoluteContentBox):
+        (FormattingContext.prototype._toAbsolutePosition):
+        (FormattingContext.prototype._toRootAbsolutePosition):
+        * LayoutReloaded/LayoutTree/Box.js:
+        (Layout.Box.prototype.rect): Deleted.
+        (Layout.Box.prototype.topLeft): Deleted.
+        (Layout.Box.prototype.bottomRight): Deleted.
+        * LayoutReloaded/Utils.js:
+        (Utils._dumpBox):
+        (Utils.mapToContainer): Deleted.
+
+2018-03-18  Zalan Bujtas  <zalan@apple.com>
+
         [LayoutReloaded] Remove left/right width/height setters from Layout.Box
         https://bugs.webkit.org/show_bug.cgi?id=183731
 
index 8136d63..991ee64 100644 (file)
@@ -59,6 +59,18 @@ Display.Box = class Box {
         return this.rect().bottomRight();
     }
 
+    size() {
+        return this.rect().size();
+    }
+
+    height() {
+        return this.rect().height();
+    }
+
+    width() {
+        return this.rect().width();
+    }
+
     setTopLeft(topLeft) {
         this.m_rect.setTopLeft(topLeft);
     }
index 2c273db..8db2213 100644 (file)
@@ -112,7 +112,9 @@ class BlockFormattingContext extends FormattingContext {
         let parent = layoutBox.parent();
         // Start from the top of the container's content box.
         let previousInFlowSibling = layoutBox.previousInFlowSibling();
-        let contentBottom = previousInFlowSibling ? previousInFlowSibling.bottomRight().top() + this.marginBottom(previousInFlowSibling) : parent.contentBox().top();
+        let contentBottom = parent.contentBox().top()
+        if (previousInFlowSibling)
+            contentBottom = this.toDisplayBox(previousInFlowSibling).bottomRight().top() + this.marginBottom(previousInFlowSibling);
         let position = new LayoutPoint(contentBottom, parent.contentBox().left());
         position.moveBy(new LayoutSize(this.marginLeft(layoutBox), this.marginTop(layoutBox)));
         this.toDisplayBox(layoutBox).setTopLeft(position);
@@ -275,8 +277,10 @@ class BlockFormattingContext extends FormattingContext {
     }
 
     _adjustBottomWithFIXME(layoutBox) {
+        // FIXME: This function is a big FIXME.
         let lastInFlowChild = layoutBox.lastInFlowChild();
-        let bottom = lastInFlowChild.rect().bottom() + this.marginBottom(lastInFlowChild);
+        let lastInFlowDisplayBox = lastInFlowChild.displayBox();
+        let bottom = lastInFlowDisplayBox.bottom() + this.marginBottom(lastInFlowChild);
         // FIXME: margin for body
         if (lastInFlowChild.name() == "RenderBody" && Utils.isHeightAuto(lastInFlowChild) && !lastInFlowChild.contentBox().height())
             bottom -= this.marginBottom(lastInFlowChild);
@@ -291,7 +295,8 @@ class BlockFormattingContext extends FormattingContext {
 
     _computeInFlowPositionedPosition(layoutBox) {
         // Start with the original, static position.
-        let relativePosition = layoutBox.topLeft();
+        let displayBox = this.toDisplayBox(layoutBox);
+        let relativePosition = displayBox.topLeft();
         // Top/bottom
         if (!Utils.isTopAuto(layoutBox))
             relativePosition.shiftTop(Utils.top(layoutBox));
@@ -302,10 +307,11 @@ class BlockFormattingContext extends FormattingContext {
             relativePosition.shiftLeft(Utils.left(layoutBox));
         else if (!Utils.isRightAuto(layoutBox))
             relativePosition.shiftLeft(-Utils.right(layoutBox));
-        this.toDisplayBox(layoutBox).setTopLeft(relativePosition);
+        displayBox.setTopLeft(relativePosition);
     }
 
     _computeOutOfFlowPosition(layoutBox) {
+        let displayBox = this.toDisplayBox(layoutBox);
         let containerSize = layoutBox.containingBlock().contentBox().size();
         // Top/bottom
         let top = Number.NaN;
@@ -315,7 +321,7 @@ class BlockFormattingContext extends FormattingContext {
         } else if (!Utils.isTopAuto(layoutBox))
             top = Utils.top(layoutBox) + this.marginTop(layoutBox);
         else if (!Utils.isBottomAuto(layoutBox))
-            top = containerSize.height() - Utils.bottom(layoutBox) - layoutBox.rect().height() - this.marginBottom(layoutBox);
+            top = containerSize.height() - Utils.bottom(layoutBox) - displayBox.height() - this.marginBottom(layoutBox);
         else
             ASSERT_NOT_REACHED();
         // Left/right
@@ -326,10 +332,10 @@ class BlockFormattingContext extends FormattingContext {
         } else if (!Utils.isLeftAuto(layoutBox))
             left = Utils.left(layoutBox) + this.marginLeft(layoutBox);
         else if (!Utils.isRightAuto(layoutBox))
-            left = containerSize.width() - Utils.right(layoutBox) - layoutBox.rect().width() - this.marginRight(layoutBox);
+            left = containerSize.width() - Utils.right(layoutBox) - displayBox.width() - this.marginRight(layoutBox);
         else
             ASSERT_NOT_REACHED();
-        this.toDisplayBox(layoutBox).setTopLeft(new LayoutPoint(top, left));
+        displayBox.setTopLeft(new LayoutPoint(top, left));
     }
 
     _shrinkToFitWidth(layoutBox) {
index a62f628..b091397 100644 (file)
@@ -74,8 +74,9 @@ class FloatingContext {
 
     _positionForClear(layoutBox) {
         ASSERT(Utils.hasClear(layoutBox));
+        let displayBox = this._formattingContext().toDisplayBox(layoutBox);
         if (this._isEmpty())
-            return layoutBox.topLeft();
+            return displayBox.topLeft();
 
         let leftBottom = Number.NaN;
         let rightBottom = Number.NaN;
@@ -85,17 +86,17 @@ class FloatingContext {
             rightBottom = this._bottom(this.m_rightFloatingBoxStack);
 
         if (!Number.isNaN(leftBottom) && !Number.isNaN(rightBottom))
-            return new LayoutPoint(Math.max(leftBottom, rightBottom), layoutBox.rect().left());
+            return new LayoutPoint(Math.max(leftBottom, rightBottom), displayBox.left());
         if (!Number.isNaN(leftBottom))
-            return new LayoutPoint(leftBottom, layoutBox.rect().left());
+            return new LayoutPoint(leftBottom, displayBox.left());
         if (!Number.isNaN(rightBottom))
-            return new LayoutPoint(rightBottom, layoutBox.rect().left());
-        return layoutBox.topLeft();
+            return new LayoutPoint(rightBottom, displayBox.left());
+        return displayBox.topLeft();
     }
 
     _computePositionToAvoidIntrudingFloats(layoutBox) {
         if (!layoutBox.establishesBlockFormattingContext() || this._isEmpty())
-            return layoutBox.topLeft();
+            return this._formattingContext().toDisplayBox(layoutBox).topLeft();
         // The border box of a table, a block-level replaced element, or an element in the normal flow that establishes
         // a new block formatting context (such as an element with 'overflow' other than 'visible') must not overlap the
         // margin box of any floats in the same block formatting context as the element itself.
@@ -180,7 +181,7 @@ class FloatingContext {
 
         if (Utils.isFloatingLeft(floatingBox) || !Utils.isFloatingPositioned(floatingBox))
             return new LayoutPoint(verticalPosition, left);
-        return new LayoutPoint(verticalPosition, right - floatingBox.rect().width());
+        return new LayoutPoint(verticalPosition, right - this._formattingContext().toDisplayBox(floatingBox).rect().width());
     }
 
     _bottom(floatingStack) {
index 7b1d522..767148f 100644 (file)
@@ -66,7 +66,7 @@ class FormattingContext {
     }
 
     absoluteMarginBox(layoutBox) {
-        let absoluteContentBox = Utils.mapToContainer(layoutBox, this.rootContainer());
+        let absoluteContentBox = this._toRootAbsolutePosition(layoutBox);
         absoluteContentBox.moveBy(new LayoutSize(-this.marginLeft(layoutBox), -this.marginTop(layoutBox)));
         absoluteContentBox.growBy(new LayoutSize(this.marginLeft(layoutBox) + this.marginRight(layoutBox), this.marginTop(layoutBox) + this.marginBottom(layoutBox)));
         return absoluteContentBox;
@@ -74,21 +74,21 @@ class FormattingContext {
 
     absoluteBorderBox(layoutBox) {
         let borderBox = layoutBox.borderBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), borderBox.size());
+        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox).topLeft(), borderBox.size());
         absoluteRect.moveBy(borderBox.topLeft());
         return absoluteRect;
     }
 
     absolutePaddingBox(layoutBox) {
         let paddingBox = layoutBox.paddingBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), paddingBox.size());
+        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox).topLeft(), paddingBox.size());
         absoluteRect.moveBy(paddingBox.topLeft());
         return absoluteRect;
     }
 
     absoluteContentBox(layoutBox) {
         let contentBox = layoutBox.contentBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), contentBox.size());
+        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox).topLeft(), contentBox.size());
         absoluteRect.moveBy(contentBox.topLeft());
         return absoluteRect;
     }
@@ -97,15 +97,28 @@ class FormattingContext {
         // We should never need to go beyond the root container.
         let containingBlock = layoutBox.containingBlock();
         ASSERT(containingBlock == this.rootContainer() || containingBlock.isDescendantOf(this.rootContainer()));
-        let topLeft = layoutBox.rect().topLeft();
+        let topLeft = this.toDisplayBox(layoutBox).topLeft();
         let ascendant = layoutBox.parent();
         while (ascendant && ascendant != containingBlock) {
-            topLeft.moveBy(ascendant.rect().topLeft());
+            topLeft.moveBy(this.toDisplayBox(ascendant).topLeft());
             ascendant = ascendant.parent();
         }
-        return new LayoutRect(topLeft, layoutBox.rect().size());
+        return new LayoutRect(topLeft, this.toDisplayBox(layoutBox).size());
     }
 
+    _toRootAbsolutePosition(layoutBox) {
+        let displayBox = this.toDisplayBox(layoutBox);
+        let topLeft = displayBox.topLeft();
+        let ascendant = layoutBox.parent();
+        while (ascendant && ascendant != this.rootContainer()) {
+            topLeft.moveBy(this.toDisplayBox(ascendant).topLeft());
+            ascendant = ascendant.parent();
+        }
+        ASSERT(ascendant);
+        return new LayoutRect(topLeft, displayBox.size());
+    }
+
+
     _descendantNeedsLayout() {
         return this.m_layoutStack.length;
     }
index ffc8c26..c22d56e 100644 (file)
@@ -118,18 +118,6 @@ Layout.Box = class Box {
         return this.m_displayBox;
     }
 
-    rect() {
-        return this.displayBox().rect();
-    }
-
-    topLeft() {
-        return this.rect().topLeft();
-    }
-
-    bottomRight() {
-        return this.rect().bottomRight();
-    }
-
     isContainer() {
         return false;
     }
index b633c90..abeb0ec 100644 (file)
@@ -468,17 +468,6 @@ class Utils {
         return window.getComputedStyle(node).float == "left";
     }
 
-    static mapToContainer(box, container) {
-        let topLeft = box.rect().topLeft();
-        let ascendant = box.parent();
-        while (ascendant && ascendant != container) {
-            topLeft.moveBy(ascendant.rect().topLeft());
-            ascendant = ascendant.parent();
-        }
-        ASSERT(ascendant);
-        return new LayoutRect(topLeft, box.rect().size());
-    }
-
     static nextBreakingOpportunity(textBox, currentPosition)
     {
         return window.nextBreakingOpportunity(textBox.content(), currentPosition);
@@ -509,7 +498,8 @@ class Utils {
         }
         if (box.isAnonymous())
             return "";
-        let boxRect = box.rect();
+        let displayBox = box.displayBox();
+        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";
     }