Changeset 230464 in webkit


Ignore:
Timestamp:
Apr 9, 2018 6:53:00 PM (6 years ago)
Author:
Alan Bujtas
Message:

[LayoutReloaded] Add support for inline-block.
https://bugs.webkit.org/show_bug.cgi?id=184434

Reviewed by Antti Koivisto.

  • LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:

(InlineFormattingContext):
(InlineFormattingContext.prototype.layout):
(InlineFormattingContext.prototype._handleInlineContainer):
(InlineFormattingContext.prototype._handleInlineBlockContainer):
(InlineFormattingContext.prototype._handleInlineContent):

  • LayoutReloaded/FormattingContext/InlineFormatting/Line.js:

(Line.prototype.addInlineContainerBox):
(Line.prototype.addTextLineBox):
(Line):

  • LayoutReloaded/LayoutTree/Box.js:

(Layout.Box.prototype.isInlineBlockBox):

  • LayoutReloaded/Utils.js:

(LayoutRect.prototype.growHorizontally):
(Utils.isBlockContainerElement):
(Utils.isInlineBlockElement):
(Utils._dumpLines.):
(Utils._dumpLines):

  • LayoutReloaded/test/index.html:
  • LayoutReloaded/test/inline-block-with-fixed-width-height.html: Added.
Location:
trunk/Tools
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r230462 r230464  
     12018-04-09  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LayoutReloaded] Add support for inline-block.
     4        https://bugs.webkit.org/show_bug.cgi?id=184434
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
     9        (InlineFormattingContext):
     10        (InlineFormattingContext.prototype.layout):
     11        (InlineFormattingContext.prototype._handleInlineContainer):
     12        (InlineFormattingContext.prototype._handleInlineBlockContainer):
     13        (InlineFormattingContext.prototype._handleInlineContent):
     14        * LayoutReloaded/FormattingContext/InlineFormatting/Line.js:
     15        (Line.prototype.addInlineContainerBox):
     16        (Line.prototype.addTextLineBox):
     17        (Line):
     18        * LayoutReloaded/LayoutTree/Box.js:
     19        (Layout.Box.prototype.isInlineBlockBox):
     20        * LayoutReloaded/Utils.js:
     21        (LayoutRect.prototype.growHorizontally):
     22        (Utils.isBlockContainerElement):
     23        (Utils.isInlineBlockElement):
     24        (Utils._dumpLines.):
     25        (Utils._dumpLines):
     26        * LayoutReloaded/test/index.html:
     27        * LayoutReloaded/test/inline-block-with-fixed-width-height.html: Added.
     28
    1292018-04-09  Timothy Hatcher  <timothy@apple.com>
    230
  • trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js

    r230386 r230464  
    2828        super(inlineFormattingState);
    2929        ASSERT(this.formattingRoot().isBlockContainerBox());
     30        this.m_inlineContainerStack = new Array();
    3031    }
    3132
     
    4041        while (this._descendantNeedsLayout()) {
    4142            let layoutBox = this._nextInLayoutQueue();
    42             if (layoutBox.isInlineContainer()) {
    43                 if (inlineContainerStack.indexOf(layoutBox) == -1) {
    44                     inlineContainerStack.push(layoutBox);
    45                     this._adjustLineForInlineContainerStart(layoutBox);
    46                     if (layoutBox.establishesFormattingContext())
    47                         this.layoutState().layout(layoutBox);
    48                     else
    49                         this._addToLayoutQueue(layoutBox.firstInFlowOrFloatChild());
    50                 } else {
    51                     inlineContainerStack.pop(layoutBox);
    52                     this._adjustLineForInlineContainerEnd(layoutBox);
    53                     this._removeFromLayoutQueue(layoutBox);
    54                     this._addToLayoutQueue(layoutBox.nextInFlowOrFloatSibling());
    55                     // Place the inflow positioned children.
    56                     this._placeInFlowPositionedChildren(this.formattingRoot());
    57                 }
    58                 continue;
    59             }
    60             this._handleInlineContent(layoutBox);
    61             this._removeFromLayoutQueue(layoutBox);
    62             this._addToLayoutQueue(layoutBox.nextInFlowOrFloatSibling());
     43            if (layoutBox.isInlineContainer())
     44                this._handleInlineContainer(layoutBox);
     45            else if (layoutBox.isInlineBlockBox())
     46                this._handleInlineBlockContainer(layoutBox);
     47            else
     48                this._handleInlineContent(layoutBox);
    6349        }
    6450        // Place the inflow positioned children.
     
    6753        this._placeOutOfFlowDescendants(this.formattingRoot());
    6854        this._commitLine();
     55        ASSERT(!this.m_inlineContainerStack.length);
    6956   }
    7057
     58    _handleInlineContainer(inlineContainer) {
     59        ASSERT(!inlineContainer.establishesFormattingContext());
     60        let inlineContainerStart = this.m_inlineContainerStack.indexOf(inlineContainer) == -1;
     61        if (inlineContainerStart) {
     62            this.m_inlineContainerStack.push(inlineContainer);
     63            this._adjustLineForInlineContainerStart(inlineContainer);
     64            this._addToLayoutQueue(inlineContainer.firstInFlowOrFloatChild());
     65            // Keep the inline container in the layout stack so that we can finish it when all the descendants are all set.
     66            return;
     67        }
     68        this.m_inlineContainerStack.pop(inlineContainer);
     69        this._adjustLineForInlineContainerEnd(inlineContainer);
     70        this._removeFromLayoutQueue(inlineContainer);
     71        this._addToLayoutQueue(inlineContainer.nextInFlowOrFloatSibling());
     72        // Place the in- and out-of-flow positioned children.
     73        this._placeInFlowPositionedChildren(inlineContainer);
     74        this._placeOutOfFlowDescendants(inlineContainer);
     75    }
     76
     77
     78    _handleInlineBlockContainer(inlineBlockContainer) {
     79        ASSERT(inlineBlockContainer.establishesFormattingContext());
     80        this._adjustLineForInlineContainerStart(inlineBlockContainer);
     81        // TODO: auto width/height
     82        let displayBox = this.displayBox(inlineBlockContainer);
     83        displayBox.setWidth(Utils.width(inlineBlockContainer) + Utils.computedHorizontalBorderAndPadding(inlineBlockContainer.node()));
     84        displayBox.setHeight(Utils.height(inlineBlockContainer) + Utils.computedVerticalBorderAndPadding(inlineBlockContainer.node()));
     85        this.layoutState().layout(inlineBlockContainer);
     86        this._line().addInlineContainerBox(displayBox.size());
     87        this._adjustLineForInlineContainerEnd(inlineBlockContainer);
     88        this._removeFromLayoutQueue(inlineBlockContainer);
     89        this._addToLayoutQueue(inlineBlockContainer.nextInFlowOrFloatSibling());
     90    }
     91
    7192    _handleInlineContent(layoutBox) {
    72         if (layoutBox.isInlineBox()) {
     93        if (layoutBox.isInlineBox())
    7394            this._handleInlineBox(layoutBox);
    74             return;
    75         }
    76         if (layoutBox.isFloatingPositioned()) {
     95        else if (layoutBox.isFloatingPositioned())
    7796            this._handleFloatingBox(layoutBox);
    78             return;
    79         }
    80         ASSERT_NOT_REACHED();
     97        else
     98            ASSERT_NOT_REACHED();
     99        this._removeFromLayoutQueue(layoutBox);
     100        this._addToLayoutQueue(layoutBox.nextInFlowOrFloatSibling());
    81101    }
    82102
  • trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/Line.js

    r230386 r230464  
    6363    }
    6464
     65    addInlineContainerBox(size) {
     66        let width = size.width();
     67        ASSERT(width <= this.m_availableWidth);
     68        this.shrink(width);
     69        let lineBoxRect = new LayoutRect(this.rect().topRight(), size);
     70        this.m_lineBoxes.push({lineBoxRect});
     71        this.m_lineRect.growHorizontally(width);
     72    }
     73
    6574    addTextLineBox(startPosition, endPosition, size) {
    66         ASSERT(size.width() <= this.m_availableWidth);
    67         this.m_availableWidth -= size.width();
     75        let width = size.width();
     76        ASSERT(width <= this.m_availableWidth);
     77        this.shrink(width);
    6878        // TODO: use the actual height instead of the line height.
    69         let lineBoxRect = new LayoutRect(this.rect().topRight(), new LayoutSize(size.width(), this.rect().height()));
     79        let lineBoxRect = new LayoutRect(this.rect().topRight(), new LayoutSize(width, this.rect().height()));
    7080        this.m_lineBoxes.push({startPosition, endPosition, lineBoxRect});
    71         this.m_lineRect.growBy(new LayoutSize(size.width(), 0));
     81        this.m_lineRect.growHorizontally(width);
    7282    }
    7383}
  • trunk/Tools/LayoutReloaded/LayoutTree/Box.js

    r230373 r230464  
    128128    }
    129129
     130    isInlineBlockBox() {
     131        return Utils.isInlineBlockElement(this.node());
     132    }
     133
    130134    isInlineLevelBox() {
    131135        return Utils.isInlineLevelElement(this.node());
  • trunk/Tools/LayoutReloaded/Utils.js

    r230373 r230464  
    209209    }
    210210
     211    growHorizontally(distance) {
     212        this.m_size.setWidth(this.m_size.width() + distance);
     213    }
     214
    211215    moveHorizontally(distance) {
    212216        this.m_topLeft.shiftLeft(distance);
     
    424428
    425429    static isBlockContainerElement(node) {
    426         if (node.nodeType != Node.ELEMENT_NODE)
     430        if (!node || node.nodeType != Node.ELEMENT_NODE)
    427431            return false;
    428432        let display = window.getComputedStyle(node).display;
     
    438442        let display = window.getComputedStyle(node).display;
    439443        return  display == "table" || display == "inline-table";
     444    }
     445
     446    static isInlineBlockElement(node) {
     447        if (!node || node.nodeType != Node.ELEMENT_NODE)
     448            return false;
     449        let display = window.getComputedStyle(node).display;
     450        return  display == "inline-block";
    440451    }
    441452
     
    581592            line.lineBoxes().forEach(function(lineBox) {
    582593                let indentation = " ".repeat(level + 1);
    583                 content += indentation + "InlineTextBox at (" + Utils.precisionRound(lineBox.lineBoxRect.left(), 2) + "," + Utils.precisionRound(lineBox.lineBoxRect.top(), 2) + ") size " + Utils.precisionRound(lineBox.lineBoxRect.width(), 2) + "x" + lineBox.lineBoxRect.height() + "\n";
     594                let inlineBoxName = lineBox.startPosition === undefined ? "InlineBox" : "InlineTextBox";
     595                content += indentation +  inlineBoxName + " at (" + Utils.precisionRound(lineBox.lineBoxRect.left(), 2) + "," + Utils.precisionRound(lineBox.lineBoxRect.top(), 2) + ") size " + Utils.precisionRound(lineBox.lineBoxRect.width(), 2) + "x" + lineBox.lineBoxRect.height() + "\n";
    584596            });
    585597        });
  • trunk/Tools/LayoutReloaded/test/index.html

    r230386 r230464  
    7979    "inline-formatting-context-floats1.html",
    8080    "inline-formatting-context-floats2.html",
    81     "inline-with-padding-border-margin-offsets.html"
     81    "inline-with-padding-border-margin-offsets.html",
     82    "inline-block-with-fixed-width-height.html"
    8283];
    8384
Note: See TracChangeset for help on using the changeset viewer.