Commit 5eab49a3 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Count usage of min/max/clamp in <length-percentage> values

This patch plumbs CSSParserContext into ConsumeLengthOrPercent(), so
that we can count usage of CSS comparison functions min/max/clamp when
they are used in <length-percentage> values.

There are three types of code paths, which are handled differently:

1. A caller takes the CSSParserMode from a CSSParserContext, and passes
it through. We change it to pass the CSSParserContext directly.

2. A caller has a CSSParserContext, but passes a possibly different
CSSParserMode. We change it to temporarily override the CSSParserMode
of the current context.

3. A caller doesn't necessarily has a CSSParserContext, and passes a
CSSParserMode. We change it to pass a newly created CSSParserContext
with the underlying document and the CSSParserMode.

Bug: 1047784
Change-Id: Iabc5bff859ff2dc302ee2eb9f0b3398f5a1952be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033892Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739408}
parent 939f1542
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_scroll_timeline_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_scroll_timeline_options.h"
#include "third_party/blink/renderer/core/css/css_to_length_conversion_data.h" #include "third_party/blink/renderer/core/css/css_to_length_conversion_data.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h" #include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
#include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h" #include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h" #include "third_party/blink/renderer/core/dom/node_computed_style.h"
...@@ -47,11 +48,13 @@ bool StringToScrollDirection(String scroll_direction, ...@@ -47,11 +48,13 @@ bool StringToScrollDirection(String scroll_direction,
return false; return false;
} }
bool StringToScrollOffset(String scroll_offset, CSSPrimitiveValue** result) { bool StringToScrollOffset(String scroll_offset,
const CSSParserContext& context,
CSSPrimitiveValue** result) {
CSSTokenizer tokenizer(scroll_offset); CSSTokenizer tokenizer(scroll_offset);
const auto tokens = tokenizer.TokenizeToEOF(); const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange range(tokens); CSSParserTokenRange range(tokens);
CSSValue* value = css_parsing_utils::ConsumeScrollOffset(range); CSSValue* value = css_parsing_utils::ConsumeScrollOffset(range, context);
if (!value) if (!value)
return false; return false;
...@@ -80,6 +83,10 @@ ScrollTimeline* ScrollTimeline::Create(Document& document, ...@@ -80,6 +83,10 @@ ScrollTimeline* ScrollTimeline::Create(Document& document,
? options->scrollSource() ? options->scrollSource()
: document.scrollingElement(); : document.scrollingElement();
// TODO(xiaochengh): Try reusing an existing context in document.
const CSSParserContext* context =
MakeGarbageCollected<CSSParserContext>(document);
ScrollDirection orientation; ScrollDirection orientation;
if (!StringToScrollDirection(options->orientation(), orientation)) { if (!StringToScrollDirection(options->orientation(), orientation)) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError, exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
...@@ -88,14 +95,15 @@ ScrollTimeline* ScrollTimeline::Create(Document& document, ...@@ -88,14 +95,15 @@ ScrollTimeline* ScrollTimeline::Create(Document& document,
} }
CSSPrimitiveValue* start_scroll_offset = nullptr; CSSPrimitiveValue* start_scroll_offset = nullptr;
if (!StringToScrollOffset(options->startScrollOffset(), if (!StringToScrollOffset(options->startScrollOffset(), *context,
&start_scroll_offset)) { &start_scroll_offset)) {
exception_state.ThrowTypeError("Invalid startScrollOffset"); exception_state.ThrowTypeError("Invalid startScrollOffset");
return nullptr; return nullptr;
} }
CSSPrimitiveValue* end_scroll_offset = nullptr; CSSPrimitiveValue* end_scroll_offset = nullptr;
if (!StringToScrollOffset(options->endScrollOffset(), &end_scroll_offset)) { if (!StringToScrollOffset(options->endScrollOffset(), *context,
&end_scroll_offset)) {
exception_state.ThrowTypeError("Invalid endScrollOffset"); exception_state.ThrowTypeError("Invalid endScrollOffset");
return nullptr; return nullptr;
} }
......
...@@ -40,6 +40,8 @@ bool CouldConsumeReservedKeyword(CSSParserTokenRange range) { ...@@ -40,6 +40,8 @@ bool CouldConsumeReservedKeyword(CSSParserTokenRange range) {
return false; return false;
} }
// TODO(xiaochengh): |context| is never nullptr in this function. Change
// parameter type to |const CSSParserContext&| to avoid confusion.
const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax, const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax,
CSSParserTokenRange& range, CSSParserTokenRange& range,
const CSSParserContext* context) { const CSSParserContext* context) {
...@@ -61,9 +63,12 @@ const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax, ...@@ -61,9 +63,12 @@ const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax,
case CSSSyntaxType::kPercentage: case CSSSyntaxType::kPercentage:
return css_property_parser_helpers::ConsumePercent( return css_property_parser_helpers::ConsumePercent(
range, ValueRange::kValueRangeAll); range, ValueRange::kValueRangeAll);
case CSSSyntaxType::kLengthPercentage: case CSSSyntaxType::kLengthPercentage: {
CSSParserContext::ParserModeOverridingScope scope(*context,
kHTMLStandardMode);
return css_property_parser_helpers::ConsumeLengthOrPercent( return css_property_parser_helpers::ConsumeLengthOrPercent(
range, kHTMLStandardMode, ValueRange::kValueRangeAll); range, *context, ValueRange::kValueRangeAll);
}
case CSSSyntaxType::kColor: case CSSSyntaxType::kColor:
return css_property_parser_helpers::ConsumeColor(range, return css_property_parser_helpers::ConsumeColor(range,
kHTMLStandardMode); kHTMLStandardMode);
......
...@@ -136,9 +136,27 @@ class CORE_EXPORT CSSParserContext final ...@@ -136,9 +136,27 @@ class CORE_EXPORT CSSParserContext final
bool IsForMarkupSanitization() const; bool IsForMarkupSanitization() const;
// Overrides |mode_| of a CSSParserContext within the scope, allowing us to
// switching parsing mode while parsing different parts of a style sheet.
// TODO(xiaochengh): This isn't the right approach, as it breaks the
// immutability of CSSParserContext. We should introduce some local context.
class ParserModeOverridingScope {
STACK_ALLOCATED();
public:
ParserModeOverridingScope(const CSSParserContext& context,
CSSParserMode mode)
: mode_reset_(const_cast<CSSParserMode*>(&context.mode_), mode) {}
private:
base::AutoReset<CSSParserMode> mode_reset_;
};
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
private: private:
friend class ParserModeOverridingScope;
KURL base_url_; KURL base_url_;
network::mojom::CSPDisposition should_check_content_security_policy_; network::mojom::CSPDisposition should_check_content_security_policy_;
......
...@@ -289,7 +289,7 @@ bool CSSPropertyParser::ConsumeCSSWideKeyword(CSSPropertyID unresolved_property, ...@@ -289,7 +289,7 @@ bool CSSPropertyParser::ConsumeCSSWideKeyword(CSSPropertyID unresolved_property,
static CSSValue* ConsumeSingleViewportDescriptor( static CSSValue* ConsumeSingleViewportDescriptor(
CSSParserTokenRange& range, CSSParserTokenRange& range,
CSSPropertyID prop_id, CSSPropertyID prop_id,
CSSParserMode css_parser_mode) { const CSSParserContext& context) {
CSSValueID id = range.Peek().Id(); CSSValueID id = range.Peek().Id();
switch (prop_id) { switch (prop_id) {
case CSSPropertyID::kMinWidth: case CSSPropertyID::kMinWidth:
...@@ -299,7 +299,7 @@ static CSSValue* ConsumeSingleViewportDescriptor( ...@@ -299,7 +299,7 @@ static CSSValue* ConsumeSingleViewportDescriptor(
if (id == CSSValueID::kAuto || id == CSSValueID::kInternalExtendToZoom) if (id == CSSValueID::kAuto || id == CSSValueID::kInternalExtendToZoom)
return ConsumeIdent(range); return ConsumeIdent(range);
return css_property_parser_helpers::ConsumeLengthOrPercent( return css_property_parser_helpers::ConsumeLengthOrPercent(
range, css_parser_mode, kValueRangeNonNegative); range, context, kValueRangeNonNegative);
case CSSPropertyID::kMinZoom: case CSSPropertyID::kMinZoom:
case CSSPropertyID::kMaxZoom: case CSSPropertyID::kMaxZoom:
case CSSPropertyID::kZoom: { case CSSPropertyID::kZoom: {
...@@ -337,13 +337,13 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id, ...@@ -337,13 +337,13 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id,
switch (prop_id) { switch (prop_id) {
case CSSPropertyID::kWidth: { case CSSPropertyID::kWidth: {
CSSValue* min_width = ConsumeSingleViewportDescriptor( CSSValue* min_width = ConsumeSingleViewportDescriptor(
range_, CSSPropertyID::kMinWidth, context_->Mode()); range_, CSSPropertyID::kMinWidth, *context_);
if (!min_width) if (!min_width)
return false; return false;
CSSValue* max_width = min_width; CSSValue* max_width = min_width;
if (!range_.AtEnd()) { if (!range_.AtEnd()) {
max_width = ConsumeSingleViewportDescriptor( max_width = ConsumeSingleViewportDescriptor(
range_, CSSPropertyID::kMaxWidth, context_->Mode()); range_, CSSPropertyID::kMaxWidth, *context_);
} }
if (!max_width || !range_.AtEnd()) if (!max_width || !range_.AtEnd())
return false; return false;
...@@ -357,13 +357,13 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id, ...@@ -357,13 +357,13 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id,
} }
case CSSPropertyID::kHeight: { case CSSPropertyID::kHeight: {
CSSValue* min_height = ConsumeSingleViewportDescriptor( CSSValue* min_height = ConsumeSingleViewportDescriptor(
range_, CSSPropertyID::kMinHeight, context_->Mode()); range_, CSSPropertyID::kMinHeight, *context_);
if (!min_height) if (!min_height)
return false; return false;
CSSValue* max_height = min_height; CSSValue* max_height = min_height;
if (!range_.AtEnd()) { if (!range_.AtEnd()) {
max_height = ConsumeSingleViewportDescriptor( max_height = ConsumeSingleViewportDescriptor(
range_, CSSPropertyID::kMaxHeight, context_->Mode()); range_, CSSPropertyID::kMaxHeight, *context_);
} }
if (!max_height || !range_.AtEnd()) if (!max_height || !range_.AtEnd())
return false; return false;
...@@ -386,7 +386,7 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id, ...@@ -386,7 +386,7 @@ bool CSSPropertyParser::ParseViewportDescriptor(CSSPropertyID prop_id,
case CSSPropertyID::kUserZoom: case CSSPropertyID::kUserZoom:
case CSSPropertyID::kOrientation: { case CSSPropertyID::kOrientation: {
CSSValue* parsed_value = CSSValue* parsed_value =
ConsumeSingleViewportDescriptor(range_, prop_id, context_->Mode()); ConsumeSingleViewportDescriptor(range_, prop_id, *context_);
if (!parsed_value || !range_.AtEnd()) if (!parsed_value || !range_.AtEnd())
return false; return false;
AddProperty(prop_id, CSSPropertyID::kInvalid, *parsed_value, important, AddProperty(prop_id, CSSPropertyID::kInvalid, *parsed_value, important,
......
...@@ -476,17 +476,17 @@ bool CanConsumeCalcValue(CalculationCategory category, ...@@ -476,17 +476,17 @@ bool CanConsumeCalcValue(CalculationCategory category,
} }
CSSPrimitiveValue* ConsumeLengthOrPercent(CSSParserTokenRange& range, CSSPrimitiveValue* ConsumeLengthOrPercent(CSSParserTokenRange& range,
CSSParserMode css_parser_mode, const CSSParserContext& context,
ValueRange value_range, ValueRange value_range,
UnitlessQuirk unitless) { UnitlessQuirk unitless) {
const CSSParserToken& token = range.Peek(); const CSSParserToken& token = range.Peek();
if (token.GetType() == kDimensionToken || token.GetType() == kNumberToken) if (token.GetType() == kDimensionToken || token.GetType() == kNumberToken)
return ConsumeLength(range, css_parser_mode, value_range, unitless); return ConsumeLength(range, context.Mode(), value_range, unitless);
if (token.GetType() == kPercentageToken) if (token.GetType() == kPercentageToken)
return ConsumePercent(range, value_range); return ConsumePercent(range, value_range);
MathFunctionParser math_parser(range, value_range); MathFunctionParser math_parser(range, &context, value_range);
if (const CSSMathFunctionValue* calculation = math_parser.Value()) { if (const CSSMathFunctionValue* calculation = math_parser.Value()) {
if (CanConsumeCalcValue(calculation->Category(), css_parser_mode)) if (CanConsumeCalcValue(calculation->Category(), context.Mode()))
return math_parser.ConsumeValue(); return math_parser.ConsumeValue();
} }
return nullptr; return nullptr;
...@@ -521,8 +521,9 @@ CSSPrimitiveValue* ConsumeSVGGeometryPropertyLength( ...@@ -521,8 +521,9 @@ CSSPrimitiveValue* ConsumeSVGGeometryPropertyLength(
CSSParserTokenRange& range, CSSParserTokenRange& range,
const CSSParserContext& context, const CSSParserContext& context,
ValueRange value_range) { ValueRange value_range) {
CSSPrimitiveValue* value = ConsumeLengthOrPercent( CSSParserContext::ParserModeOverridingScope scope(context, kSVGAttributeMode);
range, kSVGAttributeMode, value_range, UnitlessQuirk::kForbid); CSSPrimitiveValue* value = ConsumeLengthOrPercent(range, context, value_range,
UnitlessQuirk::kForbid);
if (IsNonZeroUserUnitsValue(value)) if (IsNonZeroUserUnitsValue(value))
context.Count(WebFeature::kSVGGeometryPropertyHasNonZeroUnitlessValue); context.Count(WebFeature::kSVGGeometryPropertyHasNonZeroUnitlessValue);
return value; return value;
...@@ -533,7 +534,7 @@ CSSPrimitiveValue* ConsumeGradientLengthOrPercent( ...@@ -533,7 +534,7 @@ CSSPrimitiveValue* ConsumeGradientLengthOrPercent(
const CSSParserContext& context, const CSSParserContext& context,
ValueRange value_range, ValueRange value_range,
UnitlessQuirk unitless) { UnitlessQuirk unitless) {
return ConsumeLengthOrPercent(range, context.Mode(), value_range, unitless); return ConsumeLengthOrPercent(range, context, value_range, unitless);
} }
CSSPrimitiveValue* ConsumeAngle( CSSPrimitiveValue* ConsumeAngle(
...@@ -941,13 +942,12 @@ CSSValue* ConsumeLineWidth(CSSParserTokenRange& range, ...@@ -941,13 +942,12 @@ CSSValue* ConsumeLineWidth(CSSParserTokenRange& range,
} }
static CSSValue* ConsumePositionComponent(CSSParserTokenRange& range, static CSSValue* ConsumePositionComponent(CSSParserTokenRange& range,
CSSParserMode css_parser_mode, const CSSParserContext& context,
UnitlessQuirk unitless, UnitlessQuirk unitless,
bool& horizontal_edge, bool& horizontal_edge,
bool& vertical_edge) { bool& vertical_edge) {
if (range.Peek().GetType() != kIdentToken) if (range.Peek().GetType() != kIdentToken)
return ConsumeLengthOrPercent(range, css_parser_mode, kValueRangeAll, return ConsumeLengthOrPercent(range, context, kValueRangeAll, unitless);
unitless);
CSSValueID id = range.Peek().Id(); CSSValueID id = range.Peek().Id();
if (id == CSSValueID::kLeft || id == CSSValueID::kRight) { if (id == CSSValueID::kLeft || id == CSSValueID::kRight) {
...@@ -1058,7 +1058,7 @@ bool ConsumePosition(CSSParserTokenRange& range, ...@@ -1058,7 +1058,7 @@ bool ConsumePosition(CSSParserTokenRange& range,
CSSValue*& result_y) { CSSValue*& result_y) {
bool horizontal_edge = false; bool horizontal_edge = false;
bool vertical_edge = false; bool vertical_edge = false;
CSSValue* value1 = ConsumePositionComponent(range, context.Mode(), unitless, CSSValue* value1 = ConsumePositionComponent(range, context, unitless,
horizontal_edge, vertical_edge); horizontal_edge, vertical_edge);
if (!value1) if (!value1)
return false; return false;
...@@ -1066,7 +1066,7 @@ bool ConsumePosition(CSSParserTokenRange& range, ...@@ -1066,7 +1066,7 @@ bool ConsumePosition(CSSParserTokenRange& range,
horizontal_edge = true; horizontal_edge = true;
CSSParserTokenRange range_after_first_consume = range; CSSParserTokenRange range_after_first_consume = range;
CSSValue* value2 = ConsumePositionComponent(range, context.Mode(), unitless, CSSValue* value2 = ConsumePositionComponent(range, context, unitless,
horizontal_edge, vertical_edge); horizontal_edge, vertical_edge);
if (!value2) { if (!value2) {
PositionFromOneValue(value1, result_x, result_y); PositionFromOneValue(value1, result_x, result_y);
...@@ -1083,9 +1083,10 @@ bool ConsumePosition(CSSParserTokenRange& range, ...@@ -1083,9 +1083,10 @@ bool ConsumePosition(CSSParserTokenRange& range,
!!identifier_value2 != (range.Peek().GetType() == kIdentToken) && !!identifier_value2 != (range.Peek().GetType() == kIdentToken) &&
(identifier_value2 (identifier_value2
? identifier_value2->GetValueID() ? identifier_value2->GetValueID()
: identifier_value1->GetValueID()) != CSSValueID::kCenter) : identifier_value1->GetValueID()) != CSSValueID::kCenter) {
value3 = ConsumePositionComponent(range, context.Mode(), unitless, value3 = ConsumePositionComponent(range, context, unitless, horizontal_edge,
horizontal_edge, vertical_edge); vertical_edge);
}
if (!value3) { if (!value3) {
if (vertical_edge && !value2->IsIdentifierValue()) { if (vertical_edge && !value2->IsIdentifierValue()) {
range = range_after_first_consume; range = range_after_first_consume;
...@@ -1100,9 +1101,10 @@ bool ConsumePosition(CSSParserTokenRange& range, ...@@ -1100,9 +1101,10 @@ bool ConsumePosition(CSSParserTokenRange& range,
auto* identifier_value3 = DynamicTo<CSSIdentifierValue>(value3); auto* identifier_value3 = DynamicTo<CSSIdentifierValue>(value3);
if (identifier_value3 && if (identifier_value3 &&
identifier_value3->GetValueID() != CSSValueID::kCenter && identifier_value3->GetValueID() != CSSValueID::kCenter &&
range.Peek().GetType() != kIdentToken) range.Peek().GetType() != kIdentToken) {
value4 = ConsumePositionComponent(range, context.Mode(), unitless, value4 = ConsumePositionComponent(range, context, unitless, horizontal_edge,
horizontal_edge, vertical_edge); vertical_edge);
}
if (!value4) { if (!value4) {
if (!three_value_position) { if (!three_value_position) {
...@@ -1146,25 +1148,25 @@ CSSValuePair* ConsumePosition(CSSParserTokenRange& range, ...@@ -1146,25 +1148,25 @@ CSSValuePair* ConsumePosition(CSSParserTokenRange& range,
} }
bool ConsumeOneOrTwoValuedPosition(CSSParserTokenRange& range, bool ConsumeOneOrTwoValuedPosition(CSSParserTokenRange& range,
CSSParserMode css_parser_mode, const CSSParserContext& context,
UnitlessQuirk unitless, UnitlessQuirk unitless,
CSSValue*& result_x, CSSValue*& result_x,
CSSValue*& result_y) { CSSValue*& result_y) {
bool horizontal_edge = false; bool horizontal_edge = false;
bool vertical_edge = false; bool vertical_edge = false;
CSSValue* value1 = ConsumePositionComponent(range, css_parser_mode, unitless, CSSValue* value1 = ConsumePositionComponent(range, context, unitless,
horizontal_edge, vertical_edge); horizontal_edge, vertical_edge);
if (!value1) if (!value1)
return false; return false;
if (!value1->IsIdentifierValue()) if (!value1->IsIdentifierValue())
horizontal_edge = true; horizontal_edge = true;
if (vertical_edge && ConsumeLengthOrPercent(range, css_parser_mode, if (vertical_edge &&
kValueRangeAll, unitless)) { ConsumeLengthOrPercent(range, context, kValueRangeAll, unitless)) {
// <length-percentage> is not permitted after top | bottom. // <length-percentage> is not permitted after top | bottom.
return false; return false;
} }
CSSValue* value2 = ConsumePositionComponent(range, css_parser_mode, unitless, CSSValue* value2 = ConsumePositionComponent(range, context, unitless,
horizontal_edge, vertical_edge); horizontal_edge, vertical_edge);
if (!value2) { if (!value2) {
PositionFromOneValue(value1, result_x, result_y); PositionFromOneValue(value1, result_x, result_y);
...@@ -1419,8 +1421,8 @@ static CSSValue* ConsumeDeprecatedRadialGradient( ...@@ -1419,8 +1421,8 @@ static CSSValue* ConsumeDeprecatedRadialGradient(
cssvalue::CSSGradientRepeat repeating) { cssvalue::CSSGradientRepeat repeating) {
CSSValue* center_x = nullptr; CSSValue* center_x = nullptr;
CSSValue* center_y = nullptr; CSSValue* center_y = nullptr;
ConsumeOneOrTwoValuedPosition(args, context.Mode(), UnitlessQuirk::kForbid, ConsumeOneOrTwoValuedPosition(args, context, UnitlessQuirk::kForbid, center_x,
center_x, center_y); center_y);
if ((center_x || center_y) && !ConsumeCommaIncludingWhitespace(args)) if ((center_x || center_y) && !ConsumeCommaIncludingWhitespace(args))
return nullptr; return nullptr;
...@@ -1438,10 +1440,10 @@ static CSSValue* ConsumeDeprecatedRadialGradient( ...@@ -1438,10 +1440,10 @@ static CSSValue* ConsumeDeprecatedRadialGradient(
const CSSPrimitiveValue* vertical_size = nullptr; const CSSPrimitiveValue* vertical_size = nullptr;
if (!shape && !size_keyword) { if (!shape && !size_keyword) {
horizontal_size = horizontal_size =
ConsumeLengthOrPercent(args, context.Mode(), kValueRangeNonNegative); ConsumeLengthOrPercent(args, context, kValueRangeNonNegative);
if (horizontal_size) { if (horizontal_size) {
vertical_size = vertical_size =
ConsumeLengthOrPercent(args, context.Mode(), kValueRangeNonNegative); ConsumeLengthOrPercent(args, context, kValueRangeNonNegative);
if (!vertical_size) if (!vertical_size)
return nullptr; return nullptr;
ConsumeCommaIncludingWhitespace(args); ConsumeCommaIncludingWhitespace(args);
...@@ -1491,14 +1493,13 @@ static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args, ...@@ -1491,14 +1493,13 @@ static CSSValue* ConsumeRadialGradient(CSSParserTokenRange& args,
} }
} else { } else {
CSSPrimitiveValue* center = CSSPrimitiveValue* center =
ConsumeLengthOrPercent(args, context.Mode(), kValueRangeNonNegative); ConsumeLengthOrPercent(args, context, kValueRangeNonNegative);
if (!center) if (!center)
break; break;
if (horizontal_size) if (horizontal_size)
return nullptr; return nullptr;
horizontal_size = center; horizontal_size = center;
center = center = ConsumeLengthOrPercent(args, context, kValueRangeNonNegative);
ConsumeLengthOrPercent(args, context.Mode(), kValueRangeNonNegative);
if (center) { if (center) {
vertical_size = center; vertical_size = center;
++i; ++i;
......
...@@ -62,7 +62,7 @@ CSSPrimitiveValue* ConsumePercent(CSSParserTokenRange&, ValueRange); ...@@ -62,7 +62,7 @@ CSSPrimitiveValue* ConsumePercent(CSSParserTokenRange&, ValueRange);
CSSPrimitiveValue* ConsumeAlphaValue(CSSParserTokenRange&); CSSPrimitiveValue* ConsumeAlphaValue(CSSParserTokenRange&);
CSSPrimitiveValue* ConsumeLengthOrPercent( CSSPrimitiveValue* ConsumeLengthOrPercent(
CSSParserTokenRange&, CSSParserTokenRange&,
CSSParserMode, const CSSParserContext&,
ValueRange, ValueRange,
UnitlessQuirk = UnitlessQuirk::kForbid); UnitlessQuirk = UnitlessQuirk::kForbid);
CSSPrimitiveValue* ConsumeSVGGeometryPropertyLength(CSSParserTokenRange&, CSSPrimitiveValue* ConsumeSVGGeometryPropertyLength(CSSParserTokenRange&,
...@@ -116,7 +116,7 @@ bool ConsumePosition(CSSParserTokenRange&, ...@@ -116,7 +116,7 @@ bool ConsumePosition(CSSParserTokenRange&,
CSSValue*& result_x, CSSValue*& result_x,
CSSValue*& result_y); CSSValue*& result_y);
bool ConsumeOneOrTwoValuedPosition(CSSParserTokenRange&, bool ConsumeOneOrTwoValuedPosition(CSSParserTokenRange&,
CSSParserMode, const CSSParserContext&,
UnitlessQuirk, UnitlessQuirk,
CSSValue*& result_x, CSSValue*& result_x,
CSSValue*& result_y); CSSValue*& result_y);
......
...@@ -47,7 +47,7 @@ bool IsSelfPositionOrLeftOrRightKeyword(CSSValueID); ...@@ -47,7 +47,7 @@ bool IsSelfPositionOrLeftOrRightKeyword(CSSValueID);
bool IsContentPositionKeyword(CSSValueID); bool IsContentPositionKeyword(CSSValueID);
bool IsContentPositionOrLeftOrRightKeyword(CSSValueID); bool IsContentPositionOrLeftOrRightKeyword(CSSValueID);
CSSValue* ConsumeScrollOffset(CSSParserTokenRange&); CSSValue* ConsumeScrollOffset(CSSParserTokenRange&, const CSSParserContext&);
CSSValue* ConsumeSelfPositionOverflowPosition(CSSParserTokenRange&, CSSValue* ConsumeSelfPositionOverflowPosition(CSSParserTokenRange&,
IsPositionKeyword); IsPositionKeyword);
CSSValue* ConsumeSimplifiedDefaultPosition(CSSParserTokenRange&, CSSValue* ConsumeSimplifiedDefaultPosition(CSSParserTokenRange&,
...@@ -118,7 +118,8 @@ bool ConsumeBorderImageComponents(CSSParserTokenRange&, ...@@ -118,7 +118,8 @@ bool ConsumeBorderImageComponents(CSSParserTokenRange&,
DefaultFill); DefaultFill);
CSSValue* ConsumeBorderImageRepeat(CSSParserTokenRange&); CSSValue* ConsumeBorderImageRepeat(CSSParserTokenRange&);
CSSValue* ConsumeBorderImageSlice(CSSParserTokenRange&, DefaultFill); CSSValue* ConsumeBorderImageSlice(CSSParserTokenRange&, DefaultFill);
CSSValue* ConsumeBorderImageWidth(CSSParserTokenRange&); CSSValue* ConsumeBorderImageWidth(CSSParserTokenRange&,
const CSSParserContext&);
CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange&); CSSValue* ConsumeBorderImageOutset(CSSParserTokenRange&);
CSSValue* ParseBorderRadiusCorner(CSSParserTokenRange&, CSSValue* ParseBorderRadiusCorner(CSSParserTokenRange&,
...@@ -147,7 +148,7 @@ CSSValue* ConsumeFontSize( ...@@ -147,7 +148,7 @@ CSSValue* ConsumeFontSize(
css_property_parser_helpers::UnitlessQuirk = css_property_parser_helpers::UnitlessQuirk =
css_property_parser_helpers::UnitlessQuirk::kForbid); css_property_parser_helpers::UnitlessQuirk::kForbid);
CSSValue* ConsumeLineHeight(CSSParserTokenRange&, CSSParserMode); CSSValue* ConsumeLineHeight(CSSParserTokenRange&, const CSSParserContext&);
CSSValueList* ConsumeFontFamily(CSSParserTokenRange&); CSSValueList* ConsumeFontFamily(CSSParserTokenRange&);
CSSValue* ConsumeGenericFamily(CSSParserTokenRange&); CSSValue* ConsumeGenericFamily(CSSParserTokenRange&);
...@@ -164,15 +165,13 @@ CSSIdentifierValue* ConsumeFontVariantCSS21(CSSParserTokenRange&); ...@@ -164,15 +165,13 @@ CSSIdentifierValue* ConsumeFontVariantCSS21(CSSParserTokenRange&);
CSSValue* ConsumeGridLine(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeGridLine(CSSParserTokenRange&, const CSSParserContext&);
CSSValue* ConsumeGridTrackList(CSSParserTokenRange&, CSSValue* ConsumeGridTrackList(CSSParserTokenRange&,
const CSSParserContext&, const CSSParserContext&,
CSSParserMode,
TrackListType); TrackListType);
bool ParseGridTemplateAreasRow(const WTF::String& grid_row_names, bool ParseGridTemplateAreasRow(const WTF::String& grid_row_names,
NamedGridAreaMap&, NamedGridAreaMap&,
const size_t row_count, const size_t row_count,
size_t& column_count); size_t& column_count);
CSSValue* ConsumeGridTemplatesRowsOrColumns(CSSParserTokenRange&, CSSValue* ConsumeGridTemplatesRowsOrColumns(CSSParserTokenRange&,
const CSSParserContext&, const CSSParserContext&);
CSSParserMode);
bool ConsumeGridItemPositionShorthand(bool important, bool ConsumeGridItemPositionShorthand(bool important,
CSSParserTokenRange&, CSSParserTokenRange&,
const CSSParserContext&, const CSSParserContext&,
...@@ -205,9 +204,9 @@ CSSValue* ConsumeWidthOrHeight( ...@@ -205,9 +204,9 @@ CSSValue* ConsumeWidthOrHeight(
css_property_parser_helpers::UnitlessQuirk::kForbid); css_property_parser_helpers::UnitlessQuirk::kForbid);
CSSValue* ConsumeMarginOrOffset(CSSParserTokenRange&, CSSValue* ConsumeMarginOrOffset(CSSParserTokenRange&,
CSSParserMode, const CSSParserContext&,
css_property_parser_helpers::UnitlessQuirk); css_property_parser_helpers::UnitlessQuirk);
CSSValue* ConsumeScrollPadding(CSSParserTokenRange&); CSSValue* ConsumeScrollPadding(CSSParserTokenRange&, const CSSParserContext&);
CSSValue* ConsumeOffsetPath(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeOffsetPath(CSSParserTokenRange&, const CSSParserContext&);
CSSValue* ConsumePathOrNone(CSSParserTokenRange&); CSSValue* ConsumePathOrNone(CSSParserTokenRange&);
CSSValue* ConsumeOffsetRotate(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeOffsetRotate(CSSParserTokenRange&, const CSSParserContext&);
...@@ -216,7 +215,7 @@ CSSValue* ConsumeBasicShape(CSSParserTokenRange&, const CSSParserContext&); ...@@ -216,7 +215,7 @@ CSSValue* ConsumeBasicShape(CSSParserTokenRange&, const CSSParserContext&);
bool ConsumeRadii(CSSValue* horizontal_radii[4], bool ConsumeRadii(CSSValue* horizontal_radii[4],
CSSValue* vertical_radii[4], CSSValue* vertical_radii[4],
CSSParserTokenRange&, CSSParserTokenRange&,
CSSParserMode, const CSSParserContext&,
bool use_legacy_parsing); bool use_legacy_parsing);
CSSValue* ConsumeTextDecorationLine(CSSParserTokenRange&); CSSValue* ConsumeTextDecorationLine(CSSParserTokenRange&);
...@@ -245,7 +244,7 @@ css_property_parser_helpers::UnitlessQuirk UnitlessUnlessShorthand( ...@@ -245,7 +244,7 @@ css_property_parser_helpers::UnitlessQuirk UnitlessUnlessShorthand(
template <CSSValueID start, CSSValueID end> template <CSSValueID start, CSSValueID end>
CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range, CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range,
CSSParserMode css_parser_mode) { const CSSParserContext& context) {
if (range.Peek().GetType() == kIdentToken) { if (range.Peek().GetType() == kIdentToken) {
CSSValueID id = range.Peek().Id(); CSSValueID id = range.Peek().Id();
int percent; int percent;
...@@ -261,8 +260,8 @@ CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range, ...@@ -261,8 +260,8 @@ CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range,
return CSSNumericLiteralValue::Create( return CSSNumericLiteralValue::Create(
percent, CSSPrimitiveValue::UnitType::kPercentage); percent, CSSPrimitiveValue::UnitType::kPercentage);
} }
return css_property_parser_helpers::ConsumeLengthOrPercent( return css_property_parser_helpers::ConsumeLengthOrPercent(range, context,
range, css_parser_mode, kValueRangeAll); kValueRangeAll);
} }
CSSValue* ConsumeIntrinsicLength(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeIntrinsicLength(CSSParserTokenRange&, const CSSParserContext&);
......
...@@ -670,7 +670,7 @@ bool BorderRadius::ParseShorthand( ...@@ -670,7 +670,7 @@ bool BorderRadius::ParseShorthand(
CSSValue* vertical_radii[4] = {nullptr}; CSSValue* vertical_radii[4] = {nullptr};
if (!css_parsing_utils::ConsumeRadii(horizontal_radii, vertical_radii, range, if (!css_parsing_utils::ConsumeRadii(horizontal_radii, vertical_radii, range,
context.Mode(), context,
local_context.UseAliasParsing())) local_context.UseAliasParsing()))
return false; return false;
...@@ -930,7 +930,7 @@ bool Flex::ParseShorthand(bool important, ...@@ -930,7 +930,7 @@ bool Flex::ParseShorthand(bool important,
flex_basis = css_property_parser_helpers::ConsumeIdent(range); flex_basis = css_property_parser_helpers::ConsumeIdent(range);
if (!flex_basis) { if (!flex_basis) {
flex_basis = css_property_parser_helpers::ConsumeLengthOrPercent( flex_basis = css_property_parser_helpers::ConsumeLengthOrPercent(
range, context.Mode(), kValueRangeNonNegative); range, context, kValueRangeNonNegative);
} }
if (index == 2 && !range.AtEnd()) if (index == 2 && !range.AtEnd())
return false; return false;
...@@ -1182,7 +1182,7 @@ bool ConsumeFont(bool important, ...@@ -1182,7 +1182,7 @@ bool ConsumeFont(bool important,
if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) { if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
CSSValue* line_height = CSSValue* line_height =
css_parsing_utils::ConsumeLineHeight(range, context.Mode()); css_parsing_utils::ConsumeLineHeight(range, context);
if (!line_height) if (!line_height)
return false; return false;
css_property_parser_helpers::AddProperty( css_property_parser_helpers::AddProperty(
...@@ -1628,23 +1628,22 @@ bool Grid::ParseShorthand(bool important, ...@@ -1628,23 +1628,22 @@ bool Grid::ParseShorthand(bool important,
auto_rows_value = CSSInitialValue::Create(); auto_rows_value = CSSInitialValue::Create();
} else { } else {
auto_rows_value = css_parsing_utils::ConsumeGridTrackList( auto_rows_value = css_parsing_utils::ConsumeGridTrackList(
range, context, context.Mode(), range, context, css_parsing_utils::TrackListType::kGridAuto);
css_parsing_utils::TrackListType::kGridAuto);
if (!auto_rows_value) if (!auto_rows_value)
return false; return false;
if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range))
return false; return false;
} }
if (!(template_columns = if (!(template_columns =
css_parsing_utils::ConsumeGridTemplatesRowsOrColumns( css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range,
range, context, context.Mode()))) context)))
return false; return false;
template_rows = CSSInitialValue::Create(); template_rows = CSSInitialValue::Create();
auto_columns_value = CSSInitialValue::Create(); auto_columns_value = CSSInitialValue::Create();
} else { } else {
// 3- <grid-template-rows> / [ auto-flow && dense? ] <grid-auto-columns>? // 3- <grid-template-rows> / [ auto-flow && dense? ] <grid-auto-columns>?
template_rows = css_parsing_utils::ConsumeGridTemplatesRowsOrColumns( template_rows =
range, context, context.Mode()); css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range, context);
if (!template_rows) if (!template_rows)
return false; return false;
if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range))
...@@ -1657,8 +1656,7 @@ bool Grid::ParseShorthand(bool important, ...@@ -1657,8 +1656,7 @@ bool Grid::ParseShorthand(bool important,
auto_columns_value = CSSInitialValue::Create(); auto_columns_value = CSSInitialValue::Create();
} else { } else {
auto_columns_value = css_parsing_utils::ConsumeGridTrackList( auto_columns_value = css_parsing_utils::ConsumeGridTrackList(
range, context, context.Mode(), range, context, css_parsing_utils::TrackListType::kGridAuto);
css_parsing_utils::TrackListType::kGridAuto);
if (!auto_columns_value) if (!auto_columns_value)
return false; return false;
} }
...@@ -2166,11 +2164,11 @@ bool Offset::ParseShorthand( ...@@ -2166,11 +2164,11 @@ bool Offset::ParseShorthand(
const CSSValue* offset_rotate = nullptr; const CSSValue* offset_rotate = nullptr;
if (offset_path) { if (offset_path) {
offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent( offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent(
range, context.Mode(), kValueRangeAll); range, context, kValueRangeAll);
offset_rotate = css_parsing_utils::ConsumeOffsetRotate(range, context); offset_rotate = css_parsing_utils::ConsumeOffsetRotate(range, context);
if (offset_rotate && !offset_distance) { if (offset_rotate && !offset_distance) {
offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent( offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent(
range, context.Mode(), kValueRangeAll); range, context, kValueRangeAll);
} }
} }
const CSSValue* offset_anchor = nullptr; const CSSValue* offset_anchor = nullptr;
......
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