Title: [141505] trunk
Revision
141505
Author
jchaffr...@webkit.org
Date
2013-01-31 16:48:05 -0800 (Thu, 31 Jan 2013)

Log Message

[CSS Grid Layout] Support implicit rows and columns
https://bugs.webkit.org/show_bug.cgi?id=103573

Reviewed by Ojan Vafai.

Source/WebCore:

Tests: fast/css-grid-layout/implicit-columns-auto-resolution.html
       fast/css-grid-layout/implicit-rows-auto-resolution.html

This change makes us properly initialize our GridTrack vectors's size
so that we can safely query any items during layout.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::gridTrackSize):
Added this helper function to return the track size from the grid
element's columns' / rows' definitions or the default value.

(WebCore::RenderGrid::maximumIndexInDirection):
Added this helper function to get the maximum index in a direction
taking grid item's implicit indexes into account.

(WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
Changed the funtion to not append the new tracks as we are properly
sized now.

(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
(WebCore::RenderGrid::tracksAreWiderThanMinTrackBreadth):
Updated these functions to use the new helper functions.

(WebCore::RenderGrid::layoutGridItems):
Changed this function to size both vectors when initializing them.
Also removed an unneeded bounds check as it shouldn't be needed anymore.

* rendering/RenderGrid.h:
Added the new helper functions.

* rendering/style/GridTrackSize.h:
(WebCore::GridTrackSize::GridTrackSize):
Added a constructor taking a LengthType.

LayoutTests:

* fast/css-grid-layout/implicit-columns-auto-resolution-expected.txt: Added.
* fast/css-grid-layout/implicit-columns-auto-resolution.html: Added.
* fast/css-grid-layout/implicit-rows-auto-resolution-expected.txt: Added.
* fast/css-grid-layout/implicit-rows-auto-resolution.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141504 => 141505)


--- trunk/LayoutTests/ChangeLog	2013-02-01 00:37:38 UTC (rev 141504)
+++ trunk/LayoutTests/ChangeLog	2013-02-01 00:48:05 UTC (rev 141505)
@@ -1,3 +1,15 @@
+2013-01-31  Julien Chaffraix  <jchaffr...@webkit.org>
+
+        [CSS Grid Layout] Support implicit rows and columns
+        https://bugs.webkit.org/show_bug.cgi?id=103573
+
+        Reviewed by Ojan Vafai.
+
+        * fast/css-grid-layout/implicit-columns-auto-resolution-expected.txt: Added.
+        * fast/css-grid-layout/implicit-columns-auto-resolution.html: Added.
+        * fast/css-grid-layout/implicit-rows-auto-resolution-expected.txt: Added.
+        * fast/css-grid-layout/implicit-rows-auto-resolution.html: Added.
+
 2013-01-31  Joanmarie Diggs  <jdi...@igalia.com>
 
         [GTK] fast/css/relative-positioned-block-crash.html is intermittently crashing

Added: trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution-expected.txt (0 => 141505)


--- trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution-expected.txt	2013-02-01 00:48:05 UTC (rev 141505)
@@ -0,0 +1,8 @@
+Test that resolving auto tracks on grid items works properly.
+
+XXX XXX XXX
+PASS
+XX XX XX XX XX XX
+PASS
+XXXXX
+PASS

Added: trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution.html (0 => 141505)


--- trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/implicit-columns-auto-resolution.html	2013-02-01 00:48:05 UTC (rev 141505)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<script>
+if (window.testRunner)
+    testRunner.overridePreference("WebKitCSSGridLayoutEnabled", 1);
+</script>
+<link href="" rel="stylesheet">
+<style>
+.gridAutoContent {
+    /* -webkit-grid-columns is left unset so that the grid item's column is implicit. */
+    -webkit-grid-rows: 50px;
+}
+
+/* This rule makes sure the container is smaller than any grid items to avoid distributing any extra logical space to them. */
+.constrainedContainer {
+    width: 10px;
+    height: 10px;
+}
+
+.firstRowFirstColumn {
+    font: 10px/1 Ahem;
+    /* Make us fit our grid area. */
+    width: 100%;
+    height: 100%;
+}
+</style>
+<script src=""
+<body _onload_="checkLayout('.gridAutoContent');">
+
+<p>Test that resolving auto tracks on grid items works properly.</p>
+
+<div class="constrainedContainer">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="30" data-expected-height="50">XXX XXX XXX</div>
+    </div>
+</div>
+
+<!-- Allow the extra logical space distribution to occur. -->
+<div style="width: 40px; height: 10px">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="40" data-expected-height="50">XX XX XX XX XX XX</div>
+    </div>
+</div>
+
+<div style="width: 100px; height: 10px;">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="50">XXXXX</div>
+    </div>
+</div>
+
+</body>
+</html>

Added: trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution-expected.txt (0 => 141505)


--- trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution-expected.txt	2013-02-01 00:48:05 UTC (rev 141505)
@@ -0,0 +1,8 @@
+Test that resolving auto tracks on grid items works properly.
+
+XXXXX XXXXX XXXXX
+PASS
+XXXXX XXXXX XXXXX
+PASS
+XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX
+PASS

Added: trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution.html (0 => 141505)


--- trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/implicit-rows-auto-resolution.html	2013-02-01 00:48:05 UTC (rev 141505)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<script>
+if (window.testRunner)
+    testRunner.overridePreference("WebKitCSSGridLayoutEnabled", 1);
+</script>
+<link href="" rel="stylesheet">
+<style>
+.gridAutoContent {
+    -webkit-grid-columns: 50px;
+    /* -webkit-grid-rows is left unset so that the grid item's row is implicit. */
+}
+
+/* This rule makes sure the container is smaller than any grid items to avoid distributing any extra logical space to them. */
+.constrainedContainer {
+    width: 10px;
+    height: 10px;
+}
+
+.firstRowFirstColumn {
+    font: 10px/1 Ahem;
+    /* Make us fit our grid area. */
+    width: 100%;
+    height: 100%;
+}
+</style>
+<script src=""
+<body _onload_="checkLayout('.gridAutoContent');">
+
+<p>Test that resolving auto tracks on grid items works properly.</p>
+
+<div class="constrainedContainer">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="30">XXXXX XXXXX XXXXX</div>
+    </div>
+</div>
+
+<!-- Allow the extra logical space distribution to occur. -->
+<div style="width: 40px; height: 10px">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="30">XXXXX XXXXX XXXXX</div>
+    </div>
+</div>
+
+<div style="width: 100px; height: 10px;">
+    <div class="grid gridAutoContent">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="60">XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX</div>
+    </div>
+</div>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (141504 => 141505)


--- trunk/Source/WebCore/ChangeLog	2013-02-01 00:37:38 UTC (rev 141504)
+++ trunk/Source/WebCore/ChangeLog	2013-02-01 00:48:05 UTC (rev 141505)
@@ -1,3 +1,44 @@
+2013-01-31  Julien Chaffraix  <jchaffr...@webkit.org>
+
+        [CSS Grid Layout] Support implicit rows and columns
+        https://bugs.webkit.org/show_bug.cgi?id=103573
+
+        Reviewed by Ojan Vafai.
+
+        Tests: fast/css-grid-layout/implicit-columns-auto-resolution.html
+               fast/css-grid-layout/implicit-rows-auto-resolution.html
+
+        This change makes us properly initialize our GridTrack vectors's size
+        so that we can safely query any items during layout.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::gridTrackSize):
+        Added this helper function to return the track size from the grid
+        element's columns' / rows' definitions or the default value.
+
+        (WebCore::RenderGrid::maximumIndexInDirection):
+        Added this helper function to get the maximum index in a direction
+        taking grid item's implicit indexes into account.
+
+        (WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
+        Changed the funtion to not append the new tracks as we are properly
+        sized now.
+
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
+        (WebCore::RenderGrid::tracksAreWiderThanMinTrackBreadth):
+        Updated these functions to use the new helper functions.
+
+        (WebCore::RenderGrid::layoutGridItems):
+        Changed this function to size both vectors when initializing them.
+        Also removed an unneeded bounds check as it shouldn't be needed anymore.
+
+        * rendering/RenderGrid.h:
+        Added the new helper functions.
+
+        * rendering/style/GridTrackSize.h:
+        (WebCore::GridTrackSize::GridTrackSize):
+        Added a constructor taking a LengthType.
+
 2013-01-31  Joanmarie Diggs  <jdi...@igalia.com>
 
         [GTK] fast/css/relative-positioned-block-crash.html is intermittently crashing

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (141504 => 141505)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-02-01 00:37:38 UTC (rev 141504)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-02-01 00:48:05 UTC (rev 141505)
@@ -176,7 +176,7 @@
     LayoutUnit availableLogicalSpace = (direction == ForColumns) ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding);
     Vector<GridTrack>& tracks = (direction == ForColumns) ? columnTracks : rowTracks;
     for (size_t i = 0; i < trackStyles.size(); ++i) {
-        GridTrack track;
+        GridTrack& track = tracks[i];
         const Length& minTrackBreadth = trackStyles[i].minTrackBreadth();
         const Length& maxTrackBreadth = trackStyles[i].maxTrackBreadth();
 
@@ -186,8 +186,6 @@
         track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadth);
 
         availableLogicalSpace -= track.m_usedBreadth;
-
-        tracks.append(track);
     }
 
     // FIXME: We shouldn't call resolveContentBasedTrackSizingFunctions if we have no min-content / max-content tracks.
@@ -238,6 +236,31 @@
     return (track1->m_maxBreadth - track1->m_usedBreadth) <= (track2->m_maxBreadth - track2->m_usedBreadth);
 }
 
+const GridTrackSize& RenderGrid::gridTrackSize(TrackSizingDirection direction, size_t i)
+{
+    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
+    if (i >= trackStyles.size()) {
+        // FIXME: This should match the default grid sizing (https://webkit.org/b/103333)
+        DEFINE_STATIC_LOCAL(GridTrackSize, defaultAutoSize, (Auto));
+        return defaultAutoSize;
+    }
+    return trackStyles[i];
+}
+
+size_t RenderGrid::maximumIndexInDirection(TrackSizingDirection direction) const
+{
+    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
+
+    size_t maximumIndex = trackStyles.size();
+
+    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+        GridPosition position = (direction == ForColumns) ? child->style()->gridItemColumn() : child->style()->gridItemRow();
+        maximumIndex = std::max(maximumIndex, resolveGridPosition(position) + 1);
+    }
+
+    return maximumIndex;
+}
+
 LayoutUnit RenderGrid::minContentForChild(RenderBox* child, TrackSizingDirection direction, Vector<GridTrack>& columnTracks)
 {
     bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHorizontalWritingMode();
@@ -284,12 +307,12 @@
 {
     // FIXME: Split the grid tracks once we support spanning or fractions (step 1 and 2 of the algorithm).
 
-    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
     Vector<GridTrack>& tracks = (direction == ForColumns) ? columnTracks : rowTracks;
 
     for (size_t i = 0; i < tracks.size(); ++i) {
+        const GridTrackSize& trackSize = gridTrackSize(direction, i);
         GridTrack& track = tracks[i];
-        const Length& minTrackBreadth = trackStyles[i].minTrackBreadth();
+        const Length& minTrackBreadth = trackSize.minTrackBreadth();
         if (minTrackBreadth.isMinContent() || minTrackBreadth.isMaxContent()) {
             LayoutUnit oldUsedBreadth = track.m_usedBreadth;
             resolveContentBasedTrackSizingFunctionsForItems(direction, columnTracks, rowTracks, i, &RenderGrid::minContentForChild, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth);
@@ -302,7 +325,7 @@
             availableLogicalSpace -= (track.m_usedBreadth - oldUsedBreadth);
         }
 
-        const Length& maxTrackBreadth = trackStyles[i].maxTrackBreadth();
+        const Length& maxTrackBreadth = trackSize.maxTrackBreadth();
         if (maxTrackBreadth.isMinContent() || maxTrackBreadth.isMaxContent())
             resolveContentBasedTrackSizingFunctionsForItems(direction, columnTracks, rowTracks, i, &RenderGrid::minContentForChild, &GridTrack::maxBreadthIfNotInfinite, &GridTrack::growMaxBreadth);
 
@@ -364,9 +387,9 @@
 #ifndef NDEBUG
 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(TrackSizingDirection direction, const Vector<GridTrack>& tracks)
 {
-    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
-    for (size_t i = 0; i < trackStyles.size(); ++i) {
-        const Length& minTrackBreadth = trackStyles[i].minTrackBreadth();
+    for (size_t i = 0; i < tracks.size(); ++i) {
+        const GridTrackSize& trackSize = gridTrackSize(direction, i);
+        const Length& minTrackBreadth = trackSize.minTrackBreadth();
         if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i].m_usedBreadth)
             return false;
     }
@@ -376,7 +399,8 @@
 
 void RenderGrid::layoutGridItems()
 {
-    Vector<GridTrack> columnTracks, rowTracks;
+    Vector<GridTrack> columnTracks(maximumIndexInDirection(ForColumns));
+    Vector<GridTrack> rowTracks(maximumIndexInDirection(ForRows));
     computedUsedBreadthOfGridTracks(ForColumns, columnTracks, rowTracks);
     ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, columnTracks));
     computedUsedBreadthOfGridTracks(ForRows, columnTracks, rowTracks);
@@ -388,21 +412,17 @@
         size_t columnTrack = resolveGridPosition(child->style()->gridItemColumn());
         size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
 
-        // FIXME: Properly support implicit rows and columns (bug 103573).
-        if (columnTrack < columnTracks.size() && rowTrack < rowTracks.size()) {
-            // Because the grid area cannot be styled, we don't need to adjust
-            // the grid breadth to account for 'box-sizing'.
-            LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOverrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit();
-            LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOverrideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogicalHeight() : LayoutUnit();
+        // Because the grid area cannot be styled, we don't need to adjust
+        // the grid breadth to account for 'box-sizing'.
+        LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOverrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit();
+        LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOverrideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogicalHeight() : LayoutUnit();
 
-            if (oldOverrideContainingBlockContentLogicalWidth != columnTracks[columnTrack].m_usedBreadth || oldOverrideContainingBlockContentLogicalHeight != rowTracks[rowTrack].m_usedBreadth)
-                child->setNeedsLayout(true, MarkOnlyThis);
+        if (oldOverrideContainingBlockContentLogicalWidth != columnTracks[columnTrack].m_usedBreadth || oldOverrideContainingBlockContentLogicalHeight != rowTracks[rowTrack].m_usedBreadth)
+            child->setNeedsLayout(true, MarkOnlyThis);
 
-            child->setOverrideContainingBlockContentLogicalWidth(columnTracks[columnTrack].m_usedBreadth);
-            child->setOverrideContainingBlockContentLogicalHeight(rowTracks[rowTrack].m_usedBreadth);
+        child->setOverrideContainingBlockContentLogicalWidth(columnTracks[columnTrack].m_usedBreadth);
+        child->setOverrideContainingBlockContentLogicalHeight(rowTracks[rowTrack].m_usedBreadth);
 
-        }
-
         // FIXME: Grid items should stretch to fill their cells. Once we
         // implement grid-{column,row}-align, we can also shrink to fit. For
         // now, just size as if we were a regular child.

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (141504 => 141505)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2013-02-01 00:37:38 UTC (rev 141504)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2013-02-01 00:48:05 UTC (rev 141505)
@@ -62,6 +62,9 @@
     void resolveContentBasedTrackSizingFunctionsForItems(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, size_t, SizingFunction, AccumulatorGetter, AccumulatorGrowFunction);
     void distributeSpaceToTracks(Vector<GridTrack*>&, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter, AccumulatorGrowFunction, LayoutUnit& availableLogicalSpace);
 
+    const GridTrackSize& gridTrackSize(TrackSizingDirection, size_t);
+    size_t maximumIndexInDirection(TrackSizingDirection) const;
+
     LayoutUnit minContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
     LayoutUnit maxContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
     LayoutPoint findChildLogicalPosition(RenderBox*, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks);

Modified: trunk/Source/WebCore/rendering/style/GridTrackSize.h (141504 => 141505)


--- trunk/Source/WebCore/rendering/style/GridTrackSize.h	2013-02-01 00:37:38 UTC (rev 141504)
+++ trunk/Source/WebCore/rendering/style/GridTrackSize.h	2013-02-01 00:48:05 UTC (rev 141505)
@@ -42,10 +42,10 @@
 
 class GridTrackSize {
 public:
-    GridTrackSize()
+    GridTrackSize(LengthType type = Undefined)
         : m_type(LengthTrackSizing)
-        , m_minTrackBreadth(Undefined)
-        , m_maxTrackBreadth(Undefined)
+        , m_minTrackBreadth(type)
+        , m_maxTrackBreadth(type)
     {
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to