OLD | NEW |
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 3064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3075 break; | 3075 break; |
3076 if (!consumeComma(m_valueList) || !m_valueList->current()) | 3076 if (!consumeComma(m_valueList) || !m_valueList->current()) |
3077 return nullptr; | 3077 return nullptr; |
3078 } | 3078 } |
3079 if (propId == CSSPropertyTransitionProperty && !isValidTransitionPropertyLis
t(list.get())) | 3079 if (propId == CSSPropertyTransitionProperty && !isValidTransitionPropertyLis
t(list.get())) |
3080 return nullptr; | 3080 return nullptr; |
3081 ASSERT(list->length()); | 3081 ASSERT(list->length()); |
3082 return list.release(); | 3082 return list.release(); |
3083 } | 3083 } |
3084 | 3084 |
3085 static inline bool isCSSWideKeyword(CSSParserValue& value) | 3085 static inline bool isCSSWideKeyword(const CSSParserValue& value) |
3086 { | 3086 { |
3087 return value.id == CSSValueInitial || value.id == CSSValueInherit || value.i
d == CSSValueUnset || value.id == CSSValueDefault; | 3087 return value.id == CSSValueInitial || value.id == CSSValueInherit || value.i
d == CSSValueUnset || value.id == CSSValueDefault; |
3088 } | 3088 } |
3089 | 3089 |
3090 static inline bool isValidCustomIdentForGridPositions(CSSParserValue& value) | 3090 static inline bool isValidCustomIdentForGridPositions(const CSSParserValue& valu
e) |
3091 { | 3091 { |
3092 // FIXME: we need a more general solution for <custom-ident> in all properti
es. | 3092 // FIXME: we need a more general solution for <custom-ident> in all properti
es. |
3093 return value.unit == CSSPrimitiveValue::CSS_IDENT && value.id != CSSValueSpa
n && value.id != CSSValueAuto && !isCSSWideKeyword(value); | 3093 return value.unit == CSSPrimitiveValue::CSS_IDENT && value.id != CSSValueSpa
n && value.id != CSSValueAuto && !isCSSWideKeyword(value); |
3094 } | 3094 } |
3095 | 3095 |
3096 // The function parses [ <integer> || <custom-ident> ] in <grid-line> (which can
be stand alone or with 'span'). | 3096 // The function parses [ <integer> || <custom-ident> ] in <grid-line> (which can
be stand alone or with 'span'). |
3097 bool CSSPropertyParser::parseIntegerOrCustomIdentFromGridPosition(RefPtrWillBeRa
wPtr<CSSPrimitiveValue>& numericValue, RefPtrWillBeRawPtr<CSSPrimitiveValue>& gr
idLineName) | 3097 bool CSSPropertyParser::parseIntegerOrCustomIdentFromGridPosition(RefPtrWillBeRa
wPtr<CSSPrimitiveValue>& numericValue, RefPtrWillBeRawPtr<CSSPrimitiveValue>& gr
idLineName) |
3098 { | 3098 { |
3099 CSSParserValue* value = m_valueList->current(); | 3099 CSSParserValue* value = m_valueList->current(); |
3100 if (validUnit(value, FInteger) && value->fValue) { | 3100 if (validUnit(value, FInteger) && value->fValue) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3221 size_t columnCount = 0; | 3221 size_t columnCount = 0; |
3222 bool trailingIdentWasAdded = false; | 3222 bool trailingIdentWasAdded = false; |
3223 RefPtrWillBeRawPtr<CSSValueList> templateRows = CSSValueList::createSpaceSep
arated(); | 3223 RefPtrWillBeRawPtr<CSSValueList> templateRows = CSSValueList::createSpaceSep
arated(); |
3224 | 3224 |
3225 // At least template-areas strings must be defined. | 3225 // At least template-areas strings must be defined. |
3226 if (!m_valueList->current()) | 3226 if (!m_valueList->current()) |
3227 return false; | 3227 return false; |
3228 | 3228 |
3229 while (m_valueList->current()) { | 3229 while (m_valueList->current()) { |
3230 // Handle leading <custom-ident>*. | 3230 // Handle leading <custom-ident>*. |
3231 if (trailingIdentWasAdded) { | 3231 if (!parseGridLineNames(*m_valueList, *templateRows, trailingIdentWasAdd
ed ? toCSSGridLineNamesValue(templateRows->item(templateRows->length() - 1)) : n
ullptr)) |
3232 // A row's trailing ident must be concatenated with the next row's l
eading one. | 3232 return false; |
3233 maybeParseGridLineNames(*m_valueList, *templateRows, toCSSGridLineNa
mesValue(templateRows->item(templateRows->length() - 1))); | |
3234 } else { | |
3235 maybeParseGridLineNames(*m_valueList, *templateRows); | |
3236 } | |
3237 | 3233 |
3238 // Handle a template-area's row. | 3234 // Handle a template-area's row. |
3239 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount)) | 3235 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount)) |
3240 return false; | 3236 return false; |
3241 ++rowCount; | 3237 ++rowCount; |
3242 | 3238 |
3243 // Handle template-rows's track-size. | 3239 // Handle template-rows's track-size. |
3244 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV
alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING
) { | 3240 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV
alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING
) { |
3245 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList
); | 3241 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList
); |
3246 if (!value) | 3242 if (!value) |
3247 return false; | 3243 return false; |
3248 templateRows->append(value); | 3244 templateRows->append(value); |
3249 } else { | 3245 } else { |
3250 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu
to)); | 3246 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu
to)); |
3251 } | 3247 } |
3252 | 3248 |
3253 // This will handle the trailing/leading <custom-ident>* in the grammar. | 3249 // This will handle the trailing/leading <custom-ident>* in the grammar. |
3254 const CSSParserValue* current = m_valueList->current(); | 3250 const CSSParserValue* current = m_valueList->current(); |
3255 trailingIdentWasAdded = current && current->unit == CSSParserValue::Valu
eList && current->valueList->size() > 0; | 3251 trailingIdentWasAdded = current && current->unit == CSSParserValue::Valu
eList && current->valueList->size() > 0; |
3256 maybeParseGridLineNames(*m_valueList, *templateRows); | 3252 if (!parseGridLineNames(*m_valueList, *templateRows)) |
| 3253 return false; |
3257 } | 3254 } |
3258 | 3255 |
3259 // [<track-list> /]? | 3256 // [<track-list> /]? |
3260 if (templateColumns) | 3257 if (templateColumns) |
3261 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important); | 3258 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important); |
3262 else | 3259 else |
3263 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti
fierValue(CSSValueNone), important); | 3260 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti
fierValue(CSSValueNone), important); |
3264 | 3261 |
3265 // [<line-names>? <string> [<track-size> <line-names>]? ]+ | 3262 // [<line-names>? <string> [<track-size> <line-names>]? ]+ |
3266 RefPtrWillBeRawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::crea
te(gridAreaMap, rowCount, columnCount); | 3263 RefPtrWillBeRawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::crea
te(gridAreaMap, rowCount, columnCount); |
3267 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important
); | 3264 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important
); |
3268 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important); | 3265 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important); |
3269 | 3266 |
3270 | |
3271 return true; | 3267 return true; |
3272 } | 3268 } |
3273 | 3269 |
3274 | 3270 |
3275 bool CSSPropertyParser::parseGridTemplateShorthand(bool important) | 3271 bool CSSPropertyParser::parseGridTemplateShorthand(bool important) |
3276 { | 3272 { |
3277 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3273 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3278 | 3274 |
3279 ShorthandScope scope(this, CSSPropertyGridTemplate); | 3275 ShorthandScope scope(this, CSSPropertyGridTemplate); |
3280 ASSERT(gridTemplateShorthand().length() == 3); | 3276 ASSERT(gridTemplateShorthand().length() == 3); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3434 if (!isForwardSlashOperator(m_valueList->current())) | 3430 if (!isForwardSlashOperator(m_valueList->current())) |
3435 return false; | 3431 return false; |
3436 | 3432 |
3437 if (!m_valueList->next()) | 3433 if (!m_valueList->next()) |
3438 return false; | 3434 return false; |
3439 | 3435 |
3440 property = parseGridPosition(); | 3436 property = parseGridPosition(); |
3441 return true; | 3437 return true; |
3442 } | 3438 } |
3443 | 3439 |
3444 void CSSPropertyParser::maybeParseGridLineNames(CSSParserValueList& inputList, C
SSValueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineName
s) | 3440 static inline bool isClosingBracket(const CSSParserValue& value) |
3445 { | 3441 { |
3446 if (!inputList.current() || inputList.current()->unit != CSSParserValue::Val
ueList) | 3442 return value.unit == CSSParserValue::Operator && value.iValue == ']'; |
3447 return; | 3443 } |
3448 | 3444 |
3449 CSSParserValueList* identList = inputList.current()->valueList; | 3445 bool CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSVal
ueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineNames) |
3450 if (!identList->size()) { | 3446 { |
3451 inputList.next(); | 3447 if (!inputList.current() || inputList.current()->unit != CSSParserValue::Ope
rator || inputList.current()->iValue != '[') |
3452 return; | 3448 return true; |
3453 } | |
3454 | 3449 |
3455 // Need to ensure the identList is at the heading index, since the parserLis
t might have been rewound. | 3450 // Skip '[' |
3456 identList->setCurrentIndex(0); | 3451 inputList.next(); |
3457 | 3452 |
3458 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrail
ingLineNames; | 3453 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrail
ingLineNames; |
3459 if (!lineNames) | 3454 if (!lineNames) |
3460 lineNames = CSSGridLineNamesValue::create(); | 3455 lineNames = CSSGridLineNamesValue::create(); |
3461 while (CSSParserValue* identValue = identList->current()) { | 3456 |
3462 if (identValue->unit != CSSPrimitiveValue::CSS_IDENT) | 3457 while (CSSParserValue* identValue = inputList.current()) { |
3463 return; | 3458 if (isClosingBracket(*identValue)) |
| 3459 break; |
| 3460 |
| 3461 if (!isValidCustomIdentForGridPositions(*identValue)) |
| 3462 return false; |
| 3463 |
3464 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveCustomId
entValue(identValue); | 3464 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveCustomId
entValue(identValue); |
3465 lineNames->append(lineName.release()); | 3465 lineNames->append(lineName.release()); |
3466 identList->next(); | 3466 inputList.next(); |
3467 } | 3467 } |
| 3468 |
| 3469 if (!inputList.current() || !isClosingBracket(*inputList.current())) |
| 3470 return false; |
| 3471 |
3468 if (!previousNamedAreaTrailingLineNames) | 3472 if (!previousNamedAreaTrailingLineNames) |
3469 valueList.append(lineNames.release()); | 3473 valueList.append(lineNames.release()); |
3470 | 3474 |
| 3475 // Consume ']' |
3471 inputList.next(); | 3476 inputList.next(); |
| 3477 return true; |
3472 } | 3478 } |
3473 | 3479 |
3474 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList() | 3480 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList() |
3475 { | 3481 { |
3476 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | 3482 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
3477 | 3483 |
3478 CSSParserValue* value = m_valueList->current(); | 3484 CSSParserValue* value = m_valueList->current(); |
3479 if (value->id == CSSValueNone) { | 3485 if (value->id == CSSValueNone) { |
3480 m_valueList->next(); | 3486 m_valueList->next(); |
3481 return cssValuePool().createIdentifierValue(CSSValueNone); | 3487 return cssValuePool().createIdentifierValue(CSSValueNone); |
3482 } | 3488 } |
3483 | 3489 |
3484 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated
(); | 3490 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated
(); |
3485 // Handle leading <ident>*. | 3491 // Handle leading <custom-ident>*. |
3486 maybeParseGridLineNames(*m_valueList, *values); | 3492 if (!parseGridLineNames(*m_valueList, *values)) |
| 3493 return nullptr; |
3487 | 3494 |
3488 bool seenTrackSizeOrRepeatFunction = false; | 3495 bool seenTrackSizeOrRepeatFunction = false; |
3489 while (CSSParserValue* currentValue = m_valueList->current()) { | 3496 while (CSSParserValue* currentValue = m_valueList->current()) { |
3490 if (isForwardSlashOperator(currentValue)) | 3497 if (isForwardSlashOperator(currentValue)) |
3491 break; | 3498 break; |
3492 if (currentValue->unit == CSSParserValue::Function && currentValue->func
tion->id == CSSValueRepeat) { | 3499 if (currentValue->unit == CSSParserValue::Function && currentValue->func
tion->id == CSSValueRepeat) { |
3493 if (!parseGridTrackRepeatFunction(*values)) | 3500 if (!parseGridTrackRepeatFunction(*values)) |
3494 return nullptr; | 3501 return nullptr; |
3495 seenTrackSizeOrRepeatFunction = true; | 3502 seenTrackSizeOrRepeatFunction = true; |
3496 } else { | 3503 } else { |
3497 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList
); | 3504 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList
); |
3498 if (!value) | 3505 if (!value) |
3499 return nullptr; | 3506 return nullptr; |
3500 values->append(value); | 3507 values->append(value); |
3501 seenTrackSizeOrRepeatFunction = true; | 3508 seenTrackSizeOrRepeatFunction = true; |
3502 } | 3509 } |
3503 // This will handle the trailing <ident>* in the grammar. | 3510 // This will handle the trailing <custom-ident>* in the grammar. |
3504 maybeParseGridLineNames(*m_valueList, *values); | 3511 if (!parseGridLineNames(*m_valueList, *values)) |
| 3512 return nullptr; |
3505 } | 3513 } |
3506 | 3514 |
3507 // We should have found a <track-size> or else it is not a valid <track-list
> | 3515 // We should have found a <track-size> or else it is not a valid <track-list
> |
3508 if (!seenTrackSizeOrRepeatFunction) | 3516 if (!seenTrackSizeOrRepeatFunction) |
3509 return nullptr; | 3517 return nullptr; |
3510 | 3518 |
3511 return values; | 3519 return values; |
3512 } | 3520 } |
3513 | 3521 |
3514 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) | 3522 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) |
3515 { | 3523 { |
3516 CSSParserValueList* arguments = m_valueList->current()->function->args.get()
; | 3524 CSSParserValueList* arguments = m_valueList->current()->function->args.get()
; |
3517 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0),
FPositiveInteger) || !isComma(arguments->valueAt(1))) | 3525 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0),
FPositiveInteger) || !isComma(arguments->valueAt(1))) |
3518 return false; | 3526 return false; |
3519 | 3527 |
3520 ASSERT(arguments->valueAt(0)->fValue > 0); | 3528 ASSERT(arguments->valueAt(0)->fValue > 0); |
3521 size_t repetitions = clampTo<size_t>(arguments->valueAt(0)->fValue, 0, kGrid
MaxTracks); | 3529 size_t repetitions = clampTo<size_t>(arguments->valueAt(0)->fValue, 0, kGrid
MaxTracks); |
3522 | 3530 |
3523 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS
eparated(); | 3531 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS
eparated(); |
3524 arguments->next(); // Skip the repetition count. | 3532 arguments->next(); // Skip the repetition count. |
3525 arguments->next(); // Skip the comma. | 3533 arguments->next(); // Skip the comma. |
3526 | 3534 |
3527 // Handle leading <ident>*. | 3535 // Handle leading <custom-ident>*. |
3528 maybeParseGridLineNames(*arguments, *repeatedValues); | 3536 if (!parseGridLineNames(*arguments, *repeatedValues)) |
| 3537 return false; |
3529 | 3538 |
3530 size_t numberOfTracks = 0; | 3539 size_t numberOfTracks = 0; |
3531 while (arguments->current()) { | 3540 while (arguments->current()) { |
3532 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); | 3541 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); |
3533 if (!trackSize) | 3542 if (!trackSize) |
3534 return false; | 3543 return false; |
3535 | 3544 |
3536 repeatedValues->append(trackSize); | 3545 repeatedValues->append(trackSize); |
3537 ++numberOfTracks; | 3546 ++numberOfTracks; |
3538 | 3547 |
3539 // This takes care of any trailing <ident>* in the grammar. | 3548 // This takes care of any trailing <custom-ident>* in the grammar. |
3540 maybeParseGridLineNames(*arguments, *repeatedValues); | 3549 if (!parseGridLineNames(*arguments, *repeatedValues)) |
| 3550 return false; |
3541 } | 3551 } |
3542 | 3552 |
3543 // We should have found at least one <track-size> or else it is not a valid
<track-list>. | 3553 // We should have found at least one <track-size> or else it is not a valid
<track-list>. |
3544 if (!numberOfTracks) | 3554 if (!numberOfTracks) |
3545 return false; | 3555 return false; |
3546 | 3556 |
3547 // We clamp the number of repetitions to a multiple of the repeat() track li
st's size, while staying below the max | 3557 // We clamp the number of repetitions to a multiple of the repeat() track li
st's size, while staying below the max |
3548 // grid size. | 3558 // grid size. |
3549 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); | 3559 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); |
3550 | 3560 |
(...skipping 4834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8385 } | 8395 } |
8386 } | 8396 } |
8387 | 8397 |
8388 if (!list->length()) | 8398 if (!list->length()) |
8389 return nullptr; | 8399 return nullptr; |
8390 | 8400 |
8391 return list.release(); | 8401 return list.release(); |
8392 } | 8402 } |
8393 | 8403 |
8394 } // namespace blink | 8404 } // namespace blink |
OLD | NEW |