[LayoutReloaded] Do not clone Display.Box for FloatingState stacks.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 02:24:32 +0000 (02:24 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 02:24:32 +0000 (02:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184218

Reviewed by Antti Koivisto.

Now that Display.Box is in a tree context, we can't just clone it for the purpose of caching its absolute position.

* LayoutReloaded/DisplayTree/Box.js:
(Display.Box.prototype.clone): Deleted.
* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype._positionForFloating):
(FloatingContext.prototype._moveToNextVerticalPosition):
(FloatingContext.prototype._availableSpace):
(FloatingContext.prototype._findFloatingAtVerticalPosition):
(FloatingContext.prototype._adjustedFloatingPosition):
(FloatingContext.prototype._bottom):
(FloatingContext.prototype._addFloatingBox):
(FloatingContext.prototype._mapMarginBoxToFormattingRoot):
(FloatingContext.prototype._mapDisplayMarginBoxToFormattingRoot):
* LayoutReloaded/FormattingState/FloatingState.js:
(FloatingState.prototype.addFloating):

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

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

index edd0014..826a4c5 100644 (file)
@@ -1,5 +1,29 @@
 2018-03-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LayoutReloaded] Do not clone Display.Box for FloatingState stacks.
+        https://bugs.webkit.org/show_bug.cgi?id=184218
+
+        Reviewed by Antti Koivisto.
+
+        Now that Display.Box is in a tree context, we can't just clone it for the purpose of caching its absolute position.
+
+        * LayoutReloaded/DisplayTree/Box.js:
+        (Display.Box.prototype.clone): Deleted.
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype._positionForFloating):
+        (FloatingContext.prototype._moveToNextVerticalPosition):
+        (FloatingContext.prototype._availableSpace):
+        (FloatingContext.prototype._findFloatingAtVerticalPosition):
+        (FloatingContext.prototype._adjustedFloatingPosition):
+        (FloatingContext.prototype._bottom):
+        (FloatingContext.prototype._addFloatingBox):
+        (FloatingContext.prototype._mapMarginBoxToFormattingRoot):
+        (FloatingContext.prototype._mapDisplayMarginBoxToFormattingRoot):
+        * LayoutReloaded/FormattingState/FloatingState.js:
+        (FloatingState.prototype.addFloating):
+
+2018-03-31  Zalan Bujtas  <zalan@apple.com>
+
         [LayoutReloaded] Remove all FormattingContext::absolute*Box functions.
         https://bugs.webkit.org/show_bug.cgi?id=184215
 
index 47ed150..ed54087 100644 (file)
@@ -40,12 +40,6 @@ Display.Box = class Box {
         this.m_lastChild = null;
     }
 
-    clone() {
-        let cloneBox = new Display.Box(this.m_node);
-        cloneBox.setRect(this.rect());
-        return cloneBox;
-    }
-
     setRect(rect) {
         return this.m_rect = rect;
     }
index d7f41f4..4d58a2a 100644 (file)
@@ -61,7 +61,7 @@ class FloatingContext {
         let absoluteFloatingBox = this._mapMarginBoxToFormattingRoot(floatingBox);
         if (this._isEmpty())
             return this._adjustedFloatingPosition(floatingBox, absoluteFloatingBox.top());
-        let verticalPosition = Math.max(absoluteFloatingBox.top(), this._lastFloating().top());
+        let verticalPosition = Math.max(absoluteFloatingBox.top(), this._mapDisplayMarginBoxToFormattingRoot(this._lastFloating()).top());
         let spaceNeeded = absoluteFloatingBox.width();
         while (true) {
             let floatingPair = this._findInnerMostLeftAndRight(verticalPosition);
@@ -116,9 +116,9 @@ class FloatingContext {
         let leftBottom = Number.POSITIVE_INFINITY;
         let rightBottom = Number.POSITIVE_INFINITY;
         if (floatingPair.left)
-            leftBottom = floatingPair.left.bottom();
+            leftBottom = this._mapDisplayMarginBoxToFormattingRoot(floatingPair.left).bottom();
         if (floatingPair.right)
-            rightBottom = floatingPair.right.bottom();
+            rightBottom = this._mapDisplayMarginBoxToFormattingRoot(floatingPair.right).bottom();
         return Math.min(leftBottom, rightBottom);
     }
 
@@ -126,16 +126,17 @@ class FloatingContext {
         let containingBlockContentBox = this._formattingContext().displayBox(containingBlock);
         if (floatingPair.left && floatingPair.right)
             return floatingPair.right.left() - floatingPair.left.right();
-        if (floatingPair.left)
-            return containingBlockContentBox.width() - (floatingPair.left.right() - this._mapBorderBoxToFormattingRoot(containingBlock).left());
+        if (floatingPair.left) {
+            return containingBlockContentBox.width() - (this._mapDisplayMarginBoxToFormattingRoot(floatingPair.left).right() - this._mapBorderBoxToFormattingRoot(containingBlock).left());
+        }
         if (floatingPair.right)
-            return floatingPair.right.left();
+            return this._mapDisplayMarginBoxToFormattingRoot(floatingPair.right).left();
         return containingBlockContentBox.width();
     }
 
     _findFloatingAtVerticalPosition(verticalPosition, floatingStack) {
         let index = floatingStack.length;
-        while (--index >= 0 && floatingStack[index].bottom() <= verticalPosition);
+        while (--index >= 0 && this._mapDisplayMarginBoxToFormattingRoot(floatingStack[index]).bottom() <= verticalPosition);
         return index >= 0 ? floatingStack[index] : null;
     }
 
@@ -150,13 +151,13 @@ class FloatingContext {
         let right = this._mapContentBoxToFormattingRoot(containingBlock).right();
         if (leftRightFloatings) {
             if (leftRightFloatings.left) {
-                let floatingBoxRight = leftRightFloatings.left.right();
+                let floatingBoxRight = this._mapDisplayMarginBoxToFormattingRoot(leftRightFloatings.left).right();
                 if (floatingBoxRight > left)
                     left = floatingBoxRight;
             }
 
             if (leftRightFloatings.right) {
-                let floatingBoxLeft = leftRightFloatings.right.left();
+                let floatingBoxLeft = this._mapDisplayMarginBoxToFormattingRoot(leftRightFloatings.right).left();
                 if (floatingBoxLeft < right)
                     right = floatingBoxLeft;
             }
@@ -181,21 +182,22 @@ class FloatingContext {
             return Number.NaN;
         let max = Number.NEGATIVE_INFINITY;
         for (let i = 0; i < floatingStack.length; ++i)
-            max = Math.max(floatingStack[i].bottom(), max);
+            max = Math.max(this._mapDisplayMarginBoxToFormattingRoot(floatingStack[i]).bottom(), max);
         return max;
     }
 
     _addFloatingBox(layoutBox) {
-        // Convert floating box to absolute.
-        let clonedDisplayBox = this._formattingContext().displayBox(layoutBox).clone();
-        clonedDisplayBox.setRect(this._mapMarginBoxToFormattingRoot(layoutBox));
-        this._floatingState().addFloating(layoutBox, clonedDisplayBox);
+        this._floatingState().addFloating(this._formattingContext().displayBox(layoutBox), Utils.isFloatingLeft(layoutBox));
     }
 
     _mapMarginBoxToFormattingRoot(layoutBox) {
-        let displayBox = this._formattingState().displayBox(layoutBox);
-        let rootDisplayBox = this._formattingState().displayBox(this._formattingRoot());
-        return Utils.marginBox(displayBox, rootDisplayBox);
+        ASSERT(layoutBox instanceof Layout.Box);
+        return this._mapDisplayMarginBoxToFormattingRoot(this._formattingState().displayBox(layoutBox));
+    }
+
+    _mapDisplayMarginBoxToFormattingRoot(displayBox) {
+        ASSERT(displayBox instanceof Display.Box);
+        return Utils.marginBox(displayBox, this._formattingState().displayBox(this._formattingRoot()));
     }
 
     _mapBorderBoxToFormattingRoot(layoutBox) {
index e75498a..9933800 100644 (file)
@@ -31,9 +31,9 @@ class FloatingState {
         this.m_lastFloating = null;
     }
 
-    addFloating(layoutBox, displayBox) {
+    addFloating(displayBox, isFloatingLeft) {
         this.m_lastFloating = displayBox;
-        if (Utils.isFloatingLeft(layoutBox)) {
+        if (isFloatingLeft) {
             this.m_leftFloatingBoxStack.push(displayBox);
             return;
         }