Title: [230065] trunk/Tools
Revision
230065
Author
za...@apple.com
Date
2018-03-28 20:27:58 -0700 (Wed, 28 Mar 2018)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (230064 => 230065)


--- trunk/Tools/ChangeLog	2018-03-29 02:39:35 UTC (rev 230064)
+++ trunk/Tools/ChangeLog	2018-03-29 03:27:58 UTC (rev 230065)
@@ -1,3 +1,27 @@
+2018-03-28  Zalan Bujtas  <za...@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  <cdu...@apple.com>
 
         Unreviewed iOS build fix after r230060.

Modified: trunk/Tools/LayoutReloaded/DisplayTree/Box.js (230064 => 230065)


--- trunk/Tools/LayoutReloaded/DisplayTree/Box.js	2018-03-29 02:39:35 UTC (rev 230064)
+++ trunk/Tools/LayoutReloaded/DisplayTree/Box.js	2018-03-29 03:27:58 UTC (rev 230065)
@@ -31,9 +31,19 @@
         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();

Modified: trunk/Tools/LayoutReloaded/FormattingContext/FloatingContext.js (230064 => 230065)


--- trunk/Tools/LayoutReloaded/FormattingContext/FloatingContext.js	2018-03-29 02:39:35 UTC (rev 230064)
+++ trunk/Tools/LayoutReloaded/FormattingContext/FloatingContext.js	2018-03-29 03:27:58 UTC (rev 230065)
@@ -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 @@
             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 @@
     }
 
     _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 @@
     }
 
     _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,9 +130,9 @@
         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);
     }
 
@@ -134,17 +139,17 @@
     _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 @@
         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 @@
             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;
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to