Diff
Modified: trunk/LayoutTests/ChangeLog (282143 => 282144)
--- trunk/LayoutTests/ChangeLog 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/LayoutTests/ChangeLog 2021-09-08 15:34:37 UTC (rev 282144)
@@ -1,5 +1,17 @@
2021-09-08 Simon Fraser <simon.fra...@apple.com>
+ Support percentages in the scale() transform functions, and the scale property
+ https://bugs.webkit.org/show_bug.cgi?id=202501
+
+ Reviewed by Sam Weinig.
+
+ Ref test for scales with %.
+
+ * transforms/2d/scale-percent-expected.html: Added.
+ * transforms/2d/scale-percent.html: Added.
+
+2021-09-08 Simon Fraser <simon.fra...@apple.com>
+
Add a temporarily prefixed property for mask-mode, aliased to -webkit-mask-source-type
https://bugs.webkit.org/show_bug.cgi?id=229915
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282143 => 282144)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-09-08 15:34:37 UTC (rev 282144)
@@ -1,3 +1,13 @@
+2021-09-08 Simon Fraser <simon.fra...@apple.com>
+
+ Support percentages in the scale() transform functions, and the scale property
+ https://bugs.webkit.org/show_bug.cgi?id=202501
+
+ Reviewed by Sam Weinig.
+
+ * web-platform-tests/css/css-transforms/parsing/scale-parsing-valid-expected.txt:
+ * web-platform-tests/css/css-transforms/parsing/transform-valid-expected.txt:
+
2021-09-08 Martin Robinson <mrobin...@webkit.org>
[css-position-sticky] Sticky constraints are calculated incorrectly when scrolling container has padding and borders
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/scale-parsing-valid-expected.txt (282143 => 282144)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/scale-parsing-valid-expected.txt 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/scale-parsing-valid-expected.txt 2021-09-08 15:34:37 UTC (rev 282144)
@@ -1,24 +1,24 @@
PASS e.style['scale'] = "none" should set the property value
PASS e.style['scale'] = "1" should set the property value
-FAIL e.style['scale'] = "1%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "1%" should set the property value
PASS e.style['scale'] = "100" should set the property value
-FAIL e.style['scale'] = "100%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100%" should set the property value
PASS e.style['scale'] = "100 100" should set the property value
-FAIL e.style['scale'] = "100% 100%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100% 100%" should set the property value
PASS e.style['scale'] = "100 100 1" should set the property value
-FAIL e.style['scale'] = "100% 100% 1" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100% 100% 1" should set the property value
PASS e.style['scale'] = "-100" should set the property value
-FAIL e.style['scale'] = "-100%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "-100%" should set the property value
PASS e.style['scale'] = "-100 -100" should set the property value
-FAIL e.style['scale'] = "-100% -100%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "-100% -100%" should set the property value
PASS e.style['scale'] = "-100 -100 1" should set the property value
-FAIL e.style['scale'] = "-100% -100% 1" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "-100% -100% 1" should set the property value
PASS e.style['scale'] = "100 200" should set the property value
-FAIL e.style['scale'] = "100% 200%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100% 200%" should set the property value
PASS e.style['scale'] = "100 200 1" should set the property value
-FAIL e.style['scale'] = "100% 200% 1" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100% 200% 1" should set the property value
PASS e.style['scale'] = "100 200 300" should set the property value
PASS e.style['scale'] = "100 100 2" should set the property value
-FAIL e.style['scale'] = "100% 200% 300%" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['scale'] = "100% 200% 300%" should set the property value
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/transform-valid-expected.txt (282143 => 282144)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/transform-valid-expected.txt 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/parsing/transform-valid-expected.txt 2021-09-08 15:34:37 UTC (rev 282144)
@@ -11,22 +11,22 @@
PASS e.style['transform'] = "scale(3, 4)" should set the property value
PASS e.style['transform'] = "scale(-2)" should set the property value
PASS e.style['transform'] = "scale(-5, -6)" should set the property value
-FAIL e.style['transform'] = "scale(250%)" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['transform'] = "scale(325%, 475%)" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['transform'] = "scale(1, 200%)" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['transform'] = "scale(-250%)" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['transform'] = "scale(-500%, -620%)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scale(250%)" should set the property value
+PASS e.style['transform'] = "scale(325%, 475%)" should set the property value
+PASS e.style['transform'] = "scale(1, 200%)" should set the property value
+PASS e.style['transform'] = "scale(-250%)" should set the property value
+PASS e.style['transform'] = "scale(-500%, -620%)" should set the property value
PASS e.style['transform'] = "scaleX(7)" should set the property value
-FAIL e.style['transform'] = "scaleX(720%)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scaleX(720%)" should set the property value
PASS e.style['transform'] = "scaleY(-8)" should set the property value
-FAIL e.style['transform'] = "scaleY(-85%)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scaleY(-85%)" should set the property value
PASS e.style['transform'] = "scaleZ(4)" should set the property value
-FAIL e.style['transform'] = "scaleZ(25%)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scaleZ(25%)" should set the property value
PASS e.style['transform'] = "scale3d(0.5, 2.5, 3)" should set the property value
-FAIL e.style['transform'] = "scale3d(50%, 250%, 300%)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scale3d(50%, 250%, 300%)" should set the property value
PASS e.style['transform'] = "scale3d(-0.5, 2.5, -3)" should set the property value
-FAIL e.style['transform'] = "scale3d(-50%, 250%, -300%)" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['transform'] = "scale3d(1, 200%, 3)" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['transform'] = "scale3d(-50%, 250%, -300%)" should set the property value
+PASS e.style['transform'] = "scale3d(1, 200%, 3)" should set the property value
PASS e.style['transform'] = "rotate(0)" should set the property value
PASS e.style['transform'] = "rotate(90deg)" should set the property value
PASS e.style['transform'] = "skew(0)" should set the property value
Added: trunk/LayoutTests/transforms/2d/scale-percent-expected.html (0 => 282144)
--- trunk/LayoutTests/transforms/2d/scale-percent-expected.html (rev 0)
+++ trunk/LayoutTests/transforms/2d/scale-percent-expected.html 2021-09-08 15:34:37 UTC (rev 282144)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ .box {
+ margin: 10px;
+ width: 100px;
+ height: 100px;
+ background-color: blue;
+ }
+ </style>
+</head>
+<body>
+ <div class="box" style="transform: scale(0.8)"></div>
+ <div class="box" style="transform: scale(0.8)"></div>
+ <div class="box" style="transform: scale(0.8)"></div>
+ <div class="box" style="transform: scale(0.8)"></div>
+ <div class="box" style="transform: scale(0.8)"></div>
+</body>
+</html>
Added: trunk/LayoutTests/transforms/2d/scale-percent.html (0 => 282144)
--- trunk/LayoutTests/transforms/2d/scale-percent.html (rev 0)
+++ trunk/LayoutTests/transforms/2d/scale-percent.html 2021-09-08 15:34:37 UTC (rev 282144)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ .box {
+ margin: 10px;
+ width: 100px;
+ height: 100px;
+ background-color: blue;
+ }
+ </style>
+</head>
+<body>
+ <div class="box" style="transform: scale(80%)"></div>
+ <div class="box" style="transform: scale(80%, 0.8)"></div>
+ <div class="box" style="transform: scale(calc(100% * 0.8), 0.8)"></div>
+ <div class="box" style="scale: 80%"></div>
+ <div class="box" style="scale: calc(100% * 0.8)"></div>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (282143 => 282144)
--- trunk/Source/WebCore/ChangeLog 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/ChangeLog 2021-09-08 15:34:37 UTC (rev 282144)
@@ -1,5 +1,35 @@
2021-09-08 Simon Fraser <simon.fra...@apple.com>
+ Support percentages in the scale() transform functions, and the scale property
+ https://bugs.webkit.org/show_bug.cgi?id=202501
+
+ Reviewed by Sam Weinig.
+
+ Support percentage values in the scale*() functions in the transform property, and
+ on the scale property. These value are converted by numbers by dividing by 100
+ at parse time, as we do for alpha values in colors. We have to keep calc() intact,
+ so % calcs need to be divided by 100 at use time.
+
+ Test: transforms/2d/scale-percent.html
+
+ * css/CSSPrimitiveValue.cpp:
+ (WebCore::CSSPrimitiveValue::doubleValueDividingBy100IfPercentage const):
+ * css/CSSPrimitiveValue.h:
+ * css/TransformFunctions.cpp:
+ (WebCore::transformsForValue):
+ (WebCore::scaleForValue):
+ * css/parser/CSSPropertyParser.cpp:
+ (WebCore::consumeNumbersOrPercents):
+ (WebCore::consumeTransformValue):
+ (WebCore::consumeScale):
+ * css/parser/CSSPropertyParserHelpers.cpp:
+ (WebCore::CSSPropertyParserHelpers::consumeNumberRawOrPercentRaw):
+ (WebCore::CSSPropertyParserHelpers::consumeNumberRawOrPercentRawAllowingSymbolTableIdent):
+ (WebCore::CSSPropertyParserHelpers::consumeNumberOrPercent):
+ * css/parser/CSSPropertyParserHelpers.h:
+
+2021-09-08 Simon Fraser <simon.fra...@apple.com>
+
Add a temporarily prefixed property for mask-mode, aliased to -webkit-mask-source-type
https://bugs.webkit.org/show_bug.cgi?id=229915
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (282143 => 282144)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2021-09-08 15:34:37 UTC (rev 282144)
@@ -830,6 +830,20 @@
return primitiveUnitType() != CSSUnitType::CSS_CALC ? m_value.num : m_value.calc->doubleValue();
}
+double CSSPrimitiveValue::doubleValueDividingBy100IfPercentage() const
+{
+ switch (primitiveUnitType()) {
+ case CSSUnitType::CSS_CALC:
+ return m_value.calc->primitiveType() == CSSUnitType::CSS_PERCENTAGE ? m_value.calc->doubleValue() / 100.0 : m_value.calc->doubleValue();
+
+ case CSSUnitType::CSS_PERCENTAGE:
+ return m_value.num / 100.0;
+
+ default:
+ return m_value.num;
+ }
+}
+
std::optional<bool> CSSPrimitiveValue::isZero() const
{
if (primitiveUnitType() == CSSUnitType::CSS_CALC)
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (282143 => 282144)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.h 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h 2021-09-08 15:34:37 UTC (rev 282144)
@@ -149,6 +149,8 @@
// It's usually wrong to call this; it can trigger type conversion in calc without sufficient context to resolve relative length units.
double doubleValue() const;
+
+ double doubleValueDividingBy100IfPercentage() const;
// These return nullopt for calc, for which range checking is not done at parse time: <https://www.w3.org/TR/css3-values/#calc-range>.
std::optional<bool> isZero() const;
Modified: trunk/Source/WebCore/css/TransformFunctions.cpp (282143 => 282144)
--- trunk/Source/WebCore/css/TransformFunctions.cpp 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/TransformFunctions.cpp 2021-09-08 15:34:37 UTC (rev 282144)
@@ -136,13 +136,13 @@
double sx = 1.0;
double sy = 1.0;
if (transformValue.name() == CSSValueScaleY)
- sy = firstValue.doubleValue();
+ sy = firstValue.doubleValueDividingBy100IfPercentage();
else {
- sx = firstValue.doubleValue();
+ sx = firstValue.doubleValueDividingBy100IfPercentage();
if (transformValue.name() != CSSValueScaleX) {
if (transformValue.length() > 1) {
auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1));
- sy = secondValue.doubleValue();
+ sy = secondValue.doubleValueDividingBy100IfPercentage();
} else
sy = sx;
}
@@ -156,19 +156,19 @@
double sy = 1.0;
double sz = 1.0;
if (transformValue.name() == CSSValueScaleZ)
- sz = firstValue.doubleValue();
+ sz = firstValue.doubleValueDividingBy100IfPercentage();
else if (transformValue.name() == CSSValueScaleY)
- sy = firstValue.doubleValue();
+ sy = firstValue.doubleValueDividingBy100IfPercentage();
else {
- sx = firstValue.doubleValue();
+ sx = firstValue.doubleValueDividingBy100IfPercentage();
if (transformValue.name() != CSSValueScaleX) {
if (transformValue.length() > 2) {
auto& thirdValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(2));
- sz = thirdValue.doubleValue();
+ sz = thirdValue.doubleValueDividingBy100IfPercentage();
}
if (transformValue.length() > 1) {
auto& secondValue = downcast<CSSPrimitiveValue>(*transformValue.itemWithoutBoundsCheck(1));
- sy = secondValue.doubleValue();
+ sy = secondValue.doubleValueDividingBy100IfPercentage();
} else
sy = sx;
}
@@ -396,13 +396,13 @@
if (!is<CSSPrimitiveValue>(valueItem))
return nullptr;
if (!i) {
- sx = downcast<CSSPrimitiveValue>(*valueItem).doubleValue();
+ sx = downcast<CSSPrimitiveValue>(*valueItem).doubleValueDividingBy100IfPercentage();
sy = sx;
} else if (i == 1)
- sy = downcast<CSSPrimitiveValue>(*valueItem).doubleValue();
+ sy = downcast<CSSPrimitiveValue>(*valueItem).doubleValueDividingBy100IfPercentage();
else if (i == 2) {
type = TransformOperation::SCALE_3D;
- sz = downcast<CSSPrimitiveValue>(*valueItem).doubleValue();
+ sz = downcast<CSSPrimitiveValue>(*valueItem).doubleValueDividingBy100IfPercentage();
}
}
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (282143 => 282144)
--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2021-09-08 15:34:37 UTC (rev 282144)
@@ -1793,6 +1793,32 @@
return true;
}
+static bool consumeNumbersOrPercents(CSSParserTokenRange& args, RefPtr<CSSFunctionValue>& transformValue, unsigned numberOfArguments)
+{
+ auto parseNumberAndAppend = [&] {
+ auto parsedValue = consumeNumberOrPercent(args, ValueRange::All);
+ if (!parsedValue)
+ return false;
+
+ transformValue->append(parsedValue.releaseNonNull());
+ --numberOfArguments;
+ return true;
+ };
+
+ if (!parseNumberAndAppend())
+ return false;
+
+ while (numberOfArguments) {
+ if (!consumeCommaIncludingWhitespace(args))
+ return false;
+
+ if (!parseNumberAndAppend())
+ return false;
+ }
+
+ return true;
+}
+
static bool consumePerspective(CSSParserTokenRange& args, CSSParserMode cssParserMode, RefPtr<CSSFunctionValue>& transformValue)
{
if (auto parsedValue = consumeLength(args, cssParserMode, ValueRange::NonNegative)) {
@@ -1840,12 +1866,12 @@
case CSSValueScaleY:
case CSSValueScaleZ:
case CSSValueScale:
- parsedValue = consumeNumber(args, ValueRange::All);
+ parsedValue = consumeNumberOrPercent(args, ValueRange::All);
if (!parsedValue)
return nullptr;
if (functionId == CSSValueScale && consumeCommaIncludingWhitespace(args)) {
transformValue->append(*parsedValue);
- parsedValue = consumeNumber(args, ValueRange::All);
+ parsedValue = consumeNumberOrPercent(args, ValueRange::All);
if (!parsedValue)
return nullptr;
}
@@ -1876,7 +1902,7 @@
return nullptr;
break;
case CSSValueScale3d:
- if (!consumeNumbers(args, transformValue, 3))
+ if (!consumeNumbersOrPercents(args, transformValue, 3))
return nullptr;
break;
case CSSValueRotate3d:
@@ -1983,25 +2009,25 @@
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
- RefPtr<CSSValue> x = consumeNumber(range, ValueRange::All);
+ RefPtr<CSSValue> x = consumeNumberOrPercent(range, ValueRange::All);
if (!x)
return list;
list->append(*x);
range.consumeWhitespace();
- RefPtr<CSSValue> y = consumeNumber(range, ValueRange::All);
+ RefPtr<CSSValue> y = consumeNumberOrPercent(range, ValueRange::All);
if (!y)
return list;
// If the x and y values are the same, the y value is not needed.
- if (downcast<CSSPrimitiveValue>(*x).floatValue() != downcast<CSSPrimitiveValue>(*y).floatValue())
+ if (downcast<CSSPrimitiveValue>(*x).doubleValue() != downcast<CSSPrimitiveValue>(*y).doubleValue())
list->append(*y);
range.consumeWhitespace();
- RefPtr<CSSValue> z = consumeNumber(range, ValueRange::All);
+ RefPtr<CSSValue> z = consumeNumberOrPercent(range, ValueRange::All);
if (!z)
return list;
- if (downcast<CSSPrimitiveValue>(*z).floatValue() != 1.0) {
+ if (downcast<CSSPrimitiveValue>(*z).doubleValue() != 1.0) {
// We only need to append the z value if it's set to something other than 1.
// In case y was not added yet, because it was equal to x, we must append it
// prior to appending z.
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (282143 => 282144)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-09-08 15:34:37 UTC (rev 282144)
@@ -256,7 +256,7 @@
return clampTo<IntType>(range.consumeIncludingWhitespace().numericValue());
}
-// MARK: Integer (CSSPrimitiveValue - not maintaing calc)
+// MARK: Integer (CSSPrimitiveValue - not maintaining calc)
template<typename IntType> static RefPtr<CSSPrimitiveValue> consumeIntegerTypeCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, double minimumValue, CSSValuePool& pool)
{
@@ -324,7 +324,7 @@
return std::nullopt;
}
-// MARK: Number (CSSPrimitiveValue - maintaing calc)
+// MARK: Number (CSSPrimitiveValue - maintaining calc)
static RefPtr<CSSPrimitiveValue> consumeNumberCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, CSSValuePool& pool)
{
@@ -400,7 +400,7 @@
}
-// MARK: Percent (CSSPrimitiveValue - maintaing calc)
+// MARK: Percent (CSSPrimitiveValue - maintaining calc)
static RefPtr<CSSPrimitiveValue> consumePercentCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, CSSValuePool& pool)
{
@@ -497,7 +497,7 @@
return std::nullopt;
}
-// MARK: Length (CSSPrimitiveValue - maintaing calc)
+// MARK: Length (CSSPrimitiveValue - maintaining calc)
static RefPtr<CSSPrimitiveValue> consumeLengthCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, CSSParserMode, UnitlessQuirk, CSSValuePool& pool)
{
@@ -562,7 +562,7 @@
return std::nullopt;
}
-// MARK: Angle (CSSPrimitiveValue - maintaing calc)
+// MARK: Angle (CSSPrimitiveValue - maintaining calc)
static RefPtr<CSSPrimitiveValue> consumeAngleCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, CSSParserMode, UnitlessQuirk, UnitlessZeroQuirk, CSSValuePool& pool)
{
@@ -591,7 +591,7 @@
}
-// MARK: Time (CSSPrimitiveValue - maintaing calc)
+// MARK: Time (CSSPrimitiveValue - maintaining calc)
static RefPtr<CSSPrimitiveValue> consumeTimeCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, CSSParserMode, UnitlessQuirk, CSSValuePool& pool)
{
@@ -1121,7 +1121,7 @@
// MARK: - Combination consumers with transformations based on result type.
template<typename NumberTransformer, typename PercentTransformer>
-static auto consumeNumberRawOrPercentRaw(CSSParserTokenRange& range, ValueRange valueRange, NumberTransformer&& numberTranformer, PercentTransformer&& percentTranformer) -> std::optional<decltype(numberTranformer(std::declval<double>()))>
+static auto consumeNumberRawOrPercentRaw(CSSParserTokenRange& range, ValueRange valueRange, NumberTransformer&& numberTransformer, PercentTransformer&& percentTransformer) -> std::optional<decltype(numberTransformer(std::declval<double>()))>
{
const auto& token = range.peek();
@@ -1128,20 +1128,20 @@
switch (token.type()) {
case FunctionToken: {
if (auto number = consumeNumberRawWithKnownTokenTypeFunction(range, { }, valueRange))
- return numberTranformer(*number);
+ return numberTransformer(*number);
if (auto percent = consumePercentRawWithKnownTokenTypeFunction(range, { }, valueRange))
- return percentTranformer(*percent);
+ return percentTransformer(*percent);
break;
}
case PercentageToken:
if (auto percent = consumePercentRawWithKnownTokenTypePercentage(range, { }, valueRange))
- return percentTranformer(*percent);
+ return percentTransformer(*percent);
break;
case NumberToken:
if (auto number = consumeNumberRawWithKnownTokenTypeNumber(range, { }, valueRange))
- return numberTranformer(*number);
+ return numberTransformer(*number);
break;
default:
@@ -1159,7 +1159,7 @@
// MARK: - Combination consumers that both allow lookup in the symbol table for IdentTokens and transformations based on result type.
template<typename NumberTransformer, typename PercentTransformer>
-static auto consumeNumberRawOrPercentRawAllowingSymbolTableIdent(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, NumberTransformer&& numberTranformer, PercentTransformer&& percentTranformer) -> std::optional<decltype(numberTranformer(std::declval<double>()))>
+static auto consumeNumberRawOrPercentRawAllowingSymbolTableIdent(CSSParserTokenRange& range, const CSSCalcSymbolTable& symbolTable, ValueRange valueRange, NumberTransformer&& numberTransformer, PercentTransformer&& percentTransformer) -> std::optional<decltype(numberTransformer(std::declval<double>()))>
{
auto& token = range.peek();
@@ -1166,20 +1166,20 @@
switch (token.type()) {
case FunctionToken: {
if (auto number = consumeNumberRawWithKnownTokenTypeFunction(range, symbolTable, valueRange))
- return numberTranformer(*number);
+ return numberTransformer(*number);
if (auto percent = consumePercentRawWithKnownTokenTypeFunction(range, symbolTable, valueRange))
- return percentTranformer(*percent);
+ return percentTransformer(*percent);
break;
}
case PercentageToken:
if (auto percent = consumePercentRawWithKnownTokenTypePercentage(range, symbolTable, valueRange))
- return percentTranformer(*percent);
+ return percentTransformer(*percent);
break;
case NumberToken:
if (auto number = consumeNumberRawWithKnownTokenTypeNumber(range, symbolTable, valueRange))
- return numberTranformer(*number);
+ return numberTransformer(*number);
break;
case IdentToken:
@@ -1188,7 +1188,7 @@
case CSSUnitType::CSS_PERCENTAGE:
if (auto validatedValue = validatedPercentRaw(variable->value, valueRange)) {
range.consumeIncludingWhitespace();
- return percentTranformer(*validatedValue);
+ return percentTransformer(*validatedValue);
}
break;
@@ -1195,7 +1195,7 @@
case CSSUnitType::CSS_NUMBER:
if (auto validatedValue = validatedNumberRaw(variable->value, valueRange)) {
range.consumeIncludingWhitespace();
- return numberTranformer(*validatedValue);
+ return numberTransformer(*validatedValue);
}
break;
@@ -1217,6 +1217,30 @@
return consumeNumberRawOrPercentRawAllowingSymbolTableIdent(range, symbolTable, valueRange, [](double number) { return number; }, [](double percent) { return percent / 100.0; });
}
+RefPtr<CSSPrimitiveValue> consumeNumberOrPercent(CSSParserTokenRange& range, ValueRange valueRange)
+{
+ auto& token = range.peek();
+
+ switch (token.type()) {
+ case FunctionToken:
+ if (auto value = consumeNumberCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(range, { }, valueRange, CSSValuePool::singleton()))
+ return value;
+ return consumePercentCSSPrimitiveValueWithCalcWithKnownTokenTypeFunction(range, { }, valueRange, CSSValuePool::singleton());
+
+ case NumberToken:
+ case PercentageToken: {
+ auto value = consumeNumberRawOrPercentDividedBy100Raw(range, valueRange);
+ if (value)
+ return CSSValuePool::singleton().createValue(*value, CSSUnitType::CSS_NUMBER);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return nullptr;
+}
+
std::optional<double> consumeFontWeightNumberRaw(CSSParserTokenRange& range)
{
// Values less than or equal to 0 or greater than or equal to 1000 are parse errors.
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (282143 => 282144)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2021-09-08 14:59:24 UTC (rev 282143)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2021-09-08 15:34:37 UTC (rev 282144)
@@ -80,6 +80,7 @@
RefPtr<CSSPrimitiveValue> consumePositiveInteger(CSSParserTokenRange&);
std::optional<double> consumeNumberRaw(CSSParserTokenRange&, ValueRange = ValueRange::All);
RefPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRange&, ValueRange);
+RefPtr<CSSPrimitiveValue> consumeNumberOrPercent(CSSParserTokenRange&, ValueRange);
std::optional<double> consumeFontWeightNumberRaw(CSSParserTokenRange&);
RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange&);
RefPtr<CSSPrimitiveValue> consumeFontWeightNumberWorkerSafe(CSSParserTokenRange&, CSSValuePool&);