Title: [136294] trunk/Source/WebCore
Revision
136294
Author
[email protected]
Date
2012-11-30 15:59:55 -0800 (Fri, 30 Nov 2012)

Log Message

[CSS Grid Layout] Align the grid track code with the specification's production rules
https://bugs.webkit.org/show_bug.cgi?id=103703

Reviewed by Alexis Menard.

In order to support more of the syntax and make the code more readable, this change
splits following the grammar's production rules (see
http://dev.w3.org/csswg/css3-grid-layout/#grid-definition-columns-and-grid-definit).

Refactoring covered by existing tests.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::valueForGridTrackMinMax):
(WebCore::valueForGridTrackGroup):
(WebCore::valueForGridTrackList):
* css/CSSParser.cpp:
(WebCore::CSSParser::parseGridTrackList):
(WebCore::CSSParser::parseGridTrackGroup):
(WebCore::CSSParser::parseGridTrackMinMax):
* css/CSSParser.h:
* css/StyleResolver.cpp:
(WebCore::createGridTrackMinMax):
(WebCore::createGridTrackGroup):
(WebCore::createGridTrackList):
Mechanical split of the parsing, resolving and computed style code into
<track-list>, <track-group>, <track-minmax> and <track-breadth> parts.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseGridBreadth):
Changed this function to just parse a single value (without any extra logic).

* css/StyleResolver.cpp:
(WebCore::createGridTrackBreadth):
Changed this function to take a Length as it is used to parse a <track-breadth>.
The goal is for it to be the low-level function createGridTrackMinmax will call on
each function parameter.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136293 => 136294)


--- trunk/Source/WebCore/ChangeLog	2012-11-30 23:56:14 UTC (rev 136293)
+++ trunk/Source/WebCore/ChangeLog	2012-11-30 23:59:55 UTC (rev 136294)
@@ -1,3 +1,42 @@
+2012-11-30  Julien Chaffraix  <[email protected]>
+
+        [CSS Grid Layout] Align the grid track code with the specification's production rules
+        https://bugs.webkit.org/show_bug.cgi?id=103703
+
+        Reviewed by Alexis Menard.
+
+        In order to support more of the syntax and make the code more readable, this change
+        splits following the grammar's production rules (see
+        http://dev.w3.org/csswg/css3-grid-layout/#grid-definition-columns-and-grid-definit).
+
+        Refactoring covered by existing tests.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::valueForGridTrackMinMax):
+        (WebCore::valueForGridTrackGroup):
+        (WebCore::valueForGridTrackList):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseGridTrackList):
+        (WebCore::CSSParser::parseGridTrackGroup):
+        (WebCore::CSSParser::parseGridTrackMinMax):
+        * css/CSSParser.h:
+        * css/StyleResolver.cpp:
+        (WebCore::createGridTrackMinMax):
+        (WebCore::createGridTrackGroup):
+        (WebCore::createGridTrackList):
+        Mechanical split of the parsing, resolving and computed style code into
+        <track-list>, <track-group>, <track-minmax> and <track-breadth> parts.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseGridBreadth):
+        Changed this function to just parse a single value (without any extra logic).
+
+        * css/StyleResolver.cpp:
+        (WebCore::createGridTrackBreadth):
+        Changed this function to take a Length as it is used to parse a <track-breadth>.
+        The goal is for it to be the low-level function createGridTrackMinmax will call on
+        each function parameter.
+
 2012-11-30  Simon Fraser  <[email protected]>
 
         Fix potential crash when canceling animations on renderers with no node

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (136293 => 136294)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-11-30 23:56:14 UTC (rev 136293)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-11-30 23:59:55 UTC (rev 136294)
@@ -992,16 +992,26 @@
     return zoomAdjustedPixelValue(trackSize.length().value(), style);
 }
 
+static PassRefPtr<CSSValue> valueForGridTrackMinMax(const GridTrackSize& trackSize, const RenderStyle* style)
+{
+    return valueForGridTrackBreadth(trackSize, style);
+}
+
+static PassRefPtr<CSSValue> valueForGridTrackGroup(const Vector<GridTrackSize>& trackSizes, const RenderStyle* style)
+{
+    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
+    for (size_t i = 0; i < trackSizes.size(); ++i)
+        list->append(valueForGridTrackMinMax(trackSizes[i], style));
+    return list.release();
+}
+
 static PassRefPtr<CSSValue> valueForGridTrackList(const Vector<GridTrackSize>& trackSizes, const RenderStyle* style)
 {
     // Handle the 'none' case here.
     if (!trackSizes.size())
         return cssValuePool().createIdentifierValue(CSSValueNone);
 
-    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
-    for (size_t i = 0; i < trackSizes.size(); ++i)
-        list->append(valueForGridTrackBreadth(trackSizes[i], style));
-    return list.release();
+    return valueForGridTrackGroup(trackSizes, style);
 }
 
 static PassRefPtr<CSSValue> valueForGridPosition(const GridPosition& position)

Modified: trunk/Source/WebCore/css/CSSParser.cpp (136293 => 136294)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-11-30 23:56:14 UTC (rev 136293)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-11-30 23:59:55 UTC (rev 136294)
@@ -4512,20 +4512,46 @@
     }
 
     RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
-    while (value) {
-        bool valid = validUnit(value, FLength | FPercent) || value->id == CSSValueAuto;
-        if (!valid)
+    while (m_valueList->current()) {
+        if (!parseGridTrackGroup(values.get()))
             return false;
 
-        RefPtr<CSSPrimitiveValue> primitiveValue = value->id == CSSValueAuto ? cssValuePool().createIdentifierValue(CSSValueAuto) : createPrimitiveNumericValue(value);
-        values->append(primitiveValue.release());
-        value = m_valueList->next();
+        m_valueList->next();
     }
     addProperty(propId, values.release(), important);
     return true;
 }
 
+bool CSSParser::parseGridTrackGroup(CSSValueList* values)
+{
+    return parseGridTrackMinMax(values);
+}
 
+bool CSSParser::parseGridTrackMinMax(CSSValueList* values)
+{
+    CSSParserValue* currentValue = m_valueList->current();
+    if (currentValue->id == CSSValueAuto) {
+        RefPtr<CSSPrimitiveValue> autoValue = cssValuePool().createIdentifierValue(CSSValueAuto);
+        values->append(autoValue.release());
+        return true;
+    }
+
+    if (PassRefPtr<CSSPrimitiveValue> trackBreadth = parseGridBreadth(currentValue)) {
+        values->append(trackBreadth);
+        return true;
+    }
+
+    return false;
+}
+
+PassRefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue* currentValue)
+{
+    if (!validUnit(currentValue, FLength | FPercent))
+        return 0;
+
+    return createPrimitiveNumericValue(currentValue);
+}
+
 #if ENABLE(DASHBOARD_SUPPORT)
 
 #define DASHBOARD_REGION_NUM_PARAMETERS  6

Modified: trunk/Source/WebCore/css/CSSParser.h (136293 => 136294)


--- trunk/Source/WebCore/css/CSSParser.h	2012-11-30 23:56:14 UTC (rev 136293)
+++ trunk/Source/WebCore/css/CSSParser.h	2012-11-30 23:59:55 UTC (rev 136294)
@@ -152,6 +152,9 @@
 
     bool cssGridLayoutEnabled() const;
     bool parseGridTrackList(CSSPropertyID, bool important);
+    bool parseGridTrackGroup(CSSValueList*);
+    bool parseGridTrackMinMax(CSSValueList*);
+    PassRefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue*);
 
     bool parseDashboardRegions(CSSPropertyID, bool important);
 

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (136293 => 136294)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-11-30 23:56:14 UTC (rev 136293)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-11-30 23:59:55 UTC (rev 136294)
@@ -2659,19 +2659,47 @@
     return m_element && m_element->isSVGElement();
 }
 
-static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, StyleResolver* selector, GridTrackSize& trackSize)
+static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, StyleResolver* selector, Length& workingLength)
 {
-    Length workingLength = primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | ViewportPercentageConversion | AutoConversion>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
+    workingLength = primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | ViewportPercentageConversion | AutoConversion>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
     if (workingLength.isUndefined())
         return false;
 
     if (primitiveValue->isLength())
         workingLength.setQuirk(primitiveValue->isQuirkValue());
 
+    return true;
+}
+
+static bool createGridTrackMinMax(CSSPrimitiveValue* primitiveValue, StyleResolver* selector, GridTrackSize& trackSize)
+{
+    Length workingLength;
+    if (!createGridTrackBreadth(primitiveValue, selector, workingLength))
+        return false;
+
     trackSize.setLength(workingLength);
     return true;
 }
 
+static bool createGridTrackGroup(CSSValue* value, StyleResolver* selector, Vector<GridTrackSize>& trackSizes)
+{
+    if (!value->isValueList())
+        return false;
+
+    for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
+        CSSValue* currValue = i.value();
+        if (!currValue->isPrimitiveValue())
+            return false;
+
+        GridTrackSize trackSize;
+        if (!createGridTrackMinMax(static_cast<CSSPrimitiveValue*>(currValue), selector, trackSize))
+            return false;
+
+        trackSizes.append(trackSize);
+    }
+    return true;
+}
+
 static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, StyleResolver* selector)
 {
     // Handle 'none'.
@@ -2680,22 +2708,7 @@
         return primitiveValue->getIdent() == CSSValueNone;
     }
 
-    if (value->isValueList()) {
-        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
-            CSSValue* currValue = i.value();
-            if (!currValue->isPrimitiveValue())
-                return false;
-
-            GridTrackSize trackSize;
-            if (!createGridTrackBreadth(static_cast<CSSPrimitiveValue*>(currValue), selector, trackSize))
-                return false;
-
-            trackSizes.append(trackSize);
-        }
-        return true;
-    }
-
-    return false;
+    return createGridTrackGroup(value, selector, trackSizes);
 }
 
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to