Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp

Issue 1582793002: [css-grid] Add parsing support for <auto-repeat> syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 m_valueList->next(); 1867 m_valueList->next();
1868 return cssValuePool().createIdentifierValue(CSSValueNone); 1868 return cssValuePool().createIdentifierValue(CSSValueNone);
1869 } 1869 }
1870 1870
1871 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); 1871 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
1872 // Handle leading <custom-ident>*. 1872 // Handle leading <custom-ident>*.
1873 if (!parseGridLineNames(*m_valueList, *values)) 1873 if (!parseGridLineNames(*m_valueList, *values))
1874 return nullptr; 1874 return nullptr;
1875 1875
1876 bool seenTrackSizeOrRepeatFunction = false; 1876 bool seenTrackSizeOrRepeatFunction = false;
1877 bool seenAutoRepeat = false;
1877 while (CSSParserValue* currentValue = m_valueList->current()) { 1878 while (CSSParserValue* currentValue = m_valueList->current()) {
1878 if (isForwardSlashOperator(currentValue)) 1879 if (isForwardSlashOperator(currentValue))
1879 break; 1880 break;
1880 if (currentValue->m_unit == CSSParserValue::Function && currentValue->fu nction->id == CSSValueRepeat) { 1881 if (currentValue->m_unit == CSSParserValue::Function && currentValue->fu nction->id == CSSValueRepeat) {
1881 if (!parseGridTrackRepeatFunction(*values)) 1882 bool isAutoRepeat;
1883 if (!parseGridTrackRepeatFunction(*values, isAutoRepeat))
1884 return nullptr;
1885 if (isAutoRepeat && seenAutoRepeat)
1882 return nullptr; 1886 return nullptr;
1883 seenTrackSizeOrRepeatFunction = true; 1887 seenTrackSizeOrRepeatFunction = true;
1888 seenAutoRepeat = seenAutoRepeat || isAutoRepeat;
1884 } else { 1889 } else {
1885 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList ); 1890 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList , seenAutoRepeat ? FixedSizeOnly : AllowAll);
1886 if (!value) 1891 if (!value)
1887 return nullptr; 1892 return nullptr;
1888 values->append(value); 1893 values->append(value);
1889 seenTrackSizeOrRepeatFunction = true; 1894 seenTrackSizeOrRepeatFunction = true;
1890 } 1895 }
1891 // This will handle the trailing <custom-ident>* in the grammar. 1896 // This will handle the trailing <custom-ident>* in the grammar.
1892 if (!parseGridLineNames(*m_valueList, *values)) 1897 if (!parseGridLineNames(*m_valueList, *values))
1893 return nullptr; 1898 return nullptr;
1894 } 1899 }
1895 1900
1896 // We should have found a <track-size> or else it is not a valid <track-list > 1901 // We should have found a <track-size> or else it is not a valid <track-list >
1897 if (!seenTrackSizeOrRepeatFunction) 1902 if (!seenTrackSizeOrRepeatFunction)
1898 return nullptr; 1903 return nullptr;
1899 1904
1905 // <auto-repeat> requires definite minimum track sizes in order to compute t he number of repetitions.
1906 // The above while loop detects those appearances after the <auto-repeat> bu t not the ones before.
1907 if (seenAutoRepeat) {
1908 for (auto value : *values) {
1909 if (value->isGridLineNamesValue())
1910 continue;
1911 ASSERT(value->isPrimitiveValue() || (value->isFunctionValue() && toC SSFunctionValue(*value).item(0)));
1912 const CSSPrimitiveValue& primitiveValue = value->isPrimitiveValue()
1913 ? toCSSPrimitiveValue(*value)
1914 : toCSSPrimitiveValue(*toCSSFunctionValue(*value).item(0));
1915 CSSValueID valueID = primitiveValue.getValueID();
1916 if (valueID == CSSValueMinContent || valueID == CSSValueMaxContent | | valueID == CSSValueAuto || primitiveValue.isFlex())
1917 return nullptr;
1918 }
1919 }
1920
1900 return values; 1921 return values;
1901 } 1922 }
1902 1923
1903 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) 1924 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& i sAutoRepeat)
1904 { 1925 {
1905 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ; 1926 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
1906 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1))) 1927 if (!arguments || arguments->size() < 3 || !isComma(arguments->valueAt(1)))
1907 return false; 1928 return false;
1908 1929
1909 ASSERT(arguments->valueAt(0)->fValue > 0); 1930 CSSParserValue* currentValue = arguments->valueAt(0);
1910 size_t repetitions = clampTo<size_t>(arguments->valueAt(0)->fValue, 0, kGrid MaxTracks); 1931 isAutoRepeat = currentValue->id == CSSValueAutoFill || currentValue->id == C SSValueAutoFit;
1932 if (!isAutoRepeat && !validUnit(currentValue, FPositiveInteger))
1933 return false;
1934
1935 // The number of repetitions for <auto-repeat> is not important at parsing l evel
1936 // because it will be computed later, let's set it to 1.
1937 size_t repetitions = isAutoRepeat ? 1 : clampTo<size_t>(currentValue->fValue , 0, kGridMaxTracks);
1911 1938
1912 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated(); 1939 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated();
1913 arguments->next(); // Skip the repetition count. 1940 arguments->next(); // Skip the repetition count.
1914 arguments->next(); // Skip the comma. 1941 arguments->next(); // Skip the comma.
1915 1942
1916 // Handle leading <custom-ident>*. 1943 // Handle leading <custom-ident>*.
1917 if (!parseGridLineNames(*arguments, *repeatedValues)) 1944 if (!parseGridLineNames(*arguments, *repeatedValues))
1918 return false; 1945 return false;
1919 1946
1920 size_t numberOfTracks = 0; 1947 size_t numberOfTracks = 0;
1948 TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll;
1921 while (arguments->current()) { 1949 while (arguments->current()) {
1922 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); 1950 if (isAutoRepeat && numberOfTracks)
1951 return false;
1952
1953 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments, restriction);
1923 if (!trackSize) 1954 if (!trackSize)
1924 return false; 1955 return false;
1925 1956
1926 repeatedValues->append(trackSize); 1957 repeatedValues->append(trackSize);
1927 ++numberOfTracks; 1958 ++numberOfTracks;
1928 1959
1929 // This takes care of any trailing <custom-ident>* in the grammar. 1960 // This takes care of any trailing <custom-ident>* in the grammar.
1930 if (!parseGridLineNames(*arguments, *repeatedValues)) 1961 if (!parseGridLineNames(*arguments, *repeatedValues))
1931 return false; 1962 return false;
1932 } 1963 }
(...skipping 10 matching lines...) Expand all
1943 for (size_t j = 0; j < repeatedValues->length(); ++j) 1974 for (size_t j = 0; j < repeatedValues->length(); ++j)
1944 list.append(repeatedValues->item(j)); 1975 list.append(repeatedValues->item(j));
1945 } 1976 }
1946 1977
1947 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue. 1978 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue.
1948 m_valueList->next(); 1979 m_valueList->next();
1949 return true; 1980 return true;
1950 } 1981 }
1951 1982
1952 1983
1953 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackSize(CSSParser ValueList& inputList) 1984 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackSize(CSSParser ValueList& inputList, TrackSizeRestriction restriction)
1954 { 1985 {
1955 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 1986 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1956 1987
1957 CSSParserValue* currentValue = inputList.current(); 1988 CSSParserValue* currentValue = inputList.current();
1958 inputList.next(); 1989 inputList.next();
1959 1990
1960 if (currentValue->id == CSSValueAuto) 1991 if (currentValue->id == CSSValueAuto)
1961 return cssValuePool().createIdentifierValue(CSSValueAuto); 1992 return restriction == AllowAll ? cssValuePool().createIdentifierValue(CS SValueAuto) : nullptr;
1962 1993
1963 if (currentValue->m_unit == CSSParserValue::Function && currentValue->functi on->id == CSSValueMinmax) { 1994 if (currentValue->m_unit == CSSParserValue::Function && currentValue->functi on->id == CSSValueMinmax) {
1964 // The spec defines the following grammar: minmax( <track-breadth> , <tr ack-breadth> ) 1995 // The spec defines the following grammar: minmax( <track-breadth> , <tr ack-breadth> )
1965 CSSParserValueList* arguments = currentValue->function->args.get(); 1996 CSSParserValueList* arguments = currentValue->function->args.get();
1966 if (!arguments || arguments->size() != 3 || !isComma(arguments->valueAt( 1))) 1997 if (!arguments || arguments->size() != 3 || !isComma(arguments->valueAt( 1)))
1967 return nullptr; 1998 return nullptr;
1968 1999
1969 RefPtrWillBeRawPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth (arguments->valueAt(0)); 2000 RefPtrWillBeRawPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth (arguments->valueAt(0), restriction);
1970 if (!minTrackBreadth) 2001 if (!minTrackBreadth)
1971 return nullptr; 2002 return nullptr;
1972 2003
1973 RefPtrWillBeRawPtr<CSSPrimitiveValue> maxTrackBreadth = parseGridBreadth (arguments->valueAt(2)); 2004 RefPtrWillBeRawPtr<CSSPrimitiveValue> maxTrackBreadth = parseGridBreadth (arguments->valueAt(2));
1974 if (!maxTrackBreadth) 2005 if (!maxTrackBreadth)
1975 return nullptr; 2006 return nullptr;
1976 2007
1977 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C SSValueMinmax); 2008 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C SSValueMinmax);
1978 result->append(minTrackBreadth); 2009 result->append(minTrackBreadth);
1979 result->append(maxTrackBreadth); 2010 result->append(maxTrackBreadth);
1980 return result.release(); 2011 return result.release();
1981 } 2012 }
1982 2013
1983 return parseGridBreadth(currentValue); 2014 return parseGridBreadth(currentValue, restriction);
1984 } 2015 }
1985 2016
1986 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseGridBreadth(CS SParserValue* currentValue) 2017 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseGridBreadth(CS SParserValue* currentValue, TrackSizeRestriction restriction)
1987 { 2018 {
1988 if (currentValue->id == CSSValueMinContent || currentValue->id == CSSValueMa xContent || currentValue->id == CSSValueAuto) 2019 if (currentValue->id == CSSValueMinContent || currentValue->id == CSSValueMa xContent || currentValue->id == CSSValueAuto)
1989 return cssValuePool().createIdentifierValue(currentValue->id); 2020 return restriction == AllowAll ? cssValuePool().createIdentifierValue(cu rrentValue->id) : nullptr;
1990 2021
1991 if (currentValue->unit() == CSSPrimitiveValue::UnitType::Fraction) { 2022 if (currentValue->unit() == CSSPrimitiveValue::UnitType::Fraction) {
2023 if (restriction == FixedSizeOnly)
2024 return nullptr;
2025
1992 double flexValue = currentValue->fValue; 2026 double flexValue = currentValue->fValue;
1993 2027
1994 // Fractional unit is a non-negative dimension. 2028 // Fractional unit is a non-negative dimension.
1995 if (flexValue < 0) 2029 if (flexValue < 0)
1996 return nullptr; 2030 return nullptr;
1997 2031
1998 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::UnitType ::Fraction); 2032 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::UnitType ::Fraction);
1999 } 2033 }
2000 2034
2001 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) 2035 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
(...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 ASSERT(!m_parsedCalculation); 4221 ASSERT(!m_parsedCalculation);
4188 m_parsedCalculation = CSSCalcValue::create(args, range); 4222 m_parsedCalculation = CSSCalcValue::create(args, range);
4189 4223
4190 if (!m_parsedCalculation) 4224 if (!m_parsedCalculation)
4191 return false; 4225 return false;
4192 4226
4193 return true; 4227 return true;
4194 } 4228 }
4195 4229
4196 } // namespace blink 4230 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698