RenderGrid should have a function to resolve grid position
authorjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 13:32:18 +0000 (13:32 +0000)
committerjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 13:32:18 +0000 (13:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102441

Reviewed by Ojan Vafai.

The code was doing this conversion implicitly inside RenderGrid::findChildLogicalPosition.
Also note that we also provided a fallback by returning LayoutPoint() (ie the (0, 0) position
on the grid) if we couldn't handle the value. The explicit conversion is needed in order to
support render areas and add a proper grid model to RenderGrid.

No expected change in behavior.

* rendering/RenderGrid.h:
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::resolveGridPosition):
Added this new function to handle the conversion. We re-use Length but should never see
a lot of the <length> values so I added some ASSERTs to enforce and catch that.

(WebCore::RenderGrid::findChildLogicalPosition):
Simplified the function now that it just use resolveGridPosition.

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/RenderGrid.h

index 8672e5b..21ebb7c 100644 (file)
@@ -1,3 +1,26 @@
+2012-11-16  Julien Chaffraix  <jchaffraix@webkit.org>
+
+        RenderGrid should have a function to resolve grid position
+        https://bugs.webkit.org/show_bug.cgi?id=102441
+
+        Reviewed by Ojan Vafai.
+
+        The code was doing this conversion implicitly inside RenderGrid::findChildLogicalPosition.
+        Also note that we also provided a fallback by returning LayoutPoint() (ie the (0, 0) position
+        on the grid) if we couldn't handle the value. The explicit conversion is needed in order to
+        support render areas and add a proper grid model to RenderGrid.
+
+        No expected change in behavior.
+
+        * rendering/RenderGrid.h:
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::resolveGridPosition):
+        Added this new function to handle the conversion. We re-use Length but should never see
+        a lot of the <length> values so I added some ASSERTs to enforce and catch that.
+
+        (WebCore::RenderGrid::findChildLogicalPosition):
+        Simplified the function now that it just use resolveGridPosition.
+
 2012-11-16  Ulan Degenbaev  <ulan@chromium.org>
 
         [V8] Increment the amount of externally allocated memory for the receiving V8 isolate when transferring ArrayBuffer
index 6e293cc..c5b903c 100644 (file)
@@ -175,23 +175,47 @@ void RenderGrid::layoutGridItems()
         setLogicalHeight(logicalHeight() + rowTracks[i].m_usedBreadth);
 }
 
-LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
+size_t RenderGrid::resolveGridPosition(const Length& position) const
 {
-    Length column = child->style()->gridItemColumn();
-    Length row = child->style()->gridItemRow();
-
-    // FIXME: What does a non-positive integer mean for a column/row?
-    if (!column.isPositive() || !row.isPositive())
-        return LayoutPoint();
-
     // FIXME: Handle other values for grid-{row,column} like ranges or line names.
-    if (!column.isFixed() || !row.isFixed())
-        return LayoutPoint();
+    switch (position.type()) {
+    case Fixed:
+        // FIXME: What does a non-positive integer mean for a column/row?
+        if (!position.isPositive())
+            return 0;
+
+        return position.intValue() - 1;
+    case Auto:
+        // FIXME: We should follow 'grid-auto-flow' for resolution.
+        // Until then, we use the 'grid-auto-flow: none' behavior (which is the default)
+        // and resolve 'auto' as the first row / column.
+        return 0;
+    case Relative:
+    case Percent:
+    case Intrinsic:
+    case MinIntrinsic:
+    case MinContent:
+    case MaxContent:
+    case FillAvailable:
+    case FitContent:
+    case Calculated:
+    case ViewportPercentageWidth:
+    case ViewportPercentageHeight:
+    case ViewportPercentageMin:
+    case Undefined:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
 
-    size_t columnTrack = static_cast<size_t>(column.intValue()) - 1;
-    size_t rowTrack = static_cast<size_t>(row.intValue()) - 1;
+LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
+{
+    size_t columnTrack = resolveGridPosition(child->style()->gridItemColumn());
+    size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
 
     LayoutPoint offset;
+    // FIXME: |columnTrack| and |rowTrack| should be smaller than our column / row count.
     for (size_t i = 0; i < columnTrack && i < columnTracks.size(); ++i)
         offset.setX(offset.x() + columnTracks[i].m_usedBreadth);
     for (size_t i = 0; i < rowTrack && i < rowTracks.size(); ++i)
index e5017fa..b3f4ca5 100644 (file)
@@ -50,6 +50,7 @@ private:
     void layoutGridItems();
 
     LayoutPoint findChildLogicalPosition(RenderBox*, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks);
+    size_t resolveGridPosition(const Length&) const;
 };
 
 } // namespace WebCore