Changeset 229671 in webkit
- Timestamp:
- Mar 16, 2018 10:12:24 AM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r229666 r229671 1 2018-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 1 55 2018-03-16 Chris Dumez <cdumez@apple.com> 2 56 -
trunk/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js
r229664 r229671 28 28 // New block formatting context always establishes a new floating context. 29 29 this.m_floatingContext = new FloatingContext(this); 30 this.m_displayToLayout = new Map(); 31 this.m_layoutToDisplay = new Map(); 32 this.m_layoutStack = new Array(); 30 33 } 31 34 … … 38 41 return; 39 42 // This is a post-order tree traversal layout. 40 let layoutStack = new Array();41 43 // 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()); 43 45 // 1. Go all the way down to the leaf node 44 46 // 2. Compute static position and width as we travers down 45 47 // 3. As we climb back on the tree, compute height and finialize position 46 48 // (Any subtrees with new formatting contexts need to layout synchronously) 47 while ( layoutStack.length) {49 while (this._needsLayout()) { 48 50 // Travers down on the descendants until we find a leaf node. 49 51 while (true) { 50 let layoutBox = layoutStack[layoutStack.length - 1];52 let layoutBox = this._nextInLayoutQueue(); 51 53 this.computeWidth(layoutBox); 52 54 this._computeStaticPosition(layoutBox); … … 57 59 if (!layoutBox.isContainer() || !layoutBox.hasChild()) 58 60 break; 59 layoutStack.push(layoutBox.firstChild());61 this._addToLayoutQueue(layoutBox.firstChild()); 60 62 } 61 63 62 64 // Climb back on the ancestors and compute height/final position. 63 while ( layoutStack.length) {65 while (this._needsLayout()) { 64 66 // 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(); 66 68 this.computeHeight(layoutBox); 67 69 // Adjust position now that we have all the previous floats placed in this context -if needed. … … 73 75 this._placeOutOfFlowDescendants(layoutBox); 74 76 } 77 // We are done with laying out this box. 78 this._removeFromLayoutQueue(layoutBox); 75 79 if (layoutBox.nextSibling()) { 76 layoutStack.push(layoutBox.nextSibling());80 this._addToLayoutQueue(layoutBox.nextSibling()); 77 81 break; 78 82 } … … 341 345 return new LayoutRect(topLeft, layoutBox.rect().size()); 342 346 } 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 } 343 389 } 344 -
trunk/Tools/LayoutReloaded/Layout.js
r229473 r229671 27 27 let treeBuilder = new TreeBuilder(); 28 28 let initialContainingBlock = treeBuilder.createTree(window.document, window.renderTreeStructure); 29 initialContainingBlock.setDisplayBox(new Display.Box()); 29 30 initialContainingBlock.setSize(viewportSize); 30 31 -
trunk/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata
r229522 r229671 2 2 <Workspace 3 3 version = "1.0"> 4 <FileRef 5 location = "group:DisplayTree"> 6 </FileRef> 4 7 <FileRef 5 8 location = "group:test"> -
trunk/Tools/LayoutReloaded/LayoutTree/Box.js
r229664 r229671 35 35 this.m_previousSibling = null; 36 36 this.m_isAnonymous = false; 37 this.m_rect = new LayoutRect(new LayoutPoint(0, 0), new LayoutSize(0, 0));38 37 this.m_establishedFormattingContext = null; 38 this.m_displayBox = null; 39 39 } 40 40 … … 99 99 } 100 100 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 101 111 rect() { 102 return this. m_rect.clone();112 return this.displayBox().rect(); 103 113 } 104 114 … … 112 122 113 123 setTopLeft(topLeft) { 114 this. m_rect.setTopLeft(topLeft);124 this.displayBox().setTopLeft(topLeft); 115 125 } 116 126 117 127 setSize(size) { 118 this. m_rect.setSize(size);128 this.displayBox().setSize(size); 119 129 } 120 130 121 131 setWidth(width) { 122 this. m_rect.setWidth(width);132 this.displayBox().setWidth(width); 123 133 } 124 134 125 135 setHeight(height) { 126 this. m_rect.setHeight(height);136 this.displayBox().setHeight(height); 127 137 } 128 138 … … 235 245 236 246 borderBox() { 237 return new LayoutRect(new LayoutPoint(0, 0), this.rect().size());247 return this.displayBox().borderBox(); 238 248 } 239 249 240 250 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(); 247 252 } 248 253 249 254 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(); 256 256 } 257 257 } -
trunk/Tools/LayoutReloaded/test/index.html
r229599 r229671 82 82 addJS("../LayoutTree/InlineBox.js"); 83 83 addJS("../LayoutTree/Text.js"); 84 addJS("../DisplayTree/Box.js"); 84 85 addJS("../FormattingContext/FormattingContext.js"); 85 86 addJS("../FormattingContext/FloatingContext.js");
Note: See TracChangeset
for help on using the changeset viewer.