Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp |
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp |
index 9b495d1cee0403632f8f4e33a90f92d5e349816e..f2c441391cf298e78ec8986d8da014e8506eb551 100644 |
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp |
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp |
@@ -323,7 +323,19 @@ CSSPrimitiveValue* ConsumeLengthOrPercent(CSSParserTokenRange& range, |
return nullptr; |
} |
-CSSPrimitiveValue* ConsumeAngle(CSSParserTokenRange& range) { |
+CSSPrimitiveValue* ConsumeGradientLengthOrPercent( |
alancutter (OOO until 2018)
2017/05/25 01:53:16
I don't understand the purpose of this function, c
Eric Willigers
2017/05/25 02:56:41
ConsumeLengthOrPercent accepts a CSSParserMode.
Fo
alancutter (OOO until 2018)
2017/05/25 03:11:52
Ack. You should make this reason clear in the desc
Eric Willigers
2017/05/25 03:58:14
Done.
|
+ CSSParserTokenRange& range, |
+ const CSSParserContext& context, |
+ ValueRange value_range, |
+ UnitlessQuirk unitless) { |
+ return ConsumeLengthOrPercent(range, context.Mode(), value_range, unitless); |
+} |
+ |
+CSSPrimitiveValue* ConsumeAngle( |
+ CSSParserTokenRange& range, |
+ const CSSParserContext& context, |
+ UnitlessQuirk angleQuirk, |
+ WTF::Optional<UseCounter::Feature> literalZeroFeature) { |
alancutter (OOO until 2018)
2017/05/25 01:53:16
DCHECK that the quirk is disallowed iff the featur
Eric Willigers
2017/05/25 02:56:41
Retiring the quirk argument, it was added in an ea
|
const CSSParserToken& token = range.Peek(); |
if (token.GetType() == kDimensionToken) { |
switch (token.GetUnitType()) { |
@@ -338,8 +350,10 @@ CSSPrimitiveValue* ConsumeAngle(CSSParserTokenRange& range) { |
return nullptr; |
} |
} |
- if (token.GetType() == kNumberToken && token.NumericValue() == 0) { |
+ if (token.GetType() == kNumberToken && token.NumericValue() == 0 && |
+ literalZeroFeature) { |
alancutter (OOO until 2018)
2017/05/25 01:53:16
Use the quirk parameter instead. It's completely u
|
range.ConsumeIncludingWhitespace(); |
+ context.Count(*literalZeroFeature); |
return CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kDegrees); |
} |
CalcParser calc_parser(range, kValueRangeAll); |
@@ -958,13 +972,16 @@ static CSSValue* ConsumeDeprecatedGradient(CSSParserTokenRange& args, |
return result; |
} |
-static CSSPrimitiveValue* ConsumeAngleOrPercent(CSSParserTokenRange& range, |
- CSSParserMode, |
- ValueRange value_range, |
- UnitlessQuirk) { |
+static CSSPrimitiveValue* ConsumeGradientAngleOrPercent( |
+ CSSParserTokenRange& range, |
+ const CSSParserContext& context, |
+ ValueRange value_range, |
+ UnitlessQuirk) { |
const CSSParserToken& token = range.Peek(); |
- if (token.GetType() == kDimensionToken || token.GetType() == kNumberToken) |
- return ConsumeAngle(range); |
+ if (token.GetType() == kDimensionToken || token.GetType() == kNumberToken) { |
+ return ConsumeAngle(range, context, UnitlessQuirk::kAllow, |
+ UseCounter::kZeroAngleGradient); |
+ } |
if (token.GetType() == kPercentageToken) |
return ConsumePercent(range, value_range); |
CalcParser calc_parser(range, value_range); |
@@ -978,12 +995,12 @@ static CSSPrimitiveValue* ConsumeAngleOrPercent(CSSParserTokenRange& range, |
} |
using PositionFunctor = CSSPrimitiveValue* (*)(CSSParserTokenRange&, |
- CSSParserMode, |
+ const CSSParserContext&, |
ValueRange, |
UnitlessQuirk); |
static bool ConsumeGradientColorStops(CSSParserTokenRange& range, |
- CSSParserMode css_parser_mode, |
+ const CSSParserContext& context, |
CSSGradientValue* gradient, |
PositionFunctor consume_position_func) { |
bool supports_color_hints = gradient->GradientType() == kCSSLinearGradient || |
@@ -994,12 +1011,12 @@ static bool ConsumeGradientColorStops(CSSParserTokenRange& range, |
bool previous_stop_was_color_hint = true; |
do { |
CSSGradientColorStop stop; |
- stop.color_ = ConsumeColor(range, css_parser_mode); |
+ stop.color_ = ConsumeColor(range, context.Mode()); |
// Two hints in a row are not allowed. |
if (!stop.color_ && (!supports_color_hints || previous_stop_was_color_hint)) |
return false; |
previous_stop_was_color_hint = !stop.color_; |
- stop.offset_ = consume_position_func(range, css_parser_mode, kValueRangeAll, |
+ stop.offset_ = consume_position_func(range, context, kValueRangeAll, |
UnitlessQuirk::kForbid); |
if (!stop.color_ && !stop.offset_) |
return false; |
@@ -1010,8 +1027,8 @@ static bool ConsumeGradientColorStops(CSSParserTokenRange& range, |
continue; |
// Optional second position. |
- stop.offset_ = consume_position_func( |
- range, css_parser_mode, kValueRangeAll, UnitlessQuirk::kForbid); |
+ stop.offset_ = consume_position_func(range, context, kValueRangeAll, |
+ UnitlessQuirk::kForbid); |
if (stop.offset_) |
gradient->AddStop(stop); |
} |
@@ -1025,12 +1042,13 @@ static bool ConsumeGradientColorStops(CSSParserTokenRange& range, |
return gradient->StopCount() >= 2; |
} |
-static CSSValue* ConsumeDeprecatedRadialGradient(CSSParserTokenRange& args, |
- CSSParserMode css_parser_mode, |
- CSSGradientRepeat repeating) { |
+static CSSValue* ConsumeDeprecatedRadialGradient( |
+ CSSParserTokenRange& args, |
+ const CSSParserContext& context, |
+ CSSGradientRepeat repeating) { |
CSSValue* center_x = nullptr; |
CSSValue* center_y = nullptr; |
- ConsumeOneOrTwoValuedPosition(args, css_parser_mode, UnitlessQuirk::kForbid, |
+ ConsumeOneOrTwoValuedPosition(args, context.Mode(), UnitlessQuirk::kForbid, |
center_x, center_y); |
if ((center_x || center_y) && !ConsumeCommaIncludingWhitespace(args)) |
return nullptr; |
@@ -1049,10 +1067,10 @@ static CSSValue* ConsumeDeprecatedRadialGradient(CSSParserTokenRange& args, |
const CSSPrimitiveValue* vertical_size = nullptr; |
if (!shape && !size_keyword) { |
horizontal_size = |
- ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeAll); |
+ ConsumeLengthOrPercent(args, context.Mode(), kValueRangeAll); |
if (horizontal_size) { |
vertical_size = |
- ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeAll); |
+ ConsumeLengthOrPercent(args, context.Mode(), kValueRangeAll); |
if (!vertical_size) |
return nullptr; |
ConsumeCommaIncludingWhitespace(args); |
@@ -1064,8 +1082,8 @@ static CSSValue* ConsumeDeprecatedRadialGradient(CSSParserTokenRange& args, |
CSSGradientValue* result = CSSRadialGradientValue::Create( |
center_x, center_y, shape, size_keyword, horizontal_size, vertical_size, |
repeating, kCSSPrefixedRadialGradient); |
- return ConsumeGradientColorStops(args, css_parser_mode, result, |
- ConsumeLengthOrPercent) |
+ return ConsumeGradientColorStops(args, context, result, |
+ ConsumeGradientLengthOrPercent) |
? result |
: nullptr; |
} |
@@ -1153,18 +1171,19 @@ static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args, |
CSSGradientValue* result = CSSRadialGradientValue::Create( |
center_x, center_y, shape, size_keyword, horizontal_size, vertical_size, |
repeating, kCSSRadialGradient); |
- return ConsumeGradientColorStops(args, context.Mode(), result, |
- ConsumeLengthOrPercent) |
+ return ConsumeGradientColorStops(args, context, result, |
+ ConsumeGradientLengthOrPercent) |
? result |
: nullptr; |
} |
static CSSValue* ConsumeLinearGradient(CSSParserTokenRange& args, |
- CSSParserMode css_parser_mode, |
+ const CSSParserContext& context, |
CSSGradientRepeat repeating, |
CSSGradientType gradient_type) { |
bool expect_comma = true; |
- const CSSPrimitiveValue* angle = ConsumeAngle(args); |
+ const CSSPrimitiveValue* angle = ConsumeAngle( |
+ args, context, UnitlessQuirk::kAllow, UseCounter::kZeroAngleGradient); |
const CSSIdentifierValue* end_x = nullptr; |
const CSSIdentifierValue* end_y = nullptr; |
if (!angle) { |
@@ -1190,8 +1209,8 @@ static CSSValue* ConsumeLinearGradient(CSSParserTokenRange& args, |
CSSGradientValue* result = CSSLinearGradientValue::Create( |
end_x, end_y, nullptr, nullptr, angle, repeating, gradient_type); |
- return ConsumeGradientColorStops(args, css_parser_mode, result, |
- ConsumeLengthOrPercent) |
+ return ConsumeGradientColorStops(args, context, result, |
+ ConsumeGradientLengthOrPercent) |
? result |
: nullptr; |
} |
@@ -1204,7 +1223,8 @@ static CSSValue* ConsumeConicGradient(CSSParserTokenRange& args, |
const CSSPrimitiveValue* from_angle = nullptr; |
if (ConsumeIdent<CSSValueFrom>(args)) { |
- if (!(from_angle = ConsumeAngle(args))) |
+ if (!(from_angle = ConsumeAngle(args, context, UnitlessQuirk::kAllow, |
+ UseCounter::kZeroAngleGradient))) |
return nullptr; |
} |
@@ -1225,8 +1245,8 @@ static CSSValue* ConsumeConicGradient(CSSParserTokenRange& args, |
CSSGradientValue* result = |
CSSConicGradientValue::Create(center_x, center_y, from_angle, repeating); |
- return ConsumeGradientColorStops(args, context.Mode(), result, |
- ConsumeAngleOrPercent) |
+ return ConsumeGradientColorStops(args, context, result, |
+ ConsumeGradientAngleOrPercent) |
? result |
: nullptr; |
} |
@@ -1319,28 +1339,27 @@ static CSSValue* ConsumeGeneratedImage(CSSParserTokenRange& range, |
result = ConsumeRadialGradient(args, *context, kRepeating); |
} else if (id == CSSValueWebkitLinearGradient) { |
context->Count(UseCounter::kDeprecatedWebKitLinearGradient); |
- result = ConsumeLinearGradient(args, context->Mode(), kNonRepeating, |
+ result = ConsumeLinearGradient(args, *context, kNonRepeating, |
kCSSPrefixedLinearGradient); |
} else if (id == CSSValueWebkitRepeatingLinearGradient) { |
context->Count(UseCounter::kDeprecatedWebKitRepeatingLinearGradient); |
- result = ConsumeLinearGradient(args, context->Mode(), kRepeating, |
+ result = ConsumeLinearGradient(args, *context, kRepeating, |
kCSSPrefixedLinearGradient); |
} else if (id == CSSValueRepeatingLinearGradient) { |
- result = ConsumeLinearGradient(args, context->Mode(), kRepeating, |
- kCSSLinearGradient); |
+ result = |
+ ConsumeLinearGradient(args, *context, kRepeating, kCSSLinearGradient); |
} else if (id == CSSValueLinearGradient) { |
- result = ConsumeLinearGradient(args, context->Mode(), kNonRepeating, |
+ result = ConsumeLinearGradient(args, *context, kNonRepeating, |
kCSSLinearGradient); |
} else if (id == CSSValueWebkitGradient) { |
context->Count(UseCounter::kDeprecatedWebKitGradient); |
result = ConsumeDeprecatedGradient(args, context->Mode()); |
} else if (id == CSSValueWebkitRadialGradient) { |
context->Count(UseCounter::kDeprecatedWebKitRadialGradient); |
- result = |
- ConsumeDeprecatedRadialGradient(args, context->Mode(), kNonRepeating); |
+ result = ConsumeDeprecatedRadialGradient(args, *context, kNonRepeating); |
} else if (id == CSSValueWebkitRepeatingRadialGradient) { |
context->Count(UseCounter::kDeprecatedWebKitRepeatingRadialGradient); |
- result = ConsumeDeprecatedRadialGradient(args, context->Mode(), kRepeating); |
+ result = ConsumeDeprecatedRadialGradient(args, *context, kRepeating); |
} else if (id == CSSValueConicGradient) { |
result = ConsumeConicGradient(args, *context, kNonRepeating); |
} else if (id == CSSValueRepeatingConicGradient) { |