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

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

Issue 1168453002: [CSSGridLayout] Switch from parentheses to brackets for grid line names (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed test and parsing Created 5 years, 6 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
« no previous file with comments | « Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3210 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
jfernandez 2015/06/04 22:49:56 Unneeded white line.
3232 // A row's trailing ident must be concatenated with the next row's l eading one. 3232 if (!maybeParseGridLineNames(*m_valueList, *templateRows, trailingIdentW asAdded ? toCSSGridLineNamesValue(templateRows->item(templateRows->length() - 1) ) : nullptr))
3233 maybeParseGridLineNames(*m_valueList, *templateRows, toCSSGridLineNa mesValue(templateRows->item(templateRows->length() - 1))); 3233 return false;
Julien - ping for review 2015/06/04 23:17:58 Aren't you tightening our parsing here and thus th
svillar 2015/06/05 07:25:43 Actually I acknowledge that it looks like that we
3234 } else {
3235 maybeParseGridLineNames(*m_valueList, *templateRows);
3236 }
3237 3234
3238 // Handle a template-area's row. 3235 // Handle a template-area's row.
3239 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount)) 3236 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
3240 return false; 3237 return false;
3241 ++rowCount; 3238 ++rowCount;
3242 3239
3243 // Handle template-rows's track-size. 3240 // 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 ) { 3241 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 ); 3242 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList );
3246 if (!value) 3243 if (!value)
3247 return false; 3244 return false;
3248 templateRows->append(value); 3245 templateRows->append(value);
3249 } else { 3246 } else {
3250 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to)); 3247 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to));
3251 } 3248 }
3252 3249
3253 // This will handle the trailing/leading <custom-ident>* in the grammar. 3250 // This will handle the trailing/leading <custom-ident>* in the grammar.
3254 const CSSParserValue* current = m_valueList->current(); 3251 const CSSParserValue* current = m_valueList->current();
3255 trailingIdentWasAdded = current && current->unit == CSSParserValue::Valu eList && current->valueList->size() > 0; 3252 trailingIdentWasAdded = current && current->unit == CSSParserValue::Valu eList && current->valueList->size() > 0;
3256 maybeParseGridLineNames(*m_valueList, *templateRows); 3253 if (!maybeParseGridLineNames(*m_valueList, *templateRows))
3254 return false;
3257 } 3255 }
3258 3256
3259 // [<track-list> /]? 3257 // [<track-list> /]?
3260 if (templateColumns) 3258 if (templateColumns)
3261 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important); 3259 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
3262 else 3260 else
3263 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important); 3261 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important);
3264 3262
3265 // [<line-names>? <string> [<track-size> <line-names>]? ]+ 3263 // [<line-names>? <string> [<track-size> <line-names>]? ]+
3266 RefPtrWillBeRawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::crea te(gridAreaMap, rowCount, columnCount); 3264 RefPtrWillBeRawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::crea te(gridAreaMap, rowCount, columnCount);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
3434 if (!isForwardSlashOperator(m_valueList->current())) 3432 if (!isForwardSlashOperator(m_valueList->current()))
3435 return false; 3433 return false;
3436 3434
3437 if (!m_valueList->next()) 3435 if (!m_valueList->next())
3438 return false; 3436 return false;
3439 3437
3440 property = parseGridPosition(); 3438 property = parseGridPosition();
3441 return true; 3439 return true;
3442 } 3440 }
3443 3441
3444 void CSSPropertyParser::maybeParseGridLineNames(CSSParserValueList& inputList, C SSValueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineName s) 3442 static inline bool isClosingBracket(CSSParserValue* value)
jfernandez 2015/06/04 22:49:56 Shouldn't value argument be 'const' ?
Julien - ping for review 2015/06/04 23:17:58 Even better a constant reference.
svillar 2015/06/05 07:25:43 Acknowledged.
3445 { 3443 {
3446 if (!inputList.current() || inputList.current()->unit != CSSParserValue::Val ueList) 3444 return value->unit == CSSParserValue::Operator && value->iValue == ']';
3447 return; 3445 }
3448 3446
3449 CSSParserValueList* identList = inputList.current()->valueList; 3447 bool CSSPropertyParser::maybeParseGridLineNames(CSSParserValueList& inputList, C SSValueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineName s)
3450 if (!identList->size()) { 3448 {
3451 inputList.next(); 3449 if (!inputList.current() || inputList.current()->unit != CSSParserValue::Ope rator || inputList.current()->iValue != '[')
jfernandez 2015/06/04 22:49:57 Wouldn't be a good idea to define a 'isOpenBracke
svillar 2015/06/05 07:25:43 I don't think so, it'd be just used here.
3452 return; 3450 return true;
3453 }
3454 3451
3455 // Need to ensure the identList is at the heading index, since the parserLis t might have been rewound. 3452 // Skip '['
3456 identList->setCurrentIndex(0); 3453 inputList.next();
3457 3454
3458 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrail ingLineNames; 3455 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrail ingLineNames;
3459 if (!lineNames) 3456 if (!lineNames)
3460 lineNames = CSSGridLineNamesValue::create(); 3457 lineNames = CSSGridLineNamesValue::create();
3461 while (CSSParserValue* identValue = identList->current()) { 3458
3459 while (CSSParserValue* identValue = inputList.current()) {
3460 if (isClosingBracket(identValue))
3461 break;
3462
3462 if (identValue->unit != CSSPrimitiveValue::CSS_IDENT) 3463 if (identValue->unit != CSSPrimitiveValue::CSS_IDENT)
3463 return; 3464 return false;
3465
3464 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveCustomId entValue(identValue); 3466 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveCustomId entValue(identValue);
3465 lineNames->append(lineName.release()); 3467 lineNames->append(lineName.release());
3466 identList->next(); 3468 inputList.next();
3467 } 3469 }
3470
3471 if (!inputList.current() || !isClosingBracket(inputList.current()))
3472 return false;
3473
3468 if (!previousNamedAreaTrailingLineNames) 3474 if (!previousNamedAreaTrailingLineNames)
3469 valueList.append(lineNames.release()); 3475 valueList.append(lineNames.release());
3470 3476
3477 // Consume ']'
3471 inputList.next(); 3478 inputList.next();
3479 return true;
3472 } 3480 }
3473 3481
3474 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList() 3482 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList()
3475 { 3483 {
3476 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 3484 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
3477 3485
3478 CSSParserValue* value = m_valueList->current(); 3486 CSSParserValue* value = m_valueList->current();
3479 if (value->id == CSSValueNone) { 3487 if (value->id == CSSValueNone) {
3480 m_valueList->next(); 3488 m_valueList->next();
3481 return cssValuePool().createIdentifierValue(CSSValueNone); 3489 return cssValuePool().createIdentifierValue(CSSValueNone);
3482 } 3490 }
3483 3491
3484 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); 3492 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
3485 // Handle leading <ident>*. 3493 // Handle leading <ident>*.
jfernandez 2015/06/04 22:49:56 Shouldn't be <custom-ident> ?
svillar 2015/06/05 07:25:43 Yes, that's a legacy comment.
3486 maybeParseGridLineNames(*m_valueList, *values); 3494 if (!maybeParseGridLineNames(*m_valueList, *values))
3495 return nullptr;
3487 3496
3488 bool seenTrackSizeOrRepeatFunction = false; 3497 bool seenTrackSizeOrRepeatFunction = false;
3489 while (CSSParserValue* currentValue = m_valueList->current()) { 3498 while (CSSParserValue* currentValue = m_valueList->current()) {
3490 if (isForwardSlashOperator(currentValue)) 3499 if (isForwardSlashOperator(currentValue))
3491 break; 3500 break;
3492 if (currentValue->unit == CSSParserValue::Function && currentValue->func tion->id == CSSValueRepeat) { 3501 if (currentValue->unit == CSSParserValue::Function && currentValue->func tion->id == CSSValueRepeat) {
3493 if (!parseGridTrackRepeatFunction(*values)) 3502 if (!parseGridTrackRepeatFunction(*values))
3494 return nullptr; 3503 return nullptr;
3495 seenTrackSizeOrRepeatFunction = true; 3504 seenTrackSizeOrRepeatFunction = true;
3496 } else { 3505 } else {
3497 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList ); 3506 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList );
3498 if (!value) 3507 if (!value)
3499 return nullptr; 3508 return nullptr;
3500 values->append(value); 3509 values->append(value);
3501 seenTrackSizeOrRepeatFunction = true; 3510 seenTrackSizeOrRepeatFunction = true;
3502 } 3511 }
3503 // This will handle the trailing <ident>* in the grammar. 3512 // This will handle the trailing <ident>* in the grammar.
3504 maybeParseGridLineNames(*m_valueList, *values); 3513 if (!maybeParseGridLineNames(*m_valueList, *values))
3514 return nullptr;
3505 } 3515 }
3506 3516
3507 // We should have found a <track-size> or else it is not a valid <track-list > 3517 // We should have found a <track-size> or else it is not a valid <track-list >
3508 if (!seenTrackSizeOrRepeatFunction) 3518 if (!seenTrackSizeOrRepeatFunction)
3509 return nullptr; 3519 return nullptr;
3510 3520
3511 return values; 3521 return values;
3512 } 3522 }
3513 3523
3514 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) 3524 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
3515 { 3525 {
3516 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ; 3526 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
3517 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1))) 3527 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
3518 return false; 3528 return false;
3519 3529
3520 ASSERT(arguments->valueAt(0)->fValue > 0); 3530 ASSERT(arguments->valueAt(0)->fValue > 0);
3521 size_t repetitions = clampTo<size_t>(arguments->valueAt(0)->fValue, 0, kGrid MaxTracks); 3531 size_t repetitions = clampTo<size_t>(arguments->valueAt(0)->fValue, 0, kGrid MaxTracks);
3522 3532
3523 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated(); 3533 RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceS eparated();
3524 arguments->next(); // Skip the repetition count. 3534 arguments->next(); // Skip the repetition count.
3525 arguments->next(); // Skip the comma. 3535 arguments->next(); // Skip the comma.
3526 3536
3527 // Handle leading <ident>*. 3537 // Handle leading <ident>*.
jfernandez 2015/06/04 22:49:56 Ditto.
3528 maybeParseGridLineNames(*arguments, *repeatedValues); 3538 if (!maybeParseGridLineNames(*arguments, *repeatedValues))
3539 return false;
3529 3540
3530 size_t numberOfTracks = 0; 3541 size_t numberOfTracks = 0;
3531 while (arguments->current()) { 3542 while (arguments->current()) {
3532 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); 3543 RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
3533 if (!trackSize) 3544 if (!trackSize)
3534 return false; 3545 return false;
3535 3546
3536 repeatedValues->append(trackSize); 3547 repeatedValues->append(trackSize);
3537 ++numberOfTracks; 3548 ++numberOfTracks;
3538 3549
3539 // This takes care of any trailing <ident>* in the grammar. 3550 // This takes care of any trailing <ident>* in the grammar.
3540 maybeParseGridLineNames(*arguments, *repeatedValues); 3551 if (!maybeParseGridLineNames(*arguments, *repeatedValues))
Julien - ping for review 2015/06/04 23:17:58 This function is not 'maybe' parsing anymore if we
svillar 2015/06/05 07:25:43 Sure, I also thought about that.
Julien - ping for review 2015/06/05 16:51:20 The comment was basically that with the new parser
3552 return false;
3541 } 3553 }
3542 3554
3543 // We should have found at least one <track-size> or else it is not a valid <track-list>. 3555 // We should have found at least one <track-size> or else it is not a valid <track-list>.
3544 if (!numberOfTracks) 3556 if (!numberOfTracks)
3545 return false; 3557 return false;
3546 3558
3547 // We clamp the number of repetitions to a multiple of the repeat() track li st's size, while staying below the max 3559 // 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. 3560 // grid size.
3549 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); 3561 repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks);
3550 3562
(...skipping 4834 matching lines...) Expand 10 before | Expand all | Expand 10 after
8385 } 8397 }
8386 } 8398 }
8387 8399
8388 if (!list->length()) 8400 if (!list->length())
8389 return nullptr; 8401 return nullptr;
8390 8402
8391 return list.release(); 8403 return list.release();
8392 } 8404 }
8393 8405
8394 } // namespace blink 8406 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSPropertyParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698