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

Side by Side Diff: Source/core/css/parser/BisonCSSParser-in.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: rebased and applied suggested changes. 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
« no previous file with comments | « Source/core/css/CSSShorthands.in ('k') | Source/core/css/parser/CSSPropertyParser.h » ('j') | 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 24 matching lines...) Expand all
35 #include "core/css/CSSBasicShapes.h" 35 #include "core/css/CSSBasicShapes.h"
36 #include "core/css/CSSBorderImage.h" 36 #include "core/css/CSSBorderImage.h"
37 #include "core/css/CSSCanvasValue.h" 37 #include "core/css/CSSCanvasValue.h"
38 #include "core/css/CSSCrossfadeValue.h" 38 #include "core/css/CSSCrossfadeValue.h"
39 #include "core/css/CSSCursorImageValue.h" 39 #include "core/css/CSSCursorImageValue.h"
40 #include "core/css/CSSFontFaceSrcValue.h" 40 #include "core/css/CSSFontFaceSrcValue.h"
41 #include "core/css/CSSFontFeatureValue.h" 41 #include "core/css/CSSFontFeatureValue.h"
42 #include "core/css/CSSFunctionValue.h" 42 #include "core/css/CSSFunctionValue.h"
43 #include "core/css/CSSGradientValue.h" 43 #include "core/css/CSSGradientValue.h"
44 #include "core/css/CSSGridLineNamesValue.h" 44 #include "core/css/CSSGridLineNamesValue.h"
45 #include "core/css/CSSGridTemplateAreasValue.h"
46 #include "core/css/CSSImageSetValue.h" 45 #include "core/css/CSSImageSetValue.h"
47 #include "core/css/CSSImageValue.h" 46 #include "core/css/CSSImageValue.h"
48 #include "core/css/CSSInheritedValue.h" 47 #include "core/css/CSSInheritedValue.h"
49 #include "core/css/CSSInitialValue.h" 48 #include "core/css/CSSInitialValue.h"
50 #include "core/css/CSSKeyframeRule.h" 49 #include "core/css/CSSKeyframeRule.h"
51 #include "core/css/CSSKeyframesRule.h" 50 #include "core/css/CSSKeyframesRule.h"
52 #include "core/css/CSSLineBoxContainValue.h" 51 #include "core/css/CSSLineBoxContainValue.h"
53 #include "core/css/CSSPrimitiveValue.h" 52 #include "core/css/CSSPrimitiveValue.h"
54 #include "core/css/CSSPropertySourceData.h" 53 #include "core/css/CSSPropertySourceData.h"
55 #include "core/css/CSSReflectValue.h" 54 #include "core/css/CSSReflectValue.h"
(...skipping 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 case CSSPropertyGridAutoRows: 2386 case CSSPropertyGridAutoRows:
2388 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2387 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2389 return false; 2388 return false;
2390 parsedValue = parseGridTrackSize(*m_valueList); 2389 parsedValue = parseGridTrackSize(*m_valueList);
2391 break; 2390 break;
2392 2391
2393 case CSSPropertyGridTemplateColumns: 2392 case CSSPropertyGridTemplateColumns:
2394 case CSSPropertyGridTemplateRows: 2393 case CSSPropertyGridTemplateRows:
2395 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2394 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2396 return false; 2395 return false;
2397 return parseGridTrackList(propId, important); 2396 parsedValue = parseGridTrackList(important);
2397 break;
2398 2398
2399 case CSSPropertyGridColumnEnd: 2399 case CSSPropertyGridColumnEnd:
2400 case CSSPropertyGridColumnStart: 2400 case CSSPropertyGridColumnStart:
2401 case CSSPropertyGridRowEnd: 2401 case CSSPropertyGridRowEnd:
2402 case CSSPropertyGridRowStart: 2402 case CSSPropertyGridRowStart:
2403 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2403 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2404 return false; 2404 return false;
2405 parsedValue = parseGridPosition(); 2405 parsedValue = parseGridPosition();
2406 break; 2406 break;
2407 2407
2408 case CSSPropertyGridColumn: 2408 case CSSPropertyGridColumn:
2409 case CSSPropertyGridRow: 2409 case CSSPropertyGridRow:
2410 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2410 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2411 return false; 2411 return false;
2412 return parseGridItemPositionShorthand(propId, important); 2412 return parseGridItemPositionShorthand(propId, important);
2413 2413
2414 case CSSPropertyGridArea: 2414 case CSSPropertyGridArea:
2415 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2415 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2416 return false; 2416 return false;
2417 return parseGridAreaShorthand(important); 2417 return parseGridAreaShorthand(important);
2418 2418
2419 case CSSPropertyGridTemplateAreas: 2419 case CSSPropertyGridTemplateAreas:
2420 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) 2420 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2421 return false; 2421 return false;
2422 parsedValue = parseGridTemplateAreas(); 2422 parsedValue = parseGridTemplateAreas();
2423 break; 2423 break;
2424 2424
2425 case CSSPropertyGridTemplate:
2426 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
2427 return false;
2428 return parseGridTemplateShorthand(important);
2429
2425 case CSSPropertyWebkitMarginCollapse: { 2430 case CSSPropertyWebkitMarginCollapse: {
2426 if (num == 1) { 2431 if (num == 1) {
2427 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); 2432 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
2428 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant)) 2433 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp ortant))
2429 return false; 2434 return false;
2430 CSSValue* value = m_parsedProperties.last().value(); 2435 CSSValue* value = m_parsedProperties.last().value();
2431 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important); 2436 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
2432 return true; 2437 return true;
2433 } 2438 }
2434 else if (num == 2) { 2439 else if (num == 2) {
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4602 return false; 4607 return false;
4603 } else { 4608 } else {
4604 endValue = gridMissingGridPositionValue(startValue.get()); 4609 endValue = gridMissingGridPositionValue(startValue.get());
4605 } 4610 }
4606 4611
4607 addProperty(shorthand.properties()[0], startValue, important); 4612 addProperty(shorthand.properties()[0], startValue, important);
4608 addProperty(shorthand.properties()[1], endValue, important); 4613 addProperty(shorthand.properties()[1], endValue, important);
4609 return true; 4614 return true;
4610 } 4615 }
4611 4616
4617
4618 bool CSSPropertyParser::parseGridTemplateRowsAndAreas(PassRefPtrWillBeRawPtr<CSS Value> templateColumns, bool important)
4619 {
4620 NamedGridAreaMap gridAreaMap;
4621 size_t rowCount = 0;
4622 size_t columnCount = 0;
4623 bool traillingIdentAdded = false;
4624 RefPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
4625
4626 // At least template-areas strings must be defined.
4627 if (!m_valueList->current())
4628 return false;
4629
4630 while (m_valueList->current()) {
4631 // Handle leading <custom-ident>*.
4632 if (m_valueList->current()->unit == CSSParserValue::ValueList) {
4633 if (traillingIdentAdded)
4634 parseGridLineNames(m_valueList.get(), *templateRows, static_cast <CSSGridLineNamesValue*>(templateRows->item(templateRows->length() - 1)));
Julien - ping for review 2014/03/01 01:56:12 I don't think I understand what this code is tryin
jfernandez 2014/03/03 13:02:09 The syntax indicate to concatenate one's row trail
4635 else
4636 parseGridLineNames(m_valueList.get(), *templateRows);
4637 }
4638
4639 // Handle a template-area's row.
4640 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
4641 return false;
4642 ++rowCount;
4643
4644 // Handle template-rows's track-size.
4645 if (m_valueList->current() && m_valueList->current()->unit != CSSParserV alue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING ) {
4646 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
4647 if (!value)
4648 return false;
4649 templateRows->append(value);
4650 } else {
4651 templateRows->append(cssValuePool().createIdentifierValue(CSSValueAu to));
4652 }
4653
4654 // This will handle the trailing/leading <custom-ident>* in the grammar.
4655 traillingIdentAdded = false;
4656 if (m_valueList->current() && m_valueList->current()->unit == CSSParserV alue::ValueList) {
4657 parseGridLineNames(m_valueList.get(), *templateRows);
4658 traillingIdentAdded = true;
4659 }
4660 }
4661
4662 // [<track-list> /]?
4663 if (templateColumns)
4664 addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
4665 else
4666 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdenti fierValue(CSSValueNone), important);
4667
4668 // [<line-names>? <string> [<track-size> <line-names>]? ]+
4669 RefPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaM ap, rowCount, columnCount);
4670 addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important );
4671 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important);
4672
4673
4674 return true;
4675 }
4676
4677
4678 bool CSSPropertyParser::parseGridTemplateShorthand(bool important)
4679 {
4680 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
4681
4682 ShorthandScope scope(this, CSSPropertyGridTemplate);
4683 ASSERT(gridTemplateShorthand().length() == 3);
4684
4685 // At least "none" defined.
4686 if (!m_valueList->current())
4687 return false;
4688
4689 RefPtr<CSSValue> columnsValue;
4690 RefPtr<CSSValue> rowsValue;
4691 unsigned index = 0;
4692 bool firstValueIsNone = m_valueList->current()->id == CSSValueNone;
Julien - ping for review 2014/03/01 01:56:12 I think it would be better if we returned early fo
jfernandez 2014/03/03 13:02:09 Done.
4693
4694 if (columnsValue = parseGridTrackList(important)) {
4695 if (!m_valueList->current()) {
4696 if (firstValueIsNone)
4697 rowsValue = cssValuePool().createIdentifierValue(CSSValueNone);
4698 } else if (isForwardSlashOperator(m_valueList->current()) && m_valueList ->next()) {
4699 index = m_valueList->currentIndex();
4700 rowsValue = parseGridTrackList(important);
4701 }
4702 }
4703
4704 // <grid-template-columns> / <grid-template-columns> syntax.
4705 if (columnsValue && rowsValue) {
4706 addProperty(CSSPropertyGridTemplateColumns, columnsValue, important);
4707 addProperty(CSSPropertyGridTemplateRows, rowsValue, important);
4708 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifie rValue(CSSValueNone), important);
4709 return !m_valueList->current();
Julien - ping for review 2014/03/01 01:56:12 I don't think we should be setting the values if w
jfernandez 2014/03/03 13:02:09 Done.
4710 }
4711
4712 if (columnsValue && firstValueIsNone)
Julien - ping for review 2014/03/01 01:56:12 Isn't this check redundant? If firstValueIsNone is
jfernandez 2014/03/03 13:02:09 You are right, I must be blind :) Anyway, I've eve
4713 return false; // <track-list> can't be 'none'.
4714
4715 // Need to rewind parsing to explore the alternative syntax.
4716 m_valueList->setCurrentIndex(index);
4717
4718 // [<track-list> /]? [<line-names>? <string> [<track-size> <line-names>]? ]+ syntax.
4719 return parseGridTemplateRowsAndAreas(columnsValue, important);
4720 }
4721
4722
4612 bool CSSPropertyParser::parseGridAreaShorthand(bool important) 4723 bool CSSPropertyParser::parseGridAreaShorthand(bool important)
4613 { 4724 {
4614 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 4725 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
4615 4726
4616 ShorthandScope scope(this, CSSPropertyGridArea); 4727 ShorthandScope scope(this, CSSPropertyGridArea);
4617 const StylePropertyShorthand& shorthand = gridAreaShorthand(); 4728 const StylePropertyShorthand& shorthand = gridAreaShorthand();
4618 ASSERT_UNUSED(shorthand, shorthand.length() == 4); 4729 ASSERT_UNUSED(shorthand, shorthand.length() == 4);
4619 4730
4620 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition(); 4731 RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition();
4621 if (!rowStartValue) 4732 if (!rowStartValue)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 if (!isForwardSlashOperator(m_valueList->current())) 4768 if (!isForwardSlashOperator(m_valueList->current()))
4658 return false; 4769 return false;
4659 4770
4660 if (!m_valueList->next()) 4771 if (!m_valueList->next())
4661 return false; 4772 return false;
4662 4773
4663 property = parseGridPosition(); 4774 property = parseGridPosition();
4664 return true; 4775 return true;
4665 } 4776 }
4666 4777
4667 void CSSPropertyParser::parseGridLineNames(CSSParserValueList* parserValueList, CSSValueList& valueList) 4778 void CSSPropertyParser::parseGridLineNames(CSSParserValueList* parserValueList, CSSValueList& valueList, CSSGridLineNamesValue* lineNamesToConcat)
4668 { 4779 {
4669 ASSERT(parserValueList->current() && parserValueList->current()->unit == CSS ParserValue::ValueList); 4780 ASSERT(parserValueList->current() && parserValueList->current()->unit == CSS ParserValue::ValueList);
4670 4781
4671 CSSParserValueList* identList = parserValueList->current()->valueList; 4782 CSSParserValueList* identList = parserValueList->current()->valueList;
4672 if (!identList->size()) { 4783 if (!identList->size()) {
4673 parserValueList->next(); 4784 parserValueList->next();
4674 return; 4785 return;
4675 } 4786 }
4676 4787
4677 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue: :create(); 4788 // Need to ensure the identList is at the heading index, since the parserLis t might have been rewound.
4789 identList->setCurrentIndex(0);
Julien - ping for review 2014/03/01 01:56:12 That's a really bad smell that we need this line.
jfernandez 2014/03/03 13:02:09 Yeah, this change is interesting. I found out that
4790
4791 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = lineNamesToConcat ? li neNamesToConcat : CSSGridLineNamesValue::create();
4678 while (CSSParserValue* identValue = identList->current()) { 4792 while (CSSParserValue* identValue = identList->current()) {
4679 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT); 4793 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT);
4680 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue); 4794 RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringVa lue(identValue);
4681 lineNames->append(lineName.release()); 4795 lineNames->append(lineName.release());
4682 identList->next(); 4796 identList->next();
4683 } 4797 }
4684 valueList.append(lineNames.release()); 4798 if (!lineNamesToConcat)
4799 valueList.append(lineNames.release());
4685 4800
4686 parserValueList->next(); 4801 parserValueList->next();
4687 } 4802 }
4688 4803
4689 bool CSSPropertyParser::parseGridTrackList(CSSPropertyID propId, bool important) 4804 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList(bool impo rtant)
4690 { 4805 {
4691 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); 4806 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
4692 4807
4693 CSSParserValue* value = m_valueList->current(); 4808 CSSParserValue* value = m_valueList->current();
4694 if (value->id == CSSValueNone) { 4809 if (value->id == CSSValueNone) {
4695 if (m_valueList->next()) 4810 m_valueList->next();
4696 return false; 4811 return cssValuePool().createIdentifierValue(CSSValueNone);
4697
4698 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp ortant);
4699 return true;
4700 } 4812 }
4701 4813
4702 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated (); 4814 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated ();
4703 // Handle leading <ident>*. 4815 // Handle leading <ident>*.
4704 value = m_valueList->current(); 4816 value = m_valueList->current();
4705 if (value && value->unit == CSSParserValue::ValueList) 4817 if (value && value->unit == CSSParserValue::ValueList)
4706 parseGridLineNames(m_valueList.get(), *values); 4818 parseGridLineNames(m_valueList.get(), *values);
4707 4819
4708 bool seenTrackSizeOrRepeatFunction = false; 4820 bool seenTrackSizeOrRepeatFunction = false;
4709 while (CSSParserValue* currentValue = m_valueList->current()) { 4821 while (CSSParserValue* currentValue = m_valueList->current()) {
4822 if (isForwardSlashOperator(currentValue))
4823 break;
4710 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) { 4824 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase( currentValue->function->name, "repeat(")) {
4711 if (!parseGridTrackRepeatFunction(*values)) 4825 if (!parseGridTrackRepeatFunction(*values))
4712 return false; 4826 return nullptr;
4713 seenTrackSizeOrRepeatFunction = true; 4827 seenTrackSizeOrRepeatFunction = true;
4714 } else { 4828 } else {
4715 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList ); 4829 RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList );
4716 if (!value) 4830 if (!value)
4717 return false; 4831 return nullptr;
4718 values->append(value); 4832 values->append(value);
4719 seenTrackSizeOrRepeatFunction = true; 4833 seenTrackSizeOrRepeatFunction = true;
4720 } 4834 }
4721 // This will handle the trailing <ident>* in the grammar. 4835 // This will handle the trailing <ident>* in the grammar.
4722 value = m_valueList->current(); 4836 value = m_valueList->current();
4723 if (value && value->unit == CSSParserValue::ValueList) 4837 if (value && value->unit == CSSParserValue::ValueList)
4724 parseGridLineNames(m_valueList.get(), *values); 4838 parseGridLineNames(m_valueList.get(), *values);
4725 } 4839 }
4726 4840
4727 // We should have found a <track-size> or else it is not a valid <track-list > 4841 // We should have found a <track-size> or else it is not a valid <track-list >
4728 if (!seenTrackSizeOrRepeatFunction) 4842 if (!seenTrackSizeOrRepeatFunction)
4729 return false; 4843 return nullptr;
4730 4844
4731 addProperty(propId, values.release(), important); 4845 return values;
4732 return true;
4733 } 4846 }
4734 4847
4735 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list) 4848 bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
4736 { 4849 {
4737 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ; 4850 CSSParserValueList* arguments = m_valueList->current()->function->args.get() ;
4738 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1))) 4851 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
4739 return false; 4852 return false;
4740 4853
4741 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0); 4854 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0);
4742 size_t repetitions = arguments->valueAt(0)->fValue; 4855 size_t repetitions = arguments->valueAt(0)->fValue;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
4820 4933
4821 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR); 4934 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
4822 } 4935 }
4823 4936
4824 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) 4937 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
4825 return nullptr; 4938 return nullptr;
4826 4939
4827 return createPrimitiveNumericValue(currentValue); 4940 return createPrimitiveNumericValue(currentValue);
4828 } 4941 }
4829 4942
4943 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
4944 {
4945 CSSParserValue* currentValue = m_valueList->current();
4946 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
4947 return false;
4948
4949 String gridRowNames = currentValue->string;
4950 if (!gridRowNames.length())
4951 return false;
4952
4953 Vector<String> columnNames;
4954 gridRowNames.split(' ', columnNames);
4955
4956 if (!columnCount) {
4957 columnCount = columnNames.size();
4958 ASSERT(columnCount);
4959 } else if (columnCount != columnNames.size()) {
4960 // The declaration is invalid is all the rows don't have the number of c olumns.
4961 return false;
4962 }
4963
4964 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
4965 const String& gridAreaName = columnNames[currentCol];
4966
4967 // Unamed areas are always valid (we consider them to be 1x1).
4968 if (gridAreaName == ".")
4969 continue;
4970
4971 // We handle several grid areas with the same name at once to simplify t he validation code.
4972 size_t lookAheadCol;
4973 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) {
4974 if (columnNames[lookAheadCol + 1] != gridAreaName)
4975 break;
4976 }
4977
4978 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
4979 if (gridAreaIt == gridAreaMap.end()) {
4980 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowC ount), GridSpan(currentCol, lookAheadCol)));
4981 } else {
4982 GridCoordinate& gridCoordinate = gridAreaIt->value;
4983
4984 // The following checks test that the grid area is a single filled-i n rectangle.
4985 // 1. The new row is adjacent to the previously parsed row.
4986 if (rowCount != gridCoordinate.rows.initialPositionIndex + 1)
4987 return false;
4988
4989 // 2. The new area starts at the same position as the previously par sed area.
4990 if (currentCol != gridCoordinate.columns.initialPositionIndex)
4991 return false;
4992
4993 // 3. The new area ends at the same position as the previously parse d area.
4994 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
4995 return false;
4996
4997 ++gridCoordinate.rows.finalPositionIndex;
4998 }
4999 currentCol = lookAheadCol;
5000 }
5001
5002 m_valueList->next();
5003 return true;
5004 }
5005
4830 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas() 5006 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas()
4831 { 5007 {
4832 NamedGridAreaMap gridAreaMap; 5008 NamedGridAreaMap gridAreaMap;
4833 size_t rowCount = 0; 5009 size_t rowCount = 0;
4834 size_t columnCount = 0; 5010 size_t columnCount = 0;
4835 5011
4836 while (CSSParserValue* currentValue = m_valueList->current()) { 5012 while (m_valueList->current()) {
4837 if (currentValue->unit != CSSPrimitiveValue::CSS_STRING) 5013 if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
4838 return nullptr; 5014 return nullptr;
4839
4840 String gridRowNames = currentValue->string;
4841 if (!gridRowNames.length())
4842 return nullptr;
4843
4844 Vector<String> columnNames;
4845 gridRowNames.split(' ', columnNames);
4846
4847 if (!columnCount) {
4848 columnCount = columnNames.size();
4849 ASSERT(columnCount);
4850 } else if (columnCount != columnNames.size()) {
4851 // The declaration is invalid is all the rows don't have the number of columns.
4852 return nullptr;
4853 }
4854
4855 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
4856 const String& gridAreaName = columnNames[currentCol];
4857
4858 // Unamed areas are always valid (we consider them to be 1x1).
4859 if (gridAreaName == ".")
4860 continue;
4861
4862 // We handle several grid areas with the same name at once to simpli fy the validation code.
4863 size_t lookAheadCol;
4864 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++ lookAheadCol) {
4865 if (columnNames[lookAheadCol + 1] != gridAreaName)
4866 break;
4867 }
4868
4869 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaNam e);
4870 if (gridAreaIt == gridAreaMap.end()) {
4871 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowCount), GridSpan(currentCol, lookAheadCol)));
4872 } else {
4873 GridCoordinate& gridCoordinate = gridAreaIt->value;
4874
4875 // The following checks test that the grid area is a single fill ed-in rectangle.
4876 // 1. The new row is adjacent to the previously parsed row.
4877 if (rowCount != gridCoordinate.rows.initialPositionIndex + 1)
4878 return nullptr;
4879
4880 // 2. The new area starts at the same position as the previously parsed area.
4881 if (currentCol != gridCoordinate.columns.initialPositionIndex)
4882 return nullptr;
4883
4884 // 3. The new area ends at the same position as the previously p arsed area.
4885 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
4886 return nullptr;
4887
4888 ++gridCoordinate.rows.finalPositionIndex;
4889 }
4890 currentCol = lookAheadCol;
4891 }
4892
4893 ++rowCount; 5015 ++rowCount;
4894 m_valueList->next();
4895 } 5016 }
4896 5017
4897 if (!rowCount || !columnCount) 5018 if (!rowCount || !columnCount)
4898 return nullptr; 5019 return nullptr;
4899 5020
4900 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ; 5021 return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount) ;
4901 } 5022 }
4902 5023
4903 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters) 5024 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse rValueList* args, bool counters)
4904 { 5025 {
(...skipping 5260 matching lines...) Expand 10 before | Expand all | Expand 10 after
10165 { 10286 {
10166 // The tokenizer checks for the construct of an+b. 10287 // The tokenizer checks for the construct of an+b.
10167 // However, since the {ident} rule precedes the {nth} rule, some of those 10288 // However, since the {ident} rule precedes the {nth} rule, some of those
10168 // tokens are identified as string literal. Furthermore we need to accept 10289 // tokens are identified as string literal. Furthermore we need to accept
10169 // "odd" and "even" which does not match to an+b. 10290 // "odd" and "even" which does not match to an+b.
10170 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 10291 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
10171 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 10292 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
10172 } 10293 }
10173 10294
10174 } 10295 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSShorthands.in ('k') | Source/core/css/parser/CSSPropertyParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698