Commit 137af69c authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Move CSSPrimitiveValue::GetType() down to CSSNumericLiteralValue

Only CSSNumericLiteralValue sets the |numeric_literal_unit_type_| enum,
and is therefore the only clas where |GetType()| makes sense. So this
patch moves |GetType()| to the correct place.

Bug: 979895
Change-Id: I83a48de866f2ccfdace9eb7b6d48ad4e8e531e5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693949Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676068}
parent a4cf4803
......@@ -18,6 +18,24 @@ class CORE_EXPORT CSSNumericLiteralValue : public CSSPrimitiveValue {
CSSNumericLiteralValue(double num, UnitType type);
UnitType GetType() const {
return static_cast<UnitType>(numeric_literal_unit_type_);
}
bool IsFontRelativeLength() const {
return GetType() == UnitType::kQuirkyEms || GetType() == UnitType::kEms ||
GetType() == UnitType::kExs || GetType() == UnitType::kRems ||
GetType() == UnitType::kChs;
}
bool IsQuirkyEms() const { return GetType() == UnitType::kQuirkyEms; }
bool IsViewportPercentageLength() const {
return CSSPrimitiveValue::IsViewportPercentageLength(GetType());
}
bool IsResolution() const {
return CSSPrimitiveValue::IsResolution(GetType());
}
bool IsFlex() const { return CSSPrimitiveValue::IsFlex(GetType()); }
bool IsZero() const { return !DoubleValue(); }
double DoubleValue() const { return num_; }
......
......@@ -95,15 +95,37 @@ CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::UnitTypeToUnitCategory(
CSSPrimitiveValue::UnitType CSSPrimitiveValue::TypeWithCalcResolved() const {
if (IsNumericLiteralValue())
return GetType();
return To<CSSNumericLiteralValue>(this)->GetType();
return To<CSSMathFunctionValue>(this)->TypeWithMathFunctionResolved();
}
bool CSSPrimitiveValue::IsCalculatedPercentageWithLength() const {
// TODO(crbug.com/979895): Move this function to |CSSMathFunctionValue|.
return IsCalculated() &&
To<CSSMathFunctionValue>(this)->Category() == kCalcPercentLength;
}
bool CSSPrimitiveValue::IsFontRelativeLength() const {
// TODO(crbug.com/979895): Move this function to |CSSNumericLiteralValue|.
return IsNumericLiteralValue() &&
To<CSSNumericLiteralValue>(this)->IsFontRelativeLength();
}
bool CSSPrimitiveValue::IsResolution() const {
// TODO(style-dev): Either support math functions on resolutions; or provide a
// justification for not supporting it, and move this function to
// |CSSNumericLiteralValue|.
return IsNumericLiteralValue() &&
To<CSSNumericLiteralValue>(this)->IsResolution();
}
bool CSSPrimitiveValue::IsFlex() const {
// TODO(style-dev): Either support math functions on flexible lengths; or
// provide a justification for not supporting it, and move this function to
// |CSSNumericLiteralValue|.
return IsNumericLiteralValue() && To<CSSNumericLiteralValue>(this)->IsFlex();
}
CSSPrimitiveValue::CSSPrimitiveValue(ClassType class_type)
: CSSValue(class_type) {}
......
......@@ -160,15 +160,7 @@ class CORE_EXPORT CSSPrimitiveValue : public CSSValue {
unit == UnitType::kGradians || unit == UnitType::kTurns;
}
bool IsAngle() const { return IsAngle(TypeWithCalcResolved()); }
bool IsFontRelativeLength() const {
return GetType() == UnitType::kQuirkyEms || GetType() == UnitType::kEms ||
GetType() == UnitType::kExs || GetType() == UnitType::kRems ||
GetType() == UnitType::kChs;
}
bool IsQuirkyEms() const { return GetType() == UnitType::kQuirkyEms; }
bool IsViewportPercentageLength() const {
return IsViewportPercentageLength(GetType());
}
bool IsFontRelativeLength() const;
static bool IsViewportPercentageLength(UnitType type) {
return type >= UnitType::kViewportWidth && type <= UnitType::kViewportMax;
}
......@@ -203,9 +195,9 @@ class CORE_EXPORT CSSPrimitiveValue : public CSSValue {
return type >= UnitType::kDotsPerPixel &&
type <= UnitType::kDotsPerCentimeter;
}
bool IsResolution() const { return IsResolution(GetType()); }
bool IsResolution() const;
static bool IsFlex(UnitType unit) { return unit == UnitType::kFraction; }
bool IsFlex() const { return IsFlex(GetType()); }
bool IsFlex() const;
// Creates either a |CSSNumericLiteralValue| or a |CSSMathFunctionValue|,
// depending on whether |value| is calculated or not. We should never create a
......@@ -271,11 +263,6 @@ class CORE_EXPORT CSSPrimitiveValue : public CSSValue {
static UnitType StringToUnitType(const UChar*, unsigned length);
double ComputeLengthDouble(const CSSToLengthConversionData&) const;
// TODO(crbug.com/979895): This should be moved to CSSNumericLiteralValue
inline UnitType GetType() const {
return static_cast<UnitType>(numeric_literal_unit_type_);
}
};
using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray;
......
......@@ -1232,8 +1232,8 @@ Length StyleBuilderConverter::ConvertQuirkyLength(StyleResolverState& state,
const CSSValue& value) {
Length length = ConvertLengthOrAuto(state, value);
// This is only for margins which use __qem
auto* primitive_value = DynamicTo<CSSPrimitiveValue>(value);
length.SetQuirk(primitive_value && primitive_value->IsQuirkyEms());
auto* numeric_literal = DynamicTo<CSSNumericLiteralValue>(value);
length.SetQuirk(numeric_literal && numeric_literal->IsQuirkyEms());
return length;
}
......
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