Commit b915384a authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Fix usage counter for calculated unitless SVG length

The original counter only counts unitless length literals, which is
incorrect and was exposed by a recent refactoring crrev.com/c/1696274

This patch changes the counter to also count unitless lengths involved
in math functions (e.g., calc(1 + 1%)).

Bug: 979895
Change-Id: I49744bceee307485e979addb3ea9be95d9d22922
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1750189Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686493}
parent 76392dc8
......@@ -461,14 +461,24 @@ CSSPrimitiveValue* ConsumeLengthOrPercent(CSSParserTokenRange& range,
namespace {
bool IsNonZeroUserUnitsValue(const CSSPrimitiveValue* value) {
// TODO(crbug.com/979895): This is the result of a refactoring, which might
// have revealed an existing bug in handling user units in math functions. Fix
// it if necessary.
const auto* numeric_literal = DynamicTo<CSSNumericLiteralValue>(value);
return numeric_literal &&
numeric_literal->GetType() ==
CSSPrimitiveValue::UnitType::kUserUnits &&
value->GetDoubleValue() != 0;
if (!value)
return false;
if (const auto* numeric_literal = DynamicTo<CSSNumericLiteralValue>(value)) {
return numeric_literal->GetType() ==
CSSPrimitiveValue::UnitType::kUserUnits &&
value->GetDoubleValue() != 0;
}
const auto& math_value = To<CSSMathFunctionValue>(*value);
switch (math_value.Category()) {
case kCalcNumber:
return math_value.DoubleValue() != 0;
case kCalcPercentNumber:
case kCalcLengthNumber:
case kCalcPercentLengthNumber:
return true;
default:
return false;
}
}
} // namespace
......
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