[LFC] Remove PointInContainingBlock and PositionInContainingBlock
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2018 21:35:18 +0000 (21:35 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2018 21:35:18 +0000 (21:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191954

Reviewed by Antti Koivisto.

Use Point and Position instead. Points and positions are by default in the containing block's coordinate system.

* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::contentHeightForFormattingContextRoot):
* layout/LayoutUnits.h:
(WebCore::Layout::Position::operator LayoutUnit const):
(WebCore::Layout::operator<):
(WebCore::Layout::operator==):
* layout/floats/FloatAvoider.cpp:
(WebCore::Layout::FloatAvoider::FloatAvoider):
(WebCore::Layout::FloatAvoider::setHorizontalConstraints):
(WebCore::Layout::FloatAvoider::horizontalPositionCandidate):
(WebCore::Layout::FloatAvoider::initialHorizontalPosition const):
* layout/floats/FloatBox.cpp:
(WebCore::Layout::FloatBox::horizontalPositionCandidate):
(WebCore::Layout::FloatBox::verticalPositionCandidate):
(WebCore::Layout::FloatBox::initialVerticalPosition const):
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::positionForFloat const):
(WebCore::Layout::FloatingContext::positionForFloatAvoiding const):
(WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
(WebCore::Layout::FloatingContext::floatingPosition const):
(WebCore::Layout::FloatingPair::horizontalConstraints const):
(WebCore::Layout::FloatingPair::bottom const):
* layout/floats/FloatingContext.h:
* layout/floats/FloatingState.cpp:
(WebCore::Layout::FloatingState::constraints const):
(WebCore::Layout::FloatingState::bottom const):
* layout/floats/FloatingState.h:
(WebCore::Layout::FloatingState::FloatItem::bottom const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::initializeNewLine const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238482 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContextGeometry.cpp
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/floats/FloatAvoider.cpp
Source/WebCore/layout/floats/FloatBox.cpp
Source/WebCore/layout/floats/FloatingContext.cpp
Source/WebCore/layout/floats/FloatingContext.h
Source/WebCore/layout/floats/FloatingState.cpp
Source/WebCore/layout/floats/FloatingState.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

index c9bb279..c8f6f14 100644 (file)
@@ -1,5 +1,45 @@
 2018-11-25  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Remove PointInContainingBlock and PositionInContainingBlock
+        https://bugs.webkit.org/show_bug.cgi?id=191954
+
+        Reviewed by Antti Koivisto.
+
+        Use Point and Position instead. Points and positions are by default in the containing block's coordinate system.
+
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::contentHeightForFormattingContextRoot):
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::Position::operator LayoutUnit const):
+        (WebCore::Layout::operator<):
+        (WebCore::Layout::operator==):
+        * layout/floats/FloatAvoider.cpp:
+        (WebCore::Layout::FloatAvoider::FloatAvoider):
+        (WebCore::Layout::FloatAvoider::setHorizontalConstraints):
+        (WebCore::Layout::FloatAvoider::horizontalPositionCandidate):
+        (WebCore::Layout::FloatAvoider::initialHorizontalPosition const):
+        * layout/floats/FloatBox.cpp:
+        (WebCore::Layout::FloatBox::horizontalPositionCandidate):
+        (WebCore::Layout::FloatBox::verticalPositionCandidate):
+        (WebCore::Layout::FloatBox::initialVerticalPosition const):
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::positionForFloat const):
+        (WebCore::Layout::FloatingContext::positionForFloatAvoiding const):
+        (WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
+        (WebCore::Layout::FloatingContext::floatingPosition const):
+        (WebCore::Layout::FloatingPair::horizontalConstraints const):
+        (WebCore::Layout::FloatingPair::bottom const):
+        * layout/floats/FloatingContext.h:
+        * layout/floats/FloatingState.cpp:
+        (WebCore::Layout::FloatingState::constraints const):
+        (WebCore::Layout::FloatingState::bottom const):
+        * layout/floats/FloatingState.h:
+        (WebCore::Layout::FloatingState::FloatItem::bottom const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::initializeNewLine const):
+
+2018-11-25  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Rename Layout::Position to Layout::Point
         https://bugs.webkit.org/show_bug.cgi?id=191950
 
index e70ac45..8c34f05 100644 (file)
@@ -156,7 +156,7 @@ static LayoutUnit contentHeightForFormattingContextRoot(const LayoutState& layou
 
     auto floatsBottom = layoutState.establishedFormattingState(*formattingContextRoot).floatingState().bottom(*formattingContextRoot);
     if (floatsBottom)
-        bottom = std::max(*floatsBottom, bottom);
+        bottom = std::max<LayoutUnit>(*floatsBottom, bottom);
 
     auto computedHeight = bottom - top;
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height] -> content height for formatting context root -> height(" << computedHeight << "px) layoutBox("<< &layoutBox << ")");
index daff0fe..2d0d8be 100644 (file)
 namespace WebCore {
 namespace Layout {
 
+struct Position {
+    operator LayoutUnit() const { return value; }
+    LayoutUnit value;
+};
+
+inline bool operator<(const Position& a, const Position& b)
+{
+    return a.value < b.value;
+}
+
+inline bool operator==(const Position& a, const Position& b)
+{
+    return a.value == b.value;
+}
+
 struct Point {
-    // FIXME: Use LayoutUnit<Horizontal> to avoid top/left vs. x/y confusion.
+    // FIXME: Use Position<Horizontal>, Position<Vertical> to avoid top/left vs. x/y confusion.
     LayoutUnit x; // left
     LayoutUnit y; // top
 
@@ -48,9 +63,7 @@ struct Point {
 
 // FIXME: Wrap these into structs.
 using PointInContextRoot = Point;
-using PointInContainingBlock = Point;
-using PositionInContextRoot = LayoutUnit;
-using PositionInContainingBlock = LayoutUnit;
+using PositionInContextRoot = Position;
 
 inline Point::Point(LayoutPoint point)
     : x(point.x())
index 07f20ec..b1e5d7b 100644 (file)
@@ -43,7 +43,7 @@ FloatAvoider::FloatAvoider(const Box& layoutBox, const FloatingState& floatingSt
     , m_floatingState(floatingState)
     , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutState, layoutBox, downcast<Container>(floatingState.root())))
     , m_containingBlockAbsoluteDisplayBox(layoutBox.containingBlock() == &floatingState.root() ? Display::Box(layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock())) : FormattingContext::mapBoxToAncestor(layoutState, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
-    , m_initialVerticalPosition(m_absoluteDisplayBox.top())
+    , m_initialVerticalPosition({ m_absoluteDisplayBox.top() })
 {
     ASSERT(m_layoutBox->establishesBlockFormattingContext());
 }
@@ -61,11 +61,11 @@ void FloatAvoider::setHorizontalConstraints(HorizontalConstraints horizontalCons
         // Compute the horizontal position for the new floating by taking both the contining block and the current left/right floats into account.
         auto containingBlockContentBoxLeft = m_containingBlockAbsoluteDisplayBox.left() + m_containingBlockAbsoluteDisplayBox.contentBoxLeft();
         if (isLeftAligned())
-            return std::max(containingBlockContentBoxLeft + marginLeft(), left);
+            return std::max<PositionInContextRoot>({ containingBlockContentBoxLeft + marginLeft() }, left);
 
         // Make sure it does not overflow the containing block on the right.
         auto containingBlockContentBoxRight = containingBlockContentBoxLeft + m_containingBlockAbsoluteDisplayBox.contentBoxWidth();
-        return std::min(left, containingBlockContentBoxRight - marginBoxWidth() + marginLeft());
+        return std::min<PositionInContextRoot>(left, { containingBlockContentBoxRight - marginBoxWidth() + marginLeft() });
     };
 
     auto positionCandidate = horizontalPositionCandidate(horizontalConstraints);
@@ -79,7 +79,7 @@ void FloatAvoider::setVerticalConstraint(PositionInContextRoot verticalConstrain
 
 PositionInContextRoot FloatAvoider::horizontalPositionCandidate(HorizontalConstraints horizontalConstraints)
 {
-    return isLeftAligned() ? *horizontalConstraints.left : *horizontalConstraints.right - rect().width();
+    return { isLeftAligned() ? *horizontalConstraints.left : *horizontalConstraints.right - rect().width() };
 }
 
 PositionInContextRoot FloatAvoider::verticalPositionCandidate(PositionInContextRoot verticalConstraint)
@@ -101,7 +101,7 @@ PositionInContextRoot FloatAvoider::initialHorizontalPosition() const
     auto left = isLeftAligned() ? containingBlockContentBoxLeft : containingBlockContentBoxRight - marginBoxWidth();
     left += marginLeft();
 
-    return left;
+    return { left };
 }
 
 bool FloatAvoider::overflowsContainingBlock() const
index 69dd018..45c2a3a 100644 (file)
@@ -51,12 +51,12 @@ PositionInContextRoot FloatBox::horizontalPositionCandidate(HorizontalConstraint
     auto positionCandidate = isLeftAligned() ? *horizontalConstraints.left : *horizontalConstraints.right - rect().width();
     positionCandidate += marginLeft();
 
-    return positionCandidate;
+    return { positionCandidate };
 }
 
 PositionInContextRoot FloatBox::verticalPositionCandidate(PositionInContextRoot verticalConstraint)
 {
-    return verticalConstraint + marginTop();
+    return { verticalConstraint + marginTop() };
 }
 
 PositionInContextRoot FloatBox::initialVerticalPosition() const
@@ -68,7 +68,7 @@ PositionInContextRoot FloatBox::initialVerticalPosition() const
         top = std::max(top, lastFloat->rectWithMargin().top());
     top += marginTop();
 
-    return top;
+    return { top };
 }
 
 }
index 9047fe0..48e27e2 100644 (file)
@@ -116,21 +116,21 @@ FloatingContext::FloatingContext(FloatingState& floatingState)
 {
 }
 
-PointInContainingBlock FloatingContext::positionForFloat(const Box& layoutBox) const
+Point FloatingContext::positionForFloat(const Box& layoutBox) const
 {
     ASSERT(layoutBox.isFloatingPositioned());
 
     if (m_floatingState.isEmpty()) {
         auto& displayBox = layoutState().displayBoxForLayoutBox(layoutBox);
 
-        auto alignWithContainingBlock = [&]() -> PositionInContainingBlock {
+        auto alignWithContainingBlock = [&]() -> Position {
             // If there is no floating to align with, push the box to the left/right edge of its containing block's content box.
             auto& containingBlockDisplayBox = layoutState().displayBoxForLayoutBox(*layoutBox.containingBlock());
 
             if (layoutBox.isLeftFloatingPositioned())
-                return containingBlockDisplayBox.contentBoxLeft() + displayBox.marginLeft();
+                return Position { containingBlockDisplayBox.contentBoxLeft() + displayBox.marginLeft() };
 
-            return containingBlockDisplayBox.contentBoxRight() - displayBox.marginRight() - displayBox.width();
+            return Position { containingBlockDisplayBox.contentBoxRight() - displayBox.marginRight() - displayBox.width() };
         };
 
         // No float box on the context yet -> align it with the containing block's left/right edge.
@@ -143,7 +143,7 @@ PointInContainingBlock FloatingContext::positionForFloat(const Box& layoutBox) c
     return floatBox.rectInContainingBlock().topLeft();
 }
 
-std::optional<PointInContainingBlock> FloatingContext::positionForFloatAvoiding(const Box& layoutBox) const
+std::optional<Point> FloatingContext::positionForFloatAvoiding(const Box& layoutBox) const
 {
     ASSERT(layoutBox.establishesBlockFormattingContext());
     ASSERT(!layoutBox.isFloatingPositioned());
@@ -157,7 +157,7 @@ std::optional<PointInContainingBlock> FloatingContext::positionForFloatAvoiding(
     return { floatAvoider.rectInContainingBlock().topLeft() };
 }
 
-std::optional<PositionInContainingBlock> FloatingContext::verticalPositionWithClearance(const Box& layoutBox) const
+std::optional<Position> FloatingContext::verticalPositionWithClearance(const Box& layoutBox) const
 {
     ASSERT(layoutBox.hasFloatClear());
     ASSERT(layoutBox.isBlockLevelBox());
@@ -165,7 +165,7 @@ std::optional<PositionInContainingBlock> FloatingContext::verticalPositionWithCl
     if (m_floatingState.isEmpty())
         return { };
 
-    auto bottom = [&](std::optional<PositionInContextRoot> floatBottom) -> std::optional<PositionInContainingBlock> {
+    auto bottom = [&](std::optional<PositionInContextRoot> floatBottom) -> std::optional<Position> {
         // 'bottom' is in the formatting root's coordinate system.
         if (!floatBottom)
             return { };
@@ -209,7 +209,7 @@ std::optional<PositionInContainingBlock> FloatingContext::verticalPositionWithCl
 
         // The return vertical position is in the containing block's coordinate system.
         auto containingBlockRootRelativeTop = FormattingContext::mapTopLeftToAncestor(layoutState, *layoutBox.containingBlock(), downcast<Container>(m_floatingState.root())).y;
-        return rootRelativeTop - containingBlockRootRelativeTop;
+        return Position { rootRelativeTop - containingBlockRootRelativeTop };
     };
 
     auto clear = layoutBox.style().clear();
@@ -235,7 +235,7 @@ void FloatingContext::floatingPosition(FloatAvoider& floatAvoider) const
 
     std::optional<PositionInContextRoot> bottomMost;
     auto end = Layout::end(m_floatingState);
-    for (auto iterator = begin(m_floatingState, floatAvoider.rect().top()); iterator != end; ++iterator) {
+    for (auto iterator = begin(m_floatingState, { floatAvoider.rect().top() }); iterator != end; ++iterator) {
         ASSERT(!(*iterator).isEmpty());
         auto floats = *iterator;
 
@@ -327,10 +327,10 @@ FloatAvoider::HorizontalConstraints FloatingPair::horizontalConstraints() const
     std::optional<PositionInContextRoot> rightEdge;
 
     if (left())
-        leftEdge = left()->rectWithMargin().right();
+        leftEdge = PositionInContextRoot { left()->rectWithMargin().right() };
 
     if (right())
-        rightEdge = right()->rectWithMargin().left();
+        rightEdge = PositionInContextRoot { right()->rectWithMargin().left() };
 
     return { leftEdge, rightEdge };
 }
@@ -341,8 +341,8 @@ PositionInContextRoot FloatingPair::bottom() const
     auto* right = this->right();
     ASSERT(left || right);
 
-    auto leftBottom = left ? std::optional<PositionInContextRoot>(left->rectWithMargin().bottom()) : std::nullopt;
-    auto rightBottom = right ? std::optional<PositionInContextRoot>(right->rectWithMargin().bottom()) : std::nullopt;
+    auto leftBottom = left ? std::optional<PositionInContextRoot>(PositionInContextRoot { left->rectWithMargin().bottom() }) : std::nullopt;
+    auto rightBottom = right ? std::optional<PositionInContextRoot>(PositionInContextRoot { right->rectWithMargin().bottom() }) : std::nullopt;
 
     if (leftBottom && rightBottom)
         return std::max(*leftBottom, *rightBottom);
index f8d3d8c..42eea7a 100644 (file)
@@ -50,9 +50,9 @@ public:
 
     FloatingState& floatingState() const { return m_floatingState; }
 
-    PointInContainingBlock positionForFloat(const Box&) const;
-    std::optional<PointInContainingBlock> positionForFloatAvoiding(const Box&) const;
-    std::optional<PositionInContainingBlock> verticalPositionWithClearance(const Box&) const;
+    Point positionForFloat(const Box&) const;
+    std::optional<Point> positionForFloatAvoiding(const Box&) const;
+    std::optional<Position> verticalPositionWithClearance(const Box&) const;
 
 private:
     LayoutState& layoutState() const { return m_floatingState.layoutState(); }
index 937b8a2..f465c6b 100644 (file)
@@ -115,9 +115,9 @@ FloatingState::Constraints FloatingState::constraints(PositionInContextRoot vert
             continue;
 
         if (floatItem.isLeftPositioned())
-            constraints.left = rect.right();
+            constraints.left = PositionInContextRoot { rect.right() };
         else
-            constraints.right = rect.left();
+            constraints.right = PositionInContextRoot { rect.left() };
 
         if (constraints.left && constraints.right)
             break;
@@ -125,10 +125,10 @@ FloatingState::Constraints FloatingState::constraints(PositionInContextRoot vert
 
     if (coordinateMappingIsRequired) {
         if (constraints.left)
-            constraints.left = *constraints.left - adjustedPosition.x;
+            constraints.left = PositionInContextRoot { *constraints.left - adjustedPosition.x };
 
         if (constraints.right)
-            constraints.right = *constraints.right - adjustedPosition.x;
+            constraints.right = PositionInContextRoot { *constraints.right - adjustedPosition.x };
     }
 
     return constraints;
@@ -153,10 +153,10 @@ std::optional<PositionInContextRoot> FloatingState::bottom(const Box& formatting
 
         auto floatsBottom = floatItem.rectWithMargin().bottom();
         if (bottom) {
-            bottom = std::max(*bottom, floatsBottom);
+            bottom = std::max<PositionInContextRoot>(*bottom, { floatsBottom });
             continue;
         }
-        bottom = floatsBottom;
+        bottom = PositionInContextRoot { floatsBottom };
     }
     return bottom;
 }
index 3b1cfa2..8678277 100644 (file)
@@ -74,7 +74,7 @@ public:
         bool inFormattingContext(const Box&) const;
 
         Display::Box::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); }
-        PositionInContextRoot bottom() const { return m_absoluteDisplayBox.bottom(); }
+        PositionInContextRoot bottom() const { return { m_absoluteDisplayBox.bottom() }; }
 
     private:
         WeakPtr<const Box> m_layoutBox;
index ed431c1..6dadd70 100644 (file)
@@ -95,7 +95,7 @@ void InlineFormattingContext::initializeNewLine(Line& line) const
     // Check for intruding floats and adjust logical left/available width for this line accordingly.
     auto& floatingState = formattingState().floatingState();
     if (!floatingState.isEmpty()) {
-        auto floatConstraints = floatingState.constraints(lineLogicalTop, formattingRoot);
+        auto floatConstraints = floatingState.constraints({ lineLogicalTop }, formattingRoot);
         // Check if these constraints actually put limitation on the line.
         if (floatConstraints.left && *floatConstraints.left <= formattingRootDisplayBox.contentBoxLeft())
             floatConstraints.left = { };