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

Side by Side Diff: sky/engine/core/css/parser/CSSPropertyParser.cpp

Issue 689853003: Remove CSS Grid Layout and grid media queries. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
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 22 matching lines...) Expand all
33 #include "core/css/CSSAspectRatioValue.h" 33 #include "core/css/CSSAspectRatioValue.h"
34 #include "core/css/CSSBasicShapes.h" 34 #include "core/css/CSSBasicShapes.h"
35 #include "core/css/CSSBorderImage.h" 35 #include "core/css/CSSBorderImage.h"
36 #include "core/css/CSSCanvasValue.h" 36 #include "core/css/CSSCanvasValue.h"
37 #include "core/css/CSSCrossfadeValue.h" 37 #include "core/css/CSSCrossfadeValue.h"
38 #include "core/css/CSSCursorImageValue.h" 38 #include "core/css/CSSCursorImageValue.h"
39 #include "core/css/CSSFontFaceSrcValue.h" 39 #include "core/css/CSSFontFaceSrcValue.h"
40 #include "core/css/CSSFontFeatureValue.h" 40 #include "core/css/CSSFontFeatureValue.h"
41 #include "core/css/CSSFunctionValue.h" 41 #include "core/css/CSSFunctionValue.h"
42 #include "core/css/CSSGradientValue.h" 42 #include "core/css/CSSGradientValue.h"
43 #include "core/css/CSSGridLineNamesValue.h"
44 #include "core/css/CSSGridTemplateAreasValue.h"
45 #include "core/css/CSSImageSetValue.h" 43 #include "core/css/CSSImageSetValue.h"
46 #include "core/css/CSSImageValue.h" 44 #include "core/css/CSSImageValue.h"
47 #include "core/css/CSSInheritedValue.h" 45 #include "core/css/CSSInheritedValue.h"
48 #include "core/css/CSSInitialValue.h" 46 #include "core/css/CSSInitialValue.h"
49 #include "core/css/CSSKeyframeRule.h" 47 #include "core/css/CSSKeyframeRule.h"
50 #include "core/css/CSSKeyframesRule.h" 48 #include "core/css/CSSKeyframesRule.h"
51 #include "core/css/CSSLineBoxContainValue.h" 49 #include "core/css/CSSLineBoxContainValue.h"
52 #include "core/css/CSSPrimitiveValue.h" 50 #include "core/css/CSSPrimitiveValue.h"
53 #include "core/css/CSSPropertyMetadata.h" 51 #include "core/css/CSSPropertyMetadata.h"
54 #include "core/css/CSSPropertySourceData.h" 52 #include "core/css/CSSPropertySourceData.h"
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 case CSSPropertyWebkitTransitionDuration: 1130 case CSSPropertyWebkitTransitionDuration:
1133 case CSSPropertyWebkitTransitionTimingFunction: 1131 case CSSPropertyWebkitTransitionTimingFunction:
1134 case CSSPropertyWebkitTransitionProperty: { 1132 case CSSPropertyWebkitTransitionProperty: {
1135 if (RefPtr<CSSValueList> val = parseAnimationPropertyList(propId)) { 1133 if (RefPtr<CSSValueList> val = parseAnimationPropertyList(propId)) {
1136 addPropertyWithPrefixingVariant(propId, val.release(), important); 1134 addPropertyWithPrefixingVariant(propId, val.release(), important);
1137 return true; 1135 return true;
1138 } 1136 }
1139 return false; 1137 return false;
1140 } 1138 }
1141 1139
1142 case CSSPropertyJustifySelf:
1143 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1144 return parseItemPositionOverflowPosition(propId, important);
1145 case CSSPropertyJustifyItems:
1146 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1147
1148 m_valueList->setCurrentIndex(0);
1149 return parseItemPositionOverflowPosition(propId, important);
1150 case CSSPropertyGridAutoFlow:
1151 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1152 parsedValue = parseGridAutoFlow(*m_valueList);
1153 break;
1154 case CSSPropertyGridAutoColumns:
1155 case CSSPropertyGridAutoRows:
1156 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1157 parsedValue = parseGridTrackSize(*m_valueList);
1158 break;
1159
1160 case CSSPropertyGridTemplateColumns:
1161 case CSSPropertyGridTemplateRows:
1162 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1163 parsedValue = parseGridTrackList();
1164 break;
1165
1166 case CSSPropertyGridColumnEnd:
1167 case CSSPropertyGridColumnStart:
1168 case CSSPropertyGridRowEnd:
1169 case CSSPropertyGridRowStart:
1170 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1171 parsedValue = parseGridPosition();
1172 break;
1173
1174 case CSSPropertyGridColumn:
1175 case CSSPropertyGridRow:
1176 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1177 return parseGridItemPositionShorthand(propId, important);
1178
1179 case CSSPropertyGridArea:
1180 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1181 return parseGridAreaShorthand(important);
1182
1183 case CSSPropertyGridTemplateAreas:
1184 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1185 parsedValue = parseGridTemplateAreas();
1186 break;
1187
1188 case CSSPropertyGridTemplate:
1189 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1190 return parseGridTemplateShorthand(important);
1191
1192 case CSSPropertyGrid:
1193 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1194 return parseGridShorthand(important);
1195
1196 case CSSPropertyWebkitMarginCollapse: { 1140 case CSSPropertyWebkitMarginCollapse: {
1197 if (num == 1) { 1141 if (num == 1) {
1198 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); 1142 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
1199 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant)) 1143 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant))
1200 return false; 1144 return false;
1201 CSSValue* value = m_parsedProperties.last().value(); 1145 CSSValue* value = m_parsedProperties.last().value();
1202 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important); 1146 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
1203 return true; 1147 return true;
1204 } 1148 }
1205 else if (num == 2) { 1149 else if (num == 2) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg)) ; 1328 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg)) ;
1385 break; 1329 break;
1386 case CSSPropertyShapeImageThreshold: 1330 case CSSPropertyShapeImageThreshold:
1387 validPrimitive = (!id && validUnit(value, FNumber)); 1331 validPrimitive = (!id && validUnit(value, FNumber));
1388 break; 1332 break;
1389 1333
1390 case CSSPropertyTouchAction: 1334 case CSSPropertyTouchAction:
1391 parsedValue = parseTouchAction(); 1335 parsedValue = parseTouchAction();
1392 break; 1336 break;
1393 1337
1394 case CSSPropertyAlignSelf:
1395 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1396 return parseItemPositionOverflowPosition(propId, important);
1397
1398 case CSSPropertyAlignItems:
1399 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
1400 return parseItemPositionOverflowPosition(propId, important);
1401
1402 // Properties below are validated inside parseViewportProperty, because we 1338 // Properties below are validated inside parseViewportProperty, because we
1403 // check for parser state. We need to invalidate if someone adds them outsid e 1339 // check for parser state. We need to invalidate if someone adds them outsid e
1404 // a @viewport rule. 1340 // a @viewport rule.
1405 case CSSPropertyMaxZoom: 1341 case CSSPropertyMaxZoom:
1406 case CSSPropertyMinZoom: 1342 case CSSPropertyMinZoom:
1407 case CSSPropertyOrientation: 1343 case CSSPropertyOrientation:
1408 case CSSPropertyUserZoom: 1344 case CSSPropertyUserZoom:
1409 validPrimitive = false; 1345 validPrimitive = false;
1410 break; 1346 break;
1411 1347
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 return nullptr; 2906 return nullptr;
2971 ASSERT(list->length()); 2907 ASSERT(list->length());
2972 return list.release(); 2908 return list.release();
2973 } 2909 }
2974 2910
2975 static inline bool isCSSWideKeyword(CSSParserValue& value) 2911 static inline bool isCSSWideKeyword(CSSParserValue& value)
2976 { 2912 {
2977 return value.id == CSSValueInitial || value.id == CSSValueInherit || value.i d == CSSValueDefault; 2913 return value.id == CSSValueInitial || value.id == CSSValueInherit || value.i d == CSSValueDefault;
2978 } 2914 }
2979 2915
2980 static inline bool isValidCustomIdentForGridPositions(CSSParserValue& value)
2981 {
2982 // FIXME: we need a more general solution for <custom-ident> in all properti es.
2983 return value.unit == CSSPrimitiveValue::CSS_IDENT && value.id != CSSValueSpa n && value.id != CSSValueAuto && !isCSSWideKeyword(value);
2984 }
2985
2986 // The function parses [ <integer> || <custom-ident> ] in <grid-line> (which can be stand alone or with 'span').
2987 bool CSSPropertyParser::parseIntegerOrCustomIdentFromGridPosition(RefPtr<CSSPrim itiveValue>& numericValue, RefPtr<CSSPrimitiveValue>& gridLineName)
2988 {
2989 CSSParserValue* value = m_valueList->current();
2990 if (validUnit(value, FInteger) && value->fValue) {
2991 numericValue = createPrimitiveNumericValue(value);
2992 value = m_valueList->next();
2993 if (value && isValidCustomIdentForGridPositions(*value)) {
2994 gridLineName = createPrimitiveStringValue(m_valueList->current());
2995 m_valueList->next();
2996 }
2997 return true;
2998 }
2999
3000 if (isValidCustomIdentForGridPositions(*value)) {
3001 gridLineName = createPrimitiveStringValue(m_valueList->current());
3002 value = m_valueList->next();
3003 if (value && validUnit(value, FInteger) && value->fValue) {
3004 numericValue = createPrimitiveNumericValue(value);
3005 m_valueList->next();
3006 }
3007 return true;
3008 }
3009
3010 return false;
3011 }
3012
3013 PassRefPtr<CSSValue> CSSPropertyParser::parseGridPosition()
3014 {
3015 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3016
3017 CSSParserValue* value = m_valueList->current();
3018 if (value->id == CSSValueAuto) {
3019 m_valueList->next();
3020 return cssValuePool().createIdentifierValue(CSSValueAuto);
3021 }
3022
3023 RefPtr<CSSPrimitiveValue> numericValue = nullptr;
3024 RefPtr<CSSPrimitiveValue> gridLineName = nullptr;
3025 bool hasSeenSpanKeyword = false;
3026
3027 if (parseIntegerOrCustomIdentFromGridPosition(numericValue, gridLineName)) {
3028 value = m_valueList->current();
3029 if (value && value->id == CSSValueSpan) {
3030 hasSeenSpanKeyword = true;
3031 m_valueList->next();
3032 }
3033 } else if (value->id == CSSValueSpan) {
3034 hasSeenSpanKeyword = true;
3035 if (CSSParserValue* nextValue = m_valueList->next()) {
3036 if (!isForwardSlashOperator(nextValue) && !parseIntegerOrCustomIdent FromGridPosition(numericValue, gridLineName))
3037 return nullptr;
3038 }
3039 }
3040
3041 // Check that we have consumed all the value list. For shorthands, the parse r will pass
3042 // the whole value list (including the opposite position).
3043 if (m_valueList->current() && !isForwardSlashOperator(m_valueList->current() ))
3044 return nullptr;
3045
3046 // If we didn't parse anything, this is not a valid grid position.
3047 if (!hasSeenSpanKeyword && !gridLineName && !numericValue)
3048 return nullptr;
3049
3050 // Negative numbers are not allowed for span (but are for <integer>).
3051 if (hasSeenSpanKeyword && numericValue && numericValue->getIntValue() < 0)
3052 return nullptr;
3053
3054 // For the <custom-ident> case.
3055 if (gridLineName && !numericValue && !hasSeenSpanKeyword)
3056 return cssValuePool().createValue(gridLineName->getStringValue(), CSSPri mitiveValue::CSS_STRING);
3057
3058 RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3059 if (hasSeenSpanKeyword)
3060 values->append(cssValuePool().createIdentifierValue(CSSValueSpan));
3061 if (numericValue)
3062 values->append(numericValue.release());
3063 if (gridLineName)
3064 values->append(gridLineName.release());
3065 ASSERT(values->length());
3066 return values.release();
3067 }
3068
3069 static PassRefPtr<CSSValue> gridMissingGridPositionValue(CSSValue* value)
3070 {
3071 if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->isString())
3072 return value;
3073
3074 return cssValuePool().createIdentifierValue(CSSValueAuto);
3075 }
3076
3077 bool CSSPropertyParser::parseGridItemPositionShorthand(CSSPropertyID shorthandId , bool important)
3078 {
3079 ShorthandScope scope(this, shorthandId);
3080 const StylePropertyShorthand& shorthand = shorthandForProperty(shorthandId);
3081 ASSERT(shorthand.length() == 2);
3082
3083 RefPtr<CSSValue> startValue = parseGridPosition();
3084 if (!startValue)
3085 return false;
3086
3087 RefPtr<CSSValue> endValue = nullptr;
3088 if (m_valueList->current()) {
3089 if (!isForwardSlashOperator(m_valueList->current()))
3090 return false;
3091
3092 if (!m_valueList->next())
3093 return false;
3094
3095 endValue = parseGridPosition();
3096 if (!endValue || m_valueList->current())
3097 return false;
3098 } else {
3099 endValue = gridMissingGridPositionValue(startValue.get());
3100 }
3101
3102 addProperty(shorthand.properties()[0], startValue, important);
3103 addProperty(shorthand.properties()[1], endValue, important);
3104 return true;
3105 }
3106
3107 bool CSSPropertyParser::parseGridTemplateRowsAndAreas(PassRefPtr<CSSValue> templ ateColumns, bool important)
3108 {
3109 NamedGridAreaMap gridAreaMap;
3110 size_t rowCount = 0;
3111 size_t columnCount = 0;
3112 bool trailingIdentWasAdded = false;
3113 RefPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
3114
3115 // At least template-areas strings must be defined.
3116 if (!m_valueList->current())
3117 return false;
3118
3119 while (m_valueList->current()) {
3120 // Handle leading <custom-ident>*.
3121 if (m_valueList->current()->unit == CSSParserValue::ValueList) {
3122 if (trailingIdentWasAdded) {
3123 // A row's trailing ident must be concatenated with the next row 's leading one.
3124 parseGridLineNames(*m_valueList, *templateRows, toCSSGridLineNam esValue(templateRows->item(templateRows->length() - 1)));
3125 } else {
3126 parseGridLineNames(*m_valueList, *templateRows);
3127 }
3128 }
3129
3130 // Handle a template-area's row.
3131 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3132 return false;
3133 ++rowCount;
3134
3135 // Handle template-rows's track-size.
3136 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING ) {
3137 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
3138 if (!value)
3139 return false;
3140 templateRows->append(value);
3141 } else {
3142 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to));
3143 }
3144
3145 // This will handle the trailing/leading <custom-ident>* in the grammar.
3146 trailingIdentWasAdded = false;
3147 if (m_valueList->current() && m_valueList->current()->unit == CSSParserV alue::ValueList) {
3148 parseGridLineNames(*m_valueList, *templateRows);
3149 trailingIdentWasAdded = true;
3150 }
3151 }
3152
3153 // [<track-list> /]?
3154 if (templateColumns)
3155 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
3156 else
3157 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important);
3158
3159 // [<line-names>? <string> [<track-size> <line-names>]? ]+
3160 RefPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaM ap, rowCount, columnCount);
3161 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important );
3162 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important);
3163
3164
3165 return true;
3166 }
3167
3168
3169 bool CSSPropertyParser::parseGridTemplateShorthand(bool important)
3170 {
3171 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3172
3173 ShorthandScope scope(this, CSSPropertyGridTemplate);
3174 ASSERT(gridTemplateShorthand().length() == 3);
3175
3176 // At least "none" must be defined.
3177 if (!m_valueList->current())
3178 return false;
3179
3180 bool firstValueIsNone = m_valueList->current()->id == CSSValueNone;
3181
3182 // 1- 'none' case.
3183 if (firstValueIsNone && !m_valueList->next()) {
3184 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentif ierValue(CSSValueNone), important);
3185 addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdentifier Value(CSSValueNone), important);
3186 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifie rValue(CSSValueNone), important);
3187 return true;
3188 }
3189
3190 unsigned index = 0;
3191 RefPtr<CSSValue> columnsValue = nullptr;
3192 if (firstValueIsNone) {
3193 columnsValue = cssValuePool().createIdentifierValue(CSSValueNone);
3194 } else {
3195 columnsValue = parseGridTrackList();
3196 }
3197
3198 // 2- <grid-template-columns> / <grid-template-columns> syntax.
3199 if (columnsValue) {
3200 if (!(m_valueList->current() && isForwardSlashOperator(m_valueList->curr ent()) && m_valueList->next()))
3201 return false;
3202 index = m_valueList->currentIndex();
3203 if (RefPtr<CSSValue> rowsValue = parseGridTrackList()) {
3204 if (m_valueList->current())
3205 return false;
3206 addProperty(CSSPropertyGridTemplateColumns, columnsValue, important) ;
3207 addProperty(CSSPropertyGridTemplateRows, rowsValue, important);
3208 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdent ifierValue(CSSValueNone), important);
3209 return true;
3210 }
3211 }
3212
3213
3214 // 3- [<track-list> /]? [<line-names>? <string> [<track-size> <line-names>]? ]+ syntax.
3215 // The template-columns <track-list> can't be 'none'.
3216 if (firstValueIsNone)
3217 return false;
3218 // It requires to rewind parsing due to previous syntax failures.
3219 m_valueList->setCurrentIndex(index);
3220 return parseGridTemplateRowsAndAreas(columnsValue, important);
3221 }
3222
3223 bool CSSPropertyParser::parseGridShorthand(bool important)
3224 {
3225 ShorthandScope scope(this, CSSPropertyGrid);
3226 ASSERT(shorthandForProperty(CSSPropertyGrid).length() == 4);
3227
3228 // 1- <grid-template>
3229 if (parseGridTemplateShorthand(important)) {
3230 // It can only be specified the explicit or the implicit grid properties in a single grid declaration.
3231 // The sub-properties not specified are set to their initial value, as n ormal for shorthands.
3232 addProperty(CSSPropertyGridAutoFlow, cssValuePool().createImplicitInitia lValue(), important);
3233 addProperty(CSSPropertyGridAutoColumns, cssValuePool().createImplicitIni tialValue(), important);
3234 addProperty(CSSPropertyGridAutoRows, cssValuePool().createImplicitInitia lValue(), important);
3235 return true;
3236 }
3237
3238 // Need to rewind parsing to explore the alternative syntax of this shorthan d.
3239 m_valueList->setCurrentIndex(0);
3240
3241 // 2- <grid-auto-flow> [ <grid-auto-columns> [ / <grid-auto-rows> ]? ]
3242 if (!parseValue(CSSPropertyGridAutoFlow, important))
3243 return false;
3244
3245 RefPtr<CSSValue> autoColumnsValue = nullptr;
3246 RefPtr<CSSValue> autoRowsValue = nullptr;
3247
3248 if (m_valueList->current()) {
3249 autoColumnsValue = parseGridTrackSize(*m_valueList);
3250 if (!autoColumnsValue)
3251 return false;
3252 if (m_valueList->current()) {
3253 if (!isForwardSlashOperator(m_valueList->current()) || !m_valueList- >next())
3254 return false;
3255 autoRowsValue = parseGridTrackSize(*m_valueList);
3256 if (!autoRowsValue)
3257 return false;
3258 }
3259 if (m_valueList->current())
3260 return false;
3261 } else {
3262 // Other omitted values are set to their initial values.
3263 autoColumnsValue = cssValuePool().createImplicitInitialValue();
3264 autoRowsValue = cssValuePool().createImplicitInitialValue();
3265 }
3266
3267 // if <grid-auto-rows> value is omitted, it is set to the value specified fo r grid-auto-columns.
3268 if (!autoRowsValue)
3269 autoRowsValue = autoColumnsValue;
3270
3271 addProperty(CSSPropertyGridAutoColumns, autoColumnsValue, important);
3272 addProperty(CSSPropertyGridAutoRows, autoRowsValue, important);
3273
3274 // It can only be specified the explicit or the implicit grid properties in a single grid declaration.
3275 // The sub-properties not specified are set to their initial value, as norma l for shorthands.
3276 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createImplicitIni tialValue(), important);
3277 addProperty(CSSPropertyGridTemplateRows, cssValuePool().createImplicitInitia lValue(), important);
3278 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createImplicitIniti alValue(), important);
3279
3280 return true;
3281 }
3282
3283 bool CSSPropertyParser::parseGridAreaShorthand(bool important)
3284 {
3285 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3286
3287 ShorthandScope scope(this, CSSPropertyGridArea);
3288 const StylePropertyShorthand& shorthand = gridAreaShorthand();
3289 ASSERT_UNUSED(shorthand, shorthand.length() == 4);
3290
3291 RefPtr<CSSValue> rowStartValue = parseGridPosition();
3292 if (!rowStartValue)
3293 return false;
3294
3295 RefPtr<CSSValue> columnStartValue = nullptr;
3296 if (!parseSingleGridAreaLonghand(columnStartValue))
3297 return false;
3298
3299 RefPtr<CSSValue> rowEndValue = nullptr;
3300 if (!parseSingleGridAreaLonghand(rowEndValue))
3301 return false;
3302
3303 RefPtr<CSSValue> columnEndValue = nullptr;
3304 if (!parseSingleGridAreaLonghand(columnEndValue))
3305 return false;
3306
3307 if (!columnStartValue)
3308 columnStartValue = gridMissingGridPositionValue(rowStartValue.get());
3309
3310 if (!rowEndValue)
3311 rowEndValue = gridMissingGridPositionValue(rowStartValue.get());
3312
3313 if (!columnEndValue)
3314 columnEndValue = gridMissingGridPositionValue(columnStartValue.get());
3315
3316 addProperty(CSSPropertyGridRowStart, rowStartValue, important);
3317 addProperty(CSSPropertyGridColumnStart, columnStartValue, important);
3318 addProperty(CSSPropertyGridRowEnd, rowEndValue, important);
3319 addProperty(CSSPropertyGridColumnEnd, columnEndValue, important);
3320 return true;
3321 }
3322
3323 bool CSSPropertyParser::parseSingleGridAreaLonghand(RefPtr<CSSValue>& property)
3324 {
3325 if (!m_valueList->current())
3326 return true;
3327
3328 if (!isForwardSlashOperator(m_valueList->current()))
3329 return false;
3330
3331 if (!m_valueList->next())
3332 return false;
3333
3334 property = parseGridPosition();
3335 return true;
3336 }
3337
3338 void CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSVal ueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineNames)
3339 {
3340 ASSERT(inputList.current() && inputList.current()->unit == CSSParserValue::V alueList);
3341
3342 CSSParserValueList* identList = inputList.current()->valueList;
3343 if (!identList->size()) {
3344 inputList.next();
3345 return;
3346 }
3347
3348 // Need to ensure the identList is at the heading index, since the parserLis t might have been rewound.
3349 identList->setCurrentIndex(0);
3350
3351 RefPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrailingLineNames ;
3352 if (!lineNames)
3353 lineNames = CSSGridLineNamesValue::create();
3354 while (CSSParserValue* identValue = identList->current()) {
3355 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT);
3356 RefPtr<CSSPrimitiveValue> lineName = createPrimitiveStringValue(identVal ue);
3357 lineNames->append(lineName.release());
3358 identList->next();
3359 }
3360 if (!previousNamedAreaTrailingLineNames)
3361 valueList.append(lineNames.release());
3362
3363 inputList.next();
3364 }
3365
3366 PassRefPtr<CSSValue> CSSPropertyParser::parseGridTrackList()
3367 {
3368 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3369
3370 CSSParserValue* value = m_valueList->current();
3371 if (value->id == CSSValueNone) {
3372 m_valueList->next();
3373 return cssValuePool().createIdentifierValue(CSSValueNone);
3374 }
3375
3376 RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
3377 // Handle leading <ident>*.
3378 value = m_valueList->current();
3379 if (value && value->unit == CSSParserValue::ValueList)
3380 parseGridLineNames(*m_valueList, *values);
3381
3382 bool seenTrackSizeOrRepeatFunction = false;
3383 while (CSSParserValue* currentValue = m_valueList->current()) {
3384 if (isForwardSlashOperator(currentValue))
3385 break;
3386 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) {
3387 if (!parseGridTrackRepeatFunction(*values))
3388 return nullptr;
3389 seenTrackSizeOrRepeatFunction = true;
3390 } else {
3391 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
3392 if (!value)
3393 return nullptr;
3394 values->append(value);
3395 seenTrackSizeOrRepeatFunction = true;
3396 }
3397 // This will handle the trailing <ident>* in the grammar.
3398 value = m_valueList->current();
3399 if (value && value->unit == CSSParserValue::ValueList)
3400 parseGridLineNames(*m_valueList, *values);
3401 }
3402
3403 // We should have found a <track-size> or else it is not a valid <track-list >
3404 if (!seenTrackSizeOrRepeatFunction)
3405 return nullptr;
3406
3407 return values;
3408 }
3409
3410 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
3411 {
3412 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
3413 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
3414 return false;
3415
3416 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0);
3417 size_t repetitions = arguments->valueAt(0)->fValue;
3418
3419 // The spec allows us to clamp the number of repetitions: http://www.w3.org/ TR/css-grid-1/#repeat-notation
3420 const size_t maxRepetitions = 10000;
3421 repetitions = std::min(repetitions, maxRepetitions);
3422
3423 RefPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceSeparated();
3424 arguments->next(); // Skip the repetition count.
3425 arguments->next(); // Skip the comma.
3426
3427 // Handle leading <ident>*.
3428 CSSParserValue* currentValue = arguments->current();
3429 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3430 parseGridLineNames(*arguments, *repeatedValues);
3431
3432 bool seenTrackSize = false;
3433 while (arguments->current()) {
3434 RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
3435 if (!trackSize)
3436 return false;
3437
3438 repeatedValues->append(trackSize);
3439 seenTrackSize = true;
3440
3441 // This takes care of any trailing <ident>* in the grammar.
3442 currentValue = arguments->current();
3443 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3444 parseGridLineNames(*arguments, *repeatedValues);
3445 }
3446
3447 // We should have found at least one <track-size> or else it is not a valid <track-list>.
3448 if (!seenTrackSize)
3449 return false;
3450
3451 for (size_t i = 0; i < repetitions; ++i) {
3452 for (size_t j = 0; j < repeatedValues->length(); ++j)
3453 list.append(repeatedValues->item(j));
3454 }
3455
3456 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue.
3457 m_valueList->next();
3458 return true;
3459 }
3460
3461
3462 PassRefPtr<CSSValue> CSSPropertyParser::parseGridTrackSize(CSSParserValueList& i nputList)
3463 {
3464 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3465
3466 CSSParserValue* currentValue = inputList.current();
3467 inputList.next();
3468
3469 if (currentValue->id == CSSValueAuto)
3470 return cssValuePool().createIdentifierValue(CSSValueAuto);
3471
3472 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase(curr entValue->function->name, "minmax(")) {
3473 // The spec defines the following grammar: minmax( <track-breadth> , <tr ack-breadth> )
3474 CSSParserValueList* arguments = currentValue->function->args.get();
3475 if (!arguments || arguments->size() != 3 || !isComma(arguments->valueAt( 1)))
3476 return nullptr;
3477
3478 RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(arguments-> valueAt(0));
3479 if (!minTrackBreadth)
3480 return nullptr;
3481
3482 RefPtr<CSSPrimitiveValue> maxTrackBreadth = parseGridBreadth(arguments-> valueAt(2));
3483 if (!maxTrackBreadth)
3484 return nullptr;
3485
3486 RefPtr<CSSValueList> parsedArguments = CSSValueList::createCommaSeparate d();
3487 parsedArguments->append(minTrackBreadth);
3488 parsedArguments->append(maxTrackBreadth);
3489 return CSSFunctionValue::create("minmax(", parsedArguments);
3490 }
3491
3492 return parseGridBreadth(currentValue);
3493 }
3494
3495 PassRefPtr<CSSPrimitiveValue> CSSPropertyParser::parseGridBreadth(CSSParserValue * currentValue)
3496 {
3497 if (currentValue->id == CSSValueMinContent || currentValue->id == CSSValueMa xContent)
3498 return cssValuePool().createIdentifierValue(currentValue->id);
3499
3500 if (currentValue->unit == CSSPrimitiveValue::CSS_FR) {
3501 double flexValue = currentValue->fValue;
3502
3503 // Fractional unit is a non-negative dimension.
3504 if (flexValue <= 0)
3505 return nullptr;
3506
3507 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
3508 }
3509
3510 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
3511 return nullptr;
3512
3513 return createPrimitiveNumericValue(currentValue);
3514 }
3515
3516 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3517 {
3518 CSSParserValue* currentValue = m_valueList->current();
3519 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
3520 return false;
3521
3522 String gridRowNames = currentValue->string;
3523 if (!gridRowNames.length())
3524 return false;
3525
3526 Vector<String> columnNames;
3527 gridRowNames.split(' ', columnNames);
3528
3529 if (!columnCount) {
3530 columnCount = columnNames.size();
3531 ASSERT(columnCount);
3532 } else if (columnCount != columnNames.size()) {
3533 // The declaration is invalid is all the rows don't have the number of c olumns.
3534 return false;
3535 }
3536
3537 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3538 const String& gridAreaName = columnNames[currentCol];
3539
3540 // Unamed areas are always valid (we consider them to be 1x1).
3541 if (gridAreaName == ".")
3542 continue;
3543
3544 // We handle several grid areas with the same name at once to simplify t he validation code.
3545 size_t lookAheadCol;
3546 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) {
3547 if (columnNames[lookAheadCol + 1] != gridAreaName)
3548 break;
3549 }
3550
3551 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
3552 if (gridAreaIt == gridAreaMap.end()) {
3553 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowC ount), GridSpan(currentCol, lookAheadCol)));
3554 } else {
3555 GridCoordinate& gridCoordinate = gridAreaIt->value;
3556
3557 // The following checks test that the grid area is a single filled-i n rectangle.
3558 // 1. The new row is adjacent to the previously parsed row.
3559 if (rowCount != gridCoordinate.rows.resolvedFinalPosition.next().toI nt())
3560 return false;
3561
3562 // 2. The new area starts at the same position as the previously par sed area.
3563 if (currentCol != gridCoordinate.columns.resolvedInitialPosition.toI nt())
3564 return false;
3565
3566 // 3. The new area ends at the same position as the previously parse d area.
3567 if (lookAheadCol != gridCoordinate.columns.resolvedFinalPosition.toI nt())
3568 return false;
3569
3570 ++gridCoordinate.rows.resolvedFinalPosition;
3571 }
3572 currentCol = lookAheadCol;
3573 }
3574
3575 m_valueList->next();
3576 return true;
3577 }
3578
3579 PassRefPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas()
3580 {
3581 NamedGridAreaMap gridAreaMap;
3582 size_t rowCount = 0;
3583 size_t columnCount = 0;
3584
3585 while (m_valueList->current()) {
3586 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3587 return nullptr;
3588 ++rowCount;
3589 }
3590
3591 if (!rowCount || !columnCount)
3592 return nullptr;
3593
3594 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ;
3595 }
3596
3597 PassRefPtr<CSSValue> CSSPropertyParser::parseGridAutoFlow(CSSParserValueList& li st)
3598 {
3599 // [ row | column ] && dense? | stack && [ row | column ]?
3600 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3601
3602 CSSParserValue* value = list.current();
3603 if (!value)
3604 return nullptr;
3605
3606 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
3607
3608 // First parameter.
3609 CSSValueID firstId = value->id;
3610 if (firstId != CSSValueRow && firstId != CSSValueColumn && firstId != CSSVal ueDense && firstId != CSSValueStack)
3611 return nullptr;
3612 parsedValues->append(cssValuePool().createIdentifierValue(firstId));
3613
3614 // Second parameter, if any.
3615 value = list.next();
3616 if (!value && firstId == CSSValueDense)
3617 return nullptr;
3618
3619 if (value) {
3620 switch (firstId) {
3621 case CSSValueRow:
3622 case CSSValueColumn:
3623 if (value->id != CSSValueDense && value->id != CSSValueStack)
3624 return parsedValues;
3625 break;
3626 case CSSValueDense:
3627 case CSSValueStack:
3628 if (value->id != CSSValueRow && value->id != CSSValueColumn)
3629 return parsedValues;
3630 break;
3631 default:
3632 return parsedValues;
3633 }
3634 parsedValues->append(cssValuePool().createIdentifierValue(value->id));
3635 list.next();
3636 }
3637
3638 return parsedValues;
3639 }
3640
3641 bool CSSPropertyParser::parseClipShape(CSSPropertyID propId, bool important) 2916 bool CSSPropertyParser::parseClipShape(CSSPropertyID propId, bool important)
3642 { 2917 {
3643 CSSParserValue* value = m_valueList->current(); 2918 CSSParserValue* value = m_valueList->current();
3644 CSSParserValueList* args = value->function->args.get(); 2919 CSSParserValueList* args = value->function->args.get();
3645 2920
3646 if (!equalIgnoringCase(value->function->name, "rect(") || !args) 2921 if (!equalIgnoringCase(value->function->name, "rect(") || !args)
3647 return false; 2922 return false;
3648 2923
3649 // rect(t, r, b, l) || rect(t r b l) 2924 // rect(t, r, b, l) || rect(t r b l)
3650 if (args->size() != 4 && args->size() != 7) 2925 if (args->size() != 4 && args->size() != 7)
(...skipping 3403 matching lines...) Expand 10 before | Expand all | Expand 10 after
7054 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 6329 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
7055 } 6330 }
7056 6331
7057 bool CSSPropertyParser::isSystemColor(int id) 6332 bool CSSPropertyParser::isSystemColor(int id)
7058 { 6333 {
7059 // FIXME(sky): remove 6334 // FIXME(sky): remove
7060 return false; 6335 return false;
7061 } 6336 }
7062 6337
7063 } // namespace blink 6338 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/parser/CSSPropertyParser.h ('k') | sky/engine/core/css/resolver/StyleAdjuster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698