Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor ValueRange from enum to enum class
https://bugs.webkit.org/show_bug.cgi?id=224981

Patch by Tyler Wilcock <twilco.o@protonmail.com> on 2021-04-24
Reviewed by Sam Weinig.

Source/WebCore:

Refactor ValueRange from:

enum ValueRange {
    ValueRangeAll,
    ValueRangeNonNegative
}

to:

enum ValueRange : uint8_t {
    All,
    NonNegative
}

making it smaller (one byte versus four) and harder to misuse (no
auto-coercion to number types).

* animation/CSSPropertyAnimation.cpp:
(WebCore::blendFunc):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/CSSCalculationValue.cpp:
(WebCore::CSSCalcValue::create):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/CSSCalculationValue.h:
(WebCore::CSSCalcValue::createCalculationValue const):
(WebCore::CSSCalcValue::setPermittedValueRange):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/MediaQueryExpression.cpp:
(WebCore::consumeFirstValue):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeTransformOrigin):
(WebCore::consumeLetterSpacing):
(WebCore::consumeWordSpacing):
(WebCore::consumeTabSize):
(WebCore::consumeTextSizeAdjust):
(WebCore::consumeFontSize):
(WebCore::consumeLineHeight):
(WebCore::consumeSize):
(WebCore::consumeTextIndent):
(WebCore::consumeScrollPadding):
(WebCore::consumeMaxWidthOrHeight):
(WebCore::consumeWidthOrHeight):
(WebCore::consumeMarginOrOffset):
(WebCore::consumeClipComponent):
(WebCore::consumeLineClamp):
(WebCore::consumeHyphenateLimit):
(WebCore::consumeColumnWidth):
(WebCore::consumeGapLength):
(WebCore::consumeZoom):
(WebCore::consumeAnimationIterationCount):
(WebCore::consumeAnimationValue):
(WebCore::consumeLineWidth):
(WebCore::consumeTranslate3d):
(WebCore::consumeNumbers):
(WebCore::consumePerspective):
(WebCore::consumeTransformValue):
(WebCore::consumeTranslate):
(WebCore::consumeScale):
(WebCore::consumeRotate):
(WebCore::consumePositionLonghand):
(WebCore::consumeFlexBasis):
(WebCore::consumeKerning):
(WebCore::consumeStrokeDasharray):
(WebCore::consumeBaselineShift):
(WebCore::consumeRxOrRy):
(WebCore::consumeBorderRadiusCorner):
(WebCore::consumeTextUnderlineOffset):
(WebCore::consumeTextDecorationThickness):
(WebCore::consumeVerticalAlign):
(WebCore::consumeShapeRadius):
(WebCore::consumeBasicShapePolygon):
(WebCore::consumeRadii):
(WebCore::consumeBasicShapeInset):
(WebCore::consumeBorderImageSlice):
(WebCore::consumeBorderImageOutset):
(WebCore::consumeBorderImageWidth):
(WebCore::consumeReflect):
(WebCore::consumeBackgroundSize):
(WebCore::consumeFitContent):
(WebCore::consumeGridBreadth):
(WebCore::consumeInitialLetter):
(WebCore::consumeWebkitMarqueeIncrement):
(WebCore::consumeWebkitMarqueeRepetition):
(WebCore::consumeWebkitMarqueeSpeed):
(WebCore::consumeAspectRatio):
(WebCore::CSSPropertyParser::parseSingleValue):
(WebCore::CSSPropertyParser::consumeBorderSpacing):
(WebCore::CSSPropertyParser::consumeFlex):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeNumberOrPercentDividedBy100Raw):
(WebCore::CSSPropertyParserHelpers::CalcParser::CalcParser):
(WebCore::CSSPropertyParserHelpers::consumeNumberRaw):
(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumberRaw):
(WebCore::CSSPropertyParserHelpers::consumeLengthRaw):
(WebCore::CSSPropertyParserHelpers::consumePercentRaw):
(WebCore::CSSPropertyParserHelpers::consumeAngleRaw):
(WebCore::CSSPropertyParserHelpers::consumeAngleWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumeTime):
(WebCore::CSSPropertyParserHelpers::consumePositionComponent):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientPoint):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradient):
(WebCore::CSSPropertyParserHelpers::consumeGradientColorStops):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeFilterFunction):
(WebCore::CSSPropertyParserHelpers::consumeSingleShadow):
(WebCore::CSSPropertyParserHelpers::consumeFontSizeRaw):
(WebCore::CSSPropertyParserHelpers::consumeLineHeightRaw):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserHelpers.h:
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserWorkerSafe.cpp:
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretch):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchRange):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* page/IntersectionObserver.cpp:
(WebCore::parseRootMargin):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/CalculationValue.h:
(WebCore::CalculationValue::CalculationValue):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/Length.cpp:
(WebCore::convertTo100PercentMinusLength):
(WebCore::blendMixedTypes):
(WebCore::blend):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/Length.h:
Refactor enum ValueRange to enum class ValueRange.

* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertTo100PercentMinusLength):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

Tools:

ValueRange has been refactored from enum to enum class : uint8_t to
make it smaller and harder to misuse.

* TestWebKitAPI/Tests/WebCore/CalculationValue.cpp:
(TestWebKitAPI::createTestValue):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

Canonical link: https://commits.webkit.org/236990@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276550 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
twilco authored and webkit-commit-queue committed Apr 24, 2021
1 parent ad299d6 commit 65c114b
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 159 deletions.
166 changes: 166 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,169 @@
2021-04-24 Tyler Wilcock <twilco.o@protonmail.com>

Refactor ValueRange from enum to enum class
https://bugs.webkit.org/show_bug.cgi?id=224981

Reviewed by Sam Weinig.

Refactor ValueRange from:

enum ValueRange {
ValueRangeAll,
ValueRangeNonNegative
}

to:

enum ValueRange : uint8_t {
All,
NonNegative
}

making it smaller (one byte versus four) and harder to misuse (no
auto-coercion to number types).

* animation/CSSPropertyAnimation.cpp:
(WebCore::blendFunc):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/CSSCalculationValue.cpp:
(WebCore::CSSCalcValue::create):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/CSSCalculationValue.h:
(WebCore::CSSCalcValue::createCalculationValue const):
(WebCore::CSSCalcValue::setPermittedValueRange):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/MediaQueryExpression.cpp:
(WebCore::consumeFirstValue):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeTransformOrigin):
(WebCore::consumeLetterSpacing):
(WebCore::consumeWordSpacing):
(WebCore::consumeTabSize):
(WebCore::consumeTextSizeAdjust):
(WebCore::consumeFontSize):
(WebCore::consumeLineHeight):
(WebCore::consumeSize):
(WebCore::consumeTextIndent):
(WebCore::consumeScrollPadding):
(WebCore::consumeMaxWidthOrHeight):
(WebCore::consumeWidthOrHeight):
(WebCore::consumeMarginOrOffset):
(WebCore::consumeClipComponent):
(WebCore::consumeLineClamp):
(WebCore::consumeHyphenateLimit):
(WebCore::consumeColumnWidth):
(WebCore::consumeGapLength):
(WebCore::consumeZoom):
(WebCore::consumeAnimationIterationCount):
(WebCore::consumeAnimationValue):
(WebCore::consumeLineWidth):
(WebCore::consumeTranslate3d):
(WebCore::consumeNumbers):
(WebCore::consumePerspective):
(WebCore::consumeTransformValue):
(WebCore::consumeTranslate):
(WebCore::consumeScale):
(WebCore::consumeRotate):
(WebCore::consumePositionLonghand):
(WebCore::consumeFlexBasis):
(WebCore::consumeKerning):
(WebCore::consumeStrokeDasharray):
(WebCore::consumeBaselineShift):
(WebCore::consumeRxOrRy):
(WebCore::consumeBorderRadiusCorner):
(WebCore::consumeTextUnderlineOffset):
(WebCore::consumeTextDecorationThickness):
(WebCore::consumeVerticalAlign):
(WebCore::consumeShapeRadius):
(WebCore::consumeBasicShapePolygon):
(WebCore::consumeRadii):
(WebCore::consumeBasicShapeInset):
(WebCore::consumeBorderImageSlice):
(WebCore::consumeBorderImageOutset):
(WebCore::consumeBorderImageWidth):
(WebCore::consumeReflect):
(WebCore::consumeBackgroundSize):
(WebCore::consumeFitContent):
(WebCore::consumeGridBreadth):
(WebCore::consumeInitialLetter):
(WebCore::consumeWebkitMarqueeIncrement):
(WebCore::consumeWebkitMarqueeRepetition):
(WebCore::consumeWebkitMarqueeSpeed):
(WebCore::consumeAspectRatio):
(WebCore::CSSPropertyParser::parseSingleValue):
(WebCore::CSSPropertyParser::consumeBorderSpacing):
(WebCore::CSSPropertyParser::consumeFlex):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeNumberOrPercentDividedBy100Raw):
(WebCore::CSSPropertyParserHelpers::CalcParser::CalcParser):
(WebCore::CSSPropertyParserHelpers::consumeNumberRaw):
(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumberRaw):
(WebCore::CSSPropertyParserHelpers::consumeLengthRaw):
(WebCore::CSSPropertyParserHelpers::consumePercentRaw):
(WebCore::CSSPropertyParserHelpers::consumeAngleRaw):
(WebCore::CSSPropertyParserHelpers::consumeAngleWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumeTime):
(WebCore::CSSPropertyParserHelpers::consumePositionComponent):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientPoint):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradient):
(WebCore::CSSPropertyParserHelpers::consumeGradientColorStops):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeFilterFunction):
(WebCore::CSSPropertyParserHelpers::consumeSingleShadow):
(WebCore::CSSPropertyParserHelpers::consumeFontSizeRaw):
(WebCore::CSSPropertyParserHelpers::consumeLineHeightRaw):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserHelpers.h:
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* css/parser/CSSPropertyParserWorkerSafe.cpp:
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretch):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchRange):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* page/IntersectionObserver.cpp:
(WebCore::parseRootMargin):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/CalculationValue.h:
(WebCore::CalculationValue::CalculationValue):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/Length.cpp:
(WebCore::convertTo100PercentMinusLength):
(WebCore::blendMixedTypes):
(WebCore::blend):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.

* platform/Length.h:
Refactor enum ValueRange to enum class ValueRange.

* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertTo100PercentMinusLength):
Refactor ValueRangeAll and ValueRangeNonNegative to ValueRange::All
and ValueRange::NonNegative.


2021-04-24 Zalan Bujtas <zalan@apple.com>

[RenderTreeBuilder] Subtree moving should clear the floats on all the descendants
Expand Down
14 changes: 7 additions & 7 deletions Source/WebCore/animation/CSSPropertyAnimation.cpp
Expand Up @@ -101,7 +101,7 @@ static inline Color blendFunc(const Color& from, const Color& to, const CSSPrope
return blend(from, to, context);
}

static inline Length blendFunc(const Length& from, const Length& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRangeAll)
static inline Length blendFunc(const Length& from, const Length& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRange::All)
{
return blend(from, to, context, valueRange);
}
Expand All @@ -110,7 +110,7 @@ static inline GapLength blendFunc(const GapLength& from, const GapLength& to, co
{
if (from.isNormal() || to.isNormal())
return context.progress < 0.5 ? from : to;
return blend(from.length(), to.length(), context, ValueRangeNonNegative);
return blend(from.length(), to.length(), context, ValueRange::NonNegative);
}

static inline TabSize blendFunc(const TabSize& from, const TabSize& to, const CSSPropertyBlendingContext& context)
Expand All @@ -121,8 +121,8 @@ static inline TabSize blendFunc(const TabSize& from, const TabSize& to, const CS

static inline LengthSize blendFunc(const LengthSize& from, const LengthSize& to, const CSSPropertyBlendingContext& context)
{
return { blendFunc(from.width, to.width, context, ValueRangeNonNegative),
blendFunc(from.height, to.height, context, ValueRangeNonNegative) };
return { blendFunc(from.width, to.width, context, ValueRange::NonNegative),
blendFunc(from.height, to.height, context, ValueRange::NonNegative) };
}

static inline LengthPoint blendFunc(const LengthPoint& from, const LengthPoint& to, const CSSPropertyBlendingContext& context)
Expand Down Expand Up @@ -403,7 +403,7 @@ static inline TextDecorationThickness blendFunc(const TextDecorationThickness& f
return TextDecorationThickness::createWithAuto();
}

static inline LengthBox blendFunc(const LengthBox& from, const LengthBox& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRangeNonNegative)
static inline LengthBox blendFunc(const LengthBox& from, const LengthBox& to, const CSSPropertyBlendingContext& context, ValueRange valueRange = ValueRange::NonNegative)
{
LengthBox result(blendFunc(from.top(), to.top(), context, valueRange),
blendFunc(from.right(), to.right(), context, valueRange),
Expand Down Expand Up @@ -791,7 +791,7 @@ class LengthPropertyWrapper : public PropertyWrapperGetter<const Length&> {

void blend(RenderStyle& destination, const RenderStyle& from, const RenderStyle& to, const CSSPropertyBlendingContext& context) const override
{
auto valueRange = m_flags.contains(Flags::NegativeLengthsAreInvalid) ? ValueRangeNonNegative : ValueRangeAll;
auto valueRange = m_flags.contains(Flags::NegativeLengthsAreInvalid) ? ValueRange::NonNegative : ValueRange::All;
(destination.*m_setter)(blendFunc(value(from), value(to), context, valueRange));
}

Expand Down Expand Up @@ -898,7 +898,7 @@ class LengthBoxPropertyWrapper final : public PropertyWrapperGetter<const Length
(destination.*m_setter)(context.progress ? LengthBox(value(to)) : LengthBox(value(from)));
return;
}
auto valueRange = m_flags.contains(Flags::AllowsNegativeValues) ? ValueRangeAll : ValueRangeNonNegative;
auto valueRange = m_flags.contains(Flags::AllowsNegativeValues) ? ValueRange::All : ValueRange::NonNegative;
(destination.*m_setter)(blendFunc(value(from), value(to), context, valueRange));
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSCalculationValue.cpp
Expand Up @@ -2146,7 +2146,7 @@ RefPtr<CSSCalcValue> CSSCalcValue::create(CSSValueID function, const CSSParserTo
auto expression = parser.parseCalc(tokens, function);
if (!expression)
return nullptr;
auto result = adoptRef(new CSSCalcValue(expression.releaseNonNull(), range != ValueRangeAll));
auto result = adoptRef(new CSSCalcValue(expression.releaseNonNull(), range != ValueRange::All));
LOG_WITH_STREAM(Calc, stream << "CSSCalcValue::create " << *result);
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/CSSCalculationValue.h
Expand Up @@ -122,12 +122,12 @@ inline CSSCalcValue::CSSCalcValue(Ref<CSSCalcExpressionNode>&& expression, bool
inline Ref<CalculationValue> CSSCalcValue::createCalculationValue(const CSSToLengthConversionData& conversionData) const
{
return CalculationValue::create(m_expression->createCalcExpression(conversionData),
m_shouldClampToNonNegative ? ValueRangeNonNegative : ValueRangeAll);
m_shouldClampToNonNegative ? ValueRange::NonNegative : ValueRange::All);
}

inline void CSSCalcValue::setPermittedValueRange(ValueRange range)
{
m_shouldClampToNonNegative = range != ValueRangeAll;
m_shouldClampToNonNegative = range != ValueRange::All;
}

inline void CSSCalcValue::collectDirectComputationalDependencies(HashSet<CSSPropertyID>& values) const
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/MediaQueryExpression.cpp
Expand Up @@ -186,11 +186,11 @@ inline RefPtr<CSSPrimitiveValue> consumeFirstValue(const String& mediaFeature, C
return value;

if (!featureExpectingPositiveInteger(mediaFeature) && !isAspectRatioFeature(mediaFeature)) {
if (auto value = CSSPropertyParserHelpers::consumeNumber(range, ValueRangeNonNegative))
if (auto value = CSSPropertyParserHelpers::consumeNumber(range, ValueRange::NonNegative))
return value;
}

if (auto value = CSSPropertyParserHelpers::consumeLength(range, HTMLStandardMode, ValueRangeNonNegative))
if (auto value = CSSPropertyParserHelpers::consumeLength(range, HTMLStandardMode, ValueRange::NonNegative))
return value;

if (auto value = CSSPropertyParserHelpers::consumeResolution(range))
Expand Down

0 comments on commit 65c114b

Please sign in to comment.