Title: [281785] trunk/Source/WebCore
Revision
281785
Author
[email protected]
Date
2021-08-30 16:36:42 -0700 (Mon, 30 Aug 2021)

Log Message

Remove hardcoded CSSUnitType enum values
https://bugs.webkit.org/show_bug.cgi?id=229672

Patch by Kiet Ho <[email protected]> on 2021-08-30
Reviewed by Simon Fraser.

* css/CSSPrimitiveValue.h:
(WebCore::CSSPrimitiveValue::isFontIndependentLength):
(WebCore::CSSPrimitiveValue::isLength):
(WebCore::CSSPrimitiveValue::isResolution):
(WebCore::CSSPrimitiveValue::isViewportPercentageLength):
* css/CSSUnits.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281784 => 281785)


--- trunk/Source/WebCore/ChangeLog	2021-08-30 23:10:44 UTC (rev 281784)
+++ trunk/Source/WebCore/ChangeLog	2021-08-30 23:36:42 UTC (rev 281785)
@@ -1,3 +1,17 @@
+2021-08-30  Kiet Ho  <[email protected]>
+
+        Remove hardcoded CSSUnitType enum values
+        https://bugs.webkit.org/show_bug.cgi?id=229672
+
+        Reviewed by Simon Fraser.
+
+        * css/CSSPrimitiveValue.h:
+        (WebCore::CSSPrimitiveValue::isFontIndependentLength):
+        (WebCore::CSSPrimitiveValue::isLength):
+        (WebCore::CSSPrimitiveValue::isResolution):
+        (WebCore::CSSPrimitiveValue::isViewportPercentageLength):
+        * css/CSSUnits.h:
+
 2021-08-30  Jer Noble  <[email protected]>
 
         Fix include guards in PlatformScreenMac.mm

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (281784 => 281785)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2021-08-30 23:10:44 UTC (rev 281784)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2021-08-30 23:36:42 UTC (rev 281785)
@@ -85,7 +85,7 @@
     bool isAngle() const { return unitCategory(primitiveType()) == CSSUnitCategory::Angle; }
     bool isAttr() const { return primitiveUnitType() == CSSUnitType::CSS_ATTR; }
     bool isCounter() const { return primitiveUnitType() == CSSUnitType::CSS_COUNTER; }
-    bool isFontIndependentLength() const { return primitiveUnitType() >= CSSUnitType::CSS_PX && primitiveUnitType() <= CSSUnitType::CSS_PC; }
+    bool isFontIndependentLength() const { return isFontIndependentLength(primitiveUnitType()); }
     bool isFontRelativeLength() const { return isFontRelativeLength(primitiveUnitType()); }
     bool isQuirkyEms() const { return primitiveType() == CSSUnitType::CSS_QUIRKY_EMS; }
     bool isLength() const { return isLength(static_cast<CSSUnitType>(primitiveType())); }
@@ -240,10 +240,10 @@
 
     ALWAYS_INLINE String formatNumberForCustomCSSText() const;
     NEVER_INLINE String formatNumberValue(StringView) const;
-
+    static constexpr bool isFontIndependentLength(CSSUnitType);
     static constexpr bool isFontRelativeLength(CSSUnitType);
     static constexpr bool isResolution(CSSUnitType);
-    static constexpr bool isViewportPercentageLength(CSSUnitType type) { return type >= CSSUnitType::CSS_VW && type <= CSSUnitType::CSS_VMAX; }
+    static constexpr bool isViewportPercentageLength(CSSUnitType);
 
     union {
         CSSPropertyID propertyID;
@@ -261,6 +261,16 @@
     } m_value;
 };
 
+constexpr bool CSSPrimitiveValue::isFontIndependentLength(CSSUnitType type)
+{
+    return type == CSSUnitType::CSS_PX
+        || type == CSSUnitType::CSS_CM
+        || type == CSSUnitType::CSS_MM
+        || type == CSSUnitType::CSS_IN
+        || type == CSSUnitType::CSS_PT
+        || type == CSSUnitType::CSS_PC;
+}
+
 constexpr bool CSSPrimitiveValue::isFontRelativeLength(CSSUnitType type)
 {
     return type == CSSUnitType::CSS_EMS
@@ -274,7 +284,14 @@
 
 constexpr bool CSSPrimitiveValue::isLength(CSSUnitType type)
 {
-    return (type >= CSSUnitType::CSS_EMS && type <= CSSUnitType::CSS_PC)
+    return type == CSSUnitType::CSS_EMS
+        || type == CSSUnitType::CSS_EXS
+        || type == CSSUnitType::CSS_PX
+        || type == CSSUnitType::CSS_CM
+        || type == CSSUnitType::CSS_MM
+        || type == CSSUnitType::CSS_IN
+        || type == CSSUnitType::CSS_PT
+        || type == CSSUnitType::CSS_PC
         || type == CSSUnitType::CSS_REMS
         || type == CSSUnitType::CSS_CHS
         || type == CSSUnitType::CSS_Q
@@ -286,9 +303,19 @@
 
 constexpr bool CSSPrimitiveValue::isResolution(CSSUnitType type)
 {
-    return type >= CSSUnitType::CSS_DPPX && type <= CSSUnitType::CSS_DPCM;
+    return type == CSSUnitType::CSS_DPPX
+        || type == CSSUnitType::CSS_DPI
+        || type == CSSUnitType::CSS_DPCM;
 }
 
+constexpr bool CSSPrimitiveValue::isViewportPercentageLength(CSSUnitType type)
+{
+    return type == CSSUnitType::CSS_VW
+        || type == CSSUnitType::CSS_VH
+        || type == CSSUnitType::CSS_VMIN
+        || type == CSSUnitType::CSS_VMAX;
+}
+
 template<typename T> inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::create(T&& value)
 {
     return adoptRef(*new CSSPrimitiveValue(std::forward<T>(value)));

Modified: trunk/Source/WebCore/css/CSSUnits.h (281784 => 281785)


--- trunk/Source/WebCore/css/CSSUnits.h	2021-08-30 23:10:44 UTC (rev 281784)
+++ trunk/Source/WebCore/css/CSSUnits.h	2021-08-30 23:36:42 UTC (rev 281785)
@@ -27,75 +27,74 @@
 
 namespace WebCore {
 
-// FIXME: No need to hard-code the numbers here any more, so we should remove them.
 // FIXME: No need to use all capitals and a CSS prefix on all these names. Should fix that.
 enum class CSSUnitType : uint8_t {
-    CSS_UNKNOWN = 0,
-    CSS_NUMBER = 1,
-    CSS_PERCENTAGE = 2,
-    CSS_EMS = 3,
-    CSS_EXS = 4,
-    CSS_PX = 5,
-    CSS_CM = 6,
-    CSS_MM = 7,
-    CSS_IN = 8,
-    CSS_PT = 9,
-    CSS_PC = 10,
-    CSS_DEG = 11,
-    CSS_RAD = 12,
-    CSS_GRAD = 13,
-    CSS_MS = 14,
-    CSS_S = 15,
-    CSS_HZ = 16,
-    CSS_KHZ = 17,
-    CSS_DIMENSION = 18,
-    CSS_STRING = 19,
-    CSS_URI = 20,
-    CSS_IDENT = 21,
-    CSS_ATTR = 22,
-    CSS_COUNTER = 23,
-    CSS_RECT = 24,
-    CSS_RGBCOLOR = 25,
-    CSS_VW = 26,
-    CSS_VH = 27,
-    CSS_VMIN = 28,
-    CSS_VMAX = 29,
-    CSS_DPPX = 30,
-    CSS_DPI = 31,
-    CSS_DPCM = 32,
-    CSS_FR = 33,
-    CSS_Q = 34,
-    CSS_LHS = 35,
-    CSS_RLHS = 36,
+    CSS_UNKNOWN,
+    CSS_NUMBER,
+    CSS_PERCENTAGE,
+    CSS_EMS,
+    CSS_EXS,
+    CSS_PX,
+    CSS_CM,
+    CSS_MM,
+    CSS_IN,
+    CSS_PT,
+    CSS_PC,
+    CSS_DEG,
+    CSS_RAD,
+    CSS_GRAD,
+    CSS_MS,
+    CSS_S,
+    CSS_HZ,
+    CSS_KHZ,
+    CSS_DIMENSION,
+    CSS_STRING,
+    CSS_URI,
+    CSS_IDENT,
+    CSS_ATTR,
+    CSS_COUNTER,
+    CSS_RECT,
+    CSS_RGBCOLOR,
+    CSS_VW,
+    CSS_VH,
+    CSS_VMIN,
+    CSS_VMAX,
+    CSS_DPPX,
+    CSS_DPI,
+    CSS_DPCM,
+    CSS_FR,
+    CSS_Q,
+    CSS_LHS,
+    CSS_RLHS,
 
     CustomIdent,
 
-    CSS_PAIR = 100,
-    CSS_UNICODE_RANGE = 102,
-    CSS_TURN = 107,
-    CSS_REMS = 108,
-    CSS_CHS = 109,
+    CSS_PAIR,
+    CSS_UNICODE_RANGE,
+    CSS_TURN,
+    CSS_REMS,
+    CSS_CHS,
 
-    CSS_COUNTER_NAME = 110,
+    CSS_COUNTER_NAME,
 
-    CSS_SHAPE = 111,
+    CSS_SHAPE,
 
-    CSS_QUAD = 112,
+    CSS_QUAD,
 
-    CSS_CALC = 113,
-    CSS_CALC_PERCENTAGE_WITH_NUMBER = 114,
-    CSS_CALC_PERCENTAGE_WITH_LENGTH = 115,
+    CSS_CALC,
+    CSS_CALC_PERCENTAGE_WITH_NUMBER,
+    CSS_CALC_PERCENTAGE_WITH_LENGTH,
 
-    CSS_FONT_FAMILY = 116,
+    CSS_FONT_FAMILY,
 
-    CSS_PROPERTY_ID = 117,
-    CSS_VALUE_ID = 118,
+    CSS_PROPERTY_ID,
+    CSS_VALUE_ID,
     
     // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
     // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em.
     // When the quirky value is used, if you're in quirks mode, the margin will collapse away
     // inside a table cell. This quirk is specified in the HTML spec but our impl is different.
-    CSS_QUIRKY_EMS = 120
+    CSS_QUIRKY_EMS
 
     // Note that CSSValue allocates 7 bits for m_primitiveUnitType, so there can be no value here > 127.
 };
@@ -119,4 +118,3 @@
 WTF::TextStream& operator<<(WTF::TextStream&, CSSUnitType);
 
 } // namespace WebCore
-
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to