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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp

Issue 2898133002: CSS: Use count unitless 0 supplied as <angle> (Closed)
Patch Set: test custom property Created 3 years, 7 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
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 47144acf44c6abcb6d34c70563aa65569f9d8ca5..6d2688840cc0038831bae08c7c32e2ab0a17dd62 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
@@ -323,7 +323,21 @@ CSSPrimitiveValue* ConsumeLengthOrPercent(CSSParserTokenRange& range,
return nullptr;
}
-CSSPrimitiveValue* ConsumeAngle(CSSParserTokenRange& range) {
+CSSPrimitiveValue* ConsumeGradientLengthOrPercent(
Bugs Nash 2017/05/24 06:24:20 This seems like an unnecessary wrap, why not call
Eric Willigers 2017/05/24 07:13:18 ConsumeGradientLengthOrPercent is passed by functi
+ 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,
+ UseCounter::Feature literalZero) {
+ DCHECK((angleQuirk == UnitlessQuirk::kForbid) ==
+ (literalZero == UseCounter::Feature::kNumberOfFeatures));
+
const CSSParserToken& token = range.Peek();
if (token.GetType() == kDimensionToken) {
switch (token.GetUnitType()) {
@@ -338,8 +352,10 @@ CSSPrimitiveValue* ConsumeAngle(CSSParserTokenRange& range) {
return nullptr;
}
}
- if (token.GetType() == kNumberToken && token.NumericValue() == 0) {
+ if (token.GetType() == kNumberToken && token.NumericValue() == 0 &&
+ angleQuirk == UnitlessQuirk::kAllow) {
range.ConsumeIncludingWhitespace();
+ context.Count(literalZero);
Bugs Nash 2017/05/24 06:24:20 literalZeroFeature is a bit clearer, this kinda re
Eric Willigers 2017/05/24 17:07:26 Done. Now passing Optional literalZeroFeature.
return CSSPrimitiveValue::Create(0, CSSPrimitiveValue::UnitType::kDegrees);
}
CalcParser calc_parser(range, kValueRangeAll);
@@ -937,13 +953,16 @@ static CSSValue* ConsumeDeprecatedGradient(CSSParserTokenRange& args,
return result;
}
-static CSSPrimitiveValue* ConsumeAngleOrPercent(CSSParserTokenRange& range,
- CSSParserMode,
- ValueRange value_range,
- UnitlessQuirk) {
+static CSSPrimitiveValue* ConsumeGradientAngleOrPercent(
Bugs Nash 2017/05/24 06:24:20 please add this rename to cl description
+ 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);
@@ -957,12 +976,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 ||
@@ -973,12 +992,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;
@@ -989,8 +1008,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);
}
@@ -1004,12 +1023,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;
@@ -1028,10 +1048,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);
@@ -1043,14 +1063,14 @@ 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;
}
static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args,
- CSSParserMode css_parser_mode,
+ const CSSParserContext& context,
CSSGradientRepeat repeating) {
const CSSIdentifierValue* shape = nullptr;
const CSSIdentifierValue* size_keyword = nullptr;
@@ -1078,13 +1098,13 @@ static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args,
}
} else {
CSSPrimitiveValue* center =
- ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeAll);
+ ConsumeLengthOrPercent(args, context.Mode(), kValueRangeAll);
if (!center)
break;
if (horizontal_size)
return nullptr;
horizontal_size = center;
- center = ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeAll);
+ center = ConsumeLengthOrPercent(args, context.Mode(), kValueRangeAll);
if (center) {
vertical_size = center;
++i;
@@ -1116,7 +1136,7 @@ static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args,
CSSValue* center_y = nullptr;
if (args.Peek().Id() == CSSValueAt) {
args.ConsumeIncludingWhitespace();
- ConsumePosition(args, css_parser_mode, UnitlessQuirk::kForbid, center_x,
+ ConsumePosition(args, context.Mode(), UnitlessQuirk::kForbid, center_x,
center_y);
if (!(center_x && center_y))
return nullptr;
@@ -1131,18 +1151,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, css_parser_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) {
@@ -1168,29 +1189,30 @@ 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;
}
static CSSValue* ConsumeConicGradient(CSSParserTokenRange& args,
- CSSParserMode css_parser_mode,
+ const CSSParserContext& context,
CSSGradientRepeat repeating) {
if (!RuntimeEnabledFeatures::conicGradientEnabled())
return nullptr;
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;
}
CSSValue* center_x = nullptr;
CSSValue* center_y = nullptr;
if (ConsumeIdent<CSSValueAt>(args)) {
- if (!ConsumePosition(args, css_parser_mode, UnitlessQuirk::kForbid,
- center_x, center_y))
+ if (!ConsumePosition(args, context.Mode(), UnitlessQuirk::kForbid, center_x,
+ center_y))
return nullptr;
}
@@ -1202,8 +1224,8 @@ static CSSValue* ConsumeConicGradient(CSSParserTokenRange& args,
CSSGradientValue* result =
CSSConicGradientValue::Create(center_x, center_y, from_angle, repeating);
- return ConsumeGradientColorStops(args, css_parser_mode, result,
- ConsumeAngleOrPercent)
+ return ConsumeGradientColorStops(args, context, result,
+ ConsumeGradientAngleOrPercent)
? result
: nullptr;
}
@@ -1291,37 +1313,36 @@ static CSSValue* ConsumeGeneratedImage(CSSParserTokenRange& range,
CSSParserTokenRange args = ConsumeFunction(range_copy);
CSSValue* result = nullptr;
if (id == CSSValueRadialGradient) {
- result = ConsumeRadialGradient(args, context->Mode(), kNonRepeating);
+ result = ConsumeRadialGradient(args, *context, kNonRepeating);
} else if (id == CSSValueRepeatingRadialGradient) {
- result = ConsumeRadialGradient(args, context->Mode(), kRepeating);
+ 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->Mode(), kNonRepeating);
+ result = ConsumeConicGradient(args, *context, kNonRepeating);
} else if (id == CSSValueRepeatingConicGradient) {
- result = ConsumeConicGradient(args, context->Mode(), kRepeating);
+ result = ConsumeConicGradient(args, *context, kRepeating);
} else if (id == CSSValueWebkitCrossFade) {
result = ConsumeCrossFade(args, context);
} else if (id == CSSValuePaint) {

Powered by Google App Engine
This is Rietveld 408576698