diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-c30a6232df03e1efbd9f3b226777b07e087a1122.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h')
-rw-r--r-- | chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h | 284 |
1 files changed, 260 insertions, 24 deletions
diff --git a/chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h b/chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h index 6cf2745204c..5a96ee00469 100644 --- a/chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h +++ b/chromium/third_party/blink/renderer/core/css/properties/css_parsing_utils.h @@ -5,27 +5,42 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_CSS_PARSING_UTILS_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_CSS_PARSING_UTILS_H_ +#include "base/optional.h" #include "third_party/blink/renderer/core/core_export.h" +#include "third_party/blink/renderer/core/css/css_custom_ident_value.h" +#include "third_party/blink/renderer/core/css/css_function_value.h" +#include "third_party/blink/renderer/core/css/css_identifier_value.h" #include "third_party/blink/renderer/core/css/css_numeric_literal_value.h" +#include "third_party/blink/renderer/core/css/css_primitive_value.h" +#include "third_party/blink/renderer/core/css/css_value_list.h" #include "third_party/blink/renderer/core/css/parser/css_parser_mode.h" #include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h" -#include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h" #include "third_party/blink/renderer/core/css_value_keywords.h" +#include "third_party/blink/renderer/core/frame/web_feature_forward.h" #include "third_party/blink/renderer/core/style/grid_area.h" +#include "third_party/blink/renderer/platform/geometry/length.h" // For ValueRange +#include "third_party/blink/renderer/platform/heap/handle.h" namespace blink { namespace cssvalue { class CSSFontFeatureValue; +class CSSURIValue; } // namespace cssvalue class CSSIdentifierValue; class CSSParserContext; class CSSParserLocalContext; +class CSSPropertyValue; class CSSShadowValue; +class CSSStringValue; class CSSValue; class CSSValueList; +class CSSValuePair; class StylePropertyShorthand; +// "Consume" functions, when successful, should consume all the relevant tokens +// as well as any trailing whitespace. When the start of the range doesn't +// match the type we're looking for, the range should not be modified. namespace css_parsing_utils { enum class AllowInsetAndSpread { kAllow, kForbid }; @@ -33,6 +48,7 @@ enum class AllowTextValue { kAllow, kForbid }; enum class DefaultFill { kFill, kNoFill }; enum class ParsingStyle { kLegacy, kNotLegacy }; enum class TrackListType { kGridTemplate, kGridTemplateNoRepeat, kGridAuto }; +enum class UnitlessQuirk { kAllow, kForbid }; using ConsumeAnimationItemValue = CSSValue* (*)(CSSPropertyID, CSSParserTokenRange&, @@ -42,12 +58,192 @@ using IsPositionKeyword = bool (*)(CSSValueID); constexpr size_t kMaxNumAnimationLonghands = 8; +void Complete4Sides(CSSValue* side[4]); + +// TODO(timloh): These should probably just be consumeComma and consumeSlash. +bool ConsumeCommaIncludingWhitespace(CSSParserTokenRange&); +bool ConsumeSlashIncludingWhitespace(CSSParserTokenRange&); +// consumeFunction expects the range starts with a FunctionToken. +CSSParserTokenRange ConsumeFunction(CSSParserTokenRange&); + +CSSPrimitiveValue* ConsumeInteger( + CSSParserTokenRange&, + const CSSParserContext&, + double minimum_value = -std::numeric_limits<double>::max()); +CSSPrimitiveValue* ConsumeIntegerOrNumberCalc(CSSParserTokenRange&, + const CSSParserContext&); +CSSPrimitiveValue* ConsumePositiveInteger(CSSParserTokenRange&, + const CSSParserContext&); +bool ConsumeNumberRaw(CSSParserTokenRange&, + const CSSParserContext& context, + double& result); +CSSPrimitiveValue* ConsumeNumber(CSSParserTokenRange&, + const CSSParserContext&, + ValueRange); +CSSPrimitiveValue* ConsumeLength(CSSParserTokenRange&, + const CSSParserContext&, + ValueRange, + UnitlessQuirk = UnitlessQuirk::kForbid); +CSSPrimitiveValue* ConsumePercent(CSSParserTokenRange&, + const CSSParserContext&, + ValueRange); +CSSPrimitiveValue* ConsumeAlphaValue(CSSParserTokenRange&, + const CSSParserContext&); +CSSPrimitiveValue* ConsumeLengthOrPercent( + CSSParserTokenRange&, + const CSSParserContext&, + ValueRange, + UnitlessQuirk = UnitlessQuirk::kForbid); +CSSPrimitiveValue* ConsumeSVGGeometryPropertyLength(CSSParserTokenRange&, + const CSSParserContext&, + ValueRange); + +CSSPrimitiveValue* ConsumeAngle( + CSSParserTokenRange&, + const CSSParserContext&, + base::Optional<WebFeature> unitless_zero_feature); +CSSPrimitiveValue* ConsumeAngle( + CSSParserTokenRange&, + const CSSParserContext&, + base::Optional<WebFeature> unitless_zero_feature, + double minimum_value, + double maximum_value); +CSSPrimitiveValue* ConsumeTime(CSSParserTokenRange&, + const CSSParserContext&, + ValueRange); +CSSPrimitiveValue* ConsumeResolution(CSSParserTokenRange&); + +CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange&); +CSSIdentifierValue* ConsumeIdentRange(CSSParserTokenRange&, + CSSValueID lower, + CSSValueID upper); +template <CSSValueID, CSSValueID...> +inline bool IdentMatches(CSSValueID id); +template <CSSValueID... allowedIdents> +CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange&); + +CSSCustomIdentValue* ConsumeCustomIdent(CSSParserTokenRange&, + const CSSParserContext&); +CSSStringValue* ConsumeString(CSSParserTokenRange&); +StringView ConsumeUrlAsStringView(CSSParserTokenRange&, + const CSSParserContext&); +cssvalue::CSSURIValue* ConsumeUrl(CSSParserTokenRange&, + const CSSParserContext&); +CORE_EXPORT CSSValue* ConsumeIdSelector(CSSParserTokenRange&); + +CSSValue* ConsumeColor(CSSParserTokenRange&, + const CSSParserContext&, + bool accept_quirky_colors = false); + +CSSValue* ConsumeInternalForcedBackgroundColor(CSSParserTokenRange&, + const CSSParserContext&); + +CSSValue* ConsumeLineWidth(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk); + +CSSValuePair* ConsumePosition(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk, + base::Optional<WebFeature> three_value_position); +bool ConsumePosition(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk, + base::Optional<WebFeature> three_value_position, + CSSValue*& result_x, + CSSValue*& result_y); +bool ConsumeOneOrTwoValuedPosition(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk, + CSSValue*& result_x, + CSSValue*& result_y); +bool ConsumeBorderShorthand(CSSParserTokenRange&, + const CSSParserContext&, + const CSSValue*& result_width, + const CSSValue*& result_style, + const CSSValue*& result_color); + +enum class ConsumeGeneratedImagePolicy { kAllow, kForbid }; + +CSSValue* ConsumeImage( + CSSParserTokenRange&, + const CSSParserContext&, + ConsumeGeneratedImagePolicy = ConsumeGeneratedImagePolicy::kAllow); +CSSValue* ConsumeImageOrNone(CSSParserTokenRange&, const CSSParserContext&); + +CSSValue* ConsumeAxis(CSSParserTokenRange&, const CSSParserContext& context); + +CSSIdentifierValue* ConsumeShapeBox(CSSParserTokenRange&); + +enum class IsImplicitProperty { kNotImplicit, kImplicit }; + +void AddProperty(CSSPropertyID resolved_property, + CSSPropertyID current_shorthand, + const CSSValue&, + bool important, + IsImplicitProperty, + HeapVector<CSSPropertyValue, 256>& properties); + +void CountKeywordOnlyPropertyUsage(CSSPropertyID, + const CSSParserContext&, + CSSValueID); + +const CSSValue* ParseLonghand(CSSPropertyID unresolved_property, + CSSPropertyID current_shorthand, + const CSSParserContext&, + CSSParserTokenRange&); + +bool ConsumeShorthandVia2Longhands( + const StylePropertyShorthand&, + bool important, + const CSSParserContext&, + CSSParserTokenRange&, + HeapVector<CSSPropertyValue, 256>& properties); + +bool ConsumeShorthandVia4Longhands( + const StylePropertyShorthand&, + bool important, + const CSSParserContext&, + CSSParserTokenRange&, + HeapVector<CSSPropertyValue, 256>& properties); + +bool ConsumeShorthandGreedilyViaLonghands( + const StylePropertyShorthand&, + bool important, + const CSSParserContext&, + CSSParserTokenRange&, + HeapVector<CSSPropertyValue, 256>& properties); + +void AddExpandedPropertyForValue(CSSPropertyID prop_id, + const CSSValue&, + bool, + HeapVector<CSSPropertyValue, 256>& properties); + +CSSValue* ConsumeTransformValue(CSSParserTokenRange&, const CSSParserContext&); +CSSValue* ConsumeTransformList(CSSParserTokenRange&, const CSSParserContext&); +CSSValue* ConsumeFilterFunctionList(CSSParserTokenRange&, + const CSSParserContext&); + bool IsBaselineKeyword(CSSValueID id); bool IsSelfPositionKeyword(CSSValueID); bool IsSelfPositionOrLeftOrRightKeyword(CSSValueID); bool IsContentPositionKeyword(CSSValueID); bool IsContentPositionOrLeftOrRightKeyword(CSSValueID); CORE_EXPORT bool IsCSSWideKeyword(CSSValueID); +CORE_EXPORT bool IsCSSWideKeyword(StringView); +bool IsRevertKeyword(StringView); +bool IsDefaultKeyword(StringView); +bool IsHashIdentifier(const CSSParserToken&); + +// This function returns false for CSS-wide keywords, 'default', and any +// template parameters provided. +// +// https://drafts.csswg.org/css-values-4/#identifier-value +template <CSSValueID, CSSValueID...> +bool IsCustomIdent(CSSValueID); + +// https://drafts.csswg.org/scroll-animations-1/#typedef-timeline-name +bool IsTimelineName(const CSSParserToken&); CSSValue* ConsumeScrollOffset(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeSelfPositionOverflowPosition(CSSParserTokenRange&, @@ -66,6 +262,8 @@ CSSValue* ConsumeAnimationIterationCount(CSSParserTokenRange&, CSSValue* ConsumeAnimationName(CSSParserTokenRange&, const CSSParserContext&, bool allow_quoted_name); +CSSValue* ConsumeAnimationTimeline(CSSParserTokenRange&, + const CSSParserContext&); CSSValue* ConsumeAnimationTimingFunction(CSSParserTokenRange&, const CSSParserContext&); bool ConsumeAnimationShorthand( @@ -81,10 +279,9 @@ CSSValue* ConsumeBackgroundAttachment(CSSParserTokenRange&); CSSValue* ConsumeBackgroundBlendMode(CSSParserTokenRange&); CSSValue* ConsumeBackgroundBox(CSSParserTokenRange&); CSSValue* ConsumeBackgroundComposite(CSSParserTokenRange&); -CSSValue* ConsumeMaskSourceType(CSSParserTokenRange&); bool ConsumeBackgroundPosition(CSSParserTokenRange&, const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk, + UnitlessQuirk, CSSValue*& result_x, CSSValue*& result_y); CSSValue* ConsumePrefixedBackgroundBox(CSSParserTokenRange&, AllowTextValue); @@ -152,11 +349,9 @@ CSSValue* ConsumeGapLength(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeCounter(CSSParserTokenRange&, const CSSParserContext&, int); -CSSValue* ConsumeFontSize( - CSSParserTokenRange&, - const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk = - css_property_parser_helpers::UnitlessQuirk::kForbid); +CSSValue* ConsumeFontSize(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk = UnitlessQuirk::kForbid); CSSValue* ConsumeLineHeight(CSSParserTokenRange&, const CSSParserContext&); @@ -204,20 +399,16 @@ bool ConsumeFromPageBreakBetween(CSSParserTokenRange&, CSSValueID&); bool ConsumeFromColumnBreakBetween(CSSParserTokenRange&, CSSValueID&); bool ConsumeFromColumnOrPageBreakInside(CSSParserTokenRange&, CSSValueID&); -CSSValue* ConsumeMaxWidthOrHeight( - CSSParserTokenRange&, - const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk = - css_property_parser_helpers::UnitlessQuirk::kForbid); -CSSValue* ConsumeWidthOrHeight( - CSSParserTokenRange&, - const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk = - css_property_parser_helpers::UnitlessQuirk::kForbid); +CSSValue* ConsumeMaxWidthOrHeight(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk = UnitlessQuirk::kForbid); +CSSValue* ConsumeWidthOrHeight(CSSParserTokenRange&, + const CSSParserContext&, + UnitlessQuirk = UnitlessQuirk::kForbid); CSSValue* ConsumeMarginOrOffset(CSSParserTokenRange&, const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk); + UnitlessQuirk); CSSValue* ConsumeScrollPadding(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumeOffsetPath(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ConsumePathOrNone(CSSParserTokenRange&); @@ -247,12 +438,58 @@ CSSValue* ConsumeBorderColorSide(CSSParserTokenRange&, const CSSParserLocalContext&); CSSValue* ConsumeBorderWidth(CSSParserTokenRange&, const CSSParserContext&, - css_property_parser_helpers::UnitlessQuirk); + UnitlessQuirk); CSSValue* ParsePaintStroke(CSSParserTokenRange&, const CSSParserContext&); CSSValue* ParseSpacing(CSSParserTokenRange&, const CSSParserContext&); -css_property_parser_helpers::UnitlessQuirk UnitlessUnlessShorthand( - const CSSParserLocalContext&); +UnitlessQuirk UnitlessUnlessShorthand(const CSSParserLocalContext&); + +// Template implementations are at the bottom of the file for readability. + +template <typename... emptyBaseCase> +inline bool IdentMatches(CSSValueID id) { + return false; +} +template <CSSValueID head, CSSValueID... tail> +inline bool IdentMatches(CSSValueID id) { + return id == head || IdentMatches<tail...>(id); +} + +template <typename...> +bool IsCustomIdent(CSSValueID id) { + return !IsCSSWideKeyword(id) && id != CSSValueID::kDefault; +} + +template <CSSValueID head, CSSValueID... tail> +bool IsCustomIdent(CSSValueID id) { + return id != head && IsCustomIdent<tail...>(id); +} + +template <CSSValueID... names> +CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) { + if (range.Peek().GetType() != kIdentToken || + !IdentMatches<names...>(range.Peek().Id())) + return nullptr; + 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, std::forward<Args>(args)...); + if (!value) + return nullptr; + list->Append(*value); + } while (ConsumeCommaIncludingWhitespace(range)); + DCHECK(list->length()); + return list; +} template <CSSValueID start, CSSValueID end> CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range, @@ -272,8 +509,7 @@ CSSValue* ConsumePositionLonghand(CSSParserTokenRange& range, return CSSNumericLiteralValue::Create( percent, CSSPrimitiveValue::UnitType::kPercentage); } - return css_property_parser_helpers::ConsumeLengthOrPercent(range, context, - kValueRangeAll); + return ConsumeLengthOrPercent(range, context, kValueRangeAll); } } // namespace css_parsing_utils |