Changeset 201373 in webkit
- Timestamp:
- May 25, 2016 2:22:37 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201358 r201373 1 2016-05-25 Manuel Rego Casasnovas <rego@igalia.com> 2 3 [css-grid] Simplify grid track sizes parsing 4 https://bugs.webkit.org/show_bug.cgi?id=158021 5 6 Reviewed by Sergio Villar Senin. 7 8 Previously once we saw an auto-repeat function, 9 we passed the "FixedSizeOnly" restriction to the rest of methods. 10 That way we were sure that all the tracks after the auto-repeat 11 had fixed sizes. 12 But we needed to call allTracksAreFixedSized() to be sure that 13 the tracks before the auto-repeat had fixed sizes too. 14 15 Now we're introducing a new boolean |allTracksAreFixedSized|, 16 to check in advance if the declaration contains any track not fixed. 17 If that's the case and we found an auto-repeat method, 18 we consider it invalid. 19 With this approach we avoid the loop to verify 20 that all the tracks (before and after the auto-repeat) are fixed. 21 It also allows us to simplify the code and avoid passing 22 the restriction to all the methods parsing the track size. 23 24 No new tests, no change of behavior. 25 26 * css/CSSParser.cpp: 27 (WebCore::isGridTrackFixedSized): New method to check if a grid track 28 size is fixed or not (based on old allTracksAreFixedSized()). 29 (WebCore::CSSParser::parseGridTrackList): Add new boolean to detect 30 if any track has not a fixed size. 31 (WebCore::CSSParser::parseGridTrackRepeatFunction): Ditto. 32 (WebCore::CSSParser::parseGridTrackSize): Remove usage of 33 TrackSizeRestriction enum. 34 Check here if |minTrackBreadth| is a flexible size. 35 (WebCore::CSSParser::parseGridBreadth): Remove usage of 36 TrackSizeRestriction enum. 37 (WebCore::allTracksAreFixedSized): Deleted. 38 * css/CSSParser.h: Remove TrackSizeRestriction enum and update headers. 39 1 40 2016-05-24 Myles C. Maxfield <mmaxfield@apple.com> 2 41 -
trunk/Source/WebCore/css/CSSParser.cpp
r201325 r201373 5818 5818 } 5819 5819 5820 static bool allTracksAreFixedSized(CSSValueList& valueList) 5821 { 5822 for (auto& value : valueList) { 5823 if (is<CSSGridLineNamesValue>(value)) 5824 continue; 5825 // The auto-repeat value holds a <fixed-size> = <fixed-breadth> | minmax( <fixed-breadth>, <track-breadth> ) 5826 if (is<CSSGridAutoRepeatValue>(value)) { 5827 if (!allTracksAreFixedSized(downcast<CSSValueList>(value.get()))) 5828 return false; 5829 continue; 5830 } 5831 ASSERT(value->isPrimitiveValue() || (value->isFunctionValue() && downcast<CSSFunctionValue>(value.get()).arguments())); 5832 const CSSPrimitiveValue& primitiveValue = value->isPrimitiveValue() 5833 ? downcast<CSSPrimitiveValue>(value.get()) 5834 : downcast<CSSPrimitiveValue>(*downcast<CSSFunctionValue>(value.get()).arguments()->item(0)); 5835 CSSValueID valueID = primitiveValue.getValueID(); 5836 if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex()) 5837 return false; 5838 } 5820 static bool isGridTrackFixedSized(const CSSValue& value) 5821 { 5822 ASSERT(value.isPrimitiveValue() || (value.isFunctionValue() && downcast<CSSFunctionValue>(value).arguments())); 5823 const auto& primitiveValue = value.isPrimitiveValue() 5824 ? downcast<CSSPrimitiveValue>(value) 5825 : downcast<CSSPrimitiveValue>(*downcast<CSSFunctionValue>(value).arguments()->item(0)); 5826 CSSValueID valueID = primitiveValue.getValueID(); 5827 if (valueID == CSSValueWebkitMinContent || valueID == CSSValueWebkitMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex()) 5828 return false; 5829 5830 ASSERT(primitiveValue.isLength()); 5839 5831 return true; 5840 5832 } … … 5858 5850 bool seenTrackSizeOrRepeatFunction = false; 5859 5851 bool seenAutoRepeat = false; 5852 bool allTracksAreFixedSized = true; 5860 5853 while (CSSParserValue* currentValue = m_valueList->current()) { 5861 5854 if (isForwardSlashOperator(*currentValue)) … … 5863 5856 if (currentValue->unit == CSSParserValue::Function && equalLettersIgnoringASCIICase(currentValue->function->name, "repeat(")) { 5864 5857 bool isAutoRepeat; 5865 if (!parseGridTrackRepeatFunction(values, isAutoRepeat ))5858 if (!parseGridTrackRepeatFunction(values, isAutoRepeat, allTracksAreFixedSized)) 5866 5859 return nullptr; 5867 5860 if (isAutoRepeat && seenAutoRepeat) … … 5869 5862 seenAutoRepeat = seenAutoRepeat || isAutoRepeat; 5870 5863 } else { 5871 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList , seenAutoRepeat ? FixedSizeOnly : AllowAll);5864 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList); 5872 5865 if (!value) 5873 5866 return nullptr; 5867 if (allTracksAreFixedSized) 5868 allTracksAreFixedSized = isGridTrackFixedSized(*value); 5874 5869 values->append(value.releaseNonNull()); 5875 5870 } 5876 5871 seenTrackSizeOrRepeatFunction = true; 5872 5873 if (seenAutoRepeat && !allTracksAreFixedSized) 5874 return nullptr; 5877 5875 5878 5876 // This will handle the trailing <custom-ident>* in the grammar. … … 5885 5883 return nullptr; 5886 5884 5887 // <auto-repeat> requires definite minimum track sizes in order to compute the number of repetitions.5888 // The above while loop detects those appearances after the <auto-repeat> but not the ones before.5889 if (seenAutoRepeat && !allTracksAreFixedSized(values))5890 return nullptr;5891 5892 5885 return WTFMove(values); 5893 5886 } 5894 5887 5895 bool CSSParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& isAutoRepeat )5888 bool CSSParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& isAutoRepeat, bool& allTracksAreFixedSized) 5896 5889 { 5897 5890 ASSERT(isCSSGridLayoutEnabled()); … … 5923 5916 5924 5917 unsigned numberOfTracks = 0; 5925 TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll;5926 5918 while (arguments->current()) { 5927 5919 if (isAutoRepeat && numberOfTracks) 5928 5920 return false; 5929 5921 5930 RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments , restriction);5922 RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); 5931 5923 if (!trackSize) 5932 5924 return false; 5925 if (allTracksAreFixedSized) 5926 allTracksAreFixedSized = isGridTrackFixedSized(*trackSize); 5933 5927 5934 5928 repeatedValues->append(trackSize.releaseNonNull()); … … 5962 5956 } 5963 5957 5964 RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList , TrackSizeRestriction restriction)5958 RefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList) 5965 5959 { 5966 5960 ASSERT(isCSSGridLayoutEnabled()); … … 5978 5972 return nullptr; 5979 5973 5980 TrackSizeRestriction minTrackBreadthRestriction = restriction == AllowAll ? InflexibleSizeOnly : restriction; 5981 RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0), minTrackBreadthRestriction); 5982 if (!minTrackBreadth) 5974 RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(*arguments->valueAt(0)); 5975 if (!minTrackBreadth || minTrackBreadth->isFlex()) 5983 5976 return nullptr; 5984 5977 … … 5993 5986 } 5994 5987 5995 return parseGridBreadth(currentValue , restriction);5996 } 5997 5998 RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value , TrackSizeRestriction restriction)5988 return parseGridBreadth(currentValue); 5989 } 5990 5991 RefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue& value) 5999 5992 { 6000 5993 ASSERT(isCSSGridLayoutEnabled()); 6001 5994 6002 if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto) { 6003 if (restriction == FixedSizeOnly) 6004 return nullptr; 5995 if (value.id == CSSValueWebkitMinContent || value.id == CSSValueWebkitMaxContent || value.id == CSSValueAuto) 6005 5996 return CSSValuePool::singleton().createIdentifierValue(value.id); 6006 }6007 5997 6008 5998 if (value.unit == CSSPrimitiveValue::CSS_FR) { 6009 if (restriction == FixedSizeOnly || restriction == InflexibleSizeOnly)6010 return nullptr;6011 6012 5999 double flexValue = value.fValue; 6013 6000 -
trunk/Source/WebCore/css/CSSParser.h
r201325 r201373 240 240 bool parseSingleGridAreaLonghand(RefPtr<CSSValue>&); 241 241 RefPtr<CSSValue> parseGridTrackList(); 242 bool parseGridTrackRepeatFunction(CSSValueList&, bool& isAutoRepeat); 243 enum TrackSizeRestriction { FixedSizeOnly, InflexibleSizeOnly, AllowAll }; 244 RefPtr<CSSValue> parseGridTrackSize(CSSParserValueList& inputList, TrackSizeRestriction = AllowAll); 245 RefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue&, TrackSizeRestriction = AllowAll); 242 bool parseGridTrackRepeatFunction(CSSValueList&, bool& isAutoRepeat, bool& allTracksAreFixedSized); 243 RefPtr<CSSValue> parseGridTrackSize(CSSParserValueList& inputList); 244 RefPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue&); 246 245 bool parseGridTemplateAreasRow(NamedGridAreaMap&, const unsigned, unsigned&); 247 246 RefPtr<CSSValue> parseGridTemplateAreas();
Note: See TracChangeset
for help on using the changeset viewer.