[LayoutReloaded] Remove all FormattingContext::absolute*Box functions.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 02:07:25 +0000 (02:07 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 02:07:25 +0000 (02:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184215

Reviewed by Antti Koivisto.

Use Display.Box instead.

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype._computeOutOfFlowPosition):
* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype._availableSpace):
(FloatingContext.prototype._adjustedFloatingPosition):
(FloatingContext.prototype._mapBorderBoxToFormattingRoot):
(FloatingContext.prototype._mapContentBoxToFormattingRoot):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext.prototype.absoluteBorderBox): Deleted.
(FormattingContext.prototype.absolutePaddingBox): Deleted.
(FormattingContext.prototype.absoluteContentBox): Deleted.
(FormattingContext.prototype._toAbsolutePosition): Deleted.
(FormattingContext.prototype._toRootAbsolutePosition): Deleted.
* LayoutReloaded/Utils.js:
(Utils.mapPosition):
(Utils.marginBox):
(Utils.borderBox):
(Utils.contentBox):

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

Tools/ChangeLog
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
Tools/LayoutReloaded/FormattingContext/FloatingContext.js
Tools/LayoutReloaded/FormattingContext/FormattingContext.js
Tools/LayoutReloaded/Utils.js

index 39e16c5..edd0014 100644 (file)
@@ -1,5 +1,33 @@
 2018-03-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LayoutReloaded] Remove all FormattingContext::absolute*Box functions.
+        https://bugs.webkit.org/show_bug.cgi?id=184215
+
+        Reviewed by Antti Koivisto.
+
+        Use Display.Box instead.
+
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+        (BlockFormattingContext.prototype._computeOutOfFlowPosition):
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype._availableSpace):
+        (FloatingContext.prototype._adjustedFloatingPosition):
+        (FloatingContext.prototype._mapBorderBoxToFormattingRoot):
+        (FloatingContext.prototype._mapContentBoxToFormattingRoot):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext.prototype.absoluteBorderBox): Deleted.
+        (FormattingContext.prototype.absolutePaddingBox): Deleted.
+        (FormattingContext.prototype.absoluteContentBox): Deleted.
+        (FormattingContext.prototype._toAbsolutePosition): Deleted.
+        (FormattingContext.prototype._toRootAbsolutePosition): Deleted.
+        * LayoutReloaded/Utils.js:
+        (Utils.mapPosition):
+        (Utils.marginBox):
+        (Utils.borderBox):
+        (Utils.contentBox):
+
+2018-03-31  Zalan Bujtas  <zalan@apple.com>
+
         [LayoutReloaded] Remove FormattingContext::absoluteMarginBox
         https://bugs.webkit.org/show_bug.cgi?id=184213
 
index 4be0688..963ae91 100644 (file)
@@ -321,8 +321,10 @@ class BlockFormattingContext extends FormattingContext {
             let contentBottom = previousInFlowSibling ? this.displayBox(previousInFlowSibling).bottom() : parentDisplayBox.contentBox().top();
             top = contentBottom + this.marginTop(layoutBox);
             // Convert static position (in parent coordinate system) to absolute (in containing block coordindate system).
-            if (parent != layoutBox.containingBlock())
-                top += this._toAbsolutePosition(parentDisplayBox.topLeft(), parent, layoutBox.containingBlock()).top();
+            if (parent != layoutBox.containingBlock()) {
+                ASSERT(displayBox.parent() == this.displayBox(layoutBox.containingBlock()));
+                top += Utils.mapPosition(parentDisplayBox.topLeft(), parentDisplayBox, displayBox.parent()).top();
+            }
         } else if (!Utils.isTopAuto(layoutBox))
             top = Utils.top(layoutBox) + this.marginTop(layoutBox);
         else if (!Utils.isBottomAuto(layoutBox))
@@ -339,8 +341,10 @@ class BlockFormattingContext extends FormattingContext {
             let parentDisplayBox = this.displayBox(parent);
             left = parentDisplayBox.contentBox().left() + this.marginLeft(layoutBox);
             // Convert static position (in parent coordinate system) to absolute (in containing block coordindate system).
-            if (parent != layoutBox.containingBlock())
-                left += this._toAbsolutePosition(parentDisplayBox.rect(), parent, layoutBox.containingBlock()).left();
+            if (parent != layoutBox.containingBlock()) {
+                ASSERT(displayBox.parent() == this.displayBox(layoutBox.containingBlock()));
+                left += Utils.mapPosition(parentDisplayBox.topLeft(), parentDisplayBox, displayBox.parent()).left();
+            }
         } else if (!Utils.isLeftAuto(layoutBox))
             left = Utils.left(layoutBox) + this.marginLeft(layoutBox);
         else if (!Utils.isRightAuto(layoutBox))
index ea26abc..d7f41f4 100644 (file)
@@ -127,7 +127,7 @@ class FloatingContext {
         if (floatingPair.left && floatingPair.right)
             return floatingPair.right.left() - floatingPair.left.right();
         if (floatingPair.left)
-            return containingBlockContentBox.width() - (floatingPair.left.right() - this._formattingContext().absoluteBorderBox(containingBlock).left());
+            return containingBlockContentBox.width() - (floatingPair.left.right() - this._mapBorderBoxToFormattingRoot(containingBlock).left());
         if (floatingPair.right)
             return floatingPair.right.left();
         return containingBlockContentBox.width();
@@ -146,8 +146,8 @@ class FloatingContext {
     _adjustedFloatingPosition(floatingBox, verticalPosition, leftRightFloatings) {
         let containingBlock = floatingBox.containingBlock();
         // Convert all coordinates relative to formatting context's root.
-        let left = this._formattingContext().absoluteContentBox(containingBlock).left();
-        let right = this._formattingContext().absoluteContentBox(containingBlock).right();
+        let left = this._mapContentBoxToFormattingRoot(containingBlock).left();
+        let right = this._mapContentBoxToFormattingRoot(containingBlock).right();
         if (leftRightFloatings) {
             if (leftRightFloatings.left) {
                 let floatingBoxRight = leftRightFloatings.left.right();
@@ -165,8 +165,8 @@ class FloatingContext {
         right -= this._formattingContext().marginRight(floatingBox);
         verticalPosition += this._formattingContext().marginTop(floatingBox);
         // No convert them back relative to the floatingBox's containing block.
-        let containingBlockLeft = this._formattingContext().absoluteBorderBox(containingBlock).left();
-        let containingBlockTop = this._formattingContext().absoluteBorderBox(containingBlock).top();
+        let containingBlockLeft = this._mapBorderBoxToFormattingRoot(containingBlock).left();
+        let containingBlockTop = this._mapBorderBoxToFormattingRoot(containingBlock).top();
         left -= containingBlockLeft;
         right -= containingBlockLeft;
         verticalPosition -= containingBlockTop;
@@ -198,6 +198,18 @@ class FloatingContext {
         return Utils.marginBox(displayBox, rootDisplayBox);
     }
 
+    _mapBorderBoxToFormattingRoot(layoutBox) {
+        let displayBox = this._formattingState().displayBox(layoutBox);
+        let rootDisplayBox = this._formattingState().displayBox(this._formattingRoot());
+        return Utils.borderBox(displayBox, rootDisplayBox);
+    }
+
+    _mapContentBoxToFormattingRoot(layoutBox) {
+        let displayBox = this._formattingState().displayBox(layoutBox);
+        let rootDisplayBox = this._formattingState().displayBox(this._formattingRoot());
+        return Utils.contentBox(displayBox, rootDisplayBox);
+    }
+
     _floatingState() {
         return this.m_floatingState;
     }
index 13f912a..f521f05 100644 (file)
@@ -72,44 +72,6 @@ class FormattingContext {
         return Utils.computedMarginRight(layoutBox.node());
     }
 
-    absoluteBorderBox(layoutBox) {
-        let borderBox = this.displayBox(layoutBox).borderBox();
-        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox), borderBox.size());
-        absoluteRect.moveBy(borderBox.topLeft());
-        return absoluteRect;
-    }
-
-    absolutePaddingBox(layoutBox) {
-        let paddingBox = this.displayBox(layoutBox).paddingBox();
-        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox), paddingBox.size());
-        absoluteRect.moveBy(paddingBox.topLeft());
-        return absoluteRect;
-    }
-
-    absoluteContentBox(layoutBox) {
-        let contentBox = this.displayBox(layoutBox).contentBox();
-        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox), contentBox.size());
-        absoluteRect.moveBy(contentBox.topLeft());
-        return absoluteRect;
-    }
-
-    _toAbsolutePosition(position, layoutBox, container) {
-        // We should never need to go beyond the root container.
-        ASSERT(container == this.formattingRoot() || container.isDescendantOf(this.formattingRoot()));
-        let absolutePosition = position;
-        let ascendant = layoutBox.containingBlock();
-        while (ascendant && ascendant != container) {
-            ASSERT(ascendant.isDescendantOf(this.formattingRoot()));
-            absolutePosition.moveBy(this.displayBox(ascendant).topLeft());
-            ascendant = ascendant.containingBlock();
-        }
-        return absolutePosition;
-    }
-
-    _toRootAbsolutePosition(layoutBox) {
-        return this._toAbsolutePosition(this.displayBox(layoutBox).topLeft(), layoutBox, this.formattingRoot());
-    }
-
     _descendantNeedsLayout() {
         return this.m_layoutStack.length;
     }
index b53f9c9..2e61228 100644 (file)
@@ -475,18 +475,36 @@ class Utils {
         return window.getComputedStyle(node).float == "left";
     }
 
-    static marginBox(box, container) {
+    static mapPosition(position, box, container) {
         ASSERT(box instanceof Display.Box);
         ASSERT(container instanceof Display.Box);
 
-        let marginBox = box.marginBox();
         if (box == container)
-            return marginBox;
+            return position;
         for (let ascendant = box.parent(); ascendant && ascendant != container; ascendant = ascendant.parent())
-            marginBox.moveBy(ascendant.topLeft());
-        return marginBox;
+            position.moveBy(ascendant.topLeft());
+        return position;
     }
 
+    static marginBox(box, container) {
+        let marginBox = box.marginBox();
+        let mappedPosition = Utils.mapPosition(marginBox.topLeft(), box, container);
+        return new LayoutRect(mappedPosition, marginBox.size());
+    }
+
+    static borderBox(box, container) {
+        let borderBox = box.borderBox();
+        let mappedPosition = Utils.mapPosition(box.topLeft(), box, container);
+        mappedPosition.moveBy(borderBox.topLeft());
+        return new LayoutRect(mappedPosition, borderBox.size());
+    }
+
+    static contentBox(box, container) {
+        let contentBox = box.contentBox();
+        let mappedPosition = Utils.mapPosition(box.topLeft(), box, container);
+        mappedPosition.moveBy(contentBox.topLeft());
+        return new LayoutRect(mappedPosition, contentBox.size());
+    }
 
     static textRuns(text, container) {
         return window.collectTextRuns(text, container.node());