Commit 8091ef81 authored by bugsnash's avatar bugsnash Committed by Commit bot

Refactored out property specific logic in animation list parsing.

Replaced animation list parsing method ConsumeAnimationPropertyList
with a new more general list parsing method ConsumeCommaSeparatedList.
This removes the need to pass property information to the list parsing
method, instead passing a callback function to be called on each of the
items in the list.

This is pre work to implementing the parseSingleValue method in the
property APIs for the animation properties that expect a list, as the
APIs do not take property as an argument.

The new ConsumeCommaSeparatedList method can be used in other parts of
the code base, which may be done in future patches.

This patch
- Added ConsumeCommaSeparatedList templated function to
  CSSPropertyParserHelpers
- Made each animation list property in parseSingleValue use the new
  ConsumeCommaSeparatedList method instead of
  ConsumeAnimationPropertyList
- Deleted ConsumeAnimationPropertyList method

BUG=668012

Review-Url: https://codereview.chromium.org/2849363002
Cr-Commit-Position: refs/heads/master@{#469569}
parent a2a5081b
...@@ -501,26 +501,6 @@ static bool IsValidAnimationPropertyList(const CSSValueList& value_list) { ...@@ -501,26 +501,6 @@ static bool IsValidAnimationPropertyList(const CSSValueList& value_list) {
return true; return true;
} }
static CSSValueList* ConsumeAnimationPropertyList(
CSSPropertyID property,
CSSParserTokenRange& range,
const CSSParserContext* context,
bool use_legacy_parsing) {
CSSValueList* list = CSSValueList::CreateCommaSeparated();
do {
CSSValue* value =
ConsumeAnimationValue(property, range, context, use_legacy_parsing);
if (!value)
return nullptr;
list->Append(*value);
} while (ConsumeCommaIncludingWhitespace(range));
if (property == CSSPropertyTransitionProperty &&
!IsValidAnimationPropertyList(*list))
return nullptr;
DCHECK(list->length());
return list;
}
bool CSSPropertyParser::ConsumeAnimationShorthand( bool CSSPropertyParser::ConsumeAnimationShorthand(
const StylePropertyShorthand& shorthand, const StylePropertyShorthand& shorthand,
bool use_legacy_parsing, bool use_legacy_parsing,
...@@ -1689,19 +1669,40 @@ const CSSValue* CSSPropertyParser::ParseSingleValue( ...@@ -1689,19 +1669,40 @@ const CSSValue* CSSPropertyParser::ParseSingleValue(
return ConsumeLocale(range_); return ConsumeLocale(range_);
case CSSPropertyAnimationDelay: case CSSPropertyAnimationDelay:
case CSSPropertyTransitionDelay: case CSSPropertyTransitionDelay:
return ConsumeCommaSeparatedList(ConsumeTime, range_, kValueRangeAll);
case CSSPropertyAnimationDirection: case CSSPropertyAnimationDirection:
return ConsumeCommaSeparatedList(
ConsumeIdent<CSSValueNormal, CSSValueAlternate, CSSValueReverse,
CSSValueAlternateReverse>,
range_);
case CSSPropertyAnimationDuration: case CSSPropertyAnimationDuration:
case CSSPropertyTransitionDuration: case CSSPropertyTransitionDuration:
return ConsumeCommaSeparatedList(ConsumeTime, range_,
kValueRangeNonNegative);
case CSSPropertyAnimationFillMode: case CSSPropertyAnimationFillMode:
return ConsumeCommaSeparatedList(
ConsumeIdent<CSSValueNone, CSSValueForwards, CSSValueBackwards,
CSSValueBoth>,
range_);
case CSSPropertyAnimationIterationCount: case CSSPropertyAnimationIterationCount:
return ConsumeCommaSeparatedList(ConsumeAnimationIterationCount, range_);
case CSSPropertyAnimationName: case CSSPropertyAnimationName:
return ConsumeCommaSeparatedList(
ConsumeAnimationName, range_, context_,
unresolved_property == CSSPropertyAliasWebkitAnimationName);
case CSSPropertyAnimationPlayState: case CSSPropertyAnimationPlayState:
case CSSPropertyTransitionProperty: return ConsumeCommaSeparatedList(
ConsumeIdent<CSSValueRunning, CSSValuePaused>, range_);
case CSSPropertyTransitionProperty: {
CSSValueList* list =
ConsumeCommaSeparatedList(ConsumeTransitionProperty, range_);
if (!list || !IsValidAnimationPropertyList(*list))
return nullptr;
return list;
}
case CSSPropertyAnimationTimingFunction: case CSSPropertyAnimationTimingFunction:
case CSSPropertyTransitionTimingFunction: case CSSPropertyTransitionTimingFunction:
return ConsumeAnimationPropertyList( return ConsumeCommaSeparatedList(ConsumeAnimationTimingFunction, range_);
property, range_, context_,
unresolved_property == CSSPropertyAliasWebkitAnimationName);
case CSSPropertyGridColumnGap: case CSSPropertyGridColumnGap:
case CSSPropertyGridRowGap: case CSSPropertyGridRowGap:
return ConsumeLengthOrPercent(range_, context_->Mode(), return ConsumeLengthOrPercent(range_, context_->Mode(),
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "core/css/CSSCustomIdentValue.h" #include "core/css/CSSCustomIdentValue.h"
#include "core/css/CSSIdentifierValue.h" #include "core/css/CSSIdentifierValue.h"
#include "core/css/CSSPrimitiveValue.h" #include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/parser/CSSParserMode.h" #include "core/css/parser/CSSParserMode.h"
#include "core/css/parser/CSSParserTokenRange.h" #include "core/css/parser/CSSParserTokenRange.h"
#include "platform/Length.h" // For ValueRange #include "platform/Length.h" // For ValueRange
...@@ -121,6 +122,24 @@ CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) { ...@@ -121,6 +122,24 @@ CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) {
return CSSIdentifierValue::Create(range.ConsumeIncludingWhitespace().Id()); return CSSIdentifierValue::Create(range.ConsumeIncludingWhitespace().Id());
} }
// ConsumeCommaSeparatedList takes a callback function to call on each item in
// the list, followed by the arguments to pass to this callback.
// The first argument to the callback must be the CSSParserTokenRange
template <typename Func, typename... Args>
CSSValueList* ConsumeCommaSeparatedList(Func callback,
CSSParserTokenRange& range,
Args... args) {
CSSValueList* list = CSSValueList::CreateCommaSeparated();
do {
CSSValue* value = callback(range, args...);
if (!value)
return nullptr;
list->Append(*value);
} while (ConsumeCommaIncludingWhitespace(range));
DCHECK(list->length());
return list;
}
} // namespace CSSPropertyParserHelpers } // namespace CSSPropertyParserHelpers
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment