Diff
Modified: trunk/Source/WebCore/ChangeLog (232187 => 232188)
--- trunk/Source/WebCore/ChangeLog 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/ChangeLog 2018-05-25 14:33:54 UTC (rev 232188)
@@ -1,3 +1,54 @@
+2018-05-25 Zalan Bujtas <za...@apple.com>
+
+ [LFC] Implement border and padding computation
+ https://bugs.webkit.org/show_bug.cgi?id=185972
+
+ Reviewed by Antti Koivisto.
+
+ This patch also removes redundant Display::Box methods and adds a lightweight Edge struct.
+ (Since padding is optional, if during layout we mistakenly try to access paddingTop/Left/Bottom/Right, Display::Box will assert!)
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::computeBorderAndPadding const):
+ * layout/FormattingContext.h:
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::FormattingContext::Geometry::computedBorder):
+ (WebCore::Layout::FormattingContext::Geometry::computedPadding):
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::layout const):
+ * layout/displaytree/DisplayBox.cpp:
+ (WebCore::Display::Box::marginBox const):
+ (WebCore::Display::Box::paddingBox const):
+ (WebCore::Display::Box::contentBox const):
+ * layout/displaytree/DisplayBox.h:
+ (WebCore::Display::Box::Edges::Edges):
+ (WebCore::Display::Box::setHasValidPosition):
+ (WebCore::Display::Box::setWidth):
+ (WebCore::Display::Box::setHeight):
+ (WebCore::Display::Box::setMargin):
+ (WebCore::Display::Box::setBorder):
+ (WebCore::Display::Box::setPadding):
+ (WebCore::Display::Box::marginTop const):
+ (WebCore::Display::Box::marginLeft const):
+ (WebCore::Display::Box::marginBottom const):
+ (WebCore::Display::Box::marginRight const):
+ (WebCore::Display::Box::paddingTop const):
+ (WebCore::Display::Box::paddingLeft const):
+ (WebCore::Display::Box::paddingBottom const):
+ (WebCore::Display::Box::paddingRight const):
+ (WebCore::Display::Box::borderTop const):
+ (WebCore::Display::Box::borderLeft const):
+ (WebCore::Display::Box::borderBottom const):
+ (WebCore::Display::Box::borderRight const):
+ (WebCore::Display::Box::invalidateSize): Deleted.
+ (WebCore::Display::Box::setHasValidSize): Deleted.
+ (WebCore::Display::Box::setHasValidGeometry): Deleted.
+ (WebCore::Display::Box::setRect): Deleted.
+ (WebCore::Display::Box::setSize): Deleted.
+ * layout/layouttree/LayoutBox.cpp:
+ (WebCore::Layout::Box::isPaddingEnabled const):
+ * layout/layouttree/LayoutBox.h:
+
2018-05-25 David Kilzer <ddkil...@apple.com>
Fix issues with -dealloc methods found by clang static analyzer
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (232187 => 232188)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-25 14:33:54 UTC (rev 232188)
@@ -155,6 +155,13 @@
return 0;
}
+void FormattingContext::computeBorderAndPadding(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
+{
+ displayBox.setBorder(Geometry::computedBorder(layoutContext, layoutBox));
+ if (auto padding = Geometry::computedPadding(layoutContext, layoutBox))
+ displayBox.setPadding(*padding);
+}
+
void FormattingContext::placeInFlowPositionedChildren(LayoutContext& layoutContext, const Container& container) const
{
// If this container also establishes a formatting context, then positioning already has happend in that the formatting context.
Modified: trunk/Source/WebCore/layout/FormattingContext.h (232187 => 232188)
--- trunk/Source/WebCore/layout/FormattingContext.h 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2018-05-25 14:33:54 UTC (rev 232188)
@@ -27,6 +27,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+#include "DisplayBox.h"
#include "FloatingState.h"
#include <wtf/IsoMalloc.h>
#include <wtf/WeakPtr.h>
@@ -36,10 +37,6 @@
class LayoutPoint;
class LayoutUnit;
-namespace Display {
-class Box;
-}
-
namespace Layout {
class Box;
@@ -86,6 +83,8 @@
virtual LayoutUnit marginBottom(const Box&) const;
virtual LayoutUnit marginRight(const Box&) const;
+ void computeBorderAndPadding(LayoutContext&, const Box&, Display::Box&) const;
+
void placeInFlowPositionedChildren(LayoutContext&, const Container&) const;
void layoutOutOfFlowDescendants(LayoutContext&s) const;
@@ -113,6 +112,9 @@
static LayoutUnit replacedHeight(LayoutContext&, const Box&);
static LayoutUnit replacedWidth(LayoutContext&, const Box&);
+
+ static Display::Box::Edges computedBorder(LayoutContext&, const Box&);
+ static std::optional<Display::Box::Edges> computedPadding(LayoutContext&, const Box&);
};
private:
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (232187 => 232188)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2018-05-25 14:33:54 UTC (rev 232188)
@@ -525,6 +525,32 @@
return computedWidthValue;
}
+Display::Box::Edges FormattingContext::Geometry::computedBorder(LayoutContext&, const Box& layoutBox)
+{
+ auto& style = layoutBox.style();
+ return {
+ style.borderTop().width(),
+ style.borderLeft().width(),
+ style.borderBottom().width(),
+ style.borderRight().width()
+ };
}
+
+std::optional<Display::Box::Edges> FormattingContext::Geometry::computedPadding(LayoutContext& layoutContext, const Box& layoutBox)
+{
+ if (!layoutBox.isPaddingApplicable())
+ return std::nullopt;
+
+ auto& style = layoutBox.style();
+ auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
+ return Display::Box::Edges(
+ valueForLength(style.paddingTop(), containingBlockWidth),
+ valueForLength(style.paddingLeft(), containingBlockWidth),
+ valueForLength(style.paddingBottom(), containingBlockWidth),
+ valueForLength(style.paddingRight(), containingBlockWidth)
+ );
}
+
+}
+}
#endif
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (232187 => 232188)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-25 14:33:54 UTC (rev 232188)
@@ -75,7 +75,8 @@
auto& displayBox = layoutPair.displayBox;
computeWidth(layoutContext, layoutBox, displayBox);
- computeStaticPosition(layoutContext, layoutBox, layoutPair.displayBox);
+ computeBorderAndPadding(layoutContext, layoutBox, displayBox);
+ computeStaticPosition(layoutContext, layoutBox, displayBox);
if (layoutBox.establishesFormattingContext()) {
auto formattingContext = layoutContext.formattingContext(layoutBox);
formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp (232187 => 232188)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.cpp 2018-05-25 14:33:54 UTC (rev 232188)
@@ -56,10 +56,10 @@
ASSERT(m_hasValidMargin);
auto marginBox = borderBox();
- marginBox.shiftXEdgeTo(marginBox.x() + m_marginLeft);
- marginBox.shiftYEdgeTo(marginBox.y() + m_marginTop);
- marginBox.shiftMaxXEdgeTo(marginBox.maxX() - m_marginRight);
- marginBox.shiftMaxYEdgeTo(marginBox.maxY() - m_marginBottom);
+ marginBox.shiftXEdgeTo(marginBox.x() + m_margin.left);
+ marginBox.shiftYEdgeTo(marginBox.y() + m_margin.top);
+ marginBox.shiftMaxXEdgeTo(marginBox.maxX() - m_margin.right);
+ marginBox.shiftMaxYEdgeTo(marginBox.maxY() - m_margin.bottom);
return marginBox;
}
@@ -82,10 +82,10 @@
ASSERT(m_hasValidBorder);
auto paddingBox = borderBox();
- paddingBox.shiftXEdgeTo(paddingBox.x() + m_borderLeft);
- paddingBox.shiftYEdgeTo(paddingBox.y() + m_borderTop);
- paddingBox.shiftMaxXEdgeTo(paddingBox.maxX() - m_borderRight);
- paddingBox.shiftMaxYEdgeTo(paddingBox.maxY() - m_borderBottom);
+ paddingBox.shiftXEdgeTo(paddingBox.x() + m_border.left);
+ paddingBox.shiftYEdgeTo(paddingBox.y() + m_border.top);
+ paddingBox.shiftMaxXEdgeTo(paddingBox.maxX() - m_border.right);
+ paddingBox.shiftMaxYEdgeTo(paddingBox.maxY() - m_border.bottom);
return paddingBox;
}
@@ -99,10 +99,10 @@
ASSERT(m_hasValidPadding);
auto contentBox = paddingBox();
- contentBox.shiftXEdgeTo(contentBox.x() + m_paddingLeft);
- contentBox.shiftYEdgeTo(contentBox.y() + m_paddingTop);
- contentBox.shiftMaxXEdgeTo(contentBox.maxX() - m_paddingRight);
- contentBox.shiftMaxYEdgeTo(contentBox.maxY() - m_paddingBottom);
+ contentBox.shiftXEdgeTo(contentBox.x() + m_padding.left);
+ contentBox.shiftYEdgeTo(contentBox.y() + m_padding.top);
+ contentBox.shiftMaxXEdgeTo(contentBox.maxX() - m_padding.right);
+ contentBox.shiftMaxYEdgeTo(contentBox.maxY() - m_padding.bottom);
return contentBox;
}
Modified: trunk/Source/WebCore/layout/displaytree/DisplayBox.h (232187 => 232188)
--- trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/displaytree/DisplayBox.h 2018-05-25 14:33:54 UTC (rev 232188)
@@ -97,18 +97,30 @@
BoxSizing boxSizing { BoxSizing::ContentBox };
};
- void setRect(const LayoutRect&);
void setTopLeft(const LayoutPoint&);
void setTop(LayoutUnit);
void setLeft(LayoutUnit);
- void setSize(const LayoutSize&);
void setWidth(LayoutUnit);
void setHeight(LayoutUnit);
- void setMargin(LayoutUnit marginTop, LayoutUnit marginLeft, LayoutUnit marginRight, LayoutUnit marginBottom);
- void setBorder(LayoutUnit borderTop, LayoutUnit borderLeft, LayoutUnit borderRight, LayoutUnit borderBottom);
- void setPadding(LayoutUnit paddingTop, LayoutUnit paddingLeft, LayoutUnit paddingRight, LayoutUnit paddingBottom);
+ struct Edges {
+ Edges() = default;
+ Edges(LayoutUnit top, LayoutUnit left, LayoutUnit bottom, LayoutUnit right)
+ : top(top)
+ , left(left)
+ , bottom(bottom)
+ , right(right)
+ { }
+ LayoutUnit top;
+ LayoutUnit left;
+ LayoutUnit bottom;
+ LayoutUnit right;
+ };
+ void setMargin(Edges);
+ void setBorder(Edges);
+ void setPadding(Edges);
+
#if !ASSERT_DISABLED
void invalidateTop() { m_hasValidTop = false; }
void invalidateLeft() { m_hasValidLeft = false; }
@@ -115,7 +127,6 @@
void invalidateWidth() { m_hasValidWidth = false; }
void invalidateHeight() { m_hasValidHeight = false; }
void invalidatePosition();
- void invalidateSize();
void invalidateMargin() { m_hasValidMargin = false; }
void invalidateBorder() { m_hasValidBorder = false; }
void invalidatePadding() { m_hasValidPadding = false; }
@@ -125,8 +136,6 @@
bool hasValidGeometry() const { return hasValidPosition() && hasValidSize(); }
void setHasValidPosition();
- void setHasValidSize();
- void setHasValidGeometry();
void setHasValidMargin();
void setHasValidBorder();
@@ -137,21 +146,10 @@
LayoutRect m_rect;
- LayoutUnit m_marginTop;
- LayoutUnit m_marginLeft;
- LayoutUnit m_marginBottom;
- LayoutUnit m_marginRight;
+ Edges m_margin;
+ Edges m_border;
+ Edges m_padding;
- LayoutUnit m_borderTop;
- LayoutUnit m_borderLeft;
- LayoutUnit m_borderBottom;
- LayoutUnit m_borderRight;
-
- LayoutUnit m_paddingTop;
- LayoutUnit m_paddingLeft;
- LayoutUnit m_paddingBottom;
- LayoutUnit m_paddingRight;
-
#if !ASSERT_DISABLED
bool m_hasValidTop { false };
bool m_hasValidLeft { false };
@@ -170,29 +168,11 @@
invalidateLeft();
}
-inline void Box::invalidateSize()
-{
- invalidateWidth();
- invalidateHeight();
-}
-
inline void Box::setHasValidPosition()
{
m_hasValidTop = true;
m_hasValidLeft = true;
}
-
-inline void Box::setHasValidSize()
-{
- m_hasValidWidth = true;
- m_hasValidHeight = true;
-}
-
-inline void Box::setHasValidGeometry()
-{
- setHasValidPosition();
- setHasValidSize();
-}
#endif
inline LayoutRect Box::rect() const
@@ -255,14 +235,6 @@
return m_rect.height();
}
-inline void Box::setRect(const LayoutRect& rect)
-{
-#if !ASSERT_DISABLED
- setHasValidGeometry();
-#endif
- m_rect = rect;
-}
-
inline void Box::setTopLeft(const LayoutPoint& topLeft)
{
#if !ASSERT_DISABLED
@@ -287,19 +259,12 @@
m_rect.setX(left);
}
-inline void Box::setSize(const LayoutSize& size)
-{
-#if !ASSERT_DISABLED
- setHasValidSize();
-#endif
- m_rect.setSize(size);
-}
-
inline void Box::setWidth(LayoutUnit width)
{
#if !ASSERT_DISABLED
m_hasValidWidth = true;
#endif
+ ASSERT(m_hasValidLeft);
m_rect.setWidth(width);
}
@@ -308,112 +273,104 @@
#if !ASSERT_DISABLED
m_hasValidHeight = true;
#endif
+ ASSERT(m_hasValidTop);
m_rect.setHeight(height);
}
-inline void Box::setMargin(LayoutUnit marginTop, LayoutUnit marginLeft, LayoutUnit marginRight, LayoutUnit marginBottom)
+inline void Box::setMargin(Edges margin)
{
#if !ASSERT_DISABLED
void setHasValidMargin();
#endif
- m_marginTop = marginTop;
- m_marginLeft = marginLeft;
- m_marginBottom = marginBottom;
- m_marginRight = marginRight;
+ m_margin = margin;
}
-inline void Box::setBorder(LayoutUnit borderTop, LayoutUnit borderLeft, LayoutUnit borderRight, LayoutUnit borderBottom)
+inline void Box::setBorder(Edges border)
{
#if !ASSERT_DISABLED
void setHasValidBorder();
#endif
- m_borderTop = borderTop;
- m_borderLeft = borderLeft;
- m_borderBottom = borderBottom;
- m_borderRight = borderRight;
+ m_border = border;
}
-inline void Box::setPadding(LayoutUnit paddingTop, LayoutUnit paddingLeft, LayoutUnit paddingRight, LayoutUnit paddingBottom)
+inline void Box::setPadding(Edges padding)
{
#if !ASSERT_DISABLED
void setHasValidPadding();
#endif
- m_paddingTop = paddingTop;
- m_paddingLeft = paddingLeft;
- m_paddingBottom = paddingBottom;
- m_paddingRight = paddingRight;
+ m_padding = padding;
}
inline LayoutUnit Box::marginTop() const
{
ASSERT(m_hasValidMargin);
- return m_marginTop;
+ return m_margin.top;
}
inline LayoutUnit Box::marginLeft() const
{
ASSERT(m_hasValidMargin);
- return m_marginLeft;
+ return m_margin.left;
}
inline LayoutUnit Box::marginBottom() const
{
ASSERT(m_hasValidMargin);
- return m_marginBottom;
+ return m_margin.bottom;
}
inline LayoutUnit Box::marginRight() const
{
ASSERT(m_hasValidMargin);
- return m_marginRight;
+ return m_margin.right;
}
inline LayoutUnit Box::paddingTop() const
{
ASSERT(m_hasValidPadding);
- return m_paddingTop;
+ return m_padding.top;
}
inline LayoutUnit Box::paddingLeft() const
{
ASSERT(m_hasValidPadding);
- return m_paddingLeft;
+ return m_padding.left;
}
inline LayoutUnit Box::paddingBottom() const
{
ASSERT(m_hasValidPadding);
- return m_paddingBottom;
+ return m_padding.bottom;
}
inline LayoutUnit Box::paddingRight() const
{
ASSERT(m_hasValidPadding);
- return m_paddingRight;
+ return m_padding.right;
}
inline LayoutUnit Box::borderTop() const
{
ASSERT(m_hasValidBorder);
- return m_borderTop;
+ return m_border.top;
}
inline LayoutUnit Box::borderLeft() const
{
ASSERT(m_hasValidBorder);
- return m_borderLeft;
+ return m_border.left;
}
inline LayoutUnit Box::borderBottom() const
{
ASSERT(m_hasValidBorder);
- return m_borderBottom;
+ return m_border.bottom;
}
inline LayoutUnit Box::borderRight() const
{
ASSERT(m_hasValidBorder);
- return m_borderRight;
+ return m_border.right;
}
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (232187 => 232188)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-05-25 14:33:54 UTC (rev 232188)
@@ -226,7 +226,14 @@
return m_style.overflowX() == Overflow::Visible || m_style.overflowY() == Overflow::Visible;
}
+bool Box::isPaddingApplicable() const
+{
+ // 8.4 Padding properties:
+ // Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
+ return true;
}
+
}
+}
#endif
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (232187 => 232188)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-05-25 14:19:58 UTC (rev 232187)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-05-25 14:33:54 UTC (rev 232188)
@@ -88,6 +88,8 @@
bool isInlineBox() const { return m_baseTypeFlags & InlineBoxFlag; }
bool isInlineContainer() const { return m_baseTypeFlags & InlineContainerFlag; }
+ bool isPaddingApplicable() const;
+
const RenderStyle& style() const { return m_style; }
auto& weakPtrFactory() const { return m_weakFactory; }