Diff
Modified: trunk/Source/WebCore/ChangeLog (250063 => 250064)
--- trunk/Source/WebCore/ChangeLog 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/ChangeLog 2019-09-18 23:33:08 UTC (rev 250064)
@@ -1,3 +1,46 @@
+2019-09-18 Zalan Bujtas <[email protected]>
+
+ [LFC] FormattingContext::Geometry/MarginCollapse/Quirk classes should not need to access non-const Display::Box
+ https://bugs.webkit.org/show_bug.cgi?id=201944
+ <rdar://problem/55493279>
+
+ Reviewed by Antti Koivisto.
+
+ This patch improves const correctness so that the Geometry/MarginCollapse/Quirk objects could not access non-const Display::Boxes (to mutate the display tree).
+ (The MarginCollapse::Update* functions are about updating the margin values on previously processed boxes so strictly speaking they are not margin collapsing related, but they somewhat belong to the MarginCollapse class -since they deal with margins.)
+
+ * layout/FormattingContext.h:
+ (WebCore::Layout::FormattingContext::formattingState const):
+ (WebCore::Layout::FormattingContext::formattingState):
+ * layout/FormattingState.cpp:
+ (WebCore::Layout::FormattingState::displayBox):
+ (WebCore::Layout::FormattingState::displayBox const): Deleted.
+ * layout/FormattingState.h:
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
+ * layout/blockformatting/BlockFormattingContext.h:
+ (WebCore::Layout::BlockFormattingContext::formattingState const):
+ (WebCore::Layout::BlockFormattingContext::formattingState):
+ * layout/blockformatting/BlockMarginCollapse.cpp:
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues const):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore const):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter const):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::updatePositiveNegativeMarginValues):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling const): Deleted.
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues): Deleted.
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore): Deleted.
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter): Deleted.
+ * layout/inlineformatting/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::collectInlineContent):
+ (WebCore::Layout::InlineFormattingContext::collectInlineContent const): Deleted.
+ * layout/inlineformatting/InlineFormattingContext.h:
+ (WebCore::Layout::InlineFormattingContext::formattingState const):
+ (WebCore::Layout::InlineFormattingContext::formattingState):
+ * layout/tableformatting/TableFormattingContext.h:
+ (WebCore::Layout::TableFormattingContext::formattingState const):
+ (WebCore::Layout::TableFormattingContext::formattingState):
+
2019-09-18 Chris Dumez <[email protected]>
BlobRegistry no longer needs SessionIDs
Modified: trunk/Source/WebCore/layout/FormattingContext.h (250063 => 250064)
--- trunk/Source/WebCore/layout/FormattingContext.h 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2019-09-18 23:33:08 UTC (rev 250064)
@@ -82,7 +82,8 @@
using LayoutQueue = Vector<const Box*>;
LayoutState& layoutState() const;
- FormattingState& formattingState() const { return m_formattingState; }
+ const FormattingState& formattingState() const { return m_formattingState; }
+ FormattingState& formattingState() { return m_formattingState; }
void computeBorderAndPadding(const Box&, Optional<UsedHorizontalValues> = WTF::nullopt);
Modified: trunk/Source/WebCore/layout/FormattingState.cpp (250063 => 250064)
--- trunk/Source/WebCore/layout/FormattingState.cpp 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/FormattingState.cpp 2019-09-18 23:33:08 UTC (rev 250064)
@@ -47,7 +47,7 @@
{
}
-Display::Box& FormattingState::displayBox(const Box& layoutBox) const
+Display::Box& FormattingState::displayBox(const Box& layoutBox)
{
// Should never need to mutate a display box outside of the formatting context.
ASSERT(&layoutState().establishedFormattingState(layoutBox.formattingContextRoot()) == this);
Modified: trunk/Source/WebCore/layout/FormattingState.h (250063 => 250064)
--- trunk/Source/WebCore/layout/FormattingState.h 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/FormattingState.h 2019-09-18 23:33:08 UTC (rev 250064)
@@ -65,7 +65,7 @@
LayoutState& layoutState() const { return m_layoutState; }
- Display::Box& displayBox(const Box& layoutBox) const;
+ Display::Box& displayBox(const Box& layoutBox);
// Since we layout the out-of-flow boxes at the end of the formatting context layout, it's okay to store them in the formatting state -as opposed to the containing block level.
using OutOfFlowBoxList = Vector<WeakPtr<const Box>>;
void addOutOfFlowBox(const Box& outOfFlowBox) { m_outOfFlowBoxes.append(makeWeakPtr(outOfFlowBox)); }
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (250063 => 250064)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2019-09-18 23:33:08 UTC (rev 250064)
@@ -448,9 +448,10 @@
displayBox.setContentBoxHeight(heightAndMargin.height);
displayBox.setVerticalMargin(verticalMargin);
- marginCollapse().updatePositiveNegativeMarginValues(layoutBox);
+ auto marginCollapse = this->marginCollapse();
+ MarginCollapse::updatePositiveNegativeMarginValues(*this, marginCollapse, layoutBox);
// Adjust the previous sibling's margin bottom now that this box's vertical margin is computed.
- marginCollapse().updateMarginAfterForPreviousSibling(layoutBox);
+ MarginCollapse::updateMarginAfterForPreviousSibling(*this, marginCollapse, layoutBox);
}
FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::computedIntrinsicWidthConstraints()
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (250063 => 250064)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2019-09-18 23:33:08 UTC (rev 250064)
@@ -104,8 +104,8 @@
EstimatedMarginBefore estimatedMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues);
LayoutUnit marginBeforeIgnoringCollapsingThrough(const Box&, UsedVerticalMargin::NonCollapsedValues);
- void updateMarginAfterForPreviousSibling(const Box&) const;
- void updatePositiveNegativeMarginValues(const Box&);
+ static void updateMarginAfterForPreviousSibling(BlockFormattingContext&, const MarginCollapse&, const Box&);
+ static void updatePositiveNegativeMarginValues(BlockFormattingContext&, const MarginCollapse&, const Box&);
bool marginBeforeCollapsesWithParentMarginBefore(const Box&) const;
bool marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box&) const;
@@ -125,9 +125,9 @@
MarginCollapse(const BlockFormattingContext&);
enum class MarginType { Before, After };
- PositiveAndNegativeVerticalMargin::Values positiveNegativeValues(const Box&, MarginType);
- PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues);
- PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginAfter(const Box&, UsedVerticalMargin::NonCollapsedValues);
+ PositiveAndNegativeVerticalMargin::Values positiveNegativeValues(const Box&, MarginType) const;
+ PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginBefore(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
+ PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginAfter(const Box&, UsedVerticalMargin::NonCollapsedValues) const;
bool hasClearance(const Box&) const;
LayoutState& layoutState() { return m_blockFormattingContext.layoutState(); }
@@ -165,7 +165,8 @@
bool hasPrecomputedMarginBefore(const Box&) const;
#endif
- BlockFormattingState& formattingState() const { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
+ const BlockFormattingState& formattingState() const { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
+ BlockFormattingState& formattingState() { return downcast<BlockFormattingState>(FormattingContext::formattingState()); }
private:
HashMap<const Box*, EstimatedMarginBefore> m_estimatedMarginBeforeList;
Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (250063 => 250064)
--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2019-09-18 23:33:08 UTC (rev 250064)
@@ -464,7 +464,7 @@
return *marginValues.positive + *marginValues.negative;
}
-void BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling(const Box& layoutBox) const
+void BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling(BlockFormattingContext& blockFormattingContext, const MarginCollapse& marginCollapse, const Box& layoutBox)
{
// 1. Get the margin before value from the next in-flow sibling. This is the same as this box's margin after value now since they are collapsed.
// 2. Update the collapsed margin after value as well as the positive/negative cache.
@@ -473,17 +473,17 @@
// 5. In case of collapsed through margins check if the before margin collapes with the previous inflow sibling's after margin.
// 6. If so, jump to #2.
// 7. No need to propagate to parent because its margin is not computed yet (estimated at most).
- auto& layoutState = this->layoutState();
auto* currentBox = &layoutBox;
- while (marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentBox)) {
+ auto& blockFormattingState = blockFormattingContext.formattingState();
+ while (marginCollapse.marginBeforeCollapsesWithPreviousSiblingMarginAfter(*currentBox)) {
auto& previousSibling = *currentBox->previousInFlowSibling();
- auto& previousSiblingDisplayBox = formattingContext().formattingState().displayBox(previousSibling);
+ auto& previousSiblingDisplayBox = blockFormattingState.displayBox(previousSibling);
auto previousSiblingVerticalMargin = previousSiblingDisplayBox.verticalMargin();
auto collapsedVerticalMarginBefore = previousSiblingVerticalMargin.collapsedValues().before;
- auto collapsedVerticalMarginAfter = formattingContext().geometryForBox(*currentBox).verticalMargin().before();
+ auto collapsedVerticalMarginAfter = blockFormattingContext.geometryForBox(*currentBox).verticalMargin().before();
- auto marginsCollapseThrough = this->marginsCollapseThrough(previousSibling);
+ auto marginsCollapseThrough = marginCollapse.marginsCollapseThrough(previousSibling);
if (marginsCollapseThrough)
collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
@@ -492,7 +492,6 @@
previousSiblingDisplayBox.setVerticalMargin(previousSiblingVerticalMargin);
// Update positive/negative cache.
- auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(previousSibling));
auto previousSiblingPositiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(previousSibling);
auto positiveNegativeMarginBefore = blockFormattingState.positiveAndNegativeVerticalMargin(*currentBox).before;
@@ -510,7 +509,7 @@
}
}
-PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeValues(const Box& layoutBox, MarginType marginType)
+PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeValues(const Box& layoutBox, MarginType marginType) const
{
auto& layoutState = this->layoutState();
auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
@@ -528,7 +527,7 @@
return positiveNegativeMarginAfter(layoutBox, nonCollapsedMargin);
}
-PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
+PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
{
auto firstChildCollapsedMarginBefore = [&]() -> PositiveAndNegativeVerticalMargin::Values {
if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutBox))
@@ -558,7 +557,7 @@
return computedPositiveAndNegativeMargin(collapsedMarginBefore, nonCollapsedBefore);
}
-PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
+PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues) const
{
auto lastChildCollapsedMarginAfter = [&]() -> PositiveAndNegativeVerticalMargin::Values {
if (!marginAfterCollapsesWithLastInFlowChildMarginAfter(layoutBox))
@@ -603,20 +602,19 @@
return marginValue(positiveNegativeMarginBefore(layoutBox, nonCollapsedValues)).valueOr(nonCollapsedValues.before);
}
-void BlockFormattingContext::MarginCollapse::updatePositiveNegativeMarginValues(const Box& layoutBox)
+void BlockFormattingContext::MarginCollapse::updatePositiveNegativeMarginValues(BlockFormattingContext& blockFormattingContext, const MarginCollapse& marginCollapse, const Box& layoutBox)
{
ASSERT(layoutBox.isBlockLevelBox());
- auto nonCollapsedValues = formattingContext().geometryForBox(layoutBox).verticalMargin().nonCollapsedValues();
+ auto nonCollapsedValues = blockFormattingContext.geometryForBox(layoutBox).verticalMargin().nonCollapsedValues();
- auto positiveNegativeMarginBefore = this->positiveNegativeMarginBefore(layoutBox, nonCollapsedValues);
- auto positiveNegativeMarginAfter = this->positiveNegativeMarginAfter(layoutBox, nonCollapsedValues);
+ auto positiveNegativeMarginBefore = marginCollapse.positiveNegativeMarginBefore(layoutBox, nonCollapsedValues);
+ auto positiveNegativeMarginAfter = marginCollapse.positiveNegativeMarginAfter(layoutBox, nonCollapsedValues);
- if (marginsCollapseThrough(layoutBox)) {
+ if (marginCollapse.marginsCollapseThrough(layoutBox)) {
positiveNegativeMarginBefore = computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, positiveNegativeMarginAfter);
positiveNegativeMarginAfter = positiveNegativeMarginBefore;
}
- auto& blockFormattingState = downcast<BlockFormattingState>(layoutState().formattingStateForBox(layoutBox));
- blockFormattingState.setPositiveAndNegativeVerticalMargin(layoutBox, { positiveNegativeMarginBefore, positiveNegativeMarginAfter });
+ blockFormattingContext.formattingState().setPositiveAndNegativeVerticalMargin(layoutBox, { positiveNegativeMarginBefore, positiveNegativeMarginAfter });
}
UsedVerticalMargin::CollapsedValues BlockFormattingContext::MarginCollapse::collapsedVerticalValues(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (250063 => 250064)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2019-09-18 23:33:08 UTC (rev 250064)
@@ -258,7 +258,7 @@
computeHeightAndMargin(layoutBox);
}
-void InlineFormattingContext::collectInlineContent() const
+void InlineFormattingContext::collectInlineContent()
{
// Traverse the tree and create inline items out of containers and leaf nodes. This essentially turns the tree inline structure into a flat one.
// <span>text<span></span><img></span> -> [ContainerStart][InlineBox][ContainerStart][ContainerEnd][InlineBox][ContainerEnd]
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (250063 => 250064)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2019-09-18 23:33:08 UTC (rev 250064)
@@ -106,9 +106,10 @@
void computeHeightAndMargin(const Box&);
void computeWidthAndMargin(const Box&, UsedHorizontalValues);
- void collectInlineContent() const;
+ void collectInlineContent();
- InlineFormattingState& formattingState() const { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }
+ const InlineFormattingState& formattingState() const { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }
+ InlineFormattingState& formattingState() { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }
// FIXME: Come up with a structure that requires no friending.
friend class Line;
};
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (250063 => 250064)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2019-09-18 23:16:48 UTC (rev 250063)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2019-09-18 23:33:08 UTC (rev 250064)
@@ -70,7 +70,8 @@
void initializeDisplayBoxToBlank(Display::Box&) const;
- TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
+ const TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
+ TableFormattingState& formattingState() { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
};
inline TableFormattingContext::Geometry::Geometry(const TableFormattingContext& tableFormattingContext)