Changeset 229671 in webkit


Ignore:
Timestamp:
Mar 16, 2018 10:12:24 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LayoutReloaded] Introduce Display.Box
https://bugs.webkit.org/show_bug.cgi?id=183700

Reviewed by Antti Koivisto.

Display.Box objects will end up in the display(box) tree. Currently
they are just hanging off of the Layout.Box objects.

  • LayoutReloaded/DisplayTree/Box.js: Added.

(Display.Box):
(Display.Box.prototype.rect):
(Display.Box.prototype.top):
(Display.Box.prototype.left):
(Display.Box.prototype.bottom):
(Display.Box.prototype.right):
(Display.Box.prototype.topLeft):
(Display.Box.prototype.bottomRight):
(Display.Box.prototype.setTopLeft):
(Display.Box.prototype.setSize):
(Display.Box.prototype.setWidth):
(Display.Box.prototype.setHeight):
(Display.Box.prototype.borderBox):
(Display.Box.prototype.paddingBox):
(Display.Box.prototype.contentBox):

  • LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:

(BlockFormattingContext):
(BlockFormattingContext.prototype.layout):
(BlockFormattingContext.prototype._toAbsolutePosition):
(BlockFormattingContext.prototype._needsLayout):
(BlockFormattingContext.prototype._addToLayoutQueue):
(BlockFormattingContext.prototype._nextInLayoutQueue):
(BlockFormattingContext.prototype._removeFromLayoutQueue):
(BlockFormattingContext.prototype._createDisplayBox):
(BlockFormattingContext.prototype._toDisplayBox):
(BlockFormattingContext.prototype._toLayoutBox):

  • LayoutReloaded/Layout.js:

(layout):

  • LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata:
  • LayoutReloaded/LayoutTree/Box.js:

(Layout.Box):
(Layout.Box.prototype.setDisplayBox):
(Layout.Box.prototype.displayBox):
(Layout.Box.prototype.rect):
(Layout.Box.prototype.setTopLeft):
(Layout.Box.prototype.setSize):
(Layout.Box.prototype.setWidth):
(Layout.Box.prototype.setHeight):
(Layout.Box.prototype.borderBox):
(Layout.Box.prototype.paddingBox):
(Layout.Box.prototype.contentBox):

  • LayoutReloaded/test/index.html:
Location:
trunk/Tools
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r229666 r229671  
     12018-03-16  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LayoutReloaded] Introduce Display.Box
     4        https://bugs.webkit.org/show_bug.cgi?id=183700
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Display.Box objects will end up in the display(box) tree. Currently
     9        they are just hanging off of the Layout.Box objects.
     10
     11        * LayoutReloaded/DisplayTree/Box.js: Added.
     12        (Display.Box):
     13        (Display.Box.prototype.rect):
     14        (Display.Box.prototype.top):
     15        (Display.Box.prototype.left):
     16        (Display.Box.prototype.bottom):
     17        (Display.Box.prototype.right):
     18        (Display.Box.prototype.topLeft):
     19        (Display.Box.prototype.bottomRight):
     20        (Display.Box.prototype.setTopLeft):
     21        (Display.Box.prototype.setSize):
     22        (Display.Box.prototype.setWidth):
     23        (Display.Box.prototype.setHeight):
     24        (Display.Box.prototype.borderBox):
     25        (Display.Box.prototype.paddingBox):
     26        (Display.Box.prototype.contentBox):
     27        * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
     28        (BlockFormattingContext):
     29        (BlockFormattingContext.prototype.layout):
     30        (BlockFormattingContext.prototype._toAbsolutePosition):
     31        (BlockFormattingContext.prototype._needsLayout):
     32        (BlockFormattingContext.prototype._addToLayoutQueue):
     33        (BlockFormattingContext.prototype._nextInLayoutQueue):
     34        (BlockFormattingContext.prototype._removeFromLayoutQueue):
     35        (BlockFormattingContext.prototype._createDisplayBox):
     36        (BlockFormattingContext.prototype._toDisplayBox):
     37        (BlockFormattingContext.prototype._toLayoutBox):
     38        * LayoutReloaded/Layout.js:
     39        (layout):
     40        * LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata:
     41        * LayoutReloaded/LayoutTree/Box.js:
     42        (Layout.Box):
     43        (Layout.Box.prototype.setDisplayBox):
     44        (Layout.Box.prototype.displayBox):
     45        (Layout.Box.prototype.rect):
     46        (Layout.Box.prototype.setTopLeft):
     47        (Layout.Box.prototype.setSize):
     48        (Layout.Box.prototype.setWidth):
     49        (Layout.Box.prototype.setHeight):
     50        (Layout.Box.prototype.borderBox):
     51        (Layout.Box.prototype.paddingBox):
     52        (Layout.Box.prototype.contentBox):
     53        * LayoutReloaded/test/index.html:
     54
    1552018-03-16  Chris Dumez  <cdumez@apple.com>
    256
  • trunk/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js

    r229664 r229671  
    2828        // New block formatting context always establishes a new floating context.
    2929        this.m_floatingContext = new FloatingContext(this);
     30        this.m_displayToLayout = new Map();
     31        this.m_layoutToDisplay = new Map();
     32        this.m_layoutStack = new Array();
    3033    }
    3134
     
    3841            return;
    3942        // This is a post-order tree traversal layout.
    40         let layoutStack = new Array();
    4143        // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child.
    42         layoutStack.push(this.rootContainer().firstChild());
     44        this._addToLayoutQueue(this.rootContainer().firstChild());
    4345        // 1. Go all the way down to the leaf node
    4446        // 2. Compute static position and width as we travers down
    4547        // 3. As we climb back on the tree, compute height and finialize position
    4648        // (Any subtrees with new formatting contexts need to layout synchronously)
    47         while (layoutStack.length) {
     49        while (this._needsLayout()) {
    4850            // Travers down on the descendants until we find a leaf node.
    4951            while (true) {
    50                 let layoutBox = layoutStack[layoutStack.length - 1];
     52                let layoutBox = this._nextInLayoutQueue();
    5153                this.computeWidth(layoutBox);
    5254                this._computeStaticPosition(layoutBox);
     
    5759                if (!layoutBox.isContainer() || !layoutBox.hasChild())
    5860                    break;
    59                 layoutStack.push(layoutBox.firstChild());
     61                this._addToLayoutQueue(layoutBox.firstChild());
    6062            }
    6163
    6264            // Climb back on the ancestors and compute height/final position.
    63             while (layoutStack.length) {
     65            while (this._needsLayout()) {
    6466                // All inflow descendants (if there are any) are laid out by now. Let's compute the box's height.
    65                 let layoutBox = layoutStack.pop();
     67                let layoutBox = this._nextInLayoutQueue();
    6668                this.computeHeight(layoutBox);
    6769                // Adjust position now that we have all the previous floats placed in this context -if needed.
     
    7375                    this._placeOutOfFlowDescendants(layoutBox);
    7476                }
     77                // We are done with laying out this box.
     78                this._removeFromLayoutQueue(layoutBox);
    7579                if (layoutBox.nextSibling()) {
    76                     layoutStack.push(layoutBox.nextSibling());
     80                    this._addToLayoutQueue(layoutBox.nextSibling());
    7781                    break;
    7882                }
     
    341345        return new LayoutRect(topLeft, layoutBox.rect().size());
    342346    }
     347
     348    _needsLayout() {
     349        return this.m_layoutStack.length;
     350    }
     351
     352    _addToLayoutQueue(layoutBox) {
     353        // Initialize the corresponding display box.
     354        this._createDisplayBox(layoutBox);
     355        this.m_layoutStack.push(layoutBox);
     356    }
     357
     358    _nextInLayoutQueue() {
     359        ASSERT(this.m_layoutStack.length);
     360        return this.m_layoutStack[this.m_layoutStack.length - 1];
     361    }
     362
     363    _removeFromLayoutQueue(layoutBox) {
     364        // With the current layout logic, the layoutBox should be at the top (this.m_layoutStack.pop() should do).
     365        ASSERT(this.m_layoutStack.length);
     366        ASSERT(this.m_layoutStack[this.m_layoutStack.length - 1] == layoutBox);
     367        this.m_layoutStack.splice(this.m_layoutStack.indexOf(layoutBox), 1);
     368    }
     369
     370    _createDisplayBox(layoutBox) {
     371        let displayBox = new Display.Box(layoutBox.node());
     372        this.m_displayToLayout.set(displayBox, layoutBox);
     373        this.m_layoutToDisplay.set(layoutBox, displayBox);
     374        // This is temporary.
     375        layoutBox.setDisplayBox(displayBox);
     376    }
     377
     378    _toDisplayBox(layoutBox) {
     379        ASSERT(layoutBox);
     380        ASSERT(this.m_layoutToDisplay.has(layoutBox));
     381        return this.m_layoutToDisplay.get(layout);
     382    }
     383
     384    _toLayoutBox(displayBox) {
     385        ASSERT(displayBox);
     386        ASSERT(this.m_displayToLayout.has(displayBox));
     387        return this.m_displayToLayout.get(layout);
     388    }
    343389}
    344 
  • trunk/Tools/LayoutReloaded/Layout.js

    r229473 r229671  
    2727    let treeBuilder = new TreeBuilder();
    2828    let initialContainingBlock = treeBuilder.createTree(window.document, window.renderTreeStructure);
     29    initialContainingBlock.setDisplayBox(new Display.Box());
    2930    initialContainingBlock.setSize(viewportSize);
    3031
  • trunk/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata

    r229522 r229671  
    22<Workspace
    33   version = "1.0">
     4   <FileRef
     5      location = "group:DisplayTree">
     6   </FileRef>
    47   <FileRef
    58      location = "group:test">
  • trunk/Tools/LayoutReloaded/LayoutTree/Box.js

    r229664 r229671  
    3535        this.m_previousSibling = null;
    3636        this.m_isAnonymous = false;
    37         this.m_rect = new LayoutRect(new LayoutPoint(0, 0), new LayoutSize(0, 0));
    3837        this.m_establishedFormattingContext = null;
     38        this.m_displayBox = null;
    3939    }
    4040
     
    9999    }
    100100
     101    setDisplayBox(displayBox) {
     102        ASSERT(!this.m_displayBox);
     103        this.m_displayBox = displayBox;
     104    }
     105
     106    displayBox() {
     107        ASSERT(this.m_displayBox);
     108        return this.m_displayBox;
     109    }
     110
    101111    rect() {
    102         return this.m_rect.clone();
     112        return this.displayBox().rect();
    103113    }
    104114
     
    112122
    113123    setTopLeft(topLeft) {
    114         this.m_rect.setTopLeft(topLeft);
     124        this.displayBox().setTopLeft(topLeft);
    115125    }
    116126
    117127    setSize(size) {
    118         this.m_rect.setSize(size);
     128        this.displayBox().setSize(size);
    119129    }
    120130
    121131    setWidth(width) {
    122         this.m_rect.setWidth(width);
     132        this.displayBox().setWidth(width);
    123133    }
    124134
    125135    setHeight(height) {
    126         this.m_rect.setHeight(height);
     136        this.displayBox().setHeight(height);
    127137    }
    128138
     
    235245
    236246    borderBox() {
    237         return new LayoutRect(new LayoutPoint(0, 0), this.rect().size());
     247        return this.displayBox().borderBox();
    238248    }
    239249
    240250    paddingBox() {
    241         let paddingBox = this.borderBox();
    242         let borderSize = Utils.computedBorderTopLeft(this.node());
    243         paddingBox.moveBy(borderSize);
    244         paddingBox.shrinkBy(borderSize);
    245         paddingBox.shrinkBy(Utils.computedBorderBottomRight(this.node()));
    246         return paddingBox;
     251        return this.displayBox().paddingBox();
    247252    }
    248253
    249254    contentBox() {
    250         let contentBox = this.paddingBox();
    251         let paddingSize = Utils.computedPaddingTopLeft(this.node());
    252         contentBox.moveBy(paddingSize);
    253         contentBox.shrinkBy(paddingSize);
    254         contentBox.shrinkBy(Utils.computedPaddingBottomRight(this.node()));
    255         return contentBox;
     255        return this.displayBox().contentBox();
    256256    }
    257257}
  • trunk/Tools/LayoutReloaded/test/index.html

    r229599 r229671  
    8282addJS("../LayoutTree/InlineBox.js");
    8383addJS("../LayoutTree/Text.js");
     84addJS("../DisplayTree/Box.js");
    8485addJS("../FormattingContext/FormattingContext.js");
    8586addJS("../FormattingContext/FloatingContext.js");
Note: See TracChangeset for help on using the changeset viewer.