Diff
Modified: trunk/Tools/ChangeLog (229785 => 229786)
--- trunk/Tools/ChangeLog 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/ChangeLog 2018-03-21 04:42:32 UTC (rev 229786)
@@ -1,3 +1,71 @@
+2018-03-20 Zalan Bujtas <[email protected]>
+
+ [LayoutReloaded] Disconnect Display.Box from Layout.Box
+ https://bugs.webkit.org/show_bug.cgi?id=183805
+
+ Reviewed by Antti Koivisto.
+
+ Display.Box is only accessed through the FormattingState.
+
+ * LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js:
+ (BlockFormattingContext):
+ (BlockFormattingContext.prototype.layout):
+ (BlockFormattingContext.prototype._placeInFlowPositionedChildren):
+ (BlockFormattingContext.prototype._layoutOutOfFlowDescendants):
+ (BlockFormattingContext.prototype._adjustBottomWithFIXME):
+ (BlockFormattingContext.prototype._computeOutOfFlowPosition):
+ * LayoutReloaded/FormattingContext/FormattingContext.js:
+ (FormattingContext):
+ (FormattingContext.prototype.formattingRoot):
+ (FormattingContext.prototype.formattingState):
+ (FormattingContext.prototype.layoutState):
+ (FormattingContext.prototype._toAbsolutePosition):
+ (FormattingContext.prototype._toRootAbsolutePosition):
+ (FormattingContext.prototype._addToLayoutQueue):
+ (FormattingContext.prototype.displayBox):
+ (FormattingContext.prototype._outOfFlowDescendants):
+ (FormattingContext.prototype.rootContainer): Deleted.
+ (FormattingContext.prototype.layoutContext): Deleted.
+ * LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js:
+ (InlineFormattingContext):
+ (InlineFormattingContext.prototype.layout):
+ (InlineFormattingContext.prototype._initializeLine):
+ * LayoutReloaded/FormattingState/BlockFormattingState.js:
+ (BlockFormattingState):
+ * LayoutReloaded/FormattingState/FormattingState.js:
+ (FormattingState):
+ (FormattingState.prototype.formattingRoot):
+ (FormattingState.prototype.layoutState):
+ (FormattingState.prototype.createDisplayBox):
+ (FormattingState.prototype.displayBoxMap):
+ (FormattingState.prototype.displayBox):
+ (FormattingState.prototype.layoutContext): Deleted.
+ * LayoutReloaded/FormattingState/InlineFormattingState.js:
+ (InlineFormattingState):
+ * LayoutReloaded/Layout.js:
+ (layout):
+ * LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata:
+ * LayoutReloaded/LayoutState.js: Renamed from Tools/LayoutReloaded/LayoutContext.js.
+ (LayoutState):
+ (LayoutState.prototype.layout):
+ (LayoutState.prototype._createFormattingState):
+ (LayoutState.prototype.formattingStates):
+ (LayoutState.prototype.initialDisplayBox):
+ * LayoutReloaded/LayoutTree/Box.js:
+ (Layout.Box.prototype.isOutOfFlowPositioned):
+ (Layout.Box.prototype.containingBlock):
+ (Layout.Box.prototype.setDisplayBox): Deleted.
+ (Layout.Box.prototype.displayBox): Deleted.
+ * LayoutReloaded/Utils.js:
+ (Utils.layoutTreeDump):
+ (Utils._findDisplayBox):
+ (Utils._dumpBox):
+ (Utils._dumpTree):
+ * LayoutReloaded/misc/headers/BlockFormattingContext.h:
+ * LayoutReloaded/misc/headers/FormattingContext.h:
+ * LayoutReloaded/misc/headers/LayoutContext.h:
+ * LayoutReloaded/test/index.html:
+
2018-03-19 Ryosuke Niwa <[email protected]>
Expose content attributes on _WKLinkIconParameters
Modified: trunk/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingContext/BlockFormatting/BlockFormattingContext.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class BlockFormattingContext extends FormattingContext {
- constructor(root, layoutState) {
- super(root, layoutState);
+ constructor(blockFormattingState) {
+ super(blockFormattingState);
// New block formatting context always establishes a new floating context.
this.m_floatingContext = new FloatingContext(this);
}
@@ -37,8 +37,8 @@
// This is a post-order tree traversal layout.
// 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.
- if (this.rootContainer().firstInFlowOrFloatChild())
- this._addToLayoutQueue(this.rootContainer().firstInFlowOrFloatChild());
+ if (this.formattingRoot().firstInFlowOrFloatChild())
+ this._addToLayoutQueue(this.formattingRoot().firstInFlowOrFloatChild());
// 1. Go all the way down to the leaf node
// 2. Compute static position and width as we travers down
// 3. As we climb back on the tree, compute height and finialize position
@@ -50,7 +50,7 @@
this.computeWidth(layoutBox);
this._computeStaticPosition(layoutBox);
if (layoutBox.establishesFormattingContext()) {
- this.layoutContext().layout(layoutBox);
+ this.layoutState().layout(layoutBox);
break;
}
if (!layoutBox.isContainer() || !layoutBox.hasInFlowOrFloatChild())
@@ -76,7 +76,7 @@
}
}
// Place the inflow positioned children.
- this._placeInFlowPositionedChildren(this.rootContainer());
+ this._placeInFlowPositionedChildren(this.formattingRoot());
// And take care of out-of-flow boxes as the final step.
this._layoutOutOfFlowDescendants();
}
@@ -124,7 +124,7 @@
if (!container.isContainer())
return;
// If this layoutBox also establishes a formatting context, then positioning already has happend at the formatting context.
- if (container.establishesFormattingContext() && container != this.rootContainer())
+ if (container.establishesFormattingContext() && container != this.formattingRoot())
return;
ASSERT(container.isContainer());
for (let inFlowChild = container.firstInFlowChild(); inFlowChild; inFlowChild = inFlowChild.nextInFlowSibling()) {
@@ -141,7 +141,7 @@
for (let outOfFlowBox of outOfFlowDescendants) {
this._addToLayoutQueue(outOfFlowBox);
this.computeWidth(outOfFlowBox);
- this.layoutContext().layout(outOfFlowBox);
+ this.layoutState().layout(outOfFlowBox);
this.computeHeight(outOfFlowBox);
this._computeOutOfFlowPosition(outOfFlowBox);
this._removeFromLayoutQueue(outOfFlowBox);
@@ -277,7 +277,7 @@
_adjustBottomWithFIXME(layoutBox) {
// FIXME: This function is a big FIXME.
let lastInFlowChild = layoutBox.lastInFlowChild();
- let lastInFlowDisplayBox = lastInFlowChild.displayBox();
+ let lastInFlowDisplayBox = this.displayBox(lastInFlowChild);
let bottom = lastInFlowDisplayBox.bottom() + this.marginBottom(lastInFlowChild);
// FIXME: margin for body
if (lastInFlowChild.name() == "RenderBody" && Utils.isHeightAuto(lastInFlowChild) && !this.displayBox(lastInFlowChild).contentBox().height())
@@ -318,9 +318,9 @@
// Vertically statically positioned.
// FIXME: Figure out if it is actually valid that we use the parent box as the container (which is not even in this formatting context).
let parent = layoutBox.parent();
- let parentDisplayBox = parent.displayBox();
+ let parentDisplayBox = this.displayBox(parent);
let previousInFlowSibling = layoutBox.previousInFlowSibling();
- let contentBottom = previousInFlowSibling ? previousInFlowSibling.displayBox().bottom() : parentDisplayBox.contentBox().top();
+ let contentBottom = previousInFlowSibling ? this.displayBox(previousInFlowSibling).bottom() : parentDisplayBox.contentBox().top();
top = contentBottom + this.marginTop(layoutBox);
// Convert static position (in parent coordinate system) to absolute (in containing block coordindate system).
if (parent != layoutBox.containingBlock())
@@ -338,7 +338,7 @@
// Horizontally statically positioned.
// FIXME: Figure out if it is actually valid that we use the parent box as the container (which is not even in this formatting context).
let parent = layoutBox.parent();
- let parentDisplayBox = parent.displayBox();
+ let parentDisplayBox = this.displayBox(parent);
left = parentDisplayBox.contentBox().left() + this.marginLeft(layoutBox);
// Convert static position (in parent coordinate system) to absolute (in containing block coordindate system).
if (parent != layoutBox.containingBlock())
Modified: trunk/Tools/LayoutReloaded/FormattingContext/FormattingContext.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingContext/FormattingContext.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingContext/FormattingContext.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -24,23 +24,22 @@
*/
class FormattingContext {
- constructor(rootContainer, layoutState) {
- this.m_rootContainer = rootContainer;
- this.m_layoutState = layoutState;
+ constructor(formattingState) {
+ this.m_formattingState = formattingState;
this.m_floatingContext = null;
this.m_layoutStack = new Array();
}
- rootContainer() {
- return this.m_rootContainer;
+ formattingRoot() {
+ return this.m_formattingState.formattingRoot();
}
- layoutState() {
- return this.m_layoutState;
+ formattingState() {
+ return this.m_formattingState;
}
- layoutContext() {
- return this.layoutState().layoutContext();
+ layoutState() {
+ return this.formattingState().layoutState();
}
floatingContext() {
@@ -104,11 +103,11 @@
_toAbsolutePosition(position, layoutBox, container) {
// We should never need to go beyond the root container.
- ASSERT(container == this.rootContainer() || container.isDescendantOf(this.rootContainer()));
+ ASSERT(container == this.formattingRoot() || container.isDescendantOf(this.formattingRoot()));
let absolutePosition = position;
let ascendant = layoutBox.containingBlock();
while (ascendant && ascendant != container) {
- ASSERT(ascendant.isDescendantOf(this.rootContainer()));
+ ASSERT(ascendant.isDescendantOf(this.formattingRoot()));
absolutePosition.moveBy(this.displayBox(ascendant).topLeft());
ascendant = ascendant.containingBlock();
}
@@ -116,7 +115,7 @@
}
_toRootAbsolutePosition(layoutBox) {
- return this._toAbsolutePosition(this.displayBox(layoutBox).topLeft(), layoutBox, this.rootContainer());
+ return this._toAbsolutePosition(this.displayBox(layoutBox).topLeft(), layoutBox, this.formattingRoot());
}
_descendantNeedsLayout() {
@@ -125,7 +124,7 @@
_addToLayoutQueue(layoutBox) {
// Initialize the corresponding display box.
- this.layoutState().createDisplayBox(layoutBox);
+ this.formattingState().createDisplayBox(layoutBox);
this.m_layoutStack.push(layoutBox);
}
@@ -142,7 +141,7 @@
}
displayBox(layoutBox) {
- return this.layoutState().displayBox(layoutBox);
+ return this.formattingState().displayBox(layoutBox);
}
_outOfFlowDescendants() {
@@ -154,7 +153,7 @@
// and there is not other formatting context inbetween.
let allOutOfFlowBoxes = new Array();
let descendants = new Array();
- for (let child = this.rootContainer().firstChild(); child; child = child.nextSibling())
+ for (let child = this.formattingRoot().firstChild(); child; child = child.nextSibling())
descendants.push(child);
while (descendants.length) {
let descendant = descendants.pop();
@@ -169,9 +168,9 @@
for (let outOfFlowBox of allOutOfFlowBoxes) {
let containingBlock = outOfFlowBox.containingBlock();
// Collect the out-of-flow descendant that belong to this formatting context.
- if (containingBlock == this.rootContainer())
+ if (containingBlock == this.formattingRoot())
outOfFlowBoxes.push(outOfFlowBox);
- else if (containingBlock.isDescendantOf(this.rootContainer())) {
+ else if (containingBlock.isDescendantOf(this.formattingRoot())) {
if (!containingBlock.establishesFormattingContext() || !containingBlock.isPositioned())
outOfFlowBoxes.push(outOfFlowBox);
}
Modified: trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingContext/InlineFormatting/InlineFormattingContext.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -24,8 +24,8 @@
*/
class InlineFormattingContext extends FormattingContext {
- constructor(root, layoutState) {
- super(root, layoutState);
+ constructor(inlineFormattingState) {
+ super(inlineFormattingState);
// If the block container box that initiates this inline formatting contex also establishes a block context, create a new float for us.
ASSERT(root.isBlockContainerBox());
if (root.establishesBlockFormattingContext())
@@ -42,17 +42,17 @@
layout() {
// 9.4.2 Inline formatting contexts
// In an inline formatting context, boxes are laid out horizontally, one after the other, beginning at the top of a containing block.
- if (!this.rootContainer().firstChild())
+ if (!this.formattingRoot().firstChild())
return;
// This is a post-order tree traversal layout.
// 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.
- this._addToLayoutQueue(this.rootContainer().firstChild());
+ this._addToLayoutQueue(this.formattingRoot().firstChild());
while (layoutStack.length) {
// Travers down on the descendants until we find a leaf node.
while (true) {
let layoutBox = this._nextInLayoutQueue();
if (layoutBox.establishesFormattingContext()) {
- this.layoutContext().layout(layoutBox);
+ this.layoutState().layout(layoutBox);
break;
}
if (!layoutBox.isContainer() || !layoutBox.hasChild())
@@ -70,7 +70,7 @@
}
}
}
- //this._placeOutOfFlowDescendants(this.rootContainer());
+ //this._placeOutOfFlowDescendants(this.formattingRoot());
this._commitLine();
}
@@ -106,8 +106,8 @@
_initializeLine() {
// TODO: Floats need to be taken into account.
- let contentBoxRect = this.rootContainer().contentBox();
- this.m_line = new Line(contentBoxRect.topLeft(), Utils.computedLineHeight(this.rootContainer()), contentBoxRect.width());
+ let contentBoxRect = this.formattingRoot().contentBox();
+ this.m_line = new Line(contentBoxRect.topLeft(), Utils.computedLineHeight(this.formattingRoot()), contentBoxRect.width());
}
}
Modified: trunk/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingState/BlockFormattingState.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -24,8 +24,8 @@
*/
class BlockFormattingState extends FormattingState {
- constructor(formattingRoot, layoutContext) {
- super(layoutContext);
- this._setFormattingContext(new BlockFormattingContext(formattingRoot, this));
+ constructor(formattingRoot, layoutState) {
+ super(layoutState, formattingRoot);
+ this._setFormattingContext(new BlockFormattingContext(this));
}
}
Modified: trunk/Tools/LayoutReloaded/FormattingState/FormattingState.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingState/FormattingState.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingState/FormattingState.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -24,9 +24,10 @@
*/
class FormattingState {
- constructor(layoutContext) {
- this.m_layoutContext = layoutContext;
+ constructor(layoutState, formattingRoot) {
+ this.m_layoutState = layoutState;
this.m_formattingContext = null;
+ this.m_formattingRoot = formattingRoot;
this.m_displayToLayout = new Map();
}
@@ -34,20 +35,43 @@
return this.m_formattingContext;
}
- layoutContext() {
- return this.m_layoutContext;
+ formattingRoot() {
+ return this.m_formattingRoot;
}
+ layoutState() {
+ return this.m_layoutState;
+ }
+
createDisplayBox(layoutBox) {
let displayBox = new Display.Box(layoutBox.node());
this.m_displayToLayout.set(layoutBox, displayBox);
- // This is temporary.
- layoutBox.setDisplayBox(displayBox);
}
+ displayBoxMap() {
+ return this.m_displayToLayout;
+ }
+
displayBox(layoutBox) {
ASSERT(layoutBox);
- return layoutBox.displayBox();
+ // 1. Normally we only need to access boxes within the same formatting context
+ // 2. In some cases we need size information about the root container -which is in the parent formatting context
+ // 3. In rare cases (statically positioned out-of-flow box), we need position information on sibling formatting context
+ // but in all cases it needs to be a descendant of the root container (or the container itself)
+ ASSERT(layoutBox == this.formattingRoot() || layoutBox.isDescendantOf(this.formattingRoot()));
+ let displayBox = this.m_displayToLayout.get(layoutBox);
+ if (displayBox)
+ return displayBox;
+
+ let formattingStates = this.layoutState().formattingStates();
+ for (let formattingState of formattingStates) {
+ let displayBox = formattingState[1].displayBoxMap().get(layoutBox);
+ if (displayBox)
+ return displayBox;
+ }
+ // It must be the ICB.
+ ASSERT(!layoutBox.parent());
+ return this.layoutState().initialDisplayBox();
}
_setFormattingContext(formattingContext) {
Modified: trunk/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/FormattingState/InlineFormattingState.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -24,8 +24,8 @@
*/
class InlineFormattingState extends FormattingState {
- constructor(formattingRoot, layoutContext) {
- super(layoutContext);
- this._setFormattingContext(new InlineFormattingContext(formattingRoot, this));
+ constructor(formattingRoot, layoutState) {
+ super(layoutState, formattingRoot);
+ this._setFormattingContext(new InlineFormattingContext(this));
}
}
Modified: trunk/Tools/LayoutReloaded/Layout.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/Layout.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/Layout.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -28,9 +28,7 @@
let initialContainingBlock = treeBuilder.createTree(window.document, window.renderTreeStructure);
let displayBox = new Display.Box();
displayBox.setSize(viewportSize);
- initialContainingBlock.setDisplayBox(displayBox);
-
- let layoutContext = new LayoutContext(initialContainingBlock);
- layoutContext.layout(initialContainingBlock);
- return Utils.layoutTreeDump(initialContainingBlock);
+ let layoutState = new LayoutState(displayBox);
+ layoutState.layout(initialContainingBlock);
+ return Utils.layoutTreeDump(initialContainingBlock, layoutState);
}
Deleted: trunk/Tools/LayoutReloaded/LayoutContext.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/LayoutContext.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/LayoutContext.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-class LayoutContext {
- constructor() {
- this.m_layoutStates = new Map();
- }
-
- layout(formattingRoot) {
- let formattingState = this._createFormattingState(formattingRoot);
- this.m_layoutStates.set(formattingRoot, formattingState);
- formattingState.formattingContext().layout();
- }
-
- _createFormattingState(formattingRoot) {
- ASSERT(formattingRoot.establishesFormattingContext());
- if (formattingRoot.establishesBlockFormattingContext())
- return new BlockFormattingState(formattingRoot, this);
- if (formattingRoot.establishesInlineFormattingContext())
- return new InlineFormattingState(formattingRoot, this);
- ASSERT_NOT_REACHED();
- return null;
- }
-}
Modified: trunk/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata (229785 => 229786)
--- trunk/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/LayoutReloaded.xcworkspace/contents.xcworkspacedata 2018-03-21 04:42:32 UTC (rev 229786)
@@ -20,7 +20,7 @@
location = "group:Layout.js">
</FileRef>
<FileRef
- location = "group:LayoutContext.js">
+ location = "group:LayoutState.js">
</FileRef>
<FileRef
location = "group:Utils.js">
Copied: trunk/Tools/LayoutReloaded/LayoutState.js (from rev 229785, trunk/Tools/LayoutReloaded/LayoutContext.js) (0 => 229786)
--- trunk/Tools/LayoutReloaded/LayoutState.js (rev 0)
+++ trunk/Tools/LayoutReloaded/LayoutState.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+class LayoutState {
+ constructor(initialDisplayBox) {
+ this.m_formattingStates = new Map();
+ this.m_initialDisplayBox = initialDisplayBox;
+ }
+
+ layout(formattingRoot) {
+ let formattingState = this._createFormattingState(formattingRoot);
+ this.m_formattingStates.set(formattingRoot, formattingState);
+ formattingState.formattingContext().layout();
+ }
+
+ _createFormattingState(formattingRoot) {
+ ASSERT(formattingRoot.establishesFormattingContext());
+ if (formattingRoot.establishesBlockFormattingContext())
+ return new BlockFormattingState(formattingRoot, this);
+ if (formattingRoot.establishesInlineFormattingContext())
+ return new InlineFormattingState(formattingRoot, this);
+ ASSERT_NOT_REACHED();
+ return null;
+ }
+
+ formattingStates() {
+ return this.m_formattingStates;
+ }
+
+ initialDisplayBox() {
+ return this.m_initialDisplayBox;
+ }
+}
Modified: trunk/Tools/LayoutReloaded/LayoutTree/Box.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/LayoutTree/Box.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/LayoutTree/Box.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -107,16 +107,6 @@
this.m_previousSibling = previousSibling;
}
- setDisplayBox(displayBox) {
- ASSERT(!this.m_displayBox);
- this.m_displayBox = displayBox;
- }
-
- displayBox() {
- ASSERT(this.m_displayBox);
- return this.m_displayBox;
- }
-
isContainer() {
return false;
}
@@ -183,7 +173,7 @@
}
isOutOfFlowPositioned() {
- return this.isAbsolutelyPositioned() || this.isFixedPositioned();
+ return this.isAbsolutelyPositioned();
}
isInFlowPositioned() {
@@ -209,7 +199,7 @@
return null;
if (!this.isPositioned() || this.isInFlowPositioned())
return this.parent();
- if (this.isAbsolutelyPositioned() && !this.isFixedPositioned()) {
+ if (this.isOutOfFlowPositioned() && !this.isFixedPositioned()) {
let ascendant = this.parent();
while (ascendant.parent() && !ascendant.isPositioned())
ascendant = ascendant.parent();
Modified: trunk/Tools/LayoutReloaded/Utils.js (229785 => 229786)
--- trunk/Tools/LayoutReloaded/Utils.js 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/Utils.js 2018-03-21 04:42:32 UTC (rev 229786)
@@ -491,11 +491,21 @@
}
// "RenderView at (0,0) size 1317x366\n HTML RenderBlock at (0,0) size 1317x116\n BODY RenderBody at (8,8) size 1301x100\n DIV RenderBlock at (0,0) size 100x100\n";
- static layoutTreeDump(initialContainingBlock) {
- return this._dumpBox(initialContainingBlock, 1) + this._dumpTree(initialContainingBlock, 2);
+ static layoutTreeDump(initialContainingBlock, layoutState) {
+ return this._dumpBox(layoutState, initialContainingBlock, 1) + this._dumpTree(layoutState, initialContainingBlock, 2);
}
- static _dumpBox(box, level) {
+ static _findDisplayBox(layoutState, box) {
+ for (let formattingState of layoutState.formattingStates()) {
+ let displayBox = formattingState[1].displayBoxMap().get(box);
+ if (displayBox)
+ return displayBox;
+ }
+ ASSERT(!box.parent());
+ return layoutState.initialDisplayBox();
+ }
+
+ static _dumpBox(layoutState, box, level) {
// 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);
@@ -505,7 +515,7 @@
}
if (box.isAnonymous())
return "";
- let displayBox = box.displayBox();
+ let displayBox = Utils._findDisplayBox(layoutState, box);
let boxRect = displayBox.rect();
return indentation + (box.node().tagName ? (box.node().tagName + " ") : "") + box.name() + " at (" + boxRect.left() + "," + boxRect.top() + ") size " + boxRect.width() + "x" + boxRect.height() + "\n";
}
@@ -527,14 +537,14 @@
return content;
}
- static _dumpTree(root, level) {
+ static _dumpTree(layoutState, root, level) {
let content = "";
if (root.isBlockContainerBox() && root.establishesInlineFormattingContext())
content += this._dumpLines(root, level);
for (let child = root.firstChild(); child; child = child.nextSibling()) {
- content += this._dumpBox(child, level);
+ content += this._dumpBox(layoutState, child, level);
if (child.isContainer())
- content += this._dumpTree(child, level + 1, content);
+ content += this._dumpTree(layoutState, child, level + 1, content);
}
return content;
}
Modified: trunk/Tools/LayoutReloaded/misc/headers/BlockFormattingContext.h (229785 => 229786)
--- trunk/Tools/LayoutReloaded/misc/headers/BlockFormattingContext.h 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/misc/headers/BlockFormattingContext.h 2018-03-21 04:42:32 UTC (rev 229786)
@@ -30,7 +30,7 @@
class BlockContainer;
class Box;
class FloatingContext;
-class LayoutContext;
+class LayoutState;
class BlockFormattingContext : public FormattingContext {
public:
@@ -37,7 +37,7 @@
BlockFormattingContext(BlockContainer& root);
virtual ~BlockFormattingContext();
- void layout(LayoutContext&) final;
+ void layout(LayoutState&) final;
private:
LayoutUnit computeWidth(const Box&) const final;
Modified: trunk/Tools/LayoutReloaded/misc/headers/FormattingContext.h (229785 => 229786)
--- trunk/Tools/LayoutReloaded/misc/headers/FormattingContext.h 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/misc/headers/FormattingContext.h 2018-03-21 04:42:32 UTC (rev 229786)
@@ -28,16 +28,16 @@
class Box;
class Container;
class FloatingContext;
-class LayoutContext;
+class LayoutState;
class FormattingContext {
public:
- FormattingContext(Container& rootContainer);
+ FormattingContext();
- Container& rootContainer() const;
+ Container& formattingRoot() const;
FloatingContext& floatingContext() const;
- virtual void layout(const LayoutContext&) = 0;
+ virtual void layout(const LayoutState&) = 0;
protected:
virtual LayoutUnit computeWidth(const Box&) const;
Modified: trunk/Tools/LayoutReloaded/misc/headers/LayoutContext.h (229785 => 229786)
--- trunk/Tools/LayoutReloaded/misc/headers/LayoutContext.h 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/misc/headers/LayoutContext.h 2018-03-21 04:42:32 UTC (rev 229786)
@@ -27,9 +27,9 @@
class FormattingContext;
-class LayoutContext {
+class LayoutState {
public:
- LayoutContext();
+ LayoutState();
void layoutFormattingContext(FormattingContext&);
};
Modified: trunk/Tools/LayoutReloaded/test/index.html (229785 => 229786)
--- trunk/Tools/LayoutReloaded/test/index.html 2018-03-21 03:40:17 UTC (rev 229785)
+++ trunk/Tools/LayoutReloaded/test/index.html 2018-03-21 04:42:32 UTC (rev 229786)
@@ -77,7 +77,7 @@
addJS("../Utils.js");
addJS("../Layout.js");
addJS("../TreeBuilder.js");
-addJS("../LayoutContext.js");
+addJS("../LayoutState.js");
addJS("../LayoutTree/Box.js");
addJS("../LayoutTree/Container.js");
addJS("../LayoutTree/BlockContainer.js");