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

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

Issue 1178503003: [CSS Grid Layout] Fix grid-template-areas parsing to avoid spaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 | « LayoutTests/fast/css-grid-layout/grid-template-areas-get-set-expected.txt ('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 3654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 3665
3666 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR); 3666 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
3667 } 3667 }
3668 3668
3669 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) 3669 if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
3670 return nullptr; 3670 return nullptr;
3671 3671
3672 return createPrimitiveNumericValue(currentValue); 3672 return createPrimitiveNumericValue(currentValue);
3673 } 3673 }
3674 3674
3675 static bool containsOnlyDots(const String& string) 3675 static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNam es)
3676 { 3676 {
3677 ASSERT(!string.isEmpty()); 3677 ASSERT(!gridRowNames.isEmpty());
3678 StringImpl& text = *string.impl(); 3678 Vector<String> columnNames;
3679 StringImpl& text = *gridRowNames.impl();
Julien - ping for review 2015/06/10 15:31:18 I would like a comment for this. I assume this is
Manuel Rego 2015/06/10 20:41:45 Yes. Added a comment.
3680
3681 String areaName = "";
Julien - ping for review 2015/06/10 15:31:18 You want to use StringBuilder to avoid unneeded bu
Manuel Rego 2015/06/10 20:41:45 Done.
3679 for (unsigned i = 0; i < text.length(); ++i) { 3682 for (unsigned i = 0; i < text.length(); ++i) {
3680 if (text[i] != '.') 3683 if (text[i] == ' ') {
3681 return false; 3684 if (!areaName.isEmpty()) {
3685 columnNames.append(areaName);
3686 areaName = "";
3687 }
3688 continue;
3689 }
3690 if (text[i] == '.') {
3691 if (areaName == ".")
3692 continue;
3693 if (!areaName.isEmpty()) {
3694 columnNames.append(areaName);
3695 areaName = "";
3696 }
3697 } else {
3698 if (areaName == ".") {
3699 columnNames.append(areaName);
3700 areaName = "";
3701 }
3702 }
3703
3704 areaName.append(text[i]);
3682 } 3705 }
3683 return true; 3706
3707 if (!areaName.isEmpty())
3708 columnNames.append(areaName);
3709
3710 return columnNames;
3684 } 3711 }
3685 3712
3686 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount) 3713 bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
3687 { 3714 {
3688 CSSParserValue* currentValue = m_valueList->current(); 3715 CSSParserValue* currentValue = m_valueList->current();
3689 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING) 3716 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
3690 return false; 3717 return false;
3691 3718
3692 String gridRowNames = currentValue->string; 3719 String gridRowNames = currentValue->string;
3693 if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace()) 3720 if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace())
3694 return false; 3721 return false;
3695 3722
3696 Vector<String> columnNames; 3723 Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames) ;
3697 gridRowNames.split(' ', columnNames);
3698
3699 if (!columnCount) { 3724 if (!columnCount) {
3700 columnCount = columnNames.size(); 3725 columnCount = columnNames.size();
3701 ASSERT(columnCount); 3726 ASSERT(columnCount);
3702 } else if (columnCount != columnNames.size()) { 3727 } else if (columnCount != columnNames.size()) {
3703 // The declaration is invalid is all the rows don't have the number of c olumns. 3728 // The declaration is invalid is all the rows don't have the number of c olumns.
3704 return false; 3729 return false;
3705 } 3730 }
3706 3731
3707 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) { 3732 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
3708 const String& gridAreaName = columnNames[currentCol]; 3733 const String& gridAreaName = columnNames[currentCol];
3709 3734
3710 // Unamed areas are always valid (we consider them to be 1x1). 3735 // Unamed areas are always valid (we consider them to be 1x1).
3711 if (containsOnlyDots(gridAreaName)) 3736 if (gridAreaName == ".")
3712 continue; 3737 continue;
3713 3738
3714 // We handle several grid areas with the same name at once to simplify t he validation code. 3739 // We handle several grid areas with the same name at once to simplify t he validation code.
3715 size_t lookAheadCol; 3740 size_t lookAheadCol;
3716 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) { 3741 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++look AheadCol) {
3717 if (columnNames[lookAheadCol + 1] != gridAreaName) 3742 if (columnNames[lookAheadCol + 1] != gridAreaName)
3718 break; 3743 break;
3719 } 3744 }
3720 3745
3721 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName); 3746 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
(...skipping 4755 matching lines...) Expand 10 before | Expand all | Expand 10 after
8477 } 8502 }
8478 } 8503 }
8479 8504
8480 if (!list->length()) 8505 if (!list->length())
8481 return nullptr; 8506 return nullptr;
8482 8507
8483 return list.release(); 8508 return list.release();
8484 } 8509 }
8485 8510
8486 } // namespace blink 8511 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/css-grid-layout/grid-template-areas-get-set-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698