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

Unified Diff: Source/core/css/parser/CSSParserValues.cpp

Issue 1239983004: Make CSSCalcValue work with CSSParserTokenRange (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add more subtests Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/parser/CSSParserValues.h ('k') | Source/core/css/parser/CSSPropertyParser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/parser/CSSParserValues.cpp
diff --git a/Source/core/css/parser/CSSParserValues.cpp b/Source/core/css/parser/CSSParserValues.cpp
index 0ed6621a6435ed2e1feccde3ba446f9c86b6d448..bb8c6c7d2774193789542c688026e1741bdf8123 100644
--- a/Source/core/css/parser/CSSParserValues.cpp
+++ b/Source/core/css/parser/CSSParserValues.cpp
@@ -40,15 +40,17 @@ CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU
Vector<int> bracketCounts;
stack.append(this);
bracketCounts.append(0);
- unsigned calcDepth = 0;
while (!range.atEnd()) {
ASSERT(stack.size() == bracketCounts.size());
ASSERT(!stack.isEmpty());
- const CSSParserToken& token = range.consume();
+ const CSSParserToken& token = range.peek();
+ if (token.type() != FunctionToken)
+ range.consume();
CSSParserValue value;
switch (token.type()) {
case FunctionToken: {
if (token.valueEqualsIgnoringCase("url")) {
+ range.consume();
const CSSParserToken& next = range.consumeIncludingWhitespace();
if (next.type() == BadStringToken || range.consume().type() != RightParenthesisToken) {
destroyAndClear();
@@ -62,34 +64,36 @@ CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU
break;
}
+ value.id = CSSValueInvalid;
+ value.isInt = false;
+
+ CSSValueID id = cssValueKeywordID(token.value());
+ if (id == CSSValueCalc || id == CSSValueWebkitCalc) {
+ value.m_unit = CSSParserValue::CalcFunction;
+ value.calcFunction = new CSSParserCalcFunction(range.consumeBlock());
+ break;
+ }
+ range.consume();
+ value.m_unit = CSSParserValue::Function;
CSSParserFunction* function = new CSSParserFunction;
- function->id = cssValueKeywordID(token.value());
+ function->id = id;
CSSParserValueList* list = new CSSParserValueList;
function->args = adoptPtr(list);
- value.id = CSSValueInvalid;
- value.isInt = false;
- value.m_unit = CSSParserValue::Function;
value.function = function;
stack.last()->addValue(value);
stack.append(list);
bracketCounts.append(0);
- calcDepth += (function->id == CSSValueCalc || function->id == CSSValueWebkitCalc);
continue;
}
case LeftParenthesisToken: {
- if (calcDepth == 0) {
- CSSParserValueList* list = new CSSParserValueList;
- value.setFromValueList(adoptPtr(list));
- stack.last()->addValue(value);
- stack.append(list);
- bracketCounts.append(0);
- continue;
- }
- bracketCounts.last()++;
- value.setFromOperator('(');
- break;
+ CSSParserValueList* list = new CSSParserValueList;
+ value.setFromValueList(adoptPtr(list));
+ stack.last()->addValue(value);
+ stack.append(list);
+ bracketCounts.append(0);
+ continue;
}
case RightParenthesisToken: {
if (bracketCounts.last() == 0) {
@@ -99,15 +103,8 @@ CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU
destroyAndClear();
return;
}
- CSSParserValueList* currentList = stack.last();
- CSSParserValue* current = currentList->valueAt(currentList->size()-1);
- if (current->m_unit == CSSParserValue::Function) {
- CSSValueID id = current->function->id;
- calcDepth -= (id == CSSValueCalc || id == CSSValueWebkitCalc);
- }
continue;
}
- ASSERT(calcDepth > 0);
bracketCounts.last()--;
value.setFromOperator(')');
break;
@@ -179,11 +176,6 @@ CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU
}
case DelimiterToken:
value.setFromOperator(token.delimiter());
- if (calcDepth && token.delimiter() == '+' && (&token - 1)->type() != WhitespaceToken) {
- // calc(1px+ 2px) is invalid
- destroyAndClear();
- return;
- }
break;
case CommaToken:
value.setFromOperator(',');
@@ -242,6 +234,8 @@ static void destroy(Vector<CSSParserValue, 4>& values)
for (size_t i = 0; i < numValues; i++) {
if (values[i].m_unit == CSSParserValue::Function)
delete values[i].function;
+ else if (values[i].m_unit == CSSParserValue::CalcFunction)
+ delete values[i].calcFunction;
else if (values[i].m_unit == CSSParserValue::ValueList
|| values[i].m_unit == CSSParserValue::DimensionList)
delete values[i].valueList;
« no previous file with comments | « Source/core/css/parser/CSSParserValues.h ('k') | Source/core/css/parser/CSSPropertyParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698