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

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: Added the new property to the ones runtime enabled only. Created 6 years, 8 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 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 case CSSPropertyGridAutoRows: 1213 case CSSPropertyGridAutoRows:
1214 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1214 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1215 return false; 1215 return false;
1216 parsedValue = parseGridTrackSize(*m_valueList); 1216 parsedValue = parseGridTrackSize(*m_valueList);
1217 break; 1217 break;
1218 1218
1219 case CSSPropertyGridTemplateColumns: 1219 case CSSPropertyGridTemplateColumns:
1220 case CSSPropertyGridTemplateRows: 1220 case CSSPropertyGridTemplateRows:
1221 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1221 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1222 return false; 1222 return false;
1223 return parseGridTrackList(propId, important); 1223 parsedValue = parseGridTrackList(important);
1224 break;
1224 1225
1225 case CSSPropertyGridColumnEnd: 1226 case CSSPropertyGridColumnEnd:
1226 case CSSPropertyGridColumnStart: 1227 case CSSPropertyGridColumnStart:
1227 case CSSPropertyGridRowEnd: 1228 case CSSPropertyGridRowEnd:
1228 case CSSPropertyGridRowStart: 1229 case CSSPropertyGridRowStart:
1229 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1230 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1230 return false; 1231 return false;
1231 parsedValue = parseGridPosition(); 1232 parsedValue = parseGridPosition();
1232 break; 1233 break;
1233 1234
1234 case CSSPropertyGridColumn: 1235 case CSSPropertyGridColumn:
1235 case CSSPropertyGridRow: 1236 case CSSPropertyGridRow:
1236 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1237 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1237 return false; 1238 return false;
1238 return parseGridItemPositionShorthand(propId, important); 1239 return parseGridItemPositionShorthand(propId, important);
1239 1240
1240 case CSSPropertyGridArea: 1241 case CSSPropertyGridArea:
1241 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1242 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1242 return false; 1243 return false;
1243 return parseGridAreaShorthand(important); 1244 return parseGridAreaShorthand(important);
1244 1245
1245 case CSSPropertyGridTemplateAreas: 1246 case CSSPropertyGridTemplateAreas:
1246 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 1247 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1247 return false; 1248 return false;
1248 parsedValue = parseGridTemplateAreas(); 1249 parsedValue = parseGridTemplateAreas();
1249 break; 1250 break;
1250 1251
1252 case CSSPropertyGridTemplate:
1253 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
1254 return false;
1255 return parseGridTemplateShorthand(important);
1256
1251 case CSSPropertyWebkitMarginCollapse: { 1257 case CSSPropertyWebkitMarginCollapse: {
1252 if (num == 1) { 1258 if (num == 1) {
1253 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); 1259 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
1254 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant)) 1260 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant))
1255 return false; 1261 return false;
1256 CSSValue* value = m_parsedProperties.last().value(); 1262 CSSValue* value = m_parsedProperties.last().value();
1257 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important); 1263 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
1258 return true; 1264 return true;
1259 } 1265 }
1260 else if (num == 2) { 1266 else if (num == 2) {
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3452 return false; 3458 return false;
3453 } else { 3459 } else {
3454 endValue = gridMissingGridPositionValue(startValue.get()); 3460 endValue = gridMissingGridPositionValue(startValue.get());
3455 } 3461 }
3456 3462
3457 addProperty(shorthand.properties()[0], startValue, important); 3463 addProperty(shorthand.properties()[0], startValue, important);
3458 addProperty(shorthand.properties()[1], endValue, important); 3464 addProperty(shorthand.properties()[1], endValue, important);
3459 return true; 3465 return true;
3460 } 3466 }
3461 3467
3468 bool CSSPropertyParser::parseGridTemplateRowsAndAreas(PassRefPtrWillBeRawPtr<CSS Value> templateColumns, bool important)
3469 {
3470 NamedGridAreaMap gridAreaMap;
3471 size_t rowCount = 0;
3472 size_t columnCount = 0;
3473 bool trailingIdentWasAdded = false;
3474 RefPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
3475
3476 // At least template-areas strings must be defined.
3477 if (!m_valueList->current())
3478 return false;
3479
3480 while (m_valueList->current()) {
3481 // Handle leading <custom-ident>*.
3482 if (m_valueList->current()->unit == CSSParserValue::ValueList) {
3483 if (trailingIdentWasAdded) {
3484 // A row's trailing ident must be concatenated with the next row 's leading one.
3485 parseGridLineNames(*m_valueList, *templateRows, static_cast<CSSG ridLineNamesValue*>(templateRows->item(templateRows->length() - 1)));
3486 } else {
3487 parseGridLineNames(*m_valueList, *templateRows);
3488 }
3489 }
3490
3491 // Handle a template-area's row.
3492 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3493 return false;
3494 ++rowCount;
3495
3496 // Handle template-rows's track-size.
3497 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING ) {
3498 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
3499 if (!value)
3500 return false;
3501 templateRows->append(value);
3502 } else {
3503 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to));
3504 }
3505
3506 // This will handle the trailing/leading <custom-ident>* in the grammar.
3507 trailingIdentWasAdded = false;
3508 if (m_valueList->current() && m_valueList->current()->unit == CSSParserV alue::ValueList) {
3509 parseGridLineNames(*m_valueList, *templateRows);
3510 trailingIdentWasAdded = true;
3511 }
3512 }
3513
3514 // [<track-list> /]?
3515 if (templateColumns)
3516 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
3517 else
3518 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important);
3519
3520 // [<line-names>? <string> [<track-size> <line-names>]? ]+
3521 RefPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaM ap, rowCount, columnCount);
3522 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important );
3523 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important);
3524
3525
3526 return true;
3527 }
3528
3529
3530 bool CSSPropertyParser::parseGridTemplateShorthand(bool important)
3531 {
3532 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3533
3534 ShorthandScope scope(this, CSSPropertyGridTemplate);
3535 ASSERT(gridTemplateShorthand().length() == 3);
3536
3537 // At least "none" must be defined.
3538 if (!m_valueList->current())
3539 return false;
3540
3541 bool firstValueIsNone = m_valueList->current()->id == CSSValueNone;
3542
3543 // 1- 'none' case.
3544 if (firstValueIsNone && !m_valueList->next()) {
3545 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentif ierValue(CSSValueNone), important);
3546 addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdentifier Value(CSSValueNone), important);
3547 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifie rValue(CSSValueNone), important);
3548 return true;
3549 }
3550
3551 unsigned index = 0;
3552 RefPtr<CSSValue> columnsValue = firstValueIsNone ? cssValuePool().createIden tifierValue(CSSValueNone) : parseGridTrackList(important);
3553
3554 // 2- <grid-template-columns> / <grid-template-columns> syntax.
3555 if (columnsValue) {
3556 if (!(m_valueList->current() && isForwardSlashOperator(m_valueList->curr ent()) && m_valueList->next()))
3557 return false;
3558 index = m_valueList->currentIndex();
3559 if (RefPtr<CSSValue> rowsValue = parseGridTrackList(important)) {
3560 if (m_valueList->current())
3561 return false;
3562 addProperty(CSSPropertyGridTemplateColumns, columnsValue, important) ;
3563 addProperty(CSSPropertyGridTemplateRows, rowsValue, important);
3564 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdent ifierValue(CSSValueNone), important);
3565 return true;
3566 }
3567 }
3568
3569
3570 // 3- [<track-list> /]? [<line-names>? <string> [<track-size> <line-names>]? ]+ syntax.
3571 // The template-columns <track-list> can't be 'none'.
3572 if (firstValueIsNone)
3573 return false;
3574 // It requires to rewind parsing due to previous syntax failures.
3575 m_valueList->setCurrentIndex(index);
3576 return parseGridTemplateRowsAndAreas(columnsValue, important);
3577 }
3578
3462 bool CSSPropertyParser::parseGridAreaShorthand(bool important) 3579 bool CSSPropertyParser::parseGridAreaShorthand(bool important)
3463 { 3580 {
3464 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3581 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3465 3582
3466 ShorthandScope scope(this, CSSPropertyGridArea); 3583 ShorthandScope scope(this, CSSPropertyGridArea);
3467 const StylePropertyShorthand& shorthand = gridAreaShorthand(); 3584 const StylePropertyShorthand& shorthand = gridAreaShorthand();
3468 ASSERT_UNUSED(shorthand, shorthand.length() == 4); 3585 ASSERT_UNUSED(shorthand, shorthand.length() == 4);
3469 3586
3470 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition(); 3587 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition();
3471 if (!rowStartValue) 3588 if (!rowStartValue)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 if (!isForwardSlashOperator(m_valueList->current())) 3624 if (!isForwardSlashOperator(m_valueList->current()))
3508 return false; 3625 return false;
3509 3626
3510 if (!m_valueList->next()) 3627 if (!m_valueList->next())
3511 return false; 3628 return false;
3512 3629
3513 property = parseGridPosition(); 3630 property = parseGridPosition();
3514 return true; 3631 return true;
3515 } 3632 }
3516 3633
3517 void CSSPropertyParser::parseGridLineNames(CSSParserValueList* parserValueList, CSSValueList& valueList) 3634 void CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSVal ueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineNames)
3518 { 3635 {
3519 ASSERT(parserValueList->current() && parserValueList->current()->unit == CSS ParserValue::ValueList); 3636 ASSERT(inputList.current() && inputList.current()->unit == CSSParserValue::V alueList);
3520 3637
3521 CSSParserValueList* identList = parserValueList->current()->valueList; 3638 CSSParserValueList* identList = inputList.current()->valueList;
3522 if (!identList->size()) { 3639 if (!identList->size()) {
3523 parserValueList->next(); 3640 inputList.next();
3524 return; 3641 return;
3525 } 3642 }
3526 3643
3527 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue: :create(); 3644 // Need to ensure the identList is at the heading index, since the parserLis t might have been rewound.
3645 identList->setCurrentIndex(0);
3646
3647 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrail ingLineNames ? previousNamedAreaTrailingLineNames : CSSGridLineNamesValue::creat e();
3528 while (CSSParserValue* identValue = identList->current()) { 3648 while (CSSParserValue* identValue = identList->current()) {
3529 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT); 3649 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT);
3530 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue); 3650 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue);
3531 lineNames->append(lineName.release()); 3651 lineNames->append(lineName.release());
3532 identList->next(); 3652 identList->next();
3533 } 3653 }
3534 valueList.append(lineNames.release()); 3654 if (!previousNamedAreaTrailingLineNames)
3655 valueList.append(lineNames.release());
3535 3656
3536 parserValueList->next(); 3657 inputList.next();
3537 } 3658 }
3538 3659
3539 bool CSSPropertyParser::parseGridTrackList(CSSPropertyID propId, bool important) 3660 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList(bool impo rtant)
3540 { 3661 {
3541 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3662 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3542 3663
3543 CSSParserValue* value = m_valueList->current(); 3664 CSSParserValue* value = m_valueList->current();
3544 if (value->id == CSSValueNone) { 3665 if (value->id == CSSValueNone) {
3545 if (m_valueList->next()) 3666 m_valueList->next();
3546 return false; 3667 return cssValuePool().createIdentifierValue(CSSValueNone);
3547
3548 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp ortant);
3549 return true;
3550 } 3668 }
3551 3669
3552 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); 3670 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
3553 // Handle leading <ident>*. 3671 // Handle leading <ident>*.
3554 value = m_valueList->current(); 3672 value = m_valueList->current();
3555 if (value && value->unit == CSSParserValue::ValueList) 3673 if (value && value->unit == CSSParserValue::ValueList)
3556 parseGridLineNames(m_valueList.get(), *values); 3674 parseGridLineNames(*m_valueList, *values);
3557 3675
3558 bool seenTrackSizeOrRepeatFunction = false; 3676 bool seenTrackSizeOrRepeatFunction = false;
3559 while (CSSParserValue* currentValue = m_valueList->current()) { 3677 while (CSSParserValue* currentValue = m_valueList->current()) {
3678 if (isForwardSlashOperator(currentValue))
3679 break;
3560 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) { 3680 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) {
3561 if (!parseGridTrackRepeatFunction(*values)) 3681 if (!parseGridTrackRepeatFunction(*values))
3562 return false; 3682 return nullptr;
3563 seenTrackSizeOrRepeatFunction = true; 3683 seenTrackSizeOrRepeatFunction = true;
3564 } else { 3684 } else {
3565 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList ); 3685 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList );
3566 if (!value) 3686 if (!value)
3567 return false; 3687 return nullptr;
3568 values->append(value); 3688 values->append(value);
3569 seenTrackSizeOrRepeatFunction = true; 3689 seenTrackSizeOrRepeatFunction = true;
3570 } 3690 }
3571 // This will handle the trailing <ident>* in the grammar. 3691 // This will handle the trailing <ident>* in the grammar.
3572 value = m_valueList->current(); 3692 value = m_valueList->current();
3573 if (value && value->unit == CSSParserValue::ValueList) 3693 if (value && value->unit == CSSParserValue::ValueList)
3574 parseGridLineNames(m_valueList.get(), *values); 3694 parseGridLineNames(*m_valueList, *values);
3575 } 3695 }
3576 3696
3577 // We should have found a <track-size> or else it is not a valid <track-list > 3697 // We should have found a <track-size> or else it is not a valid <track-list >
3578 if (!seenTrackSizeOrRepeatFunction) 3698 if (!seenTrackSizeOrRepeatFunction)
3579 return false; 3699 return nullptr;
3580 3700
3581 addProperty(propId, values.release(), important); 3701 return values;
3582 return true;
3583 } 3702 }
3584 3703
3585 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) 3704 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
3586 { 3705 {
3587 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ; 3706 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
3588 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1))) 3707 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
3589 return false; 3708 return false;
3590 3709
3591 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0); 3710 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0);
3592 size_t repetitions = arguments->valueAt(0)->fValue; 3711 size_t repetitions = arguments->valueAt(0)->fValue;
3593 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated(); 3712 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated();
3594 arguments->next(); // Skip the repetition count. 3713 arguments->next(); // Skip the repetition count.
3595 arguments->next(); // Skip the comma. 3714 arguments->next(); // Skip the comma.
3596 3715
3597 // Handle leading <ident>*. 3716 // Handle leading <ident>*.
3598 CSSParserValue* currentValue = arguments->current(); 3717 CSSParserValue* currentValue = arguments->current();
3599 if (currentValue && currentValue->unit == CSSParserValue::ValueList) 3718 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3600 parseGridLineNames(arguments, *repeatedValues); 3719 parseGridLineNames(*arguments, *repeatedValues);
3601 3720
3602 while (arguments->current()) { 3721 while (arguments->current()) {
3603 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); 3722 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
3604 if (!trackSize) 3723 if (!trackSize)
3605 return false; 3724 return false;
3606 3725
3607 repeatedValues->append(trackSize); 3726 repeatedValues->append(trackSize);
3608 3727
3609 // This takes care of any trailing <ident>* in the grammar. 3728 // This takes care of any trailing <ident>* in the grammar.
3610 currentValue = arguments->current(); 3729 currentValue = arguments->current();
3611 if (currentValue && currentValue->unit == CSSParserValue::ValueList) 3730 if (currentValue && currentValue->unit == CSSParserValue::ValueList)
3612 parseGridLineNames(arguments, *repeatedValues); 3731 parseGridLineNames(*arguments, *repeatedValues);
3613 } 3732 }
3614 3733
3615 for (size_t i = 0; i < repetitions; ++i) { 3734 for (size_t i = 0; i < repetitions; ++i) {
3616 for (size_t j = 0; j < repeatedValues->length(); ++j) 3735 for (size_t j = 0; j < repeatedValues->length(); ++j)
3617 list.append(repeatedValues->itemWithoutBoundsCheck(j)); 3736 list.append(repeatedValues->itemWithoutBoundsCheck(j));
3618 } 3737 }
3619 3738
3620 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue. 3739 // parseGridTrackSize iterated over the repeat arguments, move to the next v alue.
3621 m_valueList->next(); 3740 m_valueList->next();
3622 return true; 3741 return true;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 3789
3671 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR); 3790 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
3672 } 3791 }
3673 3792
3674 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) 3793 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
3675 return nullptr; 3794 return nullptr;
3676 3795
3677 return createPrimitiveNumericValue(currentValue); 3796 return createPrimitiveNumericValue(currentValue);
3678 } 3797 }
3679 3798
3799 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3800 {
3801 CSSParserValue* currentValue = m_valueList->current();
3802 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
3803 return false;
3804
3805 String gridRowNames = currentValue->string;
3806 if (!gridRowNames.length())
3807 return false;
3808
3809 Vector<String> columnNames;
3810 gridRowNames.split(' ', columnNames);
3811
3812 if (!columnCount) {
3813 columnCount = columnNames.size();
3814 ASSERT(columnCount);
3815 } else if (columnCount != columnNames.size()) {
3816 // The declaration is invalid is all the rows don't have the number of c olumns.
3817 return false;
3818 }
3819
3820 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3821 const String& gridAreaName = columnNames[currentCol];
3822
3823 // Unamed areas are always valid (we consider them to be 1x1).
3824 if (gridAreaName == ".")
3825 continue;
3826
3827 // We handle several grid areas with the same name at once to simplify t he validation code.
3828 size_t lookAheadCol;
3829 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) {
3830 if (columnNames[lookAheadCol + 1] != gridAreaName)
3831 break;
3832 }
3833
3834 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
3835 if (gridAreaIt == gridAreaMap.end()) {
3836 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowC ount), GridSpan(currentCol, lookAheadCol)));
3837 } else {
3838 GridCoordinate& gridCoordinate = gridAreaIt->value;
3839
3840 // The following checks test that the grid area is a single filled-i n rectangle.
3841 // 1. The new row is adjacent to the previously parsed row.
3842 if (rowCount != gridCoordinate.rows.finalPositionIndex + 1)
3843 return false;
3844
3845 // 2. The new area starts at the same position as the previously par sed area.
3846 if (currentCol != gridCoordinate.columns.initialPositionIndex)
3847 return false;
3848
3849 // 3. The new area ends at the same position as the previously parse d area.
3850 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
3851 return false;
3852
3853 ++gridCoordinate.rows.finalPositionIndex;
3854 }
3855 currentCol = lookAheadCol;
3856 }
3857
3858 m_valueList->next();
3859 return true;
3860 }
3861
3680 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas() 3862 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas()
3681 { 3863 {
3682 NamedGridAreaMap gridAreaMap; 3864 NamedGridAreaMap gridAreaMap;
3683 size_t rowCount = 0; 3865 size_t rowCount = 0;
3684 size_t columnCount = 0; 3866 size_t columnCount = 0;
3685 3867
3686 while (CSSParserValue* currentValue = m_valueList->current()) { 3868 while (m_valueList->current()) {
3687 if (currentValue->unit != CSSPrimitiveValue::CSS_STRING) 3869 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3688 return nullptr; 3870 return nullptr;
3689
3690 String gridRowNames = currentValue->string;
3691 if (!gridRowNames.length())
3692 return nullptr;
3693
3694 Vector<String> columnNames;
3695 gridRowNames.split(' ', columnNames);
3696
3697 if (!columnCount) {
3698 columnCount = columnNames.size();
3699 ASSERT(columnCount);
3700 } else if (columnCount != columnNames.size()) {
3701 // The declaration is invalid is all the rows don't have the number of columns.
3702 return nullptr;
3703 }
3704
3705 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3706 const String& gridAreaName = columnNames[currentCol];
3707
3708 // Unamed areas are always valid (we consider them to be 1x1).
3709 if (gridAreaName == ".")
3710 continue;
3711
3712 // We handle several grid areas with the same name at once to simpli fy the validation code.
3713 size_t lookAheadCol;
3714 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++ lookAheadCol) {
3715 if (columnNames[lookAheadCol + 1] != gridAreaName)
3716 break;
3717 }
3718
3719 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaNam e);
3720 if (gridAreaIt == gridAreaMap.end()) {
3721 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowCount), GridSpan(currentCol, lookAheadCol)));
3722 } else {
3723 GridCoordinate& gridCoordinate = gridAreaIt->value;
3724
3725 // The following checks test that the grid area is a single fill ed-in rectangle.
3726 // 1. The new row is adjacent to the previously parsed row.
3727 if (rowCount != gridCoordinate.rows.finalPositionIndex + 1)
3728 return nullptr;
3729
3730 // 2. The new area starts at the same position as the previously parsed area.
3731 if (currentCol != gridCoordinate.columns.initialPositionIndex)
3732 return nullptr;
3733
3734 // 3. The new area ends at the same position as the previously p arsed area.
3735 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
3736 return nullptr;
3737
3738 ++gridCoordinate.rows.finalPositionIndex;
3739 }
3740 currentCol = lookAheadCol;
3741 }
3742
3743 ++rowCount; 3871 ++rowCount;
3744 m_valueList->next();
3745 } 3872 }
3746 3873
3747 if (!rowCount || !columnCount) 3874 if (!rowCount || !columnCount)
3748 return nullptr; 3875 return nullptr;
3749 3876
3750 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ; 3877 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ;
3751 } 3878 }
3752 3879
3753 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters) 3880 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters)
3754 { 3881 {
(...skipping 4486 matching lines...) Expand 10 before | Expand all | Expand 10 after
8241 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill)); 8368 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill));
8242 if (!seenStroke) 8369 if (!seenStroke)
8243 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke) ); 8370 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke) );
8244 if (!seenMarkers) 8371 if (!seenMarkers)
8245 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers )); 8372 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers ));
8246 8373
8247 return parsedValues.release(); 8374 return parsedValues.release();
8248 } 8375 }
8249 8376
8250 } // namespace WebCore 8377 } // 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