Diff
Modified: trunk/Source/WebCore/ChangeLog (254335 => 254336)
--- trunk/Source/WebCore/ChangeLog 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/ChangeLog 2020-01-10 15:06:38 UTC (rev 254336)
@@ -1,3 +1,30 @@
+2020-01-10 Zalan Bujtas <[email protected]>
+
+ [LFC] Replace FormattingContext::EscapeTypes with EscapeReasons
+ https://bugs.webkit.org/show_bug.cgi?id=206050
+ <rdar://problem/58466862>
+
+ Reviewed by Antti Koivisto.
+
+ EscapeReason is more explicit about why certain formatting context escapes are allowed.
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::geometryForBox const):
+ * layout/FormattingContext.h:
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
+ (WebCore::Layout::FormattingContext::Geometry::staticVerticalPositionForOutOfFlowPositioned const):
+ (WebCore::Layout::FormattingContext::Geometry::staticHorizontalPositionForOutOfFlowPositioned const):
+ * layout/FormattingContextQuirks.cpp:
+ (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
+ * layout/floats/FloatingContext.cpp:
+ (WebCore::Layout::FloatingContext::absoluteDisplayBoxCoordinates const):
+ (WebCore::Layout::FloatingContext::mapToFloatingStateRoot const):
+ (WebCore::Layout::FloatingContext::mapTopToFloatingStateRoot const):
+ (WebCore::Layout::FloatingContext::mapPointFromFormattingContextRootToFloatingStateRoot const):
+ * layout/tableformatting/TableFormattingContext.cpp:
+ (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraHorizontalSpace):
+
2020-01-10 Charlie Turner <[email protected]>
[EME][ClearKey] Refactor CDMInstanceClearKey::updateLicense()
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -211,44 +211,61 @@
return mapHorizontalPositionToAncestor(*this, geometryForBox(layoutBox).right(), *layoutBox.containingBlock(), root());
}
-const Display::Box& FormattingContext::geometryForBox(const Box& layoutBox, Optional<EscapeType> escapeType) const
+const Display::Box& FormattingContext::geometryForBox(const Box& layoutBox, Optional<EscapeReason> escapeReason) const
{
- UNUSED_PARAM(escapeType);
+ UNUSED_PARAM(escapeReason);
#if ASSERT_ENABLED
auto isOkToAccessDisplayBox = [&] {
- // 1. Highly common case of accessing the formatting root's display box itself. This is formatting context escaping in the strict sense, since
- // the formatting context root box lives in the parent formatting context.
- // This happens e.g. when a block level box box needs to stretch horizontally and checks its containing block for horizontal space (this should probably be limited to reading horizontal constraint values).
- if (&layoutBox == &root())
+ if (!layoutBox.isInitialContainingBlock() && &layoutBox.formattingContextRoot() == &root()) {
+ // This is the non-escape case of accessing a box's geometry information within the same formatting context.
return true;
-
- // 2. Special case when accessing the ICB's display box
- if (layoutBox.isInitialContainingBlock()) {
- // There has to be a valid reason to access the ICB.
- if (!escapeType)
- return false;
- return *escapeType == EscapeType::AccessParentFormattingContext || *escapeType == EscapeType::AccessAncestorFormattingContext;
}
- // 3. Most common case of accessing box/containing block display box within the same formatting context tree.
- if (&layoutBox.formattingContextRoot() == &root())
+ if (&layoutBox == &root()) {
+ // FIXME: This is formatting context escaping in the strict sense, since the formatting context root box lives in the parent formatting context.
+ // This happens e.g. when a block level box box needs to stretch horizontally and checks its containing block for horizontal space (this should probably be limited to reading horizontal constraint values).
return true;
+ }
- if (!escapeType)
+ if (!escapeReason) {
+ // At this point any access is considered an escape.
return false;
+ }
- // 4. Accessing child formatting context subtree is relatively rare. It happens when e.g a shrink to fit (out-of-flow block level) box checks the content width.
- // Checking the content width means to get display boxes from the established formatting context (we try to access display boxes in a child formatting context)
- if (*escapeType == EscapeType::AccessChildFormattingContext && &layoutBox.formattingContextRoot().formattingContextRoot() == &root())
- return true;
+ if (*escapeReason == EscapeReason::BodyStrechesToViewportQuirk) {
+ ASSERT(layoutState().inQuirksMode());
+ return layoutBox.isInitialContainingBlock();
+ }
- // 5. Float box top/left values are mapped relative to the FloatState's root. Inline formatting contexts(A) inherit floats from parent
- // block formatting contexts(B). Floats in these inline formatting contexts(A) need to be mapped to the parent, block formatting context(B).
- if (*escapeType == EscapeType::AccessParentFormattingContext && &layoutBox.formattingContextRoot() == &root().formattingContextRoot())
+ if (*escapeReason == EscapeReason::StrokeOverflowNeedsViewportGeometry)
+ return layoutBox.isInitialContainingBlock();
+
+ if (*escapeReason == EscapeReason::NeedsGeometryFromEstablishedFormattingContext) {
+ // This is the case when a formatting root collects geometry information from the established
+ // formatting context to be able to determine width/height.
+ // e.g <div>text content</div>. The <div> is a formatting root of the IFC.
+ // In order to compute the height of the <div>, we need to look inside the IFC and gather geometry information.
+ return &layoutBox.formattingContextRoot().formattingContextRoot() == &root();
+ }
+
+ if (*escapeReason == EscapeReason::OutOfFlowBoxNeedsInFlowGeometry) {
+ // When computing the static position of an out-of-flow box, we need to gather sibling/parent geometry information
+ // as if the out-of-flow box was a simple inflow box.
+ // Now since the out-of-flow and the sibling/parent boxes could very well be in different containing block subtrees
+ // the formatting context they live in could also be very different.
return true;
+ }
- // 6. Finding the first containing block with fixed height quirk. See Quirks::heightValueOfNearestContainingBlockWithFixedHeight
- if (*escapeType == EscapeType::AccessAncestorFormattingContext) {
+ if (*escapeReason == EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates) {
+ // Float box top/left values are mapped relative to the FloatState's root. Inline formatting contexts(A) inherit floats from parent
+ // block formatting contexts(B). Floats in these inline formatting contexts(A) need to be mapped to the parent, block formatting context(B).
+ auto& formattingContextRoot = layoutBox.formattingContextRoot();
+ return &formattingContextRoot == &root() || &formattingContextRoot == &root().formattingContextRoot();
+ }
+
+ if (*escapeReason == EscapeReason::FindFixedHeightAncestorQuirk) {
+ ASSERT(layoutState().inQuirksMode());
+ // Find the first containing block with fixed height quirk. See Quirks::heightValueOfNearestContainingBlockWithFixedHeight
auto& targetFormattingRoot = layoutBox.formattingContextRoot();
auto* ancestorFormattingContextRoot = &root().formattingContextRoot();
while (true) {
@@ -258,15 +275,17 @@
return false;
ancestorFormattingContextRoot = &ancestorFormattingContextRoot->formattingContextRoot();
}
+ return false;
}
- // 7. Tables are wrapped in a 2 level formatting context structure. A <table> element initiates a block formatting context for its principal table box
- // where the caption and the table content live. It also initiates a table wrapper box which establishes the table formatting context.
- // In many cases the TFC needs access to the parent (generated) BFC.
- if (*escapeType == EscapeType::TableFormattingContextAccessParentTableWrapperBlockFormattingContext
- && (&layoutBox == &root().formattingContextRoot() || &layoutBox.formattingContextRoot() == &root().formattingContextRoot()))
- return true;
+ if (*escapeReason == EscapeReason::TableNeedsAccessToTableWrapper) {
+ // Tables are wrapped in a 2 level formatting context structure. A <table> element initiates a block formatting context for its principal table box
+ // where the caption and the table content live. It also initiates a table wrapper box which establishes the table formatting context.
+ // In many cases the TFC needs access to the parent (generated) BFC.
+ return &layoutBox == &root().formattingContextRoot();
+ }
+ ASSERT_NOT_REACHED();
return false;
};
#endif
Modified: trunk/Source/WebCore/layout/FormattingContext.h (254335 => 254336)
--- trunk/Source/WebCore/layout/FormattingContext.h 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2020-01-10 15:06:38 UTC (rev 254336)
@@ -84,13 +84,16 @@
bool isInlineFormattingContext() const { return root().establishesInlineFormattingContext(); }
bool isTableFormattingContext() const { return root().establishesTableFormattingContext(); }
- enum class EscapeType {
- AccessChildFormattingContext,
- AccessParentFormattingContext,
- AccessAncestorFormattingContext,
- TableFormattingContextAccessParentTableWrapperBlockFormattingContext
+ enum class EscapeReason {
+ NeedsGeometryFromEstablishedFormattingContext,
+ OutOfFlowBoxNeedsInFlowGeometry,
+ FloatBoxNeedsToBeInAbsoluteCoordinates,
+ FindFixedHeightAncestorQuirk,
+ BodyStrechesToViewportQuirk,
+ StrokeOverflowNeedsViewportGeometry,
+ TableNeedsAccessToTableWrapper
};
- const Display::Box& geometryForBox(const Box&, Optional<EscapeType> = WTF::nullopt) const;
+ const Display::Box& geometryForBox(const Box&, Optional<EscapeReason> = WTF::nullopt) const;
protected:
using LayoutQueue = Vector<const Box*>;
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -138,8 +138,8 @@
bottom = lineBoxes.last().logicalBottom();
} else if (formattingRootContainer.establishesBlockFormattingContext() || formattingRootContainer.establishesTableFormattingContext() || formattingRootContainer.isDocumentBox()) {
if (formattingRootContainer.hasInFlowChild()) {
- auto& firstBoxGeometry = formattingContext.geometryForBox(*formattingRootContainer.firstInFlowChild(), EscapeType::AccessChildFormattingContext);
- auto& lastBoxGeometry = formattingContext.geometryForBox(*formattingRootContainer.lastInFlowChild(), EscapeType::AccessChildFormattingContext);
+ auto& firstBoxGeometry = formattingContext.geometryForBox(*formattingRootContainer.firstInFlowChild(), EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
+ auto& lastBoxGeometry = formattingContext.geometryForBox(*formattingRootContainer.lastInFlowChild(), EscapeReason::NeedsGeometryFromEstablishedFormattingContext);
top = firstBoxGeometry.rectWithMargin().top();
bottom = lastBoxGeometry.rectWithMargin().bottom();
}
@@ -227,11 +227,11 @@
LayoutUnit top;
if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling()) {
// Add sibling offset
- auto& previousInFlowBoxGeometry = formattingContext.geometryForBox(*previousInFlowSibling, FormattingContext::EscapeType::AccessChildFormattingContext);
+ auto& previousInFlowBoxGeometry = formattingContext.geometryForBox(*previousInFlowSibling, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
top += previousInFlowBoxGeometry.bottom() + previousInFlowBoxGeometry.nonCollapsedMarginAfter();
} else {
ASSERT(layoutBox.parent());
- top = formattingContext.geometryForBox(*layoutBox.parent(), FormattingContext::EscapeType::AccessChildFormattingContext).contentBoxTop();
+ top = formattingContext.geometryForBox(*layoutBox.parent(), EscapeReason::OutOfFlowBoxNeedsInFlowGeometry).contentBoxTop();
}
// Resolve top all the way up to the containing block.
@@ -238,7 +238,7 @@
auto& containingBlock = *layoutBox.containingBlock();
// Start with the parent since we pretend that this box is normal flow.
for (auto* container = layoutBox.parent(); container != &containingBlock; container = container->containingBlock()) {
- auto& boxGeometry = formattingContext.geometryForBox(*container, FormattingContext::EscapeType::AccessChildFormattingContext);
+ auto& boxGeometry = formattingContext.geometryForBox(*container, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
// Display::Box::top is the border box top position in its containing block's coordinate system.
top += boxGeometry.top();
ASSERT(!container->isPositioned() || layoutBox.isFixedPositioned());
@@ -255,13 +255,13 @@
// Start with this box's border box offset from the parent's border box.
auto& formattingContext = this->formattingContext();
ASSERT(layoutBox.parent());
- auto left = formattingContext.geometryForBox(*layoutBox.parent(), FormattingContext::EscapeType::AccessChildFormattingContext).contentBoxLeft();
+ auto left = formattingContext.geometryForBox(*layoutBox.parent(), EscapeReason::OutOfFlowBoxNeedsInFlowGeometry).contentBoxLeft();
// Resolve left all the way up to the containing block.
auto& containingBlock = *layoutBox.containingBlock();
// Start with the parent since we pretend that this box is normal flow.
for (auto* container = layoutBox.parent(); container != &containingBlock; container = container->containingBlock()) {
- auto& boxGeometry = formattingContext.geometryForBox(*container, FormattingContext::EscapeType::AccessChildFormattingContext);
+ auto& boxGeometry = formattingContext.geometryForBox(*container, EscapeReason::OutOfFlowBoxNeedsInFlowGeometry);
// Display::Box::left is the border box left position in its containing block's coordinate system.
left += boxGeometry.left();
ASSERT(!container->isPositioned() || layoutBox.isFixedPositioned());
Modified: trunk/Source/WebCore/layout/FormattingContextQuirks.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/FormattingContextQuirks.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/FormattingContextQuirks.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -48,9 +48,9 @@
// If the only fixed value box we find is the ICB, then ignore the body and the document (vertical) margin, padding and border. So much quirkiness.
// -and it's totally insane because now we freely travel across formatting context boundaries and computed margins are nonexistent.
if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
- auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeType::AccessAncestorFormattingContext);
+ auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
- auto& containingBlockDisplayBox = formattingContext.geometryForBox(*containingBlock->containingBlock(), FormattingContext::EscapeType::AccessAncestorFormattingContext);
+ auto& containingBlockDisplayBox = formattingContext.geometryForBox(*containingBlock->containingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk);
auto horizontalConstraints = Geometry::horizontalConstraintsForInFlow(containingBlockDisplayBox);
auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, horizontalConstraints);
auto verticalPadding = boxGeometry.paddingTop().valueOr(0) + boxGeometry.paddingBottom().valueOr(0);
@@ -61,7 +61,7 @@
containingBlock = containingBlock->containingBlock();
}
// Initial containing block has to have a height.
- return formattingContext.geometryForBox(layoutBox.initialContainingBlock(), FormattingContext::EscapeType::AccessAncestorFormattingContext).contentBox().height() - bodyAndDocumentVerticalMarginPaddingAndBorder;
+ return formattingContext.geometryForBox(layoutBox.initialContainingBlock(), FormattingContext::EscapeReason::FindFixedHeightAncestorQuirk).contentBox().height() - bodyAndDocumentVerticalMarginPaddingAndBorder;
}
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -69,7 +69,7 @@
auto& documentBox = layoutBox.isDocumentBox() ? layoutBox : *layoutBox.parent();
auto& documentBoxGeometry = formattingContext.geometryForBox(documentBox);
- auto& initialContainingBlockGeometry = formattingContext.geometryForBox(initialContainingBlock(layoutBox));
+ auto& initialContainingBlockGeometry = formattingContext.geometryForBox(initialContainingBlock(layoutBox), EscapeReason::BodyStrechesToViewportQuirk);
auto strechedHeight = initialContainingBlockGeometry.contentBoxHeight();
strechedHeight -= documentBoxGeometry.verticalBorder() + documentBoxGeometry.verticalPadding().valueOr(0);
Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -425,7 +425,7 @@
auto displayBox = mapToFloatingStateRoot(floatAvoider);
if (&containingBlock == &floatingState().root()) {
- auto containingBlockGeometry = formattingContext().geometryForBox(containingBlock, FormattingContext::EscapeType::AccessParentFormattingContext);
+ auto containingBlockGeometry = formattingContext().geometryForBox(containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates);
return { displayBox, { }, { containingBlockGeometry.contentBoxLeft(), containingBlockGeometry.contentBoxRight() } };
}
auto containingBlockAbsoluteDisplayBox = mapToFloatingStateRoot(containingBlock);
@@ -436,10 +436,10 @@
Display::Box FloatingContext::mapToFloatingStateRoot(const Box& floatBox) const
{
auto& floatingStateRoot = floatingState().root();
- auto& boxGeometry = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeType::AccessParentFormattingContext);
+ auto& boxGeometry = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates);
auto topLeft = boxGeometry.topLeft();
for (auto* containingBlock = floatBox.containingBlock(); containingBlock && containingBlock != &floatingStateRoot; containingBlock = containingBlock->containingBlock())
- topLeft.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeType::AccessParentFormattingContext).topLeft());
+ topLeft.moveBy(formattingContext().geometryForBox(*containingBlock, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());
auto mappedDisplayBox = Display::Box(boxGeometry);
mappedDisplayBox.setTopLeft(topLeft);
@@ -449,9 +449,9 @@
LayoutUnit FloatingContext::mapTopToFloatingStateRoot(const Box& floatBox) const
{
auto& floatingStateRoot = floatingState().root();
- auto top = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeType::AccessParentFormattingContext).top();
+ auto top = formattingContext().geometryForBox(floatBox, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();
for (auto* container = floatBox.containingBlock(); container && container != &floatingStateRoot; container = container->containingBlock())
- top += formattingContext().geometryForBox(*container, FormattingContext::EscapeType::AccessParentFormattingContext).top();
+ top += formattingContext().geometryForBox(*container, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).top();
return top;
}
@@ -463,7 +463,7 @@
return position;
auto mappedPosition = position;
for (auto* container = &from; container && container != &to; container = container->containingBlock())
- mappedPosition.moveBy(formattingContext().geometryForBox(*container, FormattingContext::EscapeType::AccessParentFormattingContext).topLeft());
+ mappedPosition.moveBy(formattingContext().geometryForBox(*container, FormattingContext::EscapeReason::FloatBoxNeedsToBeInAbsoluteCoordinates).topLeft());
return mappedPosition;
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -466,7 +466,7 @@
// ICB is not the real ICB when lyoutFormattingContextIntegrationEnabled is on.
initialContaingBlockSize = layoutState().viewportSize();
} else
- initialContaingBlockSize = geometryForBox(root().initialContainingBlock()).contentBox().size();
+ initialContaingBlockSize = geometryForBox(root().initialContainingBlock(), EscapeReason::StrokeOverflowNeedsViewportGeometry).contentBox().size();
auto& inlineContent = formattingState.ensureDisplayInlineContent();
auto lineIndex = inlineContent.lineBoxes.size();
inlineContent.lineBoxes.append(lineContent.lineBox);
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (254335 => 254336)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-01-10 12:46:27 UTC (rev 254335)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2020-01-10 15:06:38 UTC (rev 254336)
@@ -316,7 +316,7 @@
};
auto& tableBox = root();
- auto containingBlockWidth = geometryForBox(*tableBox.containingBlock(), EscapeType::TableFormattingContextAccessParentTableWrapperBlockFormattingContext).contentBoxWidth();
+ auto containingBlockWidth = geometryForBox(*tableBox.containingBlock(), EscapeReason::TableNeedsAccessToTableWrapper).contentBoxWidth();
auto contentWidth = geometry().computedContentWidth(tableBox, containingBlockWidth);
if (contentWidth) {
if (*contentWidth > tableWidthConstraints.minimum)