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

Side by Side Diff: Source/core/css/parser/CSSPropertyParser.cpp

Issue 149373004: [CSS Grid Layout] Implementation of the grid-template shorthand. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@grid-template-working
Patch Set: Patch rebased and adapted to the new parsing approach. Created 6 years, 9 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
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 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 case CSSPropertyGridAutoRows: 1207 case CSSPropertyGridAutoRows:
1208 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1208 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1209 return false; 1209 return false;
1210 parsedValue = parseGridTrackSize(*m_valueList); 1210 parsedValue = parseGridTrackSize(*m_valueList);
1211 break; 1211 break;
1212 1212
1213 case CSSPropertyGridTemplateColumns: 1213 case CSSPropertyGridTemplateColumns:
1214 case CSSPropertyGridTemplateRows: 1214 case CSSPropertyGridTemplateRows:
1215 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1215 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1216 return false; 1216 return false;
1217 return parseGridTrackList(propId, important); 1217 parsedValue = parseGridTrackList(important);
1218 break;
1218 1219
1219 case CSSPropertyGridColumnEnd: 1220 case CSSPropertyGridColumnEnd:
1220 case CSSPropertyGridColumnStart: 1221 case CSSPropertyGridColumnStart:
1221 case CSSPropertyGridRowEnd: 1222 case CSSPropertyGridRowEnd:
1222 case CSSPropertyGridRowStart: 1223 case CSSPropertyGridRowStart:
1223 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1224 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1224 return false; 1225 return false;
1225 parsedValue = parseGridPosition(); 1226 parsedValue = parseGridPosition();
1226 break; 1227 break;
1227 1228
1228 case CSSPropertyGridColumn: 1229 case CSSPropertyGridColumn:
1229 case CSSPropertyGridRow: 1230 case CSSPropertyGridRow:
1230 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1231 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1231 return false; 1232 return false;
1232 return parseGridItemPositionShorthand(propId, important); 1233 return parseGridItemPositionShorthand(propId, important);
1233 1234
1234 case CSSPropertyGridArea: 1235 case CSSPropertyGridArea:
1235 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1236 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1236 return false; 1237 return false;
1237 return parseGridAreaShorthand(important); 1238 return parseGridAreaShorthand(important);
1238 1239
1239 case CSSPropertyGridTemplateAreas: 1240 case CSSPropertyGridTemplateAreas:
1240 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1241 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1241 return false; 1242 return false;
1242 parsedValue = parseGridTemplateAreas(); 1243 parsedValue = parseGridTemplateAreas();
1243 break; 1244 break;
1244 1245
1246 case CSSPropertyGridTemplate:
1247 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1248 return false;
1249 return parseGridTemplateShorthand(important);
1250
1245 case CSSPropertyWebkitMarginCollapse: { 1251 case CSSPropertyWebkitMarginCollapse: {
1246 if (num == 1) { 1252 if (num == 1) {
1247 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); 1253 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
1248 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant)) 1254 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant))
1249 return false; 1255 return false;
1250 CSSValue* value = m_parsedProperties.last().value(); 1256 CSSValue* value = m_parsedProperties.last().value();
1251 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important); 1257 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
1252 return true; 1258 return true;
1253 } 1259 }
1254 else if (num == 2) { 1260 else if (num == 2) {
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 return false; 3442 return false;
3437 } else { 3443 } else {
3438 endValue = gridMissingGridPositionValue(startValue.get()); 3444 endValue = gridMissingGridPositionValue(startValue.get());
3439 } 3445 }
3440 3446
3441 addProperty(shorthand.properties()[0], startValue, important); 3447 addProperty(shorthand.properties()[0], startValue, important);
3442 addProperty(shorthand.properties()[1], endValue, important); 3448 addProperty(shorthand.properties()[1], endValue, important);
3443 return true; 3449 return true;
3444 } 3450 }
3445 3451
3452 bool CSSPropertyParser::parseGridTemplateRowsAndAreas(PassRefPtrWillBeRawPtr<CSS Value> templateColumns, bool important)
3453 {
3454 NamedGridAreaMap gridAreaMap;
3455 size_t rowCount = 0;
3456 size_t columnCount = 0;
3457 bool traillingIdentAdded = false;
Julien - ping for review 2014/03/21 19:25:55 This name is not English and it would be if it was
jfernandez 2014/03/22 00:30:45 Done.
3458 RefPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
3459
3460 // At least template-areas strings must be defined.
3461 if (!m_valueList->current())
3462 return false;
3463
3464 // The template-columns <track-list> can't be 'none'.
3465 if (templateColumns && templateColumns->isPrimitiveValue() && toCSSPrimitive Value(templateColumns.get())->getValueID() == CSSValueNone)
Julien - ping for review 2014/03/21 19:25:55 This check feels misplaced and I think it should b
jfernandez 2014/03/22 00:30:45 Yes, I had lot of doubts. I understand your point
3466 return false;
3467
3468 while (m_valueList->current()) {
3469 // Handle leading <custom-ident>*.
3470 if (m_valueList->current()->unit == CSSParserValue::ValueList) {
3471 if (traillingIdentAdded) {
3472 // A row's trailing ident must be concatenated with the next row 's leading one.
3473 parseGridLineNames(*m_valueList, *templateRows, static_cast<CSSG ridLineNamesValue*>(templateRows->item(templateRows->length() - 1)));
3474 } else {
3475 parseGridLineNames(*m_valueList, *templateRows);
3476 }
3477 }
3478
3479 // Handle a template-area's row.
3480 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3481 return false;
3482 ++rowCount;
3483
3484 // Handle template-rows's track-size.
3485 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING ) {
3486 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
3487 if (!value)
3488 return false;
3489 templateRows->append(value);
3490 } else {
3491 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to));
3492 }
3493
3494 // This will handle the trailing/leading <custom-ident>* in the grammar.
3495 traillingIdentAdded = false;
3496 if (m_valueList->current() && m_valueList->current()->unit == CSSParserV alue::ValueList) {
3497 parseGridLineNames(*m_valueList, *templateRows);
3498 traillingIdentAdded = true;
3499 }
3500 }
3501
3502 // [<track-list> /]?
3503 if (templateColumns)
3504 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
3505 else
3506 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important);
3507
3508 // [<line-names>? <string> [<track-size> <line-names>]? ]+
3509 RefPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaM ap, rowCount, columnCount);
3510 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important );
3511 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important);
3512
3513
3514 return true;
3515 }
3516
3517
3518 bool CSSPropertyParser::parseGridTemplateShorthand(bool important)
3519 {
3520 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3521
3522 ShorthandScope scope(this, CSSPropertyGridTemplate);
3523 ASSERT(gridTemplateShorthand().length() == 3);
3524
3525 // At least "none" must be defined.
3526 if (!m_valueList->current())
3527 return false;
3528
3529 RefPtr<CSSValue> columnsValue;
3530 unsigned index = 0;
3531
3532 // 1- 'none' case.
3533 if (m_valueList->current()->id == CSSValueNone) {
3534 if (!m_valueList->next()) {
3535 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIde ntifierValue(CSSValueNone), important);
3536 addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdenti fierValue(CSSValueNone), important);
3537 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdent ifierValue(CSSValueNone), important);
3538 return true;
3539 }
3540 columnsValue = cssValuePool().createIdentifierValue(CSSValueNone);
3541 } else {
3542 columnsValue = parseGridTrackList(important);
3543 }
3544
3545
3546 // 2- <grid-template-columns> / <grid-template-columns> syntax.
3547 if (columnsValue) {
3548 if (!(m_valueList->current() && isForwardSlashOperator(m_valueList->curr ent()) && m_valueList->next()))
3549 return false;
3550 index = m_valueList->currentIndex();
3551 if (RefPtr<CSSValue> rowsValue = parseGridTrackList(important)) {
3552 if (m_valueList->current())
3553 return false;
3554 addProperty(CSSPropertyGridTemplateColumns, columnsValue, important) ;
3555 addProperty(CSSPropertyGridTemplateRows, rowsValue, important);
3556 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdent ifierValue(CSSValueNone), important);
3557 return true;
3558 }
3559 }
3560
3561 // 3- [<track-list> /]? [<line-names>? <string> [<track-size> <line-names>]? ]+ syntax.
3562 // It requires to rewind parsing due to previous syntax failures.
3563 m_valueList->setCurrentIndex(index);
3564 return parseGridTemplateRowsAndAreas(columnsValue, important);
3565 }
3566
3446 bool CSSPropertyParser::parseGridAreaShorthand(bool important) 3567 bool CSSPropertyParser::parseGridAreaShorthand(bool important)
3447 { 3568 {
3448 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3569 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3449 3570
3450 ShorthandScope scope(this, CSSPropertyGridArea); 3571 ShorthandScope scope(this, CSSPropertyGridArea);
3451 const StylePropertyShorthand& shorthand = gridAreaShorthand(); 3572 const StylePropertyShorthand& shorthand = gridAreaShorthand();
3452 ASSERT_UNUSED(shorthand, shorthand.length() == 4); 3573 ASSERT_UNUSED(shorthand, shorthand.length() == 4);
3453 3574
3454 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition(); 3575 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition();
3455 if (!rowStartValue) 3576 if (!rowStartValue)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 if (!isForwardSlashOperator(m_valueList->current())) 3612 if (!isForwardSlashOperator(m_valueList->current()))
3492 return false; 3613 return false;
3493 3614
3494 if (!m_valueList->next()) 3615 if (!m_valueList->next())
3495 return false; 3616 return false;
3496 3617
3497 property = parseGridPosition(); 3618 property = parseGridPosition();
3498 return true; 3619 return true;
3499 } 3620 }
3500 3621
3501 void CSSPropertyParser::parseGridLineNames(CSSParserValueList* parserValueList, CSSValueList& valueList) 3622 void CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSVal ueList& valueList, CSSGridLineNamesValue* lineNamesToConcat)
Julien - ping for review 2014/03/21 19:25:55 Let's rename lineNamesToConcat to something cleare
jfernandez 2014/03/22 00:30:45 Done.
3502 { 3623 {
3503 ASSERT(parserValueList->current() && parserValueList->current()->unit == CSS ParserValue::ValueList); 3624 ASSERT(inputList.current() && inputList.current()->unit == CSSParserValue::V alueList);
3504 3625
3505 CSSParserValueList* identList = parserValueList->current()->valueList; 3626 CSSParserValueList* identList = inputList.current()->valueList;
3506 if (!identList->size()) { 3627 if (!identList->size()) {
3507 parserValueList->next(); 3628 inputList.next();
3508 return; 3629 return;
3509 } 3630 }
3510 3631
3511 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue: :create(); 3632 // Need to ensure the identList is at the heading index, since the parserLis t might have been rewound.
3633 identList->setCurrentIndex(0);
3634
3635 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = lineNamesToConcat ? li neNamesToConcat : CSSGridLineNamesValue::create();
3512 while (CSSParserValue* identValue = identList->current()) { 3636 while (CSSParserValue* identValue = identList->current()) {
3513 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT); 3637 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT);
3514 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue); 3638 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue);
3515 lineNames->append(lineName.release()); 3639 lineNames->append(lineName.release());
3516 identList->next(); 3640 identList->next();
3517 } 3641 }
3518 valueList.append(lineNames.release()); 3642 if (!lineNamesToConcat)
3643 valueList.append(lineNames.release());
3519 3644
3520 parserValueList->next(); 3645 inputList.next();
3521 } 3646 }
3522 3647
3523 bool CSSPropertyParser::parseGridTrackList(CSSPropertyID propId, bool important) 3648 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList(bool impo rtant)
3524 { 3649 {
3525 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3650 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3526 3651
3527 CSSParserValue* value = m_valueList->current(); 3652 CSSParserValue* value = m_valueList->current();
3528 if (value->id == CSSValueNone) { 3653 if (value->id == CSSValueNone) {
3529 if (m_valueList->next()) 3654 m_valueList->next();
3530 return false; 3655 return cssValuePool().createIdentifierValue(CSSValueNone);
3531
3532 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp ortant);
3533 return true;
3534 } 3656 }
3535 3657
3536 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); 3658 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
3537 // Handle leading <ident>*. 3659 // Handle leading <ident>*.
3538 value = m_valueList->current(); 3660 value = m_valueList->current();
3539 if (value && value->unit == CSSParserValue::ValueList) 3661 if (value && value->unit == CSSParserValue::ValueList)
3540 parseGridLineNames(m_valueList.get(), *values); 3662 parseGridLineNames(*m_valueList, *values);
3541 3663
3542 bool seenTrackSizeOrRepeatFunction = false; 3664 bool seenTrackSizeOrRepeatFunction = false;
3543 while (CSSParserValue* currentValue = m_valueList->current()) { 3665 while (CSSParserValue* currentValue = m_valueList->current()) {
3666 if (isForwardSlashOperator(currentValue))
3667 break;
3544 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) { 3668 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) {
3545 if (!parseGridTrackRepeatFunction(*values)) 3669 if (!parseGridTrackRepeatFunction(*values))
3546 return false; 3670 return nullptr;
3547 seenTrackSizeOrRepeatFunction = true; 3671 seenTrackSizeOrRepeatFunction = true;
3548 } else { 3672 } else {
3549 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList ); 3673 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList );
3550 if (!value) 3674 if (!value)
3551 return false; 3675 return nullptr;
3552 values->append(value); 3676 values->append(value);
3553 seenTrackSizeOrRepeatFunction = true; 3677 seenTrackSizeOrRepeatFunction = true;
3554 } 3678 }
3555 // This will handle the trailing <ident>* in the grammar. 3679 // This will handle the trailing <ident>* in the grammar.
3556 value = m_valueList->current(); 3680 value = m_valueList->current();
3557 if (value && value->unit == CSSParserValue::ValueList) 3681 if (value && value->unit == CSSParserValue::ValueList)
3558 parseGridLineNames(m_valueList.get(), *values); 3682 parseGridLineNames(*m_valueList, *values);
3559 } 3683 }
3560 3684
3561 // We should have found a <track-size> or else it is not a valid <track-list > 3685 // We should have found a <track-size> or else it is not a valid <track-list >
3562 if (!seenTrackSizeOrRepeatFunction) 3686 if (!seenTrackSizeOrRepeatFunction)
3563 return false; 3687 return nullptr;
3564 3688
3565 addProperty(propId, values.release(), important); 3689 return values;
3566 return true;
3567 } 3690 }
3568 3691
3569 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) 3692 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
3570 { 3693 {
3571 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ; 3694 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
3572 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1))) 3695 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
3573 return false; 3696 return false;
3574 3697
3575 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0); 3698 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0);
3576 size_t repetitions = arguments->valueAt(0)->fValue; 3699 size_t repetitions = arguments->valueAt(0)->fValue;
3577 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated(); 3700 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated();
3578 arguments->next(); // Skip the repetition count. 3701 arguments->next(); // Skip the repetition count.
3579 arguments->next(); // Skip the comma. 3702 arguments->next(); // Skip the comma.
3580 3703
3581 // Handle leading <ident>*. 3704 // Handle leading <ident>*.
3582 CSSParserValue* currentValue = arguments->current(); 3705 CSSParserValue* currentValue = arguments->current();
3583 if (currentValue && currentValue->unit == CSSParserValue::ValueList) 3706 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3584 parseGridLineNames(arguments, *repeatedValues); 3707 parseGridLineNames(*arguments, *repeatedValues);
3585 3708
3586 while (arguments->current()) { 3709 while (arguments->current()) {
3587 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); 3710 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
3588 if (!trackSize) 3711 if (!trackSize)
3589 return false; 3712 return false;
3590 3713
3591 repeatedValues->append(trackSize); 3714 repeatedValues->append(trackSize);
3592 3715
3593 // This takes care of any trailing <ident>* in the grammar. 3716 // This takes care of any trailing <ident>* in the grammar.
3594 currentValue = arguments->current(); 3717 currentValue = arguments->current();
3595 if (currentValue && currentValue->unit == CSSParserValue::ValueList) 3718 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3596 parseGridLineNames(arguments, *repeatedValues); 3719 parseGridLineNames(*arguments, *repeatedValues);
3597 } 3720 }
3598 3721
3599 for (size_t i = 0; i < repetitions; ++i) { 3722 for (size_t i = 0; i < repetitions; ++i) {
3600 for (size_t j = 0; j < repeatedValues->length(); ++j) 3723 for (size_t j = 0; j < repeatedValues->length(); ++j)
3601 list.append(repeatedValues->itemWithoutBoundsCheck(j)); 3724 list.append(repeatedValues->itemWithoutBoundsCheck(j));
3602 } 3725 }
3603 3726
3604 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue. 3727 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue.
3605 m_valueList->next(); 3728 m_valueList->next();
3606 return true; 3729 return true;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3654 3777
3655 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR); 3778 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
3656 } 3779 }
3657 3780
3658 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) 3781 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
3659 return nullptr; 3782 return nullptr;
3660 3783
3661 return createPrimitiveNumericValue(currentValue); 3784 return createPrimitiveNumericValue(currentValue);
3662 } 3785 }
3663 3786
3787 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3788 {
3789 CSSParserValue* currentValue = m_valueList->current();
3790 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
3791 return false;
3792
3793 String gridRowNames = currentValue->string;
3794 if (!gridRowNames.length())
3795 return false;
3796
3797 Vector<String> columnNames;
3798 gridRowNames.split(' ', columnNames);
3799
3800 if (!columnCount) {
3801 columnCount = columnNames.size();
3802 ASSERT(columnCount);
3803 } else if (columnCount != columnNames.size()) {
3804 // The declaration is invalid is all the rows don't have the number of c olumns.
3805 return false;
3806 }
3807
3808 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3809 const String& gridAreaName = columnNames[currentCol];
3810
3811 // Unamed areas are always valid (we consider them to be 1x1).
3812 if (gridAreaName == ".")
3813 continue;
3814
3815 // We handle several grid areas with the same name at once to simplify t he validation code.
3816 size_t lookAheadCol;
3817 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) {
3818 if (columnNames[lookAheadCol + 1] != gridAreaName)
3819 break;
3820 }
3821
3822 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
3823 if (gridAreaIt == gridAreaMap.end()) {
3824 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowC ount), GridSpan(currentCol, lookAheadCol)));
3825 } else {
3826 GridCoordinate& gridCoordinate = gridAreaIt->value;
3827
3828 // The following checks test that the grid area is a single filled-i n rectangle.
3829 // 1. The new row is adjacent to the previously parsed row.
3830 if (rowCount != gridCoordinate.rows.initialPositionIndex + 1)
3831 return false;
3832
3833 // 2. The new area starts at the same position as the previously par sed area.
3834 if (currentCol != gridCoordinate.columns.initialPositionIndex)
3835 return false;
3836
3837 // 3. The new area ends at the same position as the previously parse d area.
3838 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
3839 return false;
3840
3841 ++gridCoordinate.rows.finalPositionIndex;
3842 }
3843 currentCol = lookAheadCol;
3844 }
3845
3846 m_valueList->next();
3847 return true;
3848 }
3849
3664 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas() 3850 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas()
3665 { 3851 {
3666 NamedGridAreaMap gridAreaMap; 3852 NamedGridAreaMap gridAreaMap;
3667 size_t rowCount = 0; 3853 size_t rowCount = 0;
3668 size_t columnCount = 0; 3854 size_t columnCount = 0;
3669 3855
3670 while (CSSParserValue* currentValue = m_valueList->current()) { 3856 while (m_valueList->current()) {
3671 if (currentValue->unit != CSSPrimitiveValue::CSS_STRING) 3857 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3672 return nullptr; 3858 return nullptr;
3673
3674 String gridRowNames = currentValue->string;
3675 if (!gridRowNames.length())
3676 return nullptr;
3677
3678 Vector<String> columnNames;
3679 gridRowNames.split(' ', columnNames);
3680
3681 if (!columnCount) {
3682 columnCount = columnNames.size();
3683 ASSERT(columnCount);
3684 } else if (columnCount != columnNames.size()) {
3685 // The declaration is invalid is all the rows don't have the number of columns.
3686 return nullptr;
3687 }
3688
3689 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3690 const String& gridAreaName = columnNames[currentCol];
3691
3692 // Unamed areas are always valid (we consider them to be 1x1).
3693 if (gridAreaName == ".")
3694 continue;
3695
3696 // We handle several grid areas with the same name at once to simpli fy the validation code.
3697 size_t lookAheadCol;
3698 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++ lookAheadCol) {
3699 if (columnNames[lookAheadCol + 1] != gridAreaName)
3700 break;
3701 }
3702
3703 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaNam e);
3704 if (gridAreaIt == gridAreaMap.end()) {
3705 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowCount), GridSpan(currentCol, lookAheadCol)));
3706 } else {
3707 GridCoordinate& gridCoordinate = gridAreaIt->value;
3708
3709 // The following checks test that the grid area is a single fill ed-in rectangle.
3710 // 1. The new row is adjacent to the previously parsed row.
3711 if (rowCount != gridCoordinate.rows.initialPositionIndex + 1)
3712 return nullptr;
3713
3714 // 2. The new area starts at the same position as the previously parsed area.
3715 if (currentCol != gridCoordinate.columns.initialPositionIndex)
3716 return nullptr;
3717
3718 // 3. The new area ends at the same position as the previously p arsed area.
3719 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
3720 return nullptr;
3721
3722 ++gridCoordinate.rows.finalPositionIndex;
3723 }
3724 currentCol = lookAheadCol;
3725 }
3726
3727 ++rowCount; 3859 ++rowCount;
3728 m_valueList->next();
3729 } 3860 }
3730 3861
3731 if (!rowCount || !columnCount) 3862 if (!rowCount || !columnCount)
3732 return nullptr; 3863 return nullptr;
3733 3864
3734 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ; 3865 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ;
3735 } 3866 }
3736 3867
3737 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters) 3868 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters)
3738 { 3869 {
(...skipping 4714 matching lines...) Expand 10 before | Expand all | Expand 10 after
8453 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill)); 8584 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill));
8454 if (!seenStroke) 8585 if (!seenStroke)
8455 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke) ); 8586 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke) );
8456 if (!seenMarkers) 8587 if (!seenMarkers)
8457 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers )); 8588 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers ));
8458 8589
8459 return parsedValues.release(); 8590 return parsedValues.release();
8460 } 8591 }
8461 8592
8462 } // namespace WebCore 8593 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSPropertyParser.h ('k') | Source/core/css/resolver/StyleBuilderCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698