Commit 130694fb authored by hs1217.lee's avatar hs1217.lee Committed by Commit Bot

CSS Properties & Values API:replace transform-function with transform-list.

transform-function is changed to transform-list.
<transform-list> is already a space separated list,
so <transform-list>+ is invalid.
parsing functions for transform-form type were moved to
CSSPropertyTransformUtils from CSSPropertyAPITransform.

https://drafts.css-houdini.org/css-properties-values-api-1/#supported-syntax-strings
https://github.com/w3c/css-houdini-drafts/issues/290

BUG=641877

Review-Url: https://codereview.chromium.org/2951763002
Cr-Commit-Position: refs/heads/master@{#481796}
parent 068d8eff
...@@ -8,7 +8,7 @@ PASS syntax:'<color>+', initialValue:'red' is valid ...@@ -8,7 +8,7 @@ PASS syntax:'<color>+', initialValue:'red' is valid
PASS syntax:' <length>+ | <percentage>', initialValue:'2px 8px' is valid PASS syntax:' <length>+ | <percentage>', initialValue:'2px 8px' is valid
PASS syntax:'<length>|<percentage>|<length-percentage>', initialValue:'2px' is valid PASS syntax:'<length>|<percentage>|<length-percentage>', initialValue:'2px' is valid
PASS syntax:'<color> | <image> | <url> | <integer> | <angle>', initialValue:'red' is valid PASS syntax:'<color> | <image> | <url> | <integer> | <angle>', initialValue:'red' is valid
PASS syntax:'<time> | <resolution> | <transform-function> | <custom-ident>', initialValue:'red' is valid PASS syntax:'<time> | <resolution> | <transform-list> | <custom-ident>', initialValue:'red' is valid
PASS syntax:'*', initialValue:':> hello' is valid PASS syntax:'*', initialValue:':> hello' is valid
PASS syntax:'*', initialValue:'([ brackets ]) { yay (??)}' is valid PASS syntax:'*', initialValue:'([ brackets ]) { yay (??)}' is valid
PASS syntax:'*', initialValue:'yep 'this is valid too'' is valid PASS syntax:'*', initialValue:'yep 'this is valid too'' is valid
...@@ -37,8 +37,8 @@ PASS syntax:'<time>', initialValue:'calc(2s - 9ms)' is valid ...@@ -37,8 +37,8 @@ PASS syntax:'<time>', initialValue:'calc(2s - 9ms)' is valid
PASS syntax:'<resolution>', initialValue:'10dpi' is valid PASS syntax:'<resolution>', initialValue:'10dpi' is valid
PASS syntax:'<resolution>', initialValue:'3dPpX' is valid PASS syntax:'<resolution>', initialValue:'3dPpX' is valid
PASS syntax:'<resolution>', initialValue:'-5.3dpcm' is valid PASS syntax:'<resolution>', initialValue:'-5.3dpcm' is valid
FAIL syntax:'<transform-function>', initialValue:'scale(2)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. PASS syntax:'<transform-list>', initialValue:'scale(2)' is valid
FAIL syntax:'<transform-function>+', initialValue:'translateX(2px) rotate(20deg)' is valid Failed to execute 'registerProperty' on 'CSS': The initial value provided does not parse for the given syntax. PASS syntax:'<transform-list>', initialValue:'translateX(2px) rotate(20deg)' is valid
PASS syntax:'<color>', initialValue:'rgb(12, 34, 56)' is valid PASS syntax:'<color>', initialValue:'rgb(12, 34, 56)' is valid
PASS syntax:'<color>', initialValue:'lightgoldenrodyellow' is valid PASS syntax:'<color>', initialValue:'lightgoldenrodyellow' is valid
PASS syntax:'<image>', initialValue:'url(a)' is valid PASS syntax:'<image>', initialValue:'url(a)' is valid
...@@ -116,7 +116,8 @@ PASS syntax:'<angle>', initialValue:'0' is invalid ...@@ -116,7 +116,8 @@ PASS syntax:'<angle>', initialValue:'0' is invalid
PASS syntax:'<angle>', initialValue:'10%' is invalid PASS syntax:'<angle>', initialValue:'10%' is invalid
PASS syntax:'<time>', initialValue:'2px' is invalid PASS syntax:'<time>', initialValue:'2px' is invalid
PASS syntax:'<resolution>', initialValue:'10' is invalid PASS syntax:'<resolution>', initialValue:'10' is invalid
PASS syntax:'<transform-function>', initialValue:'scale()' is invalid PASS syntax:'<transform-list>', initialValue:'scale()' is invalid
PASS syntax:'<transform-list>+', initialValue:'translateX(2px) rotate(20deg)' is invalid
PASS syntax:'<color>', initialValue:'fancy-looking' is invalid PASS syntax:'<color>', initialValue:'fancy-looking' is invalid
PASS syntax:'<image>', initialValue:'banana.png' is invalid PASS syntax:'<image>', initialValue:'banana.png' is invalid
PASS syntax:'<url>', initialValue:'banana.png' is invalid PASS syntax:'<url>', initialValue:'banana.png' is invalid
......
...@@ -29,7 +29,7 @@ assert_valid("<color>+", "red"); ...@@ -29,7 +29,7 @@ assert_valid("<color>+", "red");
assert_valid(" <length>+ | <percentage>", "2px 8px"); assert_valid(" <length>+ | <percentage>", "2px 8px");
assert_valid("<length>|<percentage>|<length-percentage>", "2px"); // Valid but silly assert_valid("<length>|<percentage>|<length-percentage>", "2px"); // Valid but silly
assert_valid("<color> | <image> | <url> | <integer> | <angle>", "red"); assert_valid("<color> | <image> | <url> | <integer> | <angle>", "red");
assert_valid("<time> | <resolution> | <transform-function> | <custom-ident>", "red"); assert_valid("<time> | <resolution> | <transform-list> | <custom-ident>", "red");
assert_valid("*", ":> hello"); assert_valid("*", ":> hello");
assert_valid("*", "([ brackets ]) { yay (??)}"); assert_valid("*", "([ brackets ]) { yay (??)}");
...@@ -62,8 +62,8 @@ assert_valid("<time>", "calc(2s - 9ms)"); ...@@ -62,8 +62,8 @@ assert_valid("<time>", "calc(2s - 9ms)");
assert_valid("<resolution>", "10dpi"); assert_valid("<resolution>", "10dpi");
assert_valid("<resolution>", "3dPpX"); assert_valid("<resolution>", "3dPpX");
assert_valid("<resolution>", "-5.3dpcm"); assert_valid("<resolution>", "-5.3dpcm");
assert_valid("<transform-function>", "scale(2)"); assert_valid("<transform-list>", "scale(2)");
assert_valid("<transform-function>+", "translateX(2px) rotate(20deg)"); assert_valid("<transform-list>", "translateX(2px) rotate(20deg)");
assert_valid("<color>", "rgb(12, 34, 56)"); assert_valid("<color>", "rgb(12, 34, 56)");
assert_valid("<color>", "lightgoldenrodyellow"); assert_valid("<color>", "lightgoldenrodyellow");
...@@ -150,7 +150,8 @@ assert_invalid("<angle>", "0"); ...@@ -150,7 +150,8 @@ assert_invalid("<angle>", "0");
assert_invalid("<angle>", "10%"); assert_invalid("<angle>", "10%");
assert_invalid("<time>", "2px"); assert_invalid("<time>", "2px");
assert_invalid("<resolution>", "10"); assert_invalid("<resolution>", "10");
assert_invalid("<transform-function>", "scale()"); assert_invalid("<transform-list>", "scale()");
assert_invalid("<transform-list>+", "translateX(2px) rotate(20deg)");
assert_invalid("<color>", "fancy-looking"); assert_invalid("<color>", "fancy-looking");
assert_invalid("<image>", "banana.png"); assert_invalid("<image>", "banana.png");
assert_invalid("<url>", "banana.png"); assert_invalid("<url>", "banana.png");
......
...@@ -372,7 +372,7 @@ CSSInterpolationTypesMap::CreateCSSInterpolationTypesForSyntax( ...@@ -372,7 +372,7 @@ CSSInterpolationTypesMap::CreateCSSInterpolationTypesForSyntax(
case CSSSyntaxType::kImage: case CSSSyntaxType::kImage:
case CSSSyntaxType::kUrl: case CSSSyntaxType::kUrl:
case CSSSyntaxType::kInteger: case CSSSyntaxType::kInteger:
case CSSSyntaxType::kTransformFunction: case CSSSyntaxType::kTransformList:
// TODO(alancutter): Support smooth interpolation of these types. // TODO(alancutter): Support smooth interpolation of these types.
break; break;
case CSSSyntaxType::kTokenStream: case CSSSyntaxType::kTokenStream:
......
...@@ -527,6 +527,8 @@ blink_core_sources("css") { ...@@ -527,6 +527,8 @@ blink_core_sources("css") {
"properties/CSSPropertyPositionUtils.h", "properties/CSSPropertyPositionUtils.h",
"properties/CSSPropertyShapeUtils.cpp", "properties/CSSPropertyShapeUtils.cpp",
"properties/CSSPropertyShapeUtils.h", "properties/CSSPropertyShapeUtils.h",
"properties/CSSPropertyTransformUtils.cpp",
"properties/CSSPropertyTransformUtils.h",
"properties/CSSPropertyTransitionPropertyUtils.cpp", "properties/CSSPropertyTransitionPropertyUtils.cpp",
"properties/CSSPropertyTransitionPropertyUtils.h", "properties/CSSPropertyTransitionPropertyUtils.h",
"properties/CSSPropertyWebkitBorderWidthUtils.cpp", "properties/CSSPropertyWebkitBorderWidthUtils.cpp",
......
...@@ -57,8 +57,8 @@ CSSSyntaxType ParseSyntaxType(String type) { ...@@ -57,8 +57,8 @@ CSSSyntaxType ParseSyntaxType(String type) {
return CSSSyntaxType::kTime; return CSSSyntaxType::kTime;
if (type == "resolution") if (type == "resolution")
return CSSSyntaxType::kResolution; return CSSSyntaxType::kResolution;
if (type == "transform-function") if (type == "transform-list")
return CSSSyntaxType::kTransformFunction; return CSSSyntaxType::kTransformList;
if (type == "custom-ident") if (type == "custom-ident")
return CSSSyntaxType::kCustomIdent; return CSSSyntaxType::kCustomIdent;
// Not an Ident, just used to indicate failure // Not an Ident, just used to indicate failure
...@@ -122,6 +122,12 @@ CSSSyntaxDescriptor::CSSSyntaxDescriptor(String input) { ...@@ -122,6 +122,12 @@ CSSSyntaxDescriptor::CSSSyntaxDescriptor(String input) {
} }
bool repeatable = ConsumeCharacterAndWhitespace(input, '+', offset); bool repeatable = ConsumeCharacterAndWhitespace(input, '+', offset);
// <transform-list> is already a space separated list,
// <transform-list>+ is invalid.
if (type == CSSSyntaxType::kTransformList && repeatable) {
syntax_components_.clear();
return;
}
ConsumeWhitespace(input, offset); ConsumeWhitespace(input, offset);
syntax_components_.push_back(CSSSyntaxComponent(type, ident, repeatable)); syntax_components_.push_back(CSSSyntaxComponent(type, ident, repeatable));
...@@ -168,8 +174,8 @@ const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax, ...@@ -168,8 +174,8 @@ const CSSValue* ConsumeSingleType(const CSSSyntaxComponent& syntax,
return ConsumeTime(range, ValueRange::kValueRangeAll); return ConsumeTime(range, ValueRange::kValueRangeAll);
case CSSSyntaxType::kResolution: case CSSSyntaxType::kResolution:
return ConsumeResolution(range); return ConsumeResolution(range);
case CSSSyntaxType::kTransformFunction: case CSSSyntaxType::kTransformList:
return nullptr; // TODO(timloh): Implement this. return ConsumeTransformList(range, *context);
case CSSSyntaxType::kCustomIdent: case CSSSyntaxType::kCustomIdent:
return ConsumeCustomIdent(range); return ConsumeCustomIdent(range);
default: default:
......
...@@ -26,7 +26,7 @@ enum class CSSSyntaxType { ...@@ -26,7 +26,7 @@ enum class CSSSyntaxType {
kAngle, kAngle,
kTime, kTime,
kResolution, kResolution,
kTransformFunction, kTransformList,
kCustomIdent, kCustomIdent,
}; };
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "core/css/CSSVariableData.h" #include "core/css/CSSVariableData.h"
#include "core/css/StyleColor.h" #include "core/css/StyleColor.h"
#include "core/css/parser/CSSParserContext.h" #include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSParserLocalContext.h"
#include "core/css/properties/CSSPropertyTransformUtils.h"
#include "core/frame/UseCounter.h" #include "core/frame/UseCounter.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
...@@ -1485,6 +1487,12 @@ void AddProperty(CSSPropertyID resolved_property, ...@@ -1485,6 +1487,12 @@ void AddProperty(CSSPropertyID resolved_property,
implicit == IsImplicitProperty::kImplicit)); implicit == IsImplicitProperty::kImplicit));
} }
CSSValue* ConsumeTransformList(CSSParserTokenRange& range,
const CSSParserContext& context) {
return CSSPropertyTransformUtils::ConsumeTransformList(
range, context, CSSParserLocalContext());
}
} // namespace CSSPropertyParserHelpers } // namespace CSSPropertyParserHelpers
} // namespace blink } // namespace blink
...@@ -157,6 +157,8 @@ CSSValueList* ConsumeCommaSeparatedList(Func callback, ...@@ -157,6 +157,8 @@ CSSValueList* ConsumeCommaSeparatedList(Func callback,
return list; return list;
} }
CSSValue* ConsumeTransformList(CSSParserTokenRange&, const CSSParserContext&);
} // namespace CSSPropertyParserHelpers } // namespace CSSPropertyParserHelpers
} // namespace blink } // namespace blink
......
...@@ -4,207 +4,19 @@ ...@@ -4,207 +4,19 @@
#include "core/css/properties/CSSPropertyAPITransform.h" #include "core/css/properties/CSSPropertyAPITransform.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/parser/CSSParserContext.h" #include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSParserLocalContext.h" #include "core/css/parser/CSSParserLocalContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h" #include "core/css/parser/CSSParserTokenRange.h"
#include "platform/Length.h" #include "core/css/properties/CSSPropertyTransformUtils.h"
namespace blink { namespace blink {
namespace {
bool ConsumeNumbers(CSSParserTokenRange& args,
CSSFunctionValue*& transform_value,
unsigned number_of_arguments) {
do {
CSSValue* parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
if (--number_of_arguments &&
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
return false;
}
} while (number_of_arguments);
return true;
}
bool ConsumePerspective(CSSParserTokenRange& args,
const CSSParserContext* context,
CSSFunctionValue*& transform_value,
bool use_legacy_parsing) {
CSSPrimitiveValue* parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeNonNegative);
if (!parsed_value && use_legacy_parsing) {
double perspective;
if (!CSSPropertyParserHelpers::ConsumeNumberRaw(args, perspective) ||
perspective < 0) {
return false;
}
context->Count(WebFeature::kUnitlessPerspectiveInTransformProperty);
parsed_value = CSSPrimitiveValue::Create(
perspective, CSSPrimitiveValue::UnitType::kPixels);
}
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
return true;
}
bool ConsumeTranslate3d(CSSParserTokenRange& args,
CSSParserMode css_parser_mode,
CSSFunctionValue*& transform_value) {
unsigned number_of_arguments = 2;
CSSValue* parsed_value = nullptr;
do {
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, css_parser_mode, kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
if (!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args))
return false;
} while (--number_of_arguments);
parsed_value = CSSPropertyParserHelpers::ConsumeLength(args, css_parser_mode,
kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
return true;
}
CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
const CSSParserContext* context,
bool use_legacy_parsing) {
CSSValueID function_id = range.Peek().FunctionId();
if (function_id == CSSValueInvalid)
return nullptr;
CSSParserTokenRange args = CSSPropertyParserHelpers::ConsumeFunction(range);
if (args.AtEnd())
return nullptr;
CSSFunctionValue* transform_value = CSSFunctionValue::Create(function_id);
CSSValue* parsed_value = nullptr;
switch (function_id) {
case CSSValueRotate:
case CSSValueRotateX:
case CSSValueRotateY:
case CSSValueRotateZ:
case CSSValueSkewX:
case CSSValueSkewY:
case CSSValueSkew:
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueSkew &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
}
break;
case CSSValueScaleX:
case CSSValueScaleY:
case CSSValueScaleZ:
case CSSValueScale:
parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueScale &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return nullptr;
}
break;
case CSSValuePerspective:
if (!ConsumePerspective(args, context, transform_value,
use_legacy_parsing)) {
return nullptr;
}
break;
case CSSValueTranslateX:
case CSSValueTranslateY:
case CSSValueTranslate:
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueTranslate &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
}
break;
case CSSValueTranslateZ:
parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeAll);
break;
case CSSValueMatrix:
case CSSValueMatrix3d:
if (!ConsumeNumbers(args, transform_value,
(function_id == CSSValueMatrix3d) ? 16 : 6)) {
return nullptr;
}
break;
case CSSValueScale3d:
if (!ConsumeNumbers(args, transform_value, 3))
return nullptr;
break;
case CSSValueRotate3d:
if (!ConsumeNumbers(args, transform_value, 3) ||
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
return nullptr;
}
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
break;
case CSSValueTranslate3d:
if (!ConsumeTranslate3d(args, context->Mode(), transform_value))
return nullptr;
break;
default:
return nullptr;
}
if (parsed_value)
transform_value->Append(*parsed_value);
if (!args.AtEnd())
return nullptr;
return transform_value;
}
} // namespace
const CSSValue* CSSPropertyAPITransform::parseSingleValue( const CSSValue* CSSPropertyAPITransform::parseSingleValue(
CSSParserTokenRange& range, CSSParserTokenRange& range,
const CSSParserContext& context, const CSSParserContext& context,
const CSSParserLocalContext& local_context) { const CSSParserLocalContext& local_context) {
if (range.Peek().Id() == CSSValueNone) return CSSPropertyTransformUtils::ConsumeTransformList(range, context,
return CSSPropertyParserHelpers::ConsumeIdent(range); local_context);
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
do {
CSSValue* parsed_transform_value =
ConsumeTransformValue(range, &context, local_context.UseAliasParsing());
if (!parsed_transform_value)
return nullptr;
list->Append(*parsed_transform_value);
} while (!range.AtEnd());
return list;
} }
} // namespace blink } // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/css/properties/CSSPropertyTransformUtils.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSParserLocalContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "platform/Length.h"
namespace blink {
namespace {
bool ConsumeNumbers(CSSParserTokenRange& args,
CSSFunctionValue*& transform_value,
unsigned number_of_arguments) {
do {
CSSValue* parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
if (--number_of_arguments &&
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
return false;
}
} while (number_of_arguments);
return true;
}
bool ConsumePerspective(CSSParserTokenRange& args,
const CSSParserContext* context,
CSSFunctionValue*& transform_value,
bool use_legacy_parsing) {
CSSPrimitiveValue* parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeNonNegative);
if (!parsed_value && use_legacy_parsing) {
double perspective;
if (!CSSPropertyParserHelpers::ConsumeNumberRaw(args, perspective) ||
perspective < 0) {
return false;
}
context->Count(WebFeature::kUnitlessPerspectiveInTransformProperty);
parsed_value = CSSPrimitiveValue::Create(
perspective, CSSPrimitiveValue::UnitType::kPixels);
}
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
return true;
}
bool ConsumeTranslate3d(CSSParserTokenRange& args,
CSSParserMode css_parser_mode,
CSSFunctionValue*& transform_value) {
unsigned number_of_arguments = 2;
CSSValue* parsed_value = nullptr;
do {
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, css_parser_mode, kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
if (!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args))
return false;
} while (--number_of_arguments);
parsed_value = CSSPropertyParserHelpers::ConsumeLength(args, css_parser_mode,
kValueRangeAll);
if (!parsed_value)
return false;
transform_value->Append(*parsed_value);
return true;
}
CSSValue* ConsumeTransformValue(CSSParserTokenRange& range,
const CSSParserContext* context,
bool use_legacy_parsing) {
CSSValueID function_id = range.Peek().FunctionId();
if (function_id == CSSValueInvalid)
return nullptr;
CSSParserTokenRange args = CSSPropertyParserHelpers::ConsumeFunction(range);
if (args.AtEnd())
return nullptr;
CSSFunctionValue* transform_value = CSSFunctionValue::Create(function_id);
CSSValue* parsed_value = nullptr;
switch (function_id) {
case CSSValueRotate:
case CSSValueRotateX:
case CSSValueRotateY:
case CSSValueRotateZ:
case CSSValueSkewX:
case CSSValueSkewY:
case CSSValueSkew:
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueSkew &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
}
break;
case CSSValueScaleX:
case CSSValueScaleY:
case CSSValueScaleZ:
case CSSValueScale:
parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueScale &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value =
CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll);
if (!parsed_value)
return nullptr;
}
break;
case CSSValuePerspective:
if (!ConsumePerspective(args, context, transform_value,
use_legacy_parsing)) {
return nullptr;
}
break;
case CSSValueTranslateX:
case CSSValueTranslateY:
case CSSValueTranslate:
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
if (function_id == CSSValueTranslate &&
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
transform_value->Append(*parsed_value);
parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent(
args, context->Mode(), kValueRangeAll);
if (!parsed_value)
return nullptr;
}
break;
case CSSValueTranslateZ:
parsed_value = CSSPropertyParserHelpers::ConsumeLength(
args, context->Mode(), kValueRangeAll);
break;
case CSSValueMatrix:
case CSSValueMatrix3d:
if (!ConsumeNumbers(args, transform_value,
(function_id == CSSValueMatrix3d) ? 16 : 6)) {
return nullptr;
}
break;
case CSSValueScale3d:
if (!ConsumeNumbers(args, transform_value, 3))
return nullptr;
break;
case CSSValueRotate3d:
if (!ConsumeNumbers(args, transform_value, 3) ||
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) {
return nullptr;
}
parsed_value = CSSPropertyParserHelpers::ConsumeAngle(
args, *context, WebFeature::kUnitlessZeroAngleTransform);
if (!parsed_value)
return nullptr;
break;
case CSSValueTranslate3d:
if (!ConsumeTranslate3d(args, context->Mode(), transform_value))
return nullptr;
break;
default:
return nullptr;
}
if (parsed_value)
transform_value->Append(*parsed_value);
if (!args.AtEnd())
return nullptr;
return transform_value;
}
} // namespace
CSSValue* CSSPropertyTransformUtils::ConsumeTransformList(
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext& local_context) {
if (range.Peek().Id() == CSSValueNone)
return CSSPropertyParserHelpers::ConsumeIdent(range);
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
do {
CSSValue* parsed_transform_value =
ConsumeTransformValue(range, &context, local_context.UseAliasParsing());
if (!parsed_transform_value)
return nullptr;
list->Append(*parsed_transform_value);
} while (!range.AtEnd());
return list;
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CSSPropertyTransformUtils_h
#define CSSPropertyTransformUtils_h
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "platform/wtf/Allocator.h"
namespace blink {
class CSSParserContext;
class CSSParserLocalContext;
class CSSParserTokenRange;
class CSSValue;
class CSSPropertyTransformUtils {
STATIC_ONLY(CSSPropertyTransformUtils);
public:
static CSSValue* ConsumeTransformList(CSSParserTokenRange&,
const CSSParserContext&,
const CSSParserLocalContext&);
};
} // namespace blink
#endif // CSSPropertyTransformUtils_h
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