[LayoutReloaded] Introduce Layout namespace
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2018 15:59:46 +0000 (15:59 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2018 15:59:46 +0000 (15:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183659

Reviewed by Antti Koivisto.

This is in preparation for introducing the display tree.
Box -> Layout.Box

* LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
(BlockFormattingContext.prototype.layout):
(BlockFormattingContext.prototype.computeWidth):
(BlockFormattingContext.prototype.computeHeight):
(BlockFormattingContext.prototype.marginTop):
(BlockFormattingContext.prototype.marginBottom):
(BlockFormattingContext.prototype._computeStaticPosition):
(BlockFormattingContext.prototype._placeInFlowPositionedChildren):
(BlockFormattingContext.prototype._placeOutOfFlowDescendants):
(BlockFormattingContext.prototype._computeOutOfFlowWidth):
(BlockFormattingContext.prototype._computeFloatingWidth):
(BlockFormattingContext.prototype._computeInFlowWidth):
(BlockFormattingContext.prototype._computeOutOfFlowHeight):
(BlockFormattingContext.prototype._computeFloatingHeight):
(BlockFormattingContext.prototype._computeInFlowHeight):
(BlockFormattingContext.prototype._horizontalConstraint):
(BlockFormattingContext.prototype._contentHeight):
(BlockFormattingContext.prototype._adjustBottomWithFIXME):
(BlockFormattingContext.prototype._computeInFlowPositionedPosition):
(BlockFormattingContext.prototype._computeOutOfFlowPosition):
(BlockFormattingContext.prototype._shrinkToFitWidth):
(BlockFormattingContext):
(BlockFormattingContext.prototype._computeHorizontalConstraint): Deleted.
(BlockFormattingContext.prototype._computeContentHeight): Deleted.
* LayoutReloaded/FormattingContext/BlockFormatting/BlockMarginCollapse.js:
(BlockMarginCollapse.marginTop):
(BlockMarginCollapse.marginBottom):
(BlockMarginCollapse._isMarginTopCollapsedWithSibling):
(BlockMarginCollapse._isMarginBottomCollapsedWithSibling):
(BlockMarginCollapse._isMarginTopCollapsedWithParent):
(BlockMarginCollapse._isMarginBottomCollapsedWithParent):
(BlockMarginCollapse._nonCollapsedMarginTop):
(BlockMarginCollapse._nonCollapsedMarginBottom):
(BlockMarginCollapse._collapsedMarginTopFromFirstChild):
(BlockMarginCollapse._collapsedMarginBottomFromLastChild):
(BlockMarginCollapse._hasAdjoiningMarginTopAndBottom):
(BlockMarginCollapse):
* LayoutReloaded/FormattingContext/FloatingContext.js:
(FloatingContext.prototype.computePosition):
(FloatingContext.prototype._positionForClear):
(FloatingContext.prototype._computePositionToAvoidIntrudingFloats):
* LayoutReloaded/FormattingContext/FormattingContext.js:
(FormattingContext.prototype.computeWidth):
(FormattingContext.prototype.computeHeight):
(FormattingContext.prototype.marginTop):
(FormattingContext.prototype.marginLeft):
(FormattingContext.prototype.marginBottom):
(FormattingContext.prototype.marginRight):
(FormattingContext.prototype.absoluteMarginBox):
(FormattingContext.prototype.absoluteBorderBox):
(FormattingContext.prototype.absolutePaddingBox):
(FormattingContext.prototype.absoluteContentBox):
(FormattingContext):
* LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
(InlineFormattingContext.prototype.layout):
* LayoutReloaded/LayoutTree/BlockContainer.js:
(BlockContainer): Deleted.
(BlockContainer.prototype.establishesInlineFormattingContext): Deleted.
* LayoutReloaded/LayoutTree/Box.js:
(Box): Deleted.
(Box.prototype.id): Deleted.
(Box.prototype.setRendererName): Deleted.
(Box.prototype.name): Deleted.
(Box.prototype.node): Deleted.
(Box.prototype.parent): Deleted.
(Box.prototype.nextSibling): Deleted.
(Box.prototype.nextInFlowSibling): Deleted.
(Box.prototype.previousSibling): Deleted.
(Box.prototype.previousInFlowSibling): Deleted.
(Box.prototype.setParent): Deleted.
(Box.prototype.setNextSibling): Deleted.
(Box.prototype.setPreviousSibling): Deleted.
(Box.prototype.rect): Deleted.
(Box.prototype.topLeft): Deleted.
(Box.prototype.bottomRight): Deleted.
(Box.prototype.setTopLeft): Deleted.
(Box.prototype.setSize): Deleted.
(Box.prototype.setWidth): Deleted.
(Box.prototype.setHeight): Deleted.
(Box.prototype.isContainer): Deleted.
(Box.prototype.isBlockLevelBox): Deleted.
(Box.prototype.isBlockContainerBox): Deleted.
(Box.prototype.isInlineLevelBox): Deleted.
(Box.prototype.setIsAnonymous): Deleted.
(Box.prototype.isAnonymous): Deleted.
(Box.prototype.establishesFormattingContext): Deleted.
(Box.prototype.establishedFormattingContext): Deleted.
(Box.prototype.establishesBlockFormattingContext): Deleted.
(Box.prototype.establishesInlineFormattingContext): Deleted.
(Box.prototype.isPositioned): Deleted.
(Box.prototype.isRelativePositioned): Deleted.
(Box.prototype.isAbsolutePositioned): Deleted.
(Box.prototype.isFixedPositioned): Deleted.
(Box.prototype.isInFlow): Deleted.
(Box.prototype.isOutOfFlowPositioned): Deleted.
(Box.prototype.isInFlowPositioned): Deleted.
(Box.prototype.isFloatingPositioned): Deleted.
(Box.prototype.isFloatingOrOutOfFlowPositioned): Deleted.
(Box.prototype.isRootElement): Deleted.
(Box.prototype.containingBlock): Deleted.
(Box.prototype.borderBox): Deleted.
(Box.prototype.paddingBox): Deleted.
(Box.prototype.contentBox): Deleted.
* LayoutReloaded/LayoutTree/Container.js:
(Container): Deleted.
(Container.prototype.isContainer): Deleted.
(Container.prototype.setFirstChild): Deleted.
(Container.prototype.setLastChild): Deleted.
(Container.prototype.firstChild): Deleted.
(Container.prototype.firstInFlowChild): Deleted.
(Container.prototype.lastChild): Deleted.
(Container.prototype.lastInFlowChild): Deleted.
(Container.prototype.hasChild): Deleted.
(Container.prototype.hasInFlowChild): Deleted.
* LayoutReloaded/LayoutTree/InitialBlockContainer.js:
(InitialBlockContainer): Deleted.
(InitialBlockContainer.prototype.establishesBlockFormattingContext): Deleted.
(InitialBlockContainer.prototype.paddingBox): Deleted.
(InitialBlockContainer.prototype.contentBox): Deleted.
* LayoutReloaded/LayoutTree/InlineBox.js:
(InlineBox): Deleted.
(InlineBox.prototype.setText): Deleted.
(InlineBox.prototype.text): Deleted.
* LayoutReloaded/TreeBuilder.js:
(TreeBuilder.prototype.createTree):
(TreeBuilder.prototype._createAndAttachBox):
* LayoutReloaded/Utils.js:
(Utils._dumpBox):

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

13 files changed:
Tools/ChangeLog
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockMarginCollapse.js
Tools/LayoutReloaded/FormattingContext/FloatingContext.js
Tools/LayoutReloaded/FormattingContext/FormattingContext.js
Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js
Tools/LayoutReloaded/LayoutTree/BlockContainer.js
Tools/LayoutReloaded/LayoutTree/Box.js
Tools/LayoutReloaded/LayoutTree/Container.js
Tools/LayoutReloaded/LayoutTree/InitialBlockContainer.js
Tools/LayoutReloaded/LayoutTree/InlineBox.js
Tools/LayoutReloaded/TreeBuilder.js
Tools/LayoutReloaded/Utils.js

index 07c39db..f4eb8d3 100644 (file)
@@ -1,3 +1,142 @@
+2018-03-15  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutReloaded] Introduce Layout namespace
+        https://bugs.webkit.org/show_bug.cgi?id=183659
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for introducing the display tree.
+        Box -> Layout.Box
+
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+        (BlockFormattingContext.prototype.layout):
+        (BlockFormattingContext.prototype.computeWidth):
+        (BlockFormattingContext.prototype.computeHeight):
+        (BlockFormattingContext.prototype.marginTop):
+        (BlockFormattingContext.prototype.marginBottom):
+        (BlockFormattingContext.prototype._computeStaticPosition):
+        (BlockFormattingContext.prototype._placeInFlowPositionedChildren):
+        (BlockFormattingContext.prototype._placeOutOfFlowDescendants):
+        (BlockFormattingContext.prototype._computeOutOfFlowWidth):
+        (BlockFormattingContext.prototype._computeFloatingWidth):
+        (BlockFormattingContext.prototype._computeInFlowWidth):
+        (BlockFormattingContext.prototype._computeOutOfFlowHeight):
+        (BlockFormattingContext.prototype._computeFloatingHeight):
+        (BlockFormattingContext.prototype._computeInFlowHeight):
+        (BlockFormattingContext.prototype._horizontalConstraint):
+        (BlockFormattingContext.prototype._contentHeight):
+        (BlockFormattingContext.prototype._adjustBottomWithFIXME):
+        (BlockFormattingContext.prototype._computeInFlowPositionedPosition):
+        (BlockFormattingContext.prototype._computeOutOfFlowPosition):
+        (BlockFormattingContext.prototype._shrinkToFitWidth):
+        (BlockFormattingContext):
+        (BlockFormattingContext.prototype._computeHorizontalConstraint): Deleted.
+        (BlockFormattingContext.prototype._computeContentHeight): Deleted.
+        * LayoutReloaded/FormattingContext/BlockFormatting/BlockMarginCollapse.js:
+        (BlockMarginCollapse.marginTop):
+        (BlockMarginCollapse.marginBottom):
+        (BlockMarginCollapse._isMarginTopCollapsedWithSibling):
+        (BlockMarginCollapse._isMarginBottomCollapsedWithSibling):
+        (BlockMarginCollapse._isMarginTopCollapsedWithParent):
+        (BlockMarginCollapse._isMarginBottomCollapsedWithParent):
+        (BlockMarginCollapse._nonCollapsedMarginTop):
+        (BlockMarginCollapse._nonCollapsedMarginBottom):
+        (BlockMarginCollapse._collapsedMarginTopFromFirstChild):
+        (BlockMarginCollapse._collapsedMarginBottomFromLastChild):
+        (BlockMarginCollapse._hasAdjoiningMarginTopAndBottom):
+        (BlockMarginCollapse):
+        * LayoutReloaded/FormattingContext/FloatingContext.js:
+        (FloatingContext.prototype.computePosition):
+        (FloatingContext.prototype._positionForClear):
+        (FloatingContext.prototype._computePositionToAvoidIntrudingFloats):
+        * LayoutReloaded/FormattingContext/FormattingContext.js:
+        (FormattingContext.prototype.computeWidth):
+        (FormattingContext.prototype.computeHeight):
+        (FormattingContext.prototype.marginTop):
+        (FormattingContext.prototype.marginLeft):
+        (FormattingContext.prototype.marginBottom):
+        (FormattingContext.prototype.marginRight):
+        (FormattingContext.prototype.absoluteMarginBox):
+        (FormattingContext.prototype.absoluteBorderBox):
+        (FormattingContext.prototype.absolutePaddingBox):
+        (FormattingContext.prototype.absoluteContentBox):
+        (FormattingContext):
+        * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
+        (InlineFormattingContext.prototype.layout):
+        * LayoutReloaded/LayoutTree/BlockContainer.js:
+        (BlockContainer): Deleted.
+        (BlockContainer.prototype.establishesInlineFormattingContext): Deleted.
+        * LayoutReloaded/LayoutTree/Box.js:
+        (Box): Deleted.
+        (Box.prototype.id): Deleted.
+        (Box.prototype.setRendererName): Deleted.
+        (Box.prototype.name): Deleted.
+        (Box.prototype.node): Deleted.
+        (Box.prototype.parent): Deleted.
+        (Box.prototype.nextSibling): Deleted.
+        (Box.prototype.nextInFlowSibling): Deleted.
+        (Box.prototype.previousSibling): Deleted.
+        (Box.prototype.previousInFlowSibling): Deleted.
+        (Box.prototype.setParent): Deleted.
+        (Box.prototype.setNextSibling): Deleted.
+        (Box.prototype.setPreviousSibling): Deleted.
+        (Box.prototype.rect): Deleted.
+        (Box.prototype.topLeft): Deleted.
+        (Box.prototype.bottomRight): Deleted.
+        (Box.prototype.setTopLeft): Deleted.
+        (Box.prototype.setSize): Deleted.
+        (Box.prototype.setWidth): Deleted.
+        (Box.prototype.setHeight): Deleted.
+        (Box.prototype.isContainer): Deleted.
+        (Box.prototype.isBlockLevelBox): Deleted.
+        (Box.prototype.isBlockContainerBox): Deleted.
+        (Box.prototype.isInlineLevelBox): Deleted.
+        (Box.prototype.setIsAnonymous): Deleted.
+        (Box.prototype.isAnonymous): Deleted.
+        (Box.prototype.establishesFormattingContext): Deleted.
+        (Box.prototype.establishedFormattingContext): Deleted.
+        (Box.prototype.establishesBlockFormattingContext): Deleted.
+        (Box.prototype.establishesInlineFormattingContext): Deleted.
+        (Box.prototype.isPositioned): Deleted.
+        (Box.prototype.isRelativePositioned): Deleted.
+        (Box.prototype.isAbsolutePositioned): Deleted.
+        (Box.prototype.isFixedPositioned): Deleted.
+        (Box.prototype.isInFlow): Deleted.
+        (Box.prototype.isOutOfFlowPositioned): Deleted.
+        (Box.prototype.isInFlowPositioned): Deleted.
+        (Box.prototype.isFloatingPositioned): Deleted.
+        (Box.prototype.isFloatingOrOutOfFlowPositioned): Deleted.
+        (Box.prototype.isRootElement): Deleted.
+        (Box.prototype.containingBlock): Deleted.
+        (Box.prototype.borderBox): Deleted.
+        (Box.prototype.paddingBox): Deleted.
+        (Box.prototype.contentBox): Deleted.
+        * LayoutReloaded/LayoutTree/Container.js:
+        (Container): Deleted.
+        (Container.prototype.isContainer): Deleted.
+        (Container.prototype.setFirstChild): Deleted.
+        (Container.prototype.setLastChild): Deleted.
+        (Container.prototype.firstChild): Deleted.
+        (Container.prototype.firstInFlowChild): Deleted.
+        (Container.prototype.lastChild): Deleted.
+        (Container.prototype.lastInFlowChild): Deleted.
+        (Container.prototype.hasChild): Deleted.
+        (Container.prototype.hasInFlowChild): Deleted.
+        * LayoutReloaded/LayoutTree/InitialBlockContainer.js:
+        (InitialBlockContainer): Deleted.
+        (InitialBlockContainer.prototype.establishesBlockFormattingContext): Deleted.
+        (InitialBlockContainer.prototype.paddingBox): Deleted.
+        (InitialBlockContainer.prototype.contentBox): Deleted.
+        * LayoutReloaded/LayoutTree/InlineBox.js:
+        (InlineBox): Deleted.
+        (InlineBox.prototype.setText): Deleted.
+        (InlineBox.prototype.text): Deleted.
+        * LayoutReloaded/TreeBuilder.js:
+        (TreeBuilder.prototype.createTree):
+        (TreeBuilder.prototype._createAndAttachBox):
+        * LayoutReloaded/Utils.js:
+        (Utils._dumpBox):
+
 2018-03-14  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Implement accessible dismiss action on iOS
index 460090d..9b90573 100644 (file)
@@ -47,33 +47,33 @@ class BlockFormattingContext extends FormattingContext {
         while (layoutStack.length) {
             // Travers down on the descendants until we find a leaf node.
             while (true) {
-                let box = layoutStack[layoutStack.length - 1];
-                box.setWidth(this.computeWidth(box));
-                box.setTopLeft(this._computeStaticPosition(box));
-                if (box.establishesFormattingContext()) {
-                    layoutContext.layoutFormattingContext(box.establishedFormattingContext());
+                let layoutBox = layoutStack[layoutStack.length - 1];
+                this.computeWidth(layoutBox);
+                this._computeStaticPosition(layoutBox);
+                if (layoutBox.establishesFormattingContext()) {
+                    layoutContext.layoutFormattingContext(layoutBox.establishedFormattingContext());
                     break;
                 }
-                if (!box.isContainer() || !box.hasChild())
+                if (!layoutBox.isContainer() || !layoutBox.hasChild())
                     break;
-                layoutStack.push(box.firstChild());
+                layoutStack.push(layoutBox.firstChild());
             }
 
             // Climb back on the ancestors and compute height/final position.
             while (layoutStack.length) {
                 // All inflow descendants (if there are any) are laid out by now. Let's compute the box's height.
-                let box = layoutStack.pop();
-                box.setHeight(this.computeHeight(box));
+                let layoutBox = layoutStack.pop();
+                this.computeHeight(layoutBox);
                 // Adjust position now that we have all the previous floats placed in this context -if needed.
-                box.setTopLeft(this.floatingContext().computePosition(box));
+                this.floatingContext().computePosition(layoutBox);
                 // Move positioned children to their final position.
-                if (box.isContainer()) {
-                    this._placeInFlowPositionedChildren(box);
+                if (layoutBox.isContainer()) {
+                    this._placeInFlowPositionedChildren(layoutBox);
                     // Place the out of flow content.
-                    this._placeOutOfFlowDescendants(box);
+                    this._placeOutOfFlowDescendants(layoutBox);
                 }
-                if (box.nextSibling()) {
-                    layoutStack.push(box.nextSibling());
+                if (layoutBox.nextSibling()) {
+                    layoutStack.push(layoutBox.nextSibling());
                     break;
                 }
             }
@@ -82,55 +82,55 @@ class BlockFormattingContext extends FormattingContext {
         this._placeOutOfFlowDescendants(this.rootContainer());
    }
 
-    computeWidth(box) {
-        if (box.isOutOfFlowPositioned())
-            return this._computeOutOfFlowWidth(box);
-        if (box.isFloatingPositioned())
-            return this._computeFloatingWidth(box);
-        return this._computeInFlowWidth(box);
+    computeWidth(layoutBox) {
+        if (layoutBox.isOutOfFlowPositioned())
+            return this._computeOutOfFlowWidth(layoutBox);
+        if (layoutBox.isFloatingPositioned())
+            return this._computeFloatingWidth(layoutBox);
+        return this._computeInFlowWidth(layoutBox);
     }
 
-    computeHeight(box) {
-        if (box.isOutOfFlowPositioned())
-            return this._computeOutOfFlowHeight(box);
-        if (box.isFloatingPositioned())
-            return this._computeFloatingHeight(box);
-        return this._computeInFlowHeight(box);
+    computeHeight(layoutBox) {
+        if (layoutBox.isOutOfFlowPositioned())
+            return this._computeOutOfFlowHeight(layoutBox);
+        if (layoutBox.isFloatingPositioned())
+            return this._computeFloatingHeight(layoutBox);
+        return this._computeInFlowHeight(layoutBox);
     }
 
-    marginTop(box) {
-        return BlockMarginCollapse.marginTop(box);
+    marginTop(layoutBox) {
+        return BlockMarginCollapse.marginTop(layoutBox);
     }
 
-    marginBottom(box) {
-        return BlockMarginCollapse.marginBottom(box);
+    marginBottom(layoutBox) {
+        return BlockMarginCollapse.marginBottom(layoutBox);
     }
 
-    _computeStaticPosition(box) {
+    _computeStaticPosition(layoutBox) {
         // In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block.
         // The vertical distance between two sibling boxes is determined by the 'margin' properties.
         // Vertical margins between adjacent block-level boxes in a block formatting context collapse.
-        let parent = box.parent();
+        let parent = layoutBox.parent();
         // Start from the top of the container's content box.
-        let previousInFlowSibling = box.previousInFlowSibling();
+        let previousInFlowSibling = layoutBox.previousInFlowSibling();
         let contentBottom = previousInFlowSibling ? previousInFlowSibling.bottomRight().top() + this.marginBottom(previousInFlowSibling) : parent.contentBox().top();
         let position = new LayoutPoint(contentBottom, parent.contentBox().left());
-        position.moveBy(new LayoutSize(this.marginLeft(box), this.marginTop(box)));
-        return position;
+        position.moveBy(new LayoutSize(this.marginLeft(layoutBox), this.marginTop(layoutBox)));
+        layoutBox.setTopLeft(position);
     }
 
     _placeInFlowPositionedChildren(container) {
         for (let inFlowChild = container.firstInFlowChild(); inFlowChild; inFlowChild = inFlowChild.nextInFlowSibling())
-            inFlowChild.setTopLeft(this._computeInFlowPositionedPosition(inFlowChild));
+            this._computeInFlowPositionedPosition(inFlowChild);
     }
 
     _placeOutOfFlowDescendants(container) {
         let outOfFlowDescendants = Utils.collectOutOfFlowDescendants(container);
         for (let outOfFlowBox of outOfFlowDescendants)
-            outOfFlowBox.setTopLeft(this._computeOutOfFlowPosition(outOfFlowBox));
+            this._computeOutOfFlowPosition(outOfFlowBox);
     }
 
-    _computeOutOfFlowWidth(box) {
+    _computeOutOfFlowWidth(layoutBox) {
         // 10.3.7 Absolutely positioned, non-replaced elements
 
         // 1. 'left' and 'width' are 'auto' and 'right' is not 'auto', then the width is shrink-to-fit. Then solve for 'left'
@@ -142,37 +142,38 @@ class BlockFormattingContext extends FormattingContext {
         // 5. 'width' is 'auto', 'left' and 'right' are not 'auto', then solve for 'width'
         // 6. 'right' is 'auto', 'left' and 'width' are not 'auto', then solve for 'right'
         let width = Number.NaN;
-        if (Utils.isWidthAuto(box) && Utils.isLeftAuto(box) && Utils.isRightAuto(box))
-            width = this._shrinkToFitWidth(box);
-        else if (Utils.isLeftAuto(box) && Utils.isWidthAuto(box) && !Utils.isRightAuto(box))
-            width = this._shrinkToFitWidth(box); // 1
-        else if (Utils.isLeftAuto(box) && Utils.isRightAuto(box) && !Utils.isWidthAuto(box))
-            width = Utils.width(box); // 2
-        else if (Utils.isWidthAuto(box) && Utils.isRightAuto(box) && !Utils.isLeftAuto(box))
-            width = this._shrinkToFitWidth(box); // 3
-        else if (Utils.isLeftAuto(box) && !Utils.isWidthAuto(box) && !Utils.isRightAuto(box))
-            width = Utils.width(box); // 4
-        else if (Utils.isWidthAuto(box) && !Utils.isLeftAuto(box) && !Utils.isRightAuto(box))
-            width = Math.max(0, box.containingBlock().contentBox().width() - Utils.right(box) - Utils.left(box)); // 5
-        else if (Utils.isRightAuto(box) && !Utils.isLeftAuto(box) && !Utils.isWidthAuto(box))
-            width = Utils.width(box); // 6
+        if (Utils.isWidthAuto(layoutBox) && Utils.isLeftAuto(layoutBox) && Utils.isRightAuto(layoutBox))
+            width = this._shrinkToFitWidth(layoutBox);
+        else if (Utils.isLeftAuto(layoutBox) && Utils.isWidthAuto(layoutBox) && !Utils.isRightAuto(layoutBox))
+            width = this._shrinkToFitWidth(layoutBox); // 1
+        else if (Utils.isLeftAuto(layoutBox) && Utils.isRightAuto(layoutBox) && !Utils.isWidthAuto(layoutBox))
+            width = Utils.width(layoutBox); // 2
+        else if (Utils.isWidthAuto(layoutBox) && Utils.isRightAuto(layoutBox) && !Utils.isLeftAuto(layoutBox))
+            width = this._shrinkToFitWidth(layoutBox); // 3
+        else if (Utils.isLeftAuto(layoutBox) && !Utils.isWidthAuto(layoutBox) && !Utils.isRightAuto(layoutBox))
+            width = Utils.width(layoutBox); // 4
+        else if (Utils.isWidthAuto(layoutBox) && !Utils.isLeftAuto(layoutBox) && !Utils.isRightAuto(layoutBox))
+            width = Math.max(0, layoutBox.containingBlock().contentBox().width() - Utils.right(layoutBox) - Utils.left(layoutBox)); // 5
+        else if (Utils.isRightAuto(layoutBox) && !Utils.isLeftAuto(layoutBox) && !Utils.isWidthAuto(layoutBox))
+            width = Utils.width(layoutBox); // 6
         else
             ASSERT_NOT_REACHED();
-        return width + Utils.computedHorizontalBorderAndPadding(box);
+        width += Utils.computedHorizontalBorderAndPadding(layoutBox);
+        layoutBox.setWidth(width);
     }
 
-    _computeFloatingWidth(box) {
+    _computeFloatingWidth(layoutBox) {
         // FIXME: missing cases
-        return Utils.width(box) + Utils.computedHorizontalBorderAndPadding(box);
+        layoutBox.setWidth(Utils.width(layoutBox) + Utils.computedHorizontalBorderAndPadding(layoutBox));
     }
 
-    _computeInFlowWidth(box) {
-        if (Utils.isWidthAuto(box))
-            return this._computeHorizontalConstraint(box);
-        return Utils.width(box) + Utils.computedHorizontalBorderAndPadding(box);
+    _computeInFlowWidth(layoutBox) {
+        if (Utils.isWidthAuto(layoutBox))
+            return layoutBox.setWidth(this._horizontalConstraint(layoutBox));
+        return layoutBox.setWidth(Utils.width(layoutBox) + Utils.computedHorizontalBorderAndPadding(layoutBox));
     }
 
-    _computeOutOfFlowHeight(box) {
+    _computeOutOfFlowHeight(layoutBox) {
         // 1. If all three of 'top', 'height', and 'bottom' are auto, set 'top' to the static position and apply rule number three below.
         // 2. If none of the three are 'auto': If both 'margin-top' and 'margin-bottom' are 'auto', solve the equation under
         //    the extra constraint that the two margins get equal values. If one of 'margin-top' or 'margin-bottom' is 'auto',
@@ -189,49 +190,50 @@ class BlockFormattingContext extends FormattingContext {
         // 7. 'height' is 'auto', 'top' and 'bottom' are not 'auto', then 'auto' values for 'margin-top' and 'margin-bottom' are set to 0 and solve for 'height'
         // 8. 'bottom' is 'auto', 'top' and 'height' are not 'auto', then set 'auto' values for 'margin-top' and 'margin-bottom' to 0 and solve for 'bottom'
         let height = Number.NaN;
-        if (Utils.isHeightAuto(box) && Utils.isBottomAuto(box) && Utils.isTopAuto(box))
-            height = this._computeContentHeight(box); // 1
-        else if (Utils.isTopAuto((box)) && Utils.isHeightAuto((box)) && !Utils.isBottomAuto((box)))
-            height = this._computeContentHeight(box); // 3
-        else if (Utils.isTopAuto((box)) && Utils.isBottomAuto((box)) && !Utils.isHeightAuto((box)))
-            height = Utils.height(box); // 4
-        else if (Utils.isHeightAuto((box)) && Utils.isBottomAuto((box)) && !Utils.isTopAuto((box)))
-            height = this._computeContentHeight(box); // 5
-        else if (Utils.isTopAuto((box)) && !Utils.isHeightAuto((box)) && !Utils.isBottomAuto((box)))
-            height = Utils.height(box); // 6
-        else if (Utils.isHeightAuto((box)) && !Utils.isTopAuto((box)) && !Utils.isBottomAuto((box)))
-            height = Math.max(0, box.containingBlock().contentBox().height() - Utils.bottom(box) - Utils.top(box)); // 7
-        else if (Utils.isBottomAuto((box)) && !Utils.isTopAuto((box)) && !Utils.isHeightAuto((box)))
-            height = Utils.height(box); // 8
+        if (Utils.isHeightAuto(layoutBox) && Utils.isBottomAuto(layoutBox) && Utils.isTopAuto(layoutBox))
+            height = this._contentHeight(layoutBox); // 1
+        else if (Utils.isTopAuto((layoutBox)) && Utils.isHeightAuto((layoutBox)) && !Utils.isBottomAuto((layoutBox)))
+            height = this._contentHeight(layoutBox); // 3
+        else if (Utils.isTopAuto((layoutBox)) && Utils.isBottomAuto((layoutBox)) && !Utils.isHeightAuto((layoutBox)))
+            height = Utils.height(layoutBox); // 4
+        else if (Utils.isHeightAuto((layoutBox)) && Utils.isBottomAuto((layoutBox)) && !Utils.isTopAuto((layoutBox)))
+            height = this._contentHeight(layoutBox); // 5
+        else if (Utils.isTopAuto((layoutBox)) && !Utils.isHeightAuto((layoutBox)) && !Utils.isBottomAuto((layoutBox)))
+            height = Utils.height(layoutBox); // 6
+        else if (Utils.isHeightAuto((layoutBox)) && !Utils.isTopAuto((layoutBox)) && !Utils.isBottomAuto((layoutBox)))
+            height = Math.max(0, layoutBox.containingBlock().contentBox().height() - Utils.bottom(layoutBox) - Utils.top(layoutBox)); // 7
+        else if (Utils.isBottomAuto((layoutBox)) && !Utils.isTopAuto((layoutBox)) && !Utils.isHeightAuto((layoutBox)))
+            height = Utils.height(layoutBox); // 8
         else
             ASSERT_NOT_REACHED();
-        return height + Utils.computedVerticalBorderAndPadding(box);
+        height += Utils.computedVerticalBorderAndPadding(layoutBox);
+        layoutBox.setHeight(height);
     }
 
-    _computeFloatingHeight(box) {
+    _computeFloatingHeight(layoutBox) {
         // FIXME: missing cases
-        return Utils.height(box) + Utils.computedVerticalBorderAndPadding(box);
+        layoutBox.setHeight(Utils.height(layoutBox) + Utils.computedVerticalBorderAndPadding(layoutBox));
     }
 
-    _computeInFlowHeight(box) {
-        if (Utils.isHeightAuto(box)) {
+    _computeInFlowHeight(layoutBox) {
+        if (Utils.isHeightAuto(layoutBox)) {
             // Only children in the normal flow are taken into account (i.e., floating boxes and absolutely positioned boxes are ignored,
             // and relatively positioned boxes are considered without their offset). Note that the child box may be an anonymous block box.
 
             // The element's height is the distance from its top content edge to the first applicable of the following:
             // 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
-            return this._computeContentHeight(box) + Utils.computedVerticalBorderAndPadding(box);
+            return layoutBox.setHeight(this._contentHeight(layoutBox) + Utils.computedVerticalBorderAndPadding(layoutBox));
         }
-        return Utils.height(box) + Utils.computedVerticalBorderAndPadding(box);
+        return layoutBox.setHeight(Utils.height(layoutBox) + Utils.computedVerticalBorderAndPadding(layoutBox));
     }
 
-    _computeHorizontalConstraint(box) {
-        let horizontalConstraint = box.containingBlock().contentBox().width();
-        horizontalConstraint -= this.marginLeft(box) + this.marginRight(box);
+    _horizontalConstraint(layoutBox) {
+        let horizontalConstraint = layoutBox.containingBlock().contentBox().width();
+        horizontalConstraint -= this.marginLeft(layoutBox) + this.marginRight(layoutBox);
         return horizontalConstraint;
     }
 
-    _computeContentHeight(box) {
+    _contentHeight(layoutBox) {
         // 10.6.3 Block-level non-replaced elements in normal flow when 'overflow' computes to 'visible'
         // The element's height is the distance from its top content edge to the first applicable of the following:
         // 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
@@ -240,82 +242,86 @@ class BlockFormattingContext extends FormattingContext {
         // 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
         // 4. zero, otherwise
         // Only children in the normal flow are taken into account.
-        if (!box.isContainer() || !box.hasInFlowChild())
+        if (!layoutBox.isContainer() || !layoutBox.hasInFlowChild())
             return 0;
-        if (box.establishesInlineFormattingContext()) {
-            ASSERT(box.establishedFormattingContext());
-            let lines = box.establishedFormattingContext().lines();
+        if (layoutBox.establishesInlineFormattingContext()) {
+            ASSERT(layoutBox.establishedFormattingContext());
+            let lines = layoutBox.establishedFormattingContext().lines();
             if (!lines.length)
                 return 0;
             let lastLine = lines[lines.length - 1];
             return lastLine.rect().bottom();
         }
-        let top = box.contentBox().top();
-        let lastInFlowChild = box.lastInFlowChild();
+        let top = layoutBox.contentBox().top();
+        let bottom = this._adjustBottomWithFIXME(layoutBox);
+        return bottom - top;
+    }
 
+    _adjustBottomWithFIXME(layoutBox) {
+        let lastInFlowChild = layoutBox.lastInFlowChild();
         let bottom = lastInFlowChild.rect().bottom() + this.marginBottom(lastInFlowChild);
         // FIXME: margin for body
         if (lastInFlowChild.name() == "RenderBody" && Utils.isHeightAuto(lastInFlowChild) && !lastInFlowChild.contentBox().height())
             bottom -= this.marginBottom(lastInFlowChild);
         // FIXME: figure out why floatings part of the initial block formatting context get propagated to HTML
-        if (box.node().tagName == "HTML") {
+        if (layoutBox.node().tagName == "HTML") {
             let floatingBottom = this.floatingContext().bottom();
             if (!Number.isNaN(floatingBottom))
                 bottom = Math.max(floatingBottom, bottom);
         }
-        return bottom - top;
+        return bottom;
     }
 
-    _computeInFlowPositionedPosition(box) {
+    _computeInFlowPositionedPosition(layoutBox) {
         // Start with the original, static position.
-        let relativePosition = box.topLeft();
+        let relativePosition = layoutBox.topLeft();
         // Top/bottom
-        if (!Utils.isTopAuto(box))
-            relativePosition.shiftTop(Utils.top(box));
-        else if (!Utils.isBottomAuto(box))
-            relativePosition.shiftTop(-Utils.bottom(box));
+        if (!Utils.isTopAuto(layoutBox))
+            relativePosition.shiftTop(Utils.top(layoutBox));
+        else if (!Utils.isBottomAuto(layoutBox))
+            relativePosition.shiftTop(-Utils.bottom(layoutBox));
         // Left/right
-        if (!Utils.isLeftAuto(box))
-            relativePosition.shiftLeft(Utils.left(box));
-        else if (!Utils.isRightAuto(box))
-            relativePosition.shiftLeft(-Utils.right(box));
-        return relativePosition;
+        if (!Utils.isLeftAuto(layoutBox))
+            relativePosition.shiftLeft(Utils.left(layoutBox));
+        else if (!Utils.isRightAuto(layoutBox))
+            relativePosition.shiftLeft(-Utils.right(layoutBox));
+        layoutBox.setTopLeft(relativePosition);
     }
 
-    _computeOutOfFlowPosition(box) {
-        let containerSize = box.containingBlock().contentBox().size();
+    _computeOutOfFlowPosition(layoutBox) {
+        let containerSize = layoutBox.containingBlock().contentBox().size();
         // Top/bottom
         let top = Number.NaN;
-        if (Utils.isTopAuto(box) && Utils.isBottomAuto(box)) {
+        if (Utils.isTopAuto(layoutBox) && Utils.isBottomAuto(layoutBox)) {
             // Convert static position to absolute.
-            top = Utils.mapStaticToAbsolute(box).top();
-        } else if (!Utils.isTopAuto(box))
-            top = Utils.top(box) + this.marginTop(box);
-        else if (!Utils.isBottomAuto(box))
-            top = containerSize.height() - Utils.bottom(box) - box.rect().height() - this.marginBottom(box);
+            top = Utils.mapStaticToAbsolute(layoutBox).top();
+        } else if (!Utils.isTopAuto(layoutBox))
+            top = Utils.top(layoutBox) + this.marginTop(layoutBox);
+        else if (!Utils.isBottomAuto(layoutBox))
+            top = containerSize.height() - Utils.bottom(layoutBox) - layoutBox.rect().height() - this.marginBottom(layoutBox);
         else
             ASSERT_NOT_REACHED();
         // Left/right
         let left = Number.NaN;
-        if (Utils.isLeftAuto(box) && Utils.isRightAuto(box)) {
+        if (Utils.isLeftAuto(layoutBox) && Utils.isRightAuto(layoutBox)) {
             // Convert static position to absolute.
-            left = Utils.mapStaticToAbsolute(box).left();
-        } else if (!Utils.isLeftAuto(box))
-            left = Utils.left(box) + this.marginLeft(box);
-        else if (!Utils.isRightAuto(box))
-            left = containerSize.width() - Utils.right(box) - box.rect().width() - this.marginRight(box);
+            left = Utils.mapStaticToAbsolute(layoutBox).left();
+        } else if (!Utils.isLeftAuto(layoutBox))
+            left = Utils.left(layoutBox) + this.marginLeft(layoutBox);
+        else if (!Utils.isRightAuto(layoutBox))
+            left = containerSize.width() - Utils.right(layoutBox) - layoutBox.rect().width() - this.marginRight(layoutBox);
         else
             ASSERT_NOT_REACHED();
-        return new LayoutPoint(top, left);
+        layoutBox.setTopLeft(new LayoutPoint(top, left));
     }
 
-    _shrinkToFitWidth(box) {
+    _shrinkToFitWidth(layoutBox) {
         // FIXME: this is naive.
-        ASSERT(Utils.isWidthAuto(box));
-        if (!box.isContainer() || !box.hasChild())
+        ASSERT(Utils.isWidthAuto(layoutBox));
+        if (!layoutBox.isContainer() || !layoutBox.hasChild())
             return 0;
         let width = 0;
-        for (let inFlowChild = box.firstInFlowChild(); inFlowChild; inFlowChild = inFlowChild.nextInFlowSibling()) {
+        for (let inFlowChild = layoutBox.firstInFlowChild(); inFlowChild; inFlowChild = inFlowChild.nextInFlowSibling()) {
             let widthCandidate = Utils.isWidthAuto(inFlowChild) ? this._shrinkToFitWidth(inFlowChild) : Utils.width(inFlowChild);
             width = Math.max(width, widthCandidate + Utils.computedHorizontalBorderAndPadding(inFlowChild));
         }
index e8259a5..db2d4d3 100644 (file)
  */
 class BlockMarginCollapse {
 
-    static marginTop(box) {
-        if (box.isAnonymous())
+    static marginTop(layoutBox) {
+        if (layoutBox.isAnonymous())
             return 0;
         // TODO: take _hasAdjoiningMarginTopAndBottom() into account.
-        if (this._isMarginTopCollapsedWithParent(box))
+        if (this._isMarginTopCollapsedWithParent(layoutBox))
             return 0;
         // Floats and out of flow positioned boxes do not collapse their margins.
-        if (!this._isMarginTopCollapsedWithSibling(box))
-            return this._nonCollapsedMarginTop(box);
+        if (!this._isMarginTopCollapsedWithSibling(layoutBox))
+            return this._nonCollapsedMarginTop(layoutBox);
         // The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling,
         // unless that sibling has clearance.
-        let previousInFlowSibling = box.previousInFlowSibling();
+        let previousInFlowSibling = layoutBox.previousInFlowSibling();
         if (previousInFlowSibling) {
             let previousSiblingMarginBottom = this._nonCollapsedMarginBottom(previousInFlowSibling);
-            let marginTop = this._nonCollapsedMarginTop(box);
+            let marginTop = this._nonCollapsedMarginTop(layoutBox);
             return this._marginValue(marginTop, previousSiblingMarginBottom);
         }
-        return this._nonCollapsedMarginTop(box);
+        return this._nonCollapsedMarginTop(layoutBox);
     }
 
-    static marginBottom(box) {
-        if (box.isAnonymous())
+    static marginBottom(layoutBox) {
+        if (layoutBox.isAnonymous())
             return 0;
         // TODO: take _hasAdjoiningMarginTopAndBottom() into account.
-        if (this._isMarginBottomCollapsedWithParent(box))
+        if (this._isMarginBottomCollapsedWithParent(layoutBox))
             return 0;
         // Floats and out of flow positioned boxes do not collapse their margins.
-        if (!this._isMarginBottomCollapsedWithSibling(box))
-            return this._nonCollapsedMarginBottom(box);
+        if (!this._isMarginBottomCollapsedWithSibling(layoutBox))
+            return this._nonCollapsedMarginBottom(layoutBox);
         // The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling,
         // unless that sibling has clearance.
-        if (box.nextInFlowSibling())
+        if (layoutBox.nextInFlowSibling())
             return 0;
-        return this._nonCollapsedMarginBottom(box);
+        return this._nonCollapsedMarginBottom(layoutBox);
     }
 
-    static _isMarginTopCollapsedWithSibling(box) {
-        if (box.isFloatingPositioned())
+    static _isMarginTopCollapsedWithSibling(layoutBox) {
+        if (layoutBox.isFloatingPositioned())
             return false;
-        if (!box.isPositioned() || box.isInFlowPositioned())
+        if (!layoutBox.isPositioned() || layoutBox.isInFlowPositioned())
             return true;
         // Out of flow positioned.
-        ASSERT(box.isOutOfFlowPositioned());
-        return Utils.isTopAuto(box);
+        ASSERT(layoutBox.isOutOfFlowPositioned());
+        return Utils.isTopAuto(layoutBox);
     }
 
-    static _isMarginBottomCollapsedWithSibling(box) {
-        if (box.isFloatingPositioned())
+    static _isMarginBottomCollapsedWithSibling(layoutBox) {
+        if (layoutBox.isFloatingPositioned())
             return false;
-        if (!box.isPositioned() || box.isInFlowPositioned())
+        if (!layoutBox.isPositioned() || layoutBox.isInFlowPositioned())
             return true;
         // Out of flow positioned.
-        ASSERT(box.isOutOfFlowPositioned());
-        return Utils.isBottomAuto(box);
+        ASSERT(layoutBox.isOutOfFlowPositioned());
+        return Utils.isBottomAuto(layoutBox);
     }
 
-    static _isMarginTopCollapsedWithParent(box) {
+    static _isMarginTopCollapsedWithParent(layoutBox) {
         // The first inflow child could propagate its top margin to parent.
         // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
-        if (box.isAnonymous())
+        if (layoutBox.isAnonymous())
             return false;
-        if (box.isFloatingOrOutOfFlowPositioned())
+        if (layoutBox.isFloatingOrOutOfFlowPositioned())
             return false;
-        let parent = box.parent();
+        let parent = layoutBox.parent();
         // Is this box the first inlflow child?
-        if (parent.firstInFlowChild() != box)
+        if (parent.firstInFlowChild() != layoutBox)
             return false;
         if (parent.establishesBlockFormattingContext())
             return false;
@@ -103,16 +103,16 @@ class BlockMarginCollapse {
         return true;
     }
 
-    static _isMarginBottomCollapsedWithParent(box) {
+    static _isMarginBottomCollapsedWithParent(layoutBox) {
         // last inflow box to parent.
         // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
-        if (box.isAnonymous())
+        if (layoutBox.isAnonymous())
             return false;
-        if (box.isFloatingOrOutOfFlowPositioned())
+        if (layoutBox.isFloatingOrOutOfFlowPositioned())
             return false;
-        let parent = box.parent();
+        let parent = layoutBox.parent();
         // Is this the last inlflow child?
-        if (parent.lastInFlowChild() != box)
+        if (parent.lastInFlowChild() != layoutBox)
             return false;
         if (parent.establishesBlockFormattingContext())
             return false;
@@ -128,32 +128,32 @@ class BlockMarginCollapse {
         return true;
     }
 
-    static _nonCollapsedMarginTop(box) {
+    static _nonCollapsedMarginTop(layoutBox) {
         // Non collapsed margin top includes collapsed margin from inflow first child.
-        return this._marginValue(Utils.computedMarginTop(box), this._collapsedMarginTopFromFirstChild(box));
+        return this._marginValue(Utils.computedMarginTop(layoutBox), this._collapsedMarginTopFromFirstChild(layoutBox));
     }
 
-    static _nonCollapsedMarginBottom(box) {
+    static _nonCollapsedMarginBottom(layoutBox) {
         // Non collapsed margin bottom includes collapsed margin from inflow last child.
-        return this._marginValue(Utils.computedMarginBottom(box), this._collapsedMarginBottomFromLastChild(box));
+        return this._marginValue(Utils.computedMarginBottom(layoutBox), this._collapsedMarginBottomFromLastChild(layoutBox));
     }
 
-    static _collapsedMarginTopFromFirstChild(box) {
+    static _collapsedMarginTopFromFirstChild(layoutBox) {
         // Check if the first child collapses its margin top.
-        if (!box.isContainer() || !box.firstInFlowChild())
+        if (!layoutBox.isContainer() || !layoutBox.firstInFlowChild())
             return 0;
-        let firstInFlowChild = box.firstInFlowChild();
+        let firstInFlowChild = layoutBox.firstInFlowChild();
         if (!this._isMarginTopCollapsedWithParent(firstInFlowChild))
             return 0;
         // Collect collapsed margin top recursively.
         return this._marginValue(Utils.computedMarginTop(firstInFlowChild), this._collapsedMarginTopFromFirstChild(firstInFlowChild));
     }
 
-    static _collapsedMarginBottomFromLastChild(box) {
+    static _collapsedMarginBottomFromLastChild(layoutBox) {
         // Check if the last child propagates its margin bottom.
-        if (!box.isContainer() || !box.lastInFlowChild())
+        if (!layoutBox.isContainer() || !layoutBox.lastInFlowChild())
             return 0;
-        let lastInFlowChild = box.lastInFlowChild();
+        let lastInFlowChild = layoutBox.lastInFlowChild();
         if (!this._isMarginBottomCollapsedWithParent(lastInFlowChild))
             return 0;
         // Collect collapsed margin bottom recursively.
@@ -175,7 +175,7 @@ class BlockMarginCollapse {
         return currentMarginValue + candidateMarginValue;
     }
 
-    static _hasAdjoiningMarginTopAndBottom(box) {
+    static _hasAdjoiningMarginTopAndBottom(layoutBox) {
         // Two margins are adjoining if and only if:
         // 1. both belong to in-flow block-level boxes that participate in the same block formatting context
         // 2. no line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for this purpose.)
index 9832128..e723cda 100644 (file)
@@ -31,18 +31,18 @@ class FloatingContext {
         this.m_formattingContext = formattingContext;
     }
 
-    computePosition(box) {
-        if (box.isOutOfFlowPositioned())
-            return box.topLeft();
-        if (box.isFloatingPositioned()) {
-            let position = this._positionForFloating(box);
-            this._addFloating(box);
-            return position;
+    computePosition(layoutBox) {
+        if (layoutBox.isOutOfFlowPositioned())
+            return;
+        if (layoutBox.isFloatingPositioned()) {
+            let position = this._positionForFloating(layoutBox);
+            this._addFloating(layoutBox);
+            return layoutBox.setTopLeft(position);
         }
-        if (Utils.hasClear(box))
-            return this._positionForClear(box);
+        if (Utils.hasClear(layoutBox))
+            return layoutBox.setTopLeft(this._positionForClear(layoutBox));
         // Intruding floats might force this box move.
-        return this._computePositionToAvoidIntrudingFloats(box);
+        return layoutBox.setTopLeft(this._computePositionToAvoidIntrudingFloats(layoutBox));
     }
 
     bottom() {
@@ -71,35 +71,35 @@ class FloatingContext {
         return Math.Nan;
     }
 
-    _positionForClear(box) {
-        ASSERT(Utils.hasClear(box));
+    _positionForClear(layoutBox) {
+        ASSERT(Utils.hasClear(layoutBox));
         if (this._isEmpty())
-            return box.topLeft();
+            return layoutBox.topLeft();
 
         let leftBottom = Number.NaN;
         let rightBottom = Number.NaN;
-        if (Utils.hasClearLeft(box) || Utils.hasClearBoth(box))
+        if (Utils.hasClearLeft(layoutBox) || Utils.hasClearBoth(layoutBox))
             leftBottom = this._bottom(this.m_leftFloatingBoxStack);
-        if (Utils.hasClearRight(box) || Utils.hasClearBoth(box))
+        if (Utils.hasClearRight(layoutBox) || Utils.hasClearBoth(layoutBox))
             rightBottom = this._bottom(this.m_rightFloatingBoxStack);
 
         if (!Number.isNaN(leftBottom) && !Number.isNaN(rightBottom))
-            return new LayoutPoint(Math.max(leftBottom, rightBottom), box.rect().left());
+            return new LayoutPoint(Math.max(leftBottom, rightBottom), layoutBox.rect().left());
         if (!Number.isNaN(leftBottom))
-            return new LayoutPoint(leftBottom, box.rect().left());
+            return new LayoutPoint(leftBottom, layoutBox.rect().left());
         if (!Number.isNaN(rightBottom))
-            return new LayoutPoint(rightBottom, box.rect().left());
-        return box.topLeft();
+            return new LayoutPoint(rightBottom, layoutBox.rect().left());
+        return layoutBox.topLeft();
     }
 
-    _computePositionToAvoidIntrudingFloats(box) {
-        if (!box.establishesBlockFormattingContext() || this._isEmpty())
-            return box.topLeft();
+    _computePositionToAvoidIntrudingFloats(layoutBox) {
+        if (!layoutBox.establishesBlockFormattingContext() || this._isEmpty())
+            return layoutBox.topLeft();
         // The border box of a table, a block-level replaced element, or an element in the normal flow that establishes
         // a new block formatting context (such as an element with 'overflow' other than 'visible') must not overlap the
         // margin box of any floats in the same block formatting context as the element itself.
         // For some reason, we position this as if it was floating left.
-        return this._positionForFloating(box);
+        return this._positionForFloating(layoutBox);
     }
 
     _addFloating(floatingBox) {
index 1c2c3c2..eec87d9 100644 (file)
@@ -40,52 +40,52 @@ class FormattingContext {
     layout(layoutContext) {
     }
 
-    computeWidth(box) {
+    computeWidth(layoutBox) {
     }
 
-    computeHeight(box) {
+    computeHeight(layoutBox) {
     }
 
-    marginTop(box) {
-        return Utils.computedMarginTop(box);
+    marginTop(layoutBox) {
+        return Utils.computedMarginTop(layoutBox);
     }
     
-    marginLeft(box) {
-        return Utils.computedMarginLeft(box);
+    marginLeft(layoutBox) {
+        return Utils.computedMarginLeft(layoutBox);
     }
     
-    marginBottom(box) {
-        return Utils.computedMarginBottom(box);
+    marginBottom(layoutBox) {
+        return Utils.computedMarginBottom(layoutBox);
     }
     
-    marginRight(box) {
-        return Utils.computedMarginRight(box);
+    marginRight(layoutBox) {
+        return Utils.computedMarginRight(layoutBox);
     }
 
-    absoluteMarginBox(box) {
-        let absoluteContentBox = Utils.mapToContainer(box, this.rootContainer());
-        absoluteContentBox.moveBy(new LayoutSize(-this.marginLeft(box), -this.marginTop(box)));
-        absoluteContentBox.growBy(new LayoutSize(this.marginLeft(box) + this.marginRight(box), this.marginTop(box) + this.marginBottom(box)));
+    absoluteMarginBox(layoutBox) {
+        let absoluteContentBox = Utils.mapToContainer(layoutBox, this.rootContainer());
+        absoluteContentBox.moveBy(new LayoutSize(-this.marginLeft(layoutBox), -this.marginTop(layoutBox)));
+        absoluteContentBox.growBy(new LayoutSize(this.marginLeft(layoutBox) + this.marginRight(layoutBox), this.marginTop(layoutBox) + this.marginBottom(layoutBox)));
         return absoluteContentBox;
     }
 
-    absoluteBorderBox(box) {
-        let borderBox = box.borderBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(box, this.rootContainer()).topLeft(), borderBox.size());
+    absoluteBorderBox(layoutBox) {
+        let borderBox = layoutBox.borderBox();
+        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), borderBox.size());
         absoluteRect.moveBy(borderBox.topLeft());
         return absoluteRect;
     }
 
-    absolutePaddingBox(box) {
-        let paddingBox = box.paddingBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(box, this.rootContainer()).topLeft(), paddingBox.size());
+    absolutePaddingBox(layoutBox) {
+        let paddingBox = layoutBox.paddingBox();
+        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), paddingBox.size());
         absoluteRect.moveBy(paddingBox.topLeft());
         return absoluteRect;
     }
 
-    absoluteContentBox(box) {
-        let contentBox = box.contentBox();
-        let absoluteRect = new LayoutRect(Utils.mapToContainer(box, this.rootContainer()).topLeft(), contentBox.size());
+    absoluteContentBox(layoutBox) {
+        let contentBox = layoutBox.contentBox();
+        let absoluteRect = new LayoutRect(Utils.mapToContainer(layoutBox, this.rootContainer()).topLeft(), contentBox.size());
         absoluteRect.moveBy(contentBox.topLeft());
         return absoluteRect;
     }
index 605975e..41a36b9 100644 (file)
@@ -51,20 +51,20 @@ class InlineFormattingContext extends FormattingContext {
         while (layoutStack.length) {
             // Travers down on the descendants until we find a leaf node.
             while (true) {
-                let box = layoutStack[layoutStack.length - 1];
-                if (box.establishesFormattingContext()) {
-                    layoutContext.layoutFormattingContext(box.establishedFormattingContext());
+                let layoutBox = layoutStack[layoutStack.length - 1];
+                if (layoutBox.establishesFormattingContext()) {
+                    layoutContext.layoutFormattingContext(layoutBox.establishedFormattingContext());
                     break;
                 }
-                if (!box.isContainer() || !box.hasChild())
+                if (!layoutBox.isContainer() || !layoutBox.hasChild())
                     break;
                 layoutStack.push(box.firstChild());
             }
             while (layoutStack.length) {
-                let box = layoutStack.pop();
-                this._handleInlineBox(box);
-                if (box.nextSibling()) {
-                    layoutStack.push(box.nextSibling());
+                let layoutBox = layoutStack.pop();
+                this._handleInlineBox(layoutBox);
+                if (layoutBox.nextSibling()) {
+                    layoutStack.push(layoutBox.nextSibling());
                     break;
                 }
             }
index c9491c1..a77bf8c 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class BlockContainer extends Container {
+Layout.BlockContainer = class BlockContainer extends Layout.Container {
     constructor(node, id) {
         super(node, id);
     }
index 056b08a..b539765 100644 (file)
@@ -23,7 +23,9 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class Box {
+var Layout = { }
+
+Layout.Box = class Box {
     constructor(node, id) {
         this.m_id = id;
         this.m_rendererName = null;
index b4f6310..1042bf5 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class Container extends Box {
+Layout.Container = class Container extends Layout.Box {
     constructor(node, id) {
         super(node, id);
         this.m_firstChild = null;
index adab548..9f80f85 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class InitialBlockContainer extends BlockContainer {
+Layout.InitialBlockContainer = class InitialBlockContainer extends Layout.BlockContainer {
     constructor(document, id, name) {
         super(document, id);
     }
index 4a2ed50..8091fa5 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class InlineBox extends Box {
+Layout.InlineBox = class InlineBox extends Layout.Box {
     constructor(node, id) {
         super(node, id);
         this.m_text = null;
index 839c245..60db289 100644 (file)
@@ -28,7 +28,7 @@ class TreeBuilder {
 
     createTree(document, renderTreeDump) {
         // Root.
-        let initialBlockContainer = new InitialBlockContainer(document, parseInt(renderTreeDump.substring(0, renderTreeDump.indexOf("("))));
+        let initialBlockContainer = new Layout.InitialBlockContainer(document, parseInt(renderTreeDump.substring(0, renderTreeDump.indexOf("("))));
         initialBlockContainer.setRendererName("RenderView");
         renderTreeDump = renderTreeDump.substring(renderTreeDump.indexOf("|") + 1);
 
@@ -53,13 +53,13 @@ class TreeBuilder {
         let text = null;
         let node = this._findNode(initialBlockContainer.node(), id, name);
         if (name == "RenderBlock" || name == "RenderBody")
-            box = new BlockContainer(node, id);
+            box = new Layout.BlockContainer(node, id);
         else if (name == "RenderInline") {
-            box = new InlineContainer(node, id);
+            box = new Layout.InlineContainer(node, id);
         } else if (name == "RenderText") {
             text = new Text(node, id);
         } else
-            box = new Box(node, id);
+            box = new Layout.Box(node, id);
 
         if (box)
             box.setRendererName(name);
@@ -68,7 +68,7 @@ class TreeBuilder {
         // WebKit does not construct anonymous inline container for text if the text
         // is a direct child of a block container.
         if (text && !parentBox.isInlineContainer) {
-            box = new InlineBox(null, -1);
+            box = new Layout.InlineBox(null, -1);
             box.setIsAnonymous();
             box.setText(text);
         }
index d305121..fad364b 100644 (file)
@@ -531,7 +531,7 @@ class Utils {
         // Skip anonymous boxes for now -This is the case where WebKit does not generate an anon inline container for text content where the text is a direct child
         // of a block container.
         let indentation = " ".repeat(level);
-        if (box instanceof InlineBox) {
+        if (box instanceof Layout.InlineBox) {
             if (box.text())
                 return indentation + "#text RenderText\n";
         }