Title: [200821] trunk
Revision
200821
Author
[email protected]
Date
2016-05-13 00:41:49 -0700 (Fri, 13 May 2016)

Log Message

[css-grid] Show auto-repeat line names in ComputedStyle
https://bugs.webkit.org/show_bug.cgi?id=157622

Reviewed by Darin Adler.

Source/WebCore:

Add the necessary machinery to show the named lines from auto-repeat tracks in
getComputedStyle(). A new class OrderedNamedLinesCollector was added to abstract the
retrieval of line names no matter where they come from (explicit or auto-repeat tracks).

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::OrderedNamedLinesCollector::OrderedNamedLinesCollector):
(WebCore::OrderedNamedLinesCollector::isEmpty): TRUE if we don't have named lines neither on
explicit nor auto-repeat tracks.
(WebCore::OrderedNamedLinesCollector::appendLines): Add the named lines found for a given
index to the CSSGridLineNamesValue.
(WebCore::OrderedNamedLinesCollector::collectLineNamesForIndex): Collects named lines found
for a given index.
(WebCore::addValuesForNamedGridLinesAtIndex): Use the collector to gather named lines.
(WebCore::valueForGridTrackList): Ditto.

LayoutTests:

* fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (200820 => 200821)


--- trunk/LayoutTests/ChangeLog	2016-05-13 07:33:28 UTC (rev 200820)
+++ trunk/LayoutTests/ChangeLog	2016-05-13 07:41:49 UTC (rev 200821)
@@ -1,3 +1,12 @@
+2016-05-12  Sergio Villar Senin  <[email protected]>
+
+        [css-grid] Show auto-repeat line names in ComputedStyle
+        https://bugs.webkit.org/show_bug.cgi?id=157622
+
+        Reviewed by Darin Adler.
+
+        * fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt:
+
 2016-05-12  Myles C. Maxfield  <[email protected]>
 
         Text shadow sometimes clipped unexpectedly

Modified: trunk/LayoutTests/fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt (200820 => 200821)


--- trunk/LayoutTests/fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt	2016-05-13 07:33:28 UTC (rev 200820)
+++ trunk/LayoutTests/fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt	2016-05-13 07:41:49 UTC (rev 200821)
@@ -4,33 +4,33 @@
 
 
 Test auto-repeat syntax.
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be [foo bar] 200px [foo bar] 200px [foo bar] 200px [foo bar] 200px. Was 200px 200px 200px 200px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-columns') is "[foo bar] 200px [foo bar] 200px [foo bar] 200px [foo bar] 200px"
 PASS element.style.gridTemplateColumns is "repeat(auto-fill, [foo bar] 200px)"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be 200px [foo bar] 200px [foo bar] 200px [foo bar]. Was 200px 200px 200px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-rows') is "200px [foo bar] 200px [foo bar] 200px [foo bar]"
 PASS element.style.gridTemplateRows is "repeat(auto-fill, 20em [foo bar])"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be [foo bar] 400px [foo bar] 400px. Was 400px 400px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-columns') is "[foo bar] 400px [foo bar] 400px"
 PASS element.style.gridTemplateColumns is "repeat(auto-fill, [foo bar] minmax(300px, 1fr))"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be [foo] 175px [bar foo] 175px [bar foo] 175px [bar]. Was 175px 175px 175px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-rows') is "[foo] 175px [bar foo] 175px [bar foo] 175px [bar]"
 PASS element.style.gridTemplateRows is "repeat(auto-fill, [foo] minmax(175px, -webkit-max-content) [bar])"
 PASS getComputedStyle(element, '').getPropertyValue('grid-template-columns') is "100px 100px 100px 250px 250px"
 PASS element.style.gridTemplateColumns is "repeat(auto-fill, minmax(50px, 100px)) 250px 250px"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be 450px 50px [bar] 50px [bar foo] 10px [foo] 10px. Was 450px 50px [foo] 50px [foo] 10px 10px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-rows') is "450px 50px [bar] 50px [bar foo] 10px [foo] 10px"
 PASS element.style.gridTemplateRows is "450px repeat(auto-fill, minmax(5em, -webkit-max-content) [bar]) [foo] 1em [foo] 1em"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be [start] 80px [foo bar] 200px [foo bar] 200px [foo bar] 200px [end]. Was [start] 80px 200px [end] 200px 200px.
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-columns') is "[start] 80px [foo bar] 200px [foo bar] 200px [foo bar] 200px [end]"
 PASS element.style.gridTemplateColumns is "[start] 10% repeat(auto-fill, [foo bar] 200px) [end]"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be 75px [prev] 200px [foo bar next] 150px [last end]. Was 75px [prev] 200px [next] 150px [last end].
+PASS getComputedStyle(element, '').getPropertyValue('grid-template-rows') is "75px [prev] 200px [foo bar next] 150px [last end]"
 PASS element.style.gridTemplateRows is "75px [prev] repeat(auto-fill, 20em [foo bar]) [next] 15em [last end]"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be none. Was 150px 150px 150px 150px 150px.
+FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be none. Was [foo bar] 150px [foo bar] 150px [foo bar] 150px [foo bar] 150px [foo bar] 150px.
 PASS element.style.gridTemplateColumns is "repeat(auto-fit, [foo bar] 150px)"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be none. Was 240px 240px.
+FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be none. Was 240px [foo bar] 240px [foo bar].
 PASS element.style.gridTemplateRows is "repeat(auto-fit, 24em [foo bar])"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be none. Was 400px 400px.
+FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be none. Was [foo bar] 400px [foo bar] 400px.
 PASS element.style.gridTemplateColumns is "repeat(auto-fit, [foo bar] minmax(270px, 1fr))"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be none. Was 200px 200px 200px.
+FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be none. Was [foo] 200px [bar foo] 200px [bar foo] 200px [bar].
 PASS element.style.gridTemplateRows is "repeat(auto-fit, [foo] minmax(20em, -webkit-max-content) [bar])"
 FAIL getComputedStyle(element, '').getPropertyValue('grid-template-columns') should be 20px 20px. Was 300px 300px 20px 20px.
 PASS element.style.gridTemplateColumns is "repeat(auto-fit, minmax(300px, -webkit-min-content)) 20px 20px"
-FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be 60px [foo] 10px [foo] 10px. Was 60px 300px [foo] 10px [foo] 10px.
+FAIL getComputedStyle(element, '').getPropertyValue('grid-template-rows') should be 60px [foo] 10px [foo] 10px. Was 60px 300px [bar foo] 10px [foo] 10px.
 PASS element.style.gridTemplateRows is "10% repeat(auto-fit, minmax(30em, -webkit-max-content) [bar]) [foo] 1em [foo] 1em"
 
 Test invalid repeat syntax.

Modified: trunk/Source/WebCore/ChangeLog (200820 => 200821)


--- trunk/Source/WebCore/ChangeLog	2016-05-13 07:33:28 UTC (rev 200820)
+++ trunk/Source/WebCore/ChangeLog	2016-05-13 07:41:49 UTC (rev 200821)
@@ -1,3 +1,25 @@
+2016-05-12  Sergio Villar Senin  <[email protected]>
+
+        [css-grid] Show auto-repeat line names in ComputedStyle
+        https://bugs.webkit.org/show_bug.cgi?id=157622
+
+        Reviewed by Darin Adler.
+
+        Add the necessary machinery to show the named lines from auto-repeat tracks in
+        getComputedStyle(). A new class OrderedNamedLinesCollector was added to abstract the
+        retrieval of line names no matter where they come from (explicit or auto-repeat tracks).
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::OrderedNamedLinesCollector::OrderedNamedLinesCollector):
+        (WebCore::OrderedNamedLinesCollector::isEmpty): TRUE if we don't have named lines neither on
+        explicit nor auto-repeat tracks.
+        (WebCore::OrderedNamedLinesCollector::appendLines): Add the named lines found for a given
+        index to the CSSGridLineNamesValue.
+        (WebCore::OrderedNamedLinesCollector::collectLineNamesForIndex): Collects named lines found
+        for a given index.
+        (WebCore::addValuesForNamedGridLinesAtIndex): Use the collector to gather named lines.
+        (WebCore::valueForGridTrackList): Ditto.
+
 2016-05-13  Tina Liu  <[email protected]>
 
         Revert r199691.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (200820 => 200821)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-05-13 07:33:28 UTC (rev 200820)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-05-13 07:41:49 UTC (rev 200821)
@@ -1034,26 +1034,90 @@
     }
 }
 
-static void addValuesForNamedGridLinesAtIndex(const OrderedNamedGridLinesMap& orderedNamedGridLines, size_t i, CSSValueList& list)
+class OrderedNamedLinesCollector {
+    WTF_MAKE_NONCOPYABLE(OrderedNamedLinesCollector);
+public:
+    OrderedNamedLinesCollector(const RenderStyle& style, bool isRowAxis, unsigned repetitions)
+        : m_orderedNamedGridLines(isRowAxis ? style.orderedNamedGridColumnLines() : style.orderedNamedGridRowLines())
+        , m_orderedNamedAutoRepeatGridLines(isRowAxis ? style.autoRepeatOrderedNamedGridColumnLines() : style.autoRepeatOrderedNamedGridRowLines())
+        , m_insertionPoint(isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint())
+        , m_repetitions(repetitions)
+    {
+    }
+
+    bool isEmpty() const { return m_orderedNamedGridLines.isEmpty() && m_orderedNamedAutoRepeatGridLines.isEmpty(); }
+    void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const;
+
+private:
+
+    enum NamedLinesType { NamedLines, AutoRepeatNamedLines };
+    void appendLines(CSSGridLineNamesValue&, unsigned index, NamedLinesType) const;
+
+    const OrderedNamedGridLinesMap& m_orderedNamedGridLines;
+    const OrderedNamedGridLinesMap& m_orderedNamedAutoRepeatGridLines;
+    unsigned m_insertionPoint;
+    unsigned m_repetitions;
+};
+
+void OrderedNamedLinesCollector::appendLines(CSSGridLineNamesValue& lineNamesValue, unsigned index, NamedLinesType type) const
 {
-    const Vector<String>& namedGridLines = orderedNamedGridLines.get(i);
-    if (namedGridLines.isEmpty())
+    auto iter = type == NamedLines ? m_orderedNamedGridLines.find(index) : m_orderedNamedAutoRepeatGridLines.find(index);
+    auto endIter = type == NamedLines ? m_orderedNamedGridLines.end() : m_orderedNamedAutoRepeatGridLines.end();
+    if (iter == endIter)
         return;
 
     auto& cssValuePool = CSSValuePool::singleton();
-    RefPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue::create();
-    for (auto& name : namedGridLines)
-        lineNames->append(cssValuePool.createValue(name, CSSPrimitiveValue::CSS_STRING));
-    list.append(lineNames.releaseNonNull());
+    for (auto lineName : iter->value)
+        lineNamesValue.append(cssValuePool.createValue(lineName, CSSPrimitiveValue::CSS_STRING));
 }
 
+void OrderedNamedLinesCollector::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const
+{
+    ASSERT(!isEmpty());
+    if (m_orderedNamedAutoRepeatGridLines.isEmpty() || i < m_insertionPoint) {
+        appendLines(lineNamesValue, i, NamedLines);
+        return;
+    }
+
+    ASSERT(m_repetitions);
+    if (i > m_insertionPoint + m_repetitions) {
+        appendLines(lineNamesValue, i - (m_repetitions - 1), NamedLines);
+        return;
+    }
+
+    if (i == m_insertionPoint) {
+        appendLines(lineNamesValue, i, NamedLines);
+        appendLines(lineNamesValue, 0, AutoRepeatNamedLines);
+        return;
+    }
+
+    if (i == m_insertionPoint + m_repetitions) {
+        appendLines(lineNamesValue, 1, AutoRepeatNamedLines);
+        appendLines(lineNamesValue, m_insertionPoint + 1, NamedLines);
+        return;
+    }
+
+    appendLines(lineNamesValue, 1, AutoRepeatNamedLines);
+    appendLines(lineNamesValue, 0, AutoRepeatNamedLines);
+}
+
+static void addValuesForNamedGridLinesAtIndex(OrderedNamedLinesCollector& collector, unsigned i, CSSValueList& list)
+{
+    if (collector.isEmpty())
+        return;
+
+    auto lineNames = CSSGridLineNamesValue::create();
+    collector.collectLineNamesForIndex(lineNames.get(), i);
+    if (lineNames->length())
+        list.append(WTFMove(lineNames));
+}
+
 static Ref<CSSValue> valueForGridTrackList(GridTrackSizingDirection direction, RenderObject* renderer, const RenderStyle& style)
 {
     bool isRowAxis = direction == ForColumns;
     bool isRenderGrid = is<RenderGrid>(renderer);
     auto& trackSizes = isRowAxis ? style.gridColumns() : style.gridRows();
     auto& autoRepeatTrackSizes = isRowAxis ? style.gridAutoRepeatColumns() : style.gridAutoRepeatRows();
-    auto& orderedNamedGridLines = isRowAxis ? style.orderedNamedGridColumnLines() : style.orderedNamedGridRowLines();
 
     // Handle the 'none' case.
     bool trackListIsEmpty = trackSizes.isEmpty() && autoRepeatTrackSizes.isEmpty();
@@ -1064,11 +1128,11 @@
         trackListIsEmpty = !downcast<RenderBlock>(*renderer).firstChild();
     }
 
-    if (trackListIsEmpty) {
-        ASSERT(orderedNamedGridLines.isEmpty());
+    if (trackListIsEmpty)
         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
-    }
 
+    unsigned repetitions = isRenderGrid ? downcast<RenderGrid>(renderer)->autoRepeatCountForDirection(direction) : 0;
+    OrderedNamedLinesCollector collector(style, isRowAxis, repetitions);
     auto list = CSSValueList::createSpaceSeparated();
     unsigned insertionIndex;
     if (isRenderGrid) {
@@ -1082,23 +1146,23 @@
         LayoutUnit gutterSize = grid.guttersSize(direction, 2);
         LayoutUnit offsetBetweenTracks = grid.offsetBetweenTracks(direction);
         for (; i < trackPositions.size() - 2; ++i) {
-            addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
+            addValuesForNamedGridLinesAtIndex(collector, i, list.get());
             list.get().append(zoomAdjustedPixelValue(trackPositions[i + 1] - trackPositions[i] - gutterSize - offsetBetweenTracks, style));
         }
         // Last track line does not have any gutter or distribution offset.
-        addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
+        addValuesForNamedGridLinesAtIndex(collector, i, list.get());
         list.get().append(zoomAdjustedPixelValue(trackPositions[i + 1] - trackPositions[i], style));
         insertionIndex = trackPositions.size() - 1;
     } else {
         for (unsigned i = 0; i < trackSizes.size(); ++i) {
-            addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
+            addValuesForNamedGridLinesAtIndex(collector, i, list.get());
             list.get().append(specifiedValueForGridTrackSize(trackSizes[i], style));
         }
         insertionIndex = trackSizes.size();
     }
 
     // Those are the trailing <ident>* allowed in the syntax.
-    addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, insertionIndex, list.get());
+    addValuesForNamedGridLinesAtIndex(collector, insertionIndex, list.get());
     return WTFMove(list);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to