[LayoutReloaded] Remove FormattingContext::absoluteMarginBox
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 01:12:13 +0000 (01:12 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Apr 2018 01:12:13 +0000 (01:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184213

Reviewed by Antti Koivisto.

Display.Box already has the margin values.

* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype._positionForFloating):
(FloatingContext.prototype._addFloatingBox):
(FloatingContext.prototype._mapMarginBoxToFormattingRoot):
(FloatingContext.prototype._formattingRoot):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext.prototype.absoluteMarginBox): Deleted.
* LayoutReloaded/Utils.js:
(Utils.marginBox):

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

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

index 129efda..39e16c5 100644 (file)
@@ -1,5 +1,24 @@
 2018-03-31  Zalan Bujtas  <zalan@apple.com>
 
+        [LayoutReloaded] Remove FormattingContext::absoluteMarginBox
+        https://bugs.webkit.org/show_bug.cgi?id=184213
+
+        Reviewed by Antti Koivisto.
+
+        Display.Box already has the margin values.
+
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype._positionForFloating):
+        (FloatingContext.prototype._addFloatingBox):
+        (FloatingContext.prototype._mapMarginBoxToFormattingRoot):
+        (FloatingContext.prototype._formattingRoot):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext.prototype.absoluteMarginBox): Deleted.
+        * LayoutReloaded/Utils.js:
+        (Utils.marginBox):
+
+2018-03-31  Zalan Bujtas  <zalan@apple.com>
+
         [layoutReloaded] Introduce margin to Display.Box
         https://bugs.webkit.org/show_bug.cgi?id=184212
 
index f434d0e..ea26abc 100644 (file)
@@ -58,7 +58,7 @@ class FloatingContext {
     }
 
     _positionForFloating(floatingBox) {
-        let absoluteFloatingBox = this._formattingContext().absoluteMarginBox(floatingBox);
+        let absoluteFloatingBox = this._mapMarginBoxToFormattingRoot(floatingBox);
         if (this._isEmpty())
             return this._adjustedFloatingPosition(floatingBox, absoluteFloatingBox.top());
         let verticalPosition = Math.max(absoluteFloatingBox.top(), this._lastFloating().top());
@@ -188,10 +188,16 @@ class FloatingContext {
     _addFloatingBox(layoutBox) {
         // Convert floating box to absolute.
         let clonedDisplayBox = this._formattingContext().displayBox(layoutBox).clone();
-        clonedDisplayBox.setRect(this._formattingContext().absoluteMarginBox(layoutBox));
+        clonedDisplayBox.setRect(this._mapMarginBoxToFormattingRoot(layoutBox));
         this._floatingState().addFloating(layoutBox, clonedDisplayBox);
     }
 
+    _mapMarginBoxToFormattingRoot(layoutBox) {
+        let displayBox = this._formattingState().displayBox(layoutBox);
+        let rootDisplayBox = this._formattingState().displayBox(this._formattingRoot());
+        return Utils.marginBox(displayBox, rootDisplayBox);
+    }
+
     _floatingState() {
         return this.m_floatingState;
     }
@@ -200,6 +206,10 @@ class FloatingContext {
         return this.m_parentFormattingContext;
     }
 
+    _formattingRoot() {
+        return this._formattingState().formattingRoot();
+    }
+
     _formattingState() {
         return this._floatingState().formattingState();
     }
index c1455d4..13f912a 100644 (file)
@@ -72,14 +72,6 @@ class FormattingContext {
         return Utils.computedMarginRight(layoutBox.node());
     }
 
-    absoluteMarginBox(layoutBox) {
-        let displayBox = this.displayBox(layoutBox);
-        let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox), displayBox.borderBox().size());
-        absoluteRect.moveBy(new LayoutSize(-displayBox.marginLeft(), -displayBox.marginTop()));
-        absoluteRect.growBy(new LayoutSize(displayBox.marginLeft() + displayBox.marginRight(), displayBox.marginTop() + displayBox.marginBottom()));
-        return absoluteRect;
-    }
-
     absoluteBorderBox(layoutBox) {
         let borderBox = this.displayBox(layoutBox).borderBox();
         let absoluteRect = new LayoutRect(this._toRootAbsolutePosition(layoutBox), borderBox.size());
index 6537066..b53f9c9 100644 (file)
@@ -475,6 +475,19 @@ class Utils {
         return window.getComputedStyle(node).float == "left";
     }
 
+    static marginBox(box, container) {
+        ASSERT(box instanceof Display.Box);
+        ASSERT(container instanceof Display.Box);
+
+        let marginBox = box.marginBox();
+        if (box == container)
+            return marginBox;
+        for (let ascendant = box.parent(); ascendant && ascendant != container; ascendant = ascendant.parent())
+            marginBox.moveBy(ascendant.topLeft());
+        return marginBox;
+    }
+
+
     static textRuns(text, container) {
         return window.collectTextRuns(text, container.node());
     }