[LayoutReloaded] Convert floating left/right stack display boxes absolute to the...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2018 03:27:58 +0000 (03:27 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2018 03:27:58 +0000 (03:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184123

Reviewed by Antti Koivisto.

1. The left/right floating array should hold the Display.Box (and not the Layout.Box)
2. Clone the Display.Box and convert its rect absolute to the formatting context's root so that we
don't have to keep converting the coordinates while computing the positions.

* LayoutReloaded/DisplayTree/Box.js:
(Display.Box.prototype.clone):
(Display.Box.prototype.setRect):
* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype.computePosition):
(FloatingContext.prototype._positionForFloating):
(FloatingContext.prototype._addFloating):
(FloatingContext.prototype._moveToNextVerticalPosition):
(FloatingContext.prototype._availableSpace):
(FloatingContext.prototype._findFloatingAtVerticalPosition):
(FloatingContext.prototype._adjustedFloatingPosition):
(FloatingContext.prototype._bottom):

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

Tools/ChangeLog
Tools/LayoutReloaded/DisplayTree/Box.js
Tools/LayoutReloaded/FormattingContext/FloatingContext.js

index 365c238ffbdeb9fb5373fdcbe644cc5bf7124329..12ebc1d7abd50249337347a82646d7630527bc08 100644 (file)
@@ -1,3 +1,27 @@
+2018-03-28  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutReloaded] Convert floating left/right stack display boxes absolute to the formatting context's root.
+        https://bugs.webkit.org/show_bug.cgi?id=184123
+
+        Reviewed by Antti Koivisto.
+
+        1. The left/right floating array should hold the Display.Box (and not the Layout.Box)
+        2. Clone the Display.Box and convert its rect absolute to the formatting context's root so that we
+        don't have to keep converting the coordinates while computing the positions. 
+
+        * LayoutReloaded/DisplayTree/Box.js:
+        (Display.Box.prototype.clone):
+        (Display.Box.prototype.setRect):
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype.computePosition):
+        (FloatingContext.prototype._positionForFloating):
+        (FloatingContext.prototype._addFloating):
+        (FloatingContext.prototype._moveToNextVerticalPosition):
+        (FloatingContext.prototype._availableSpace):
+        (FloatingContext.prototype._findFloatingAtVerticalPosition):
+        (FloatingContext.prototype._adjustedFloatingPosition):
+        (FloatingContext.prototype._bottom):
+
 2018-03-28  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed iOS build fix after r230060.
index 67ef0a600d89472cf861f1893ef3b49ef9c889fc..45abba62bfe5546ec02a6f89fd40dcdd303f9831 100644 (file)
@@ -31,9 +31,19 @@ Display.Box = class Box {
         this.m_rect = new LayoutRect(new LayoutPoint(0, 0), new LayoutSize(0, 0));
     }
 
+    clone() {
+        let cloneBox = new Display.Box(this.m_node);
+        cloneBox.setRect(this.rect());
+        return cloneBox;
+    }
+
     rect() {
         return this.m_rect.clone();
     }
+
+    setRect(rect) {
+        return this.m_rect = rect;
+    }
     
     top() {
         return this.rect().top();
index 59cef9ffd44d19df6f1e89b31e8f00eeeda1db52..5572d85396ddd89f422d43b8f5a2c077bccc7b84 100644 (file)
@@ -23,6 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// All geometry here is absolute to the formatting context's root.
 class FloatingContext {
     constructor(formattingContext) {
         this.m_leftFloatingBoxStack = new Array();
@@ -36,9 +37,9 @@ class FloatingContext {
             return;
         let displayBox = this._formattingContext().displayBox(layoutBox);
         if (layoutBox.isFloatingPositioned()) {
-            let position = this._positionForFloating(layoutBox);
+            displayBox.setTopLeft(this._positionForFloating(layoutBox));
             this._addFloating(layoutBox);
-            return displayBox.setTopLeft(position);
+            return;
         }
         if (Utils.hasClear(layoutBox))
             return displayBox.setTopLeft(this._positionForClear(layoutBox));
@@ -59,10 +60,11 @@ class FloatingContext {
     }
 
     _positionForFloating(floatingBox) {
+        let absoluteFloatingBox = this._formattingContext().absoluteMarginBox(floatingBox);
         if (this._isEmpty())
-            return this._adjustedFloatingPosition(floatingBox, this._formattingContext().absoluteMarginBox(floatingBox).top());
-        let verticalPosition = Math.max(this._formattingContext().absoluteMarginBox(floatingBox).top(), this._formattingContext().absoluteMarginBox(this.m_lastFloating).top());
-        let spaceNeeded = this._formattingContext().absoluteMarginBox(floatingBox).width();
+            return this._adjustedFloatingPosition(floatingBox, absoluteFloatingBox.top());
+        let verticalPosition = Math.max(absoluteFloatingBox.top(), this.m_lastFloating.top());
+        let spaceNeeded = absoluteFloatingBox.width();
         while (true) {
             let floatingPair = this._findInnerMostLeftAndRight(verticalPosition);
             if (this._availableSpace(floatingBox.containingBlock(), floatingPair) >= spaceNeeded)
@@ -105,12 +107,15 @@ class FloatingContext {
     }
 
     _addFloating(floatingBox) {
-        this.m_lastFloating = floatingBox;
+        // Convert floating box to absolute.
+        let floatingDisplayBox = this._formattingContext().displayBox(floatingBox).clone();
+        floatingDisplayBox.setRect(this._formattingContext().absoluteMarginBox(floatingBox));
+        this.m_lastFloating = floatingDisplayBox;
         if (Utils.isFloatingLeft(floatingBox)) {
-            this.m_leftFloatingBoxStack.push(floatingBox);
+            this.m_leftFloatingBoxStack.push(floatingDisplayBox);
             return;
         }
-        this.m_rightFloatingBoxStack.push(floatingBox);
+        this.m_rightFloatingBoxStack.push(floatingDisplayBox);
     }
 
     _findInnerMostLeftAndRight(verticalPosition) {
@@ -125,26 +130,26 @@ class FloatingContext {
         let leftBottom = Number.POSITIVE_INFINITY;
         let rightBottom = Number.POSITIVE_INFINITY;
         if (floatingPair.left)
-            leftBottom = this._formattingContext().absoluteMarginBox(floatingPair.left).bottom();
+            leftBottom = floatingPair.left.bottom();
         if (floatingPair.right)
-            rightBottom = this._formattingContext().absoluteMarginBox(floatingPair.right).bottom();
+            rightBottom = floatingPair.right.bottom();
         return Math.min(leftBottom, rightBottom);
     }
 
     _availableSpace(containingBlock, floatingPair) {
         let containingBlockContentBox = this._formattingContext().displayBox(containingBlock);
         if (floatingPair.left && floatingPair.right)
-            return this._formattingContext().absoluteMarginBox(floatingPair.right).left() - this._formattingContext().absoluteMarginBox(floatingPair.left).right();
+            return floatingPair.right.left() - floatingPair.left.right();
         if (floatingPair.left)
-            return containingBlockContentBox.width() - (this._formattingContext().absoluteMarginBox(floatingPair.left).right() - this._formattingContext().absoluteBorderBox(containingBlock).left());
+            return containingBlockContentBox.width() - (floatingPair.left.right() - this._formattingContext().absoluteBorderBox(containingBlock).left());
         if (floatingPair.right)
-            return this._formattingContext().absoluteMarginBox(floatingPair.right).left();
+            return floatingPair.right.left();
         return containingBlockContentBox.width();
     }
 
     _findFloatingAtVerticalPosition(verticalPosition, floatingStack) {
         let index = floatingStack.length;
-        while (--index >= 0 && this._formattingContext().absoluteMarginBox(floatingStack[index]).bottom() <= verticalPosition);
+        while (--index >= 0 && floatingStack[index].bottom() <= verticalPosition);
         return index >= 0 ? floatingStack[index] : null;
     }
 
@@ -159,13 +164,13 @@ class FloatingContext {
         let right = this._formattingContext().absoluteContentBox(containingBlock).right();
         if (leftRightFloatings) {
             if (leftRightFloatings.left) {
-                let floatingBoxRight = this._formattingContext().absoluteMarginBox(leftRightFloatings.left).right();
+                let floatingBoxRight = leftRightFloatings.left.right();
                 if (floatingBoxRight > left)
                     left = floatingBoxRight;
             }
 
             if (leftRightFloatings.right) {
-                let floatingBoxLeft = this._formattingContext().absoluteMarginBox(leftRightFloatings.right).left();
+                let floatingBoxLeft = leftRightFloatings.right.left();
                 if (floatingBoxLeft < right)
                     right = floatingBoxLeft;
             }
@@ -190,7 +195,7 @@ class FloatingContext {
             return Number.NaN;
         let max = Number.NEGATIVE_INFINITY;
         for (let i = 0; i < floatingStack.length; ++i)
-            max = Math.max(this._formattingContext().absoluteMarginBox(floatingStack[i]).bottom(), max);
+            max = Math.max(floatingStack[i].bottom(), max);
         return max;
     }