Diff
Modified: trunk/Source/WebCore/ChangeLog (232224 => 232225)
--- trunk/Source/WebCore/ChangeLog 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/ChangeLog 2018-05-26 15:26:03 UTC (rev 232225)
@@ -1,3 +1,40 @@
+2018-05-26 Zalan Bujtas <[email protected]>
+
+ [LFC] Implement margin computation
+ https://bugs.webkit.org/show_bug.cgi?id=186008
+
+ Reviewed by Antti Koivisto.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::computeMargin const):
+ (WebCore::Layout::FormattingContext::marginTop const): Deleted.
+ (WebCore::Layout::FormattingContext::marginLeft const): Deleted.
+ (WebCore::Layout::FormattingContext::marginBottom const): Deleted.
+ (WebCore::Layout::FormattingContext::marginRight const): Deleted.
+ * layout/FormattingContext.h:
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::layout const):
+ (WebCore::Layout::BlockFormattingContext::computeMargin const):
+ (WebCore::Layout::BlockFormattingContext::marginTop const): Deleted.
+ (WebCore::Layout::BlockFormattingContext::marginBottom const): Deleted.
+ * layout/blockformatting/BlockFormattingContext.h:
+ * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeight):
+ (WebCore::Layout::BlockFormattingContext::Geometry::computedMargin):
+ * layout/blockformatting/BlockMarginCollapse.cpp:
+ (WebCore::Layout::_isMarginBottomCollapsedWithParent):
+ (WebCore::Layout::collapsedMarginBottomFromLastChild):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginTop):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBottom):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::isMarginBottomCollapsedWithParent):
+ (WebCore::Layout::BlockFormattingContext::MarginCollapse::isMarginTopCollapsedWithParentMarginBottom):
+ (WebCore::Layout::BlockMarginCollapse::marginTop): Deleted.
+ (WebCore::Layout::BlockMarginCollapse::marginBottom): Deleted.
+ (WebCore::Layout::BlockMarginCollapse::isMarginBottomCollapsedWithParent): Deleted.
+ (WebCore::Layout::BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom): Deleted.
+ * layout/blockformatting/BlockMarginCollapse.h: Removed.
+
2018-05-25 Myles C. Maxfield <[email protected]>
[Cocoa] Delete unnecessary WebCascadeList in ComplexTextController
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (232224 => 232225)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-05-26 15:26:03 UTC (rev 232225)
@@ -400,7 +400,6 @@
115CFA7E208B8E10001E6991 /* InlineFormattingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA7C208B8E10001E6991 /* InlineFormattingState.h */; };
115CFA82208B8EDA001E6991 /* FloatingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA80208B8EDA001E6991 /* FloatingState.h */; };
115CFA86208B9066001E6991 /* FloatingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA84208B9066001E6991 /* FloatingContext.h */; };
- 115CFA8A208B921A001E6991 /* BlockMarginCollapse.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA88208B921A001E6991 /* BlockMarginCollapse.h */; };
115CFA97208B952B001E6991 /* LayoutBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA95208B952B001E6991 /* LayoutBox.h */; };
119340791FE8B92300935F1E /* RenderTreeBuilderTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340771FE8B92300935F1E /* RenderTreeBuilderTable.h */; };
1193408A1FEB355D00935F1E /* RenderTreeBuilderRuby.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340881FEB355D00935F1E /* RenderTreeBuilderRuby.h */; };
@@ -5754,7 +5753,6 @@
115CFA81208B8EDA001E6991 /* FloatingState.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FloatingState.cpp; sourceTree = "<group>"; };
115CFA84208B9066001E6991 /* FloatingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FloatingContext.h; sourceTree = "<group>"; };
115CFA85208B9066001E6991 /* FloatingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FloatingContext.cpp; sourceTree = "<group>"; };
- 115CFA88208B921A001E6991 /* BlockMarginCollapse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlockMarginCollapse.h; sourceTree = "<group>"; };
115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockMarginCollapse.cpp; sourceTree = "<group>"; };
115CFA95208B952B001E6991 /* LayoutBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutBox.h; sourceTree = "<group>"; };
115CFA96208B952B001E6991 /* LayoutBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutBox.cpp; sourceTree = "<group>"; };
@@ -15727,7 +15725,6 @@
1123AFDA209ABB2000736ACC /* BlockInvalidation.cpp */,
1123AFD9209ABB2000736ACC /* BlockInvalidation.h */,
115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */,
- 115CFA88208B921A001E6991 /* BlockMarginCollapse.h */,
);
path = blockformatting;
sourceTree = "<group>";
@@ -27168,7 +27165,6 @@
976D6C7F122B8A3D001FD1F7 /* BlobURL.h in Headers */,
115CFA6E208AFAB7001E6991 /* BlockFormattingContext.h in Headers */,
115CFA7A208B8D9D001E6991 /* BlockFormattingState.h in Headers */,
- 115CFA8A208B921A001E6991 /* BlockMarginCollapse.h in Headers */,
BC5EB5E10E81BE8700B25965 /* BorderData.h in Headers */,
589556ED18D4A44000764B03 /* BorderEdge.h in Headers */,
BC5EB5DB0E81B7EA00B25965 /* BorderValue.h in Headers */,
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (232224 => 232225)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-26 15:26:03 UTC (rev 232225)
@@ -135,26 +135,11 @@
displayBox.setHeight(computedHeight);
}
-LayoutUnit FormattingContext::marginTop(const Box&) const
+void FormattingContext::computeMargin(LayoutContext&, const Box&, Display::Box& displayBox) const
{
- return 0;
+ displayBox.setMargin({ 0, 0, 0, 0 });
}
-LayoutUnit FormattingContext::marginLeft(const Box&) const
-{
- return 0;
-}
-
-LayoutUnit FormattingContext::marginBottom(const Box&) const
-{
- return 0;
-}
-
-LayoutUnit FormattingContext::marginRight(const Box&) const
-{
- return 0;
-}
-
void FormattingContext::computeBorderAndPadding(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
{
displayBox.setBorder(Geometry::computedBorder(layoutContext, layoutBox));
Modified: trunk/Source/WebCore/layout/FormattingContext.h (232224 => 232225)
--- trunk/Source/WebCore/layout/FormattingContext.h 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2018-05-26 15:26:03 UTC (rev 232225)
@@ -78,11 +78,7 @@
virtual void computeFloatingHeight(LayoutContext&, const Box&, Display::Box&) const;
virtual void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const = 0;
- virtual LayoutUnit marginTop(const Box&) const;
- virtual LayoutUnit marginLeft(const Box&) const;
- virtual LayoutUnit marginBottom(const Box&) const;
- virtual LayoutUnit marginRight(const Box&) const;
-
+ virtual void computeMargin(LayoutContext&, const Box&, Display::Box&) const;
void computeBorderAndPadding(LayoutContext&, const Box&, Display::Box&) const;
void placeInFlowPositionedChildren(LayoutContext&, const Container&) const;
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (232224 => 232225)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-26 15:26:03 UTC (rev 232225)
@@ -29,7 +29,6 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "BlockFormattingState.h"
-#include "BlockMarginCollapse.h"
#include "DisplayBox.h"
#include "FloatingContext.h"
#include "FloatingState.h"
@@ -75,6 +74,7 @@
auto& displayBox = layoutPair.displayBox;
computeWidth(layoutContext, layoutBox, displayBox);
+ computeMargin(layoutContext, layoutBox, displayBox);
computeBorderAndPadding(layoutContext, layoutBox, displayBox);
computeStaticPosition(layoutContext, layoutBox, displayBox);
if (layoutBox.establishesFormattingContext()) {
@@ -169,17 +169,12 @@
displayBox.setWidth(computedWidth);
}
-LayoutUnit BlockFormattingContext::marginTop(const Box& layoutBox) const
+void BlockFormattingContext::computeMargin(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
{
- return BlockMarginCollapse::marginTop(layoutBox);
+ displayBox.setMargin(Geometry::computedMargin(layoutContext, layoutBox));
}
-LayoutUnit BlockFormattingContext::marginBottom(const Box& layoutBox) const
-{
- return BlockMarginCollapse::marginBottom(layoutBox);
}
-
}
-}
#endif
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (232224 => 232225)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2018-05-26 15:26:03 UTC (rev 232225)
@@ -55,10 +55,8 @@
void computeInFlowPositionedPosition(LayoutContext&, const Box&, Display::Box&) const override;
void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const override;
void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override;
+ void computeMargin(LayoutContext&, const Box&, Display::Box&) const override;
- LayoutUnit marginTop(const Box&) const override;
- LayoutUnit marginBottom(const Box&) const override;
-
// This class implements positioning and sizing for boxes participating in a block formatting context.
class Geometry {
public:
@@ -67,7 +65,23 @@
static LayoutPoint staticPosition(LayoutContext&, const Box&);
static LayoutPoint inFlowPositionedPosition(LayoutContext&, const Box&);
+
+ static Display::Box::Edges computedMargin(LayoutContext&, const Box&);
};
+
+ // This class implements margin collapsing for block formatting context.
+ class MarginCollapse {
+ public:
+ static LayoutUnit marginTop(const Box&);
+ static LayoutUnit marginBottom(const Box&);
+
+ static bool isMarginBottomCollapsedWithParent(const Box&);
+ static bool isMarginTopCollapsedWithParentMarginBottom(const Box&);
+
+ private:
+ static LayoutUnit collapsedMarginBottomFromLastChild(const Box&);
+ static LayoutUnit nonCollapsedMarginBottom(const Box&);
+ };
};
}
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (232224 => 232225)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2018-05-26 15:26:03 UTC (rev 232225)
@@ -64,7 +64,7 @@
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin...
auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild();
ASSERT(lastInFlowChild);
- if (!BlockMarginCollapse::isMarginBottomCollapsedWithParent(*lastInFlowChild)) {
+ if (!BlockFormattingContext::MarginCollapse::isMarginBottomCollapsedWithParent(*lastInFlowChild)) {
auto* lastInFlowDisplayBox = layoutContext.displayBoxForLayoutBox(*lastInFlowChild);
ASSERT(lastInFlowDisplayBox);
return lastInFlowDisplayBox->bottom() + lastInFlowDisplayBox->marginBottom();
@@ -72,7 +72,7 @@
// 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
auto* inFlowChild = lastInFlowChild;
- while (inFlowChild && BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom(*inFlowChild))
+ while (inFlowChild && BlockFormattingContext::MarginCollapse::isMarginTopCollapsedWithParentMarginBottom(*inFlowChild))
inFlowChild = inFlowChild->previousInFlowSibling();
if (inFlowChild) {
auto* inFlowDisplayBox = layoutContext.displayBoxForLayoutBox(*inFlowChild);
@@ -199,7 +199,20 @@
return { displayBox.left() + leftDelta, displayBox.top() + topDelta };
}
+Display::Box::Edges BlockFormattingContext::Geometry::computedMargin(LayoutContext& layoutContext, const Box& layoutBox)
+{
+ auto& style = layoutBox.style();
+ auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
+
+ return Display::Box::Edges(
+ BlockFormattingContext::MarginCollapse::marginTop(layoutBox),
+ valueForLength(style.marginLeft(), containingBlockWidth),
+ BlockFormattingContext::MarginCollapse::marginBottom(layoutBox),
+ valueForLength(style.marginRight(), containingBlockWidth)
+ );
}
+
}
+}
#endif
Modified: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp (232224 => 232225)
--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp 2018-05-26 15:26:03 UTC (rev 232225)
@@ -24,7 +24,7 @@
*/
#include "config.h"
-#include "BlockMarginCollapse.h"
+#include "BlockFormattingContext.h"
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
@@ -32,13 +32,10 @@
#include "LayoutContainer.h"
#include "LayoutUnit.h"
#include "RenderStyle.h"
-#include <wtf/IsoMallocInlines.h>
namespace WebCore {
namespace Layout {
-WTF_MAKE_ISO_ALLOCATED_IMPL(BlockMarginCollapse);
-
static LayoutUnit marginValue(LayoutUnit currentMarginValue, LayoutUnit candidateMarginValue)
{
if (!candidateMarginValue)
@@ -128,20 +125,6 @@
return marginValue(firstInFlowChild.style().marginTop().value(), collapsedMarginTopFromFirstChild(firstInFlowChild));
}
-static LayoutUnit collapsedMarginBottomFromLastChild(const Box& layoutBox)
-{
- // Check if the last child propagates its margin bottom.
- if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild())
- return 0;
-
- auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild();
- if (!BlockMarginCollapse::isMarginBottomCollapsedWithParent(lastInFlowChild))
- return 0;
-
- // Collect collapsed margin bottom recursively.
- return marginValue(lastInFlowChild.style().marginBottom().value(), collapsedMarginBottomFromLastChild(lastInFlowChild));
-}
-
static LayoutUnit nonCollapsedMarginTop(const Box& layoutBox)
{
// Non collapsed margin top includes collapsed margin from inflow first child.
@@ -148,12 +131,6 @@
return marginValue(layoutBox.style().marginTop().value(), collapsedMarginTopFromFirstChild(layoutBox));
}
-static LayoutUnit nonCollapsedMarginBottom(const Box& layoutBox)
-{
- // Non collapsed margin bottom includes collapsed margin from inflow last child.
- return marginValue(layoutBox.style().marginBottom().value(), collapsedMarginBottomFromLastChild(layoutBox));
-}
-
/*static bool hasAdjoiningMarginTopAndBottom(const Box&)
{
// Two margins are adjoining if and only if:
@@ -169,7 +146,7 @@
return false;
}*/
-LayoutUnit BlockMarginCollapse::marginTop(const Box& layoutBox)
+LayoutUnit BlockFormattingContext::MarginCollapse::marginTop(const Box& layoutBox)
{
if (layoutBox.isAnonymous())
return 0;
@@ -193,13 +170,13 @@
return marginValue(marginTop, previousSiblingMarginBottom);
}
-LayoutUnit BlockMarginCollapse::marginBottom(const Box& layoutBox)
+LayoutUnit BlockFormattingContext::MarginCollapse::marginBottom(const Box& layoutBox)
{
if (layoutBox.isAnonymous())
return 0;
// TODO: take _hasAdjoiningMarginTopAndBottom() into account.
- if (isMarginBottomCollapsedWithParent(layoutBox))
+ if (BlockFormattingContext::MarginCollapse::isMarginBottomCollapsedWithParent(layoutBox))
return 0;
// Floats and out of flow positioned boxes do not collapse their margins.
@@ -213,7 +190,7 @@
return nonCollapsedMarginBottom(layoutBox);
}
-bool BlockMarginCollapse::isMarginBottomCollapsedWithParent(const Box& layoutBox)
+bool BlockFormattingContext::MarginCollapse::isMarginBottomCollapsedWithParent(const Box& layoutBox)
{
// last inflow box to parent.
// https://www.w3.org/TR/CSS21/box.html#collapsing-margins
@@ -249,11 +226,31 @@
return true;
}
-bool BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom(const Box&)
+bool BlockFormattingContext::MarginCollapse::isMarginTopCollapsedWithParentMarginBottom(const Box&)
{
return false;
}
+LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild(const Box& layoutBox)
+{
+ // Check if the last child propagates its margin bottom.
+ if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild())
+ return 0;
+
+ auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild();
+ if (!isMarginBottomCollapsedWithParent(lastInFlowChild))
+ return 0;
+
+ // Collect collapsed margin bottom recursively.
+ return marginValue(lastInFlowChild.style().marginBottom().value(), collapsedMarginBottomFromLastChild(lastInFlowChild));
}
+
+LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom(const Box& layoutBox)
+{
+ // Non collapsed margin bottom includes collapsed margin from inflow last child.
+ return marginValue(layoutBox.style().marginBottom().value(), collapsedMarginBottomFromLastChild(layoutBox));
}
+
+}
+}
#endif
Deleted: trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.h (232224 => 232225)
--- trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.h 2018-05-26 10:55:47 UTC (rev 232224)
+++ trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.h 2018-05-26 15:26:03 UTC (rev 232225)
@@ -1,52 +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. AND ITS CONTRIBUTORS ``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 ITS 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.
- */
-
-#pragma once
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-#include "LayoutUnit.h"
-#include <wtf/IsoMalloc.h>
-
-namespace WebCore {
-
-namespace Layout {
-
-class Box;
-
-// This class implements margin collapsing for block formatting context.
-class BlockMarginCollapse {
- WTF_MAKE_ISO_ALLOCATED(BlockMarginCollapse);
-public:
- static LayoutUnit marginTop(const Box&);
- static LayoutUnit marginBottom(const Box&);
-
- static bool isMarginBottomCollapsedWithParent(const Box&);
- static bool isMarginTopCollapsedWithParentMarginBottom(const Box&);
-};
-
-}
-}
-#endif