[CSS Grid Layout] Simplify the interface of GridResolvedPosition
[WebKit-https.git] / Source / WebCore / rendering / style / GridResolvedPosition.h
index 95556cdebebbbdc4b71ed2c41df592ab39e3bf59..9752b360f06e6a8dd828abf7402f42b9379fa547 100644 (file)
@@ -41,59 +41,46 @@ class GridSpan;
 class RenderBox;
 class RenderStyle;
 
-enum GridPositionSide {
-    ColumnStartSide,
-    ColumnEndSide,
-    RowStartSide,
-    RowEndSide
-};
-
 enum GridTrackSizingDirection {
     ForColumns,
     ForRows
 };
 
-// This class represents an index into one of the dimensions of the grid array.
-// Wraps an unsigned integer just for the purpose of knowing what we manipulate in the grid code.
-class GridResolvedPosition {
+class GridUnresolvedSpan {
 public:
-    static GridResolvedPosition adjustGridPositionForRowEndColumnEndSide(unsigned resolvedPosition)
+    GridUnresolvedSpan(GridPosition initialPosition, GridPositionSide initialPositionSide, GridPosition finalPosition, GridPositionSide finalPositionSide)
+        : m_initialPosition(initialPosition)
+        , m_finalPosition(finalPosition)
+        , m_initialPositionSide(initialPositionSide)
+        , m_finalPositionSide(finalPositionSide)
     {
-        return resolvedPosition ? GridResolvedPosition(resolvedPosition - 1) : GridResolvedPosition(0);
     }
 
-    static GridResolvedPosition adjustGridPositionForSide(unsigned resolvedPosition, GridPositionSide side)
-    {
-        // An item finishing on the N-th line belongs to the N-1-th cell.
-        if (side == ColumnEndSide || side == RowEndSide)
-            return adjustGridPositionForRowEndColumnEndSide(resolvedPosition);
+    const GridPosition& initialPosition() const { return m_initialPosition; }
+    const GridPosition& finalPosition() const { return m_finalPosition; }
+    GridPositionSide initialPositionSide() const { return m_initialPositionSide; }
+    GridPositionSide finalPositionSide() const { return m_finalPositionSide; }
 
-        return GridResolvedPosition(resolvedPosition);
-    }
+    bool requiresAutoPlacement() const;
+    void adjustGridPositionsFromStyle(const RenderStyle& gridContainerStyle);
 
-    static GridSpan resolveGridPositionsFromAutoPlacementPosition(const RenderStyle&, const RenderBox&, GridTrackSizingDirection, const GridResolvedPosition&);
-    static void adjustNamedGridItemPosition(const RenderStyle&, GridPosition&, GridPositionSide);
-    static void adjustGridPositionsFromStyle(const RenderStyle&, GridPosition& initialPosition, GridPosition& finalPosition, GridPositionSide initialPositionSide, GridPositionSide finalPositionSide);
-    static std::unique_ptr<GridSpan> resolveGridPositionsFromStyle(const RenderStyle&, const RenderBox&, GridTrackSizingDirection);
-    static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const RenderStyle&, const GridPosition&, GridPositionSide);
-    static GridResolvedPosition resolveGridPositionFromStyle(const RenderStyle&, const GridPosition&, GridPositionSide);
-    static std::unique_ptr<GridSpan> resolveGridPositionAgainstOppositePosition(const RenderStyle&, const GridResolvedPosition&, const GridPosition&, GridPositionSide);
-    static std::unique_ptr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosition(const RenderStyle&, const GridResolvedPosition&, const GridPosition&, GridPositionSide);
-    static std::unique_ptr<GridSpan> resolveRowStartColumnStartNamedGridLinePositionAgainstOppositePosition(const GridResolvedPosition&, const GridPosition&, const Vector<unsigned>&);
-    static std::unique_ptr<GridSpan> resolveRowEndColumnEndNamedGridLinePositionAgainstOppositePosition(const GridResolvedPosition&, const GridPosition&, const Vector<unsigned>&);
+private:
+    GridPosition m_initialPosition;
+    GridPosition m_finalPosition;
+    GridPositionSide m_initialPositionSide;
+    GridPositionSide m_finalPositionSide;
+};
 
+// This class represents an index into one of the dimensions of the grid array.
+// Wraps an unsigned integer just for the purpose of knowing what we manipulate in the grid code.
+class GridResolvedPosition {
+public:
     GridResolvedPosition(unsigned position)
         : m_integerPosition(position)
     {
     }
 
-    GridResolvedPosition(const GridPosition& position, GridPositionSide side)
-    {
-        ASSERT(position.integerPosition());
-        unsigned integerPosition = position.integerPosition() - 1;
-
-        m_integerPosition = adjustGridPositionForSide(integerPosition, side).m_integerPosition;
-    }
+    GridResolvedPosition(const GridPosition&, GridPositionSide);
 
     GridResolvedPosition& operator*()
     {
@@ -146,11 +133,13 @@ public:
         return GridResolvedPosition(m_integerPosition + 1);
     }
 
+    static GridSpan resolveGridPositionsFromAutoPlacementPosition(const RenderStyle&, const RenderBox&, GridTrackSizingDirection, const GridResolvedPosition&);
+    static GridSpan resolveGridPositionsFromStyle(const GridUnresolvedSpan&, const RenderStyle&);
+    static GridUnresolvedSpan unresolvedSpanFromStyle(const RenderStyle&, const RenderBox&, GridTrackSizingDirection);
     static unsigned explicitGridColumnCount(const RenderStyle&);
     static unsigned explicitGridRowCount(const RenderStyle&);
 
 private:
-
     unsigned m_integerPosition;
 };