Convert ENinePieceImageRule into an enum class and rename
https://bugs.webkit.org/show_bug.cgi?id=202889

Reviewed by Alex Christensen.

Enum classify ENinePieceImageRule.

The bitfield in NinePieceImage isn't saving anything so don't use one there.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::valueForRepeatRule):
* css/CSSToStyleMap.cpp:
(WebCore::CSSToStyleMap::mapNinePieceImageRepeat):
* css/StyleBuilderCustom.h:
(WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
* rendering/style/NinePieceImage.cpp:
(WebCore::NinePieceImage::NinePieceImage):
(WebCore::NinePieceImage::computeMiddleTileScale):
(WebCore::NinePieceImage::computeTileScales):
(WebCore::NinePieceImage::Data::Data):
(WebCore::NinePieceImage::Data::create):
* rendering/style/NinePieceImage.h:
(WebCore::NinePieceImage::horizontalRule const):
(WebCore::NinePieceImage::setHorizontalRule):
(WebCore::NinePieceImage::verticalRule const):
(WebCore::NinePieceImage::setVerticalRule):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index c5f9251..ad9089c 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,34 @@
 2019-10-13  Simon Fraser  <simon.fraser@apple.com>
 
+        Convert ENinePieceImageRule into an enum class and rename
+        https://bugs.webkit.org/show_bug.cgi?id=202889
+
+        Reviewed by Alex Christensen.
+
+        Enum classify ENinePieceImageRule.
+        
+        The bitfield in NinePieceImage isn't saving anything so don't use one there.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::valueForRepeatRule):
+        * css/CSSToStyleMap.cpp:
+        (WebCore::CSSToStyleMap::mapNinePieceImageRepeat):
+        * css/StyleBuilderCustom.h:
+        (WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
+        * rendering/style/NinePieceImage.cpp:
+        (WebCore::NinePieceImage::NinePieceImage):
+        (WebCore::NinePieceImage::computeMiddleTileScale):
+        (WebCore::NinePieceImage::computeTileScales):
+        (WebCore::NinePieceImage::Data::Data):
+        (WebCore::NinePieceImage::Data::create):
+        * rendering/style/NinePieceImage.h:
+        (WebCore::NinePieceImage::horizontalRule const):
+        (WebCore::NinePieceImage::setHorizontalRule):
+        (WebCore::NinePieceImage::verticalRule const):
+        (WebCore::NinePieceImage::setVerticalRule):
+
+2019-10-13  Simon Fraser  <simon.fraser@apple.com>
+
         Clarify the naming of the radius-related functions on BorderData
         https://bugs.webkit.org/show_bug.cgi?id=202888
 
diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
index 99ca66c..52172bc 100644
--- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
@@ -470,17 +470,17 @@
 
 const unsigned numComputedProperties = WTF_ARRAY_LENGTH(computedProperties);
 
-static CSSValueID valueForRepeatRule(int rule)
+static CSSValueID valueForRepeatRule(NinePieceImageRule rule)
 {
     switch (rule) {
-        case RepeatImageRule:
-            return CSSValueRepeat;
-        case RoundImageRule:
-            return CSSValueRound;
-        case SpaceImageRule:
-            return CSSValueSpace;
-        default:
-            return CSSValueStretch;
+    case NinePieceImageRule::Repeat:
+        return CSSValueRepeat;
+    case NinePieceImageRule::Round:
+        return CSSValueRound;
+    case NinePieceImageRule::Space:
+        return CSSValueSpace;
+    default:
+        return CSSValueStretch;
     }
 }
 
diff --git a/Source/WebCore/css/CSSToStyleMap.cpp b/Source/WebCore/css/CSSToStyleMap.cpp
index e93de99..c85920b 100644
--- a/Source/WebCore/css/CSSToStyleMap.cpp
+++ b/Source/WebCore/css/CSSToStyleMap.cpp
@@ -645,36 +645,36 @@
     CSSValueID firstIdentifier = pair->first()->valueID();
     CSSValueID secondIdentifier = pair->second()->valueID();
 
-    ENinePieceImageRule horizontalRule;
+    NinePieceImageRule horizontalRule;
     switch (firstIdentifier) {
     case CSSValueStretch:
-        horizontalRule = StretchImageRule;
+        horizontalRule = NinePieceImageRule::Stretch;
         break;
     case CSSValueRound:
-        horizontalRule = RoundImageRule;
+        horizontalRule = NinePieceImageRule::Round;
         break;
     case CSSValueSpace:
-        horizontalRule = SpaceImageRule;
+        horizontalRule = NinePieceImageRule::Space;
         break;
     default: // CSSValueRepeat
-        horizontalRule = RepeatImageRule;
+        horizontalRule = NinePieceImageRule::Repeat;
         break;
     }
     image.setHorizontalRule(horizontalRule);
 
-    ENinePieceImageRule verticalRule;
+    NinePieceImageRule verticalRule;
     switch (secondIdentifier) {
     case CSSValueStretch:
-        verticalRule = StretchImageRule;
+        verticalRule = NinePieceImageRule::Stretch;
         break;
     case CSSValueRound:
-        verticalRule = RoundImageRule;
+        verticalRule = NinePieceImageRule::Round;
         break;
     case CSSValueSpace:
-        verticalRule = SpaceImageRule;
+        verticalRule = NinePieceImageRule::Space;
         break;
     default: // CSSValueRepeat
-        verticalRule = RepeatImageRule;
+        verticalRule = NinePieceImageRule::Repeat;
         break;
     }
     image.setVerticalRule(verticalRule);
diff --git a/Source/WebCore/css/StyleBuilderCustom.h b/Source/WebCore/css/StyleBuilderCustom.h
index c5c2bf5..28de116 100644
--- a/Source/WebCore/css/StyleBuilderCustom.h
+++ b/Source/WebCore/css/StyleBuilderCustom.h
@@ -521,8 +521,8 @@
             image.setOutset(LengthBox(0));
             break;
         case Repeat:
-            image.setHorizontalRule(StretchImageRule);
-            image.setVerticalRule(StretchImageRule);
+            image.setHorizontalRule(NinePieceImageRule::Stretch);
+            image.setVerticalRule(NinePieceImageRule::Stretch);
             break;
         case Slice:
             // Masks have a different initial value for slices. Preserve the value of 0 for backwards compatibility.
diff --git a/Source/WebCore/rendering/style/NinePieceImage.cpp b/Source/WebCore/rendering/style/NinePieceImage.cpp
index 76286de..bc54197 100644
--- a/Source/WebCore/rendering/style/NinePieceImage.cpp
+++ b/Source/WebCore/rendering/style/NinePieceImage.cpp
@@ -45,7 +45,7 @@
 {
 }
 
-NinePieceImage::NinePieceImage(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule)
+NinePieceImage::NinePieceImage(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule)
     : m_data(Data::create(WTFMove(image), imageSlices, fill, borderSlices, outset, horizontalRule, verticalRule))
 {
 }
@@ -150,7 +150,7 @@
     return FloatSize(scale, scale);
 }
 
-FloatSize NinePieceImage::computeMiddleTileScale(const Vector<FloatSize>& scales, const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, ENinePieceImageRule hRule, ENinePieceImageRule vRule)
+FloatSize NinePieceImage::computeMiddleTileScale(const Vector<FloatSize>& scales, const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, NinePieceImageRule hRule, NinePieceImageRule vRule)
 {
     FloatSize scale(1, 1);
     if (isEmptyPieceRect(MiddlePiece, destinationRects, sourceRects))
@@ -158,14 +158,14 @@
 
     // Unlike the side pieces, the middle piece can have "stretch" specified in one axis but not the other.
     // In fact the side pieces don't even use the scale factor unless they have a rule other than "stretch".
-    if (hRule == StretchImageRule)
+    if (hRule == NinePieceImageRule::Stretch)
         scale.setWidth(destinationRects[MiddlePiece].width() / sourceRects[MiddlePiece].width());
     else if (!isEmptyPieceRect(TopPiece, destinationRects, sourceRects))
         scale.setWidth(scales[TopPiece].width());
     else if (!isEmptyPieceRect(BottomPiece, destinationRects, sourceRects))
         scale.setWidth(scales[BottomPiece].width());
 
-    if (vRule == StretchImageRule)
+    if (vRule == NinePieceImageRule::Stretch)
         scale.setHeight(destinationRects[MiddlePiece].height() / sourceRects[MiddlePiece].height());
     else if (!isEmptyPieceRect(LeftPiece, destinationRects, sourceRects))
         scale.setHeight(scales[LeftPiece].height());
@@ -175,7 +175,7 @@
     return scale;
 }
 
-Vector<FloatSize> NinePieceImage::computeTileScales(const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, ENinePieceImageRule hRule, ENinePieceImageRule vRule)
+Vector<FloatSize> NinePieceImage::computeTileScales(const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, NinePieceImageRule hRule, NinePieceImageRule vRule)
 {
     Vector<FloatSize> scales(MaxPiece, FloatSize(1, 1));
 
@@ -223,14 +223,9 @@
     }
 }
 
-inline NinePieceImage::Data::Data()
-    : fill(false)
-    , horizontalRule(StretchImageRule)
-    , verticalRule(StretchImageRule)
-{
-}
+inline NinePieceImage::Data::Data() = default;
 
-inline NinePieceImage::Data::Data(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule)
+inline NinePieceImage::Data::Data(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule)
     : fill(fill)
     , horizontalRule(horizontalRule)
     , verticalRule(verticalRule)
@@ -258,7 +253,7 @@
     return adoptRef(*new Data);
 }
 
-inline Ref<NinePieceImage::Data> NinePieceImage::Data::create(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule)
+inline Ref<NinePieceImage::Data> NinePieceImage::Data::create(RefPtr<StyleImage>&& image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule)
 {
     return adoptRef(*new Data(WTFMove(image), imageSlices, fill, borderSlices, outset, horizontalRule, verticalRule));
 }
diff --git a/Source/WebCore/rendering/style/NinePieceImage.h b/Source/WebCore/rendering/style/NinePieceImage.h
index 12a99ba..133b9a1 100644
--- a/Source/WebCore/rendering/style/NinePieceImage.h
+++ b/Source/WebCore/rendering/style/NinePieceImage.h
@@ -34,8 +34,14 @@
 class LayoutRect;
 class RenderStyle;
 
-enum ENinePieceImageRule { StretchImageRule, RoundImageRule, SpaceImageRule, RepeatImageRule };
+enum class NinePieceImageRule : uint8_t {
+    Stretch,
+    Round,
+    Space,
+    Repeat,
+};
 
+// Used for array indexing, so not an enum class.
 enum ImagePiece {
     MinPiece = 0,
     TopLeftPiece = MinPiece,
@@ -101,7 +107,7 @@
 class NinePieceImage {
 public:
     NinePieceImage();
-    NinePieceImage(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule);
+    NinePieceImage(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule);
 
     bool operator==(const NinePieceImage& other) const { return m_data == other.m_data; }
     bool operator!=(const NinePieceImage& other) const { return m_data != other.m_data; }
@@ -122,11 +128,11 @@
     const LengthBox& outset() const { return m_data->outset; }
     void setOutset(LengthBox outset) { m_data.access().outset = WTFMove(outset); }
 
-    ENinePieceImageRule horizontalRule() const { return static_cast<ENinePieceImageRule>(m_data->horizontalRule); }
-    void setHorizontalRule(ENinePieceImageRule rule) { m_data.access().horizontalRule = rule; }
+    NinePieceImageRule horizontalRule() const { return m_data->horizontalRule; }
+    void setHorizontalRule(NinePieceImageRule rule) { m_data.access().horizontalRule = rule; }
     
-    ENinePieceImageRule verticalRule() const { return static_cast<ENinePieceImageRule>(m_data->verticalRule); }
-    void setVerticalRule(ENinePieceImageRule rule) { m_data.access().verticalRule = rule; }
+    NinePieceImageRule verticalRule() const { return m_data->verticalRule; }
+    void setVerticalRule(NinePieceImageRule rule) { m_data.access().verticalRule = rule; }
 
     void copyImageSlicesFrom(const NinePieceImage& other)
     {
@@ -176,23 +182,23 @@
     static void scaleSlicesIfNeeded(const LayoutSize&, LayoutBoxExtent& slices, float deviceScaleFactor);
 
     static FloatSize computeSideTileScale(ImagePiece, const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects);
-    static FloatSize computeMiddleTileScale(const Vector<FloatSize>& scales, const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, ENinePieceImageRule hRule, ENinePieceImageRule vRule);
-    static Vector<FloatSize> computeTileScales(const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, ENinePieceImageRule hRule, ENinePieceImageRule vRule);
+    static FloatSize computeMiddleTileScale(const Vector<FloatSize>& scales, const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, NinePieceImageRule hRule, NinePieceImageRule vRule);
+    static Vector<FloatSize> computeTileScales(const Vector<FloatRect>& destinationRects, const Vector<FloatRect>& sourceRects, NinePieceImageRule hRule, NinePieceImageRule vRule);
 
     void paint(GraphicsContext&, RenderElement*, const RenderStyle&, const LayoutRect& destination, const LayoutSize& source, float deviceScaleFactor, CompositeOperator) const;
 
 private:
     struct Data : RefCounted<Data> {
         static Ref<Data> create();
-        static Ref<Data> create(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule);
+        static Ref<Data> create(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule);
         Ref<Data> copy() const;
 
         bool operator==(const Data&) const;
         bool operator!=(const Data& other) const { return !(*this == other); }
 
-        bool fill : 1;
-        unsigned horizontalRule : 2; // ENinePieceImageRule
-        unsigned verticalRule : 2; // ENinePieceImageRule
+        bool fill { false };
+        NinePieceImageRule horizontalRule { NinePieceImageRule::Stretch };
+        NinePieceImageRule verticalRule { NinePieceImageRule::Stretch };
         RefPtr<StyleImage> image;
         LengthBox imageSlices { { 100, Percent }, { 100, Percent }, { 100, Percent }, { 100, Percent } };
         LengthBox borderSlices { { 1, Relative }, { 1, Relative }, { 1, Relative }, { 1, Relative } };
@@ -200,7 +206,7 @@
 
     private:
         Data();
-        Data(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule);
+        Data(RefPtr<StyleImage>&&, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, NinePieceImageRule horizontalRule, NinePieceImageRule verticalRule);
         Data(const Data&);
     };