Bug 1598528 : convert NS_STYLE_TEXT_ORIENTATION_* to an enum class in nsStyleConsts.h r=emilio
authorjeffin143 <jeffinsam@karunya.edu.in>
Tue, 26 Nov 2019 04:50:04 +0000
changeset 503809 5004f4181ad73cf46c2bc05dcee7274b2c05d758
parent 503808 40fc032b53b7e6bbe186425f89defbead3491b7e
child 503810 afe9af7c0dd5a993b42cfcc15e1e5b4c3c2c3830
push id101556
push usercbrindusan@mozilla.com
push dateTue, 26 Nov 2019 05:46:24 +0000
treeherderautoland@5004f4181ad7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1598528
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1598528 : convert NS_STYLE_TEXT_ORIENTATION_* to an enum class in nsStyleConsts.h r=emilio Differential Revision: https://phabricator.services.mozilla.com/D54252
gfx/src/nsFontMetrics.cpp
gfx/src/nsFontMetrics.h
layout/base/nsBidiPresUtils.cpp
layout/base/nsLayoutUtils.cpp
layout/style/ServoBindings.toml
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
servo/components/style/properties/longhands/inherited_box.mako.rs
--- a/gfx/src/nsFontMetrics.cpp
+++ b/gfx/src/nsFontMetrics.cpp
@@ -53,23 +53,23 @@ class AutoTextRun {
  private:
   static gfx::ShapedTextFlags ComputeFlags(nsFontMetrics* aMetrics) {
     gfx::ShapedTextFlags flags = gfx::ShapedTextFlags();
     if (aMetrics->GetTextRunRTL()) {
       flags |= gfx::ShapedTextFlags::TEXT_IS_RTL;
     }
     if (aMetrics->GetVertical()) {
       switch (aMetrics->GetTextOrientation()) {
-        case NS_STYLE_TEXT_ORIENTATION_MIXED:
+        case StyleTextOrientation::Mixed:
           flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED;
           break;
-        case NS_STYLE_TEXT_ORIENTATION_UPRIGHT:
+        case StyleTextOrientation::Upright:
           flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
           break;
-        case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS:
+        case StyleTextOrientation::Sideways:
           flags |= gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
           break;
       }
     }
     return flags;
   }
 
   RefPtr<gfxTextRun> mTextRun;
@@ -111,17 +111,17 @@ nsFontMetrics::nsFontMetrics(const nsFon
                              nsDeviceContext* aContext)
     : mFont(aFont),
       mLanguage(aParams.language),
       mDeviceContext(aContext),
       mP2A(aContext->AppUnitsPerDevPixel()),
       mOrientation(aParams.orientation),
       mTextRunRTL(false),
       mVertical(false),
-      mTextOrientation(0) {
+      mTextOrientation(mozilla::StyleTextOrientation::Mixed) {
   gfxFontStyle style(
       aFont.style, aFont.weight, aFont.stretch, gfxFloat(aFont.size) / mP2A,
       aParams.language, aParams.explicitLanguage, aFont.sizeAdjust,
       aFont.systemFont, mDeviceContext->IsPrinterContext(),
       aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
       aFont.synthesis & NS_FONT_SYNTHESIS_STYLE, aFont.languageOverride);
 
   aFont.AddFontFeaturesToStyle(&style, mOrientation == eVertical);
@@ -246,20 +246,20 @@ nscoord nsFontMetrics::AveCharWidth() {
   return CEIL_TO_TWIPS(GetMetrics(this).aveCharWidth);
 }
 
 nscoord nsFontMetrics::SpaceWidth() {
   // For vertical text with mixed or sideways orientation, we want the
   // width of a horizontal space (even if we're using vertical line-spacing
   // metrics, as with "writing-mode:vertical-*;text-orientation:mixed").
   return CEIL_TO_TWIPS(
-      GetMetrics(this, mVertical && mTextOrientation ==
-                                        NS_STYLE_TEXT_ORIENTATION_UPRIGHT
-                           ? eVertical
-                           : eHorizontal)
+      GetMetrics(this,
+                 mVertical && mTextOrientation == StyleTextOrientation::Upright
+                     ? eVertical
+                     : eHorizontal)
           .spaceWidth);
 }
 
 int32_t nsFontMetrics::GetMaxStringLength() {
   const gfxFont::Metrics& m = GetMetrics(this);
   const double x = 32767.0 / std::max(1.0, m.maxAdvance);
   int32_t len = (int32_t)floor(x);
   return std::max(1, len);
--- a/gfx/src/nsFontMetrics.h
+++ b/gfx/src/nsFontMetrics.h
@@ -221,20 +221,22 @@ class nsFontMetrics final {
                                                   DrawTarget* aDrawTarget);
 
   void SetTextRunRTL(bool aIsRTL) { mTextRunRTL = aIsRTL; }
   bool GetTextRunRTL() const { return mTextRunRTL; }
 
   void SetVertical(bool aVertical) { mVertical = aVertical; }
   bool GetVertical() const { return mVertical; }
 
-  void SetTextOrientation(uint8_t aTextOrientation) {
+  void SetTextOrientation(mozilla::StyleTextOrientation aTextOrientation) {
     mTextOrientation = aTextOrientation;
   }
-  uint8_t GetTextOrientation() const { return mTextOrientation; }
+  mozilla::StyleTextOrientation GetTextOrientation() const {
+    return mTextOrientation;
+  }
 
   gfxFontGroup* GetThebesFontGroup() const { return mFontGroup; }
   gfxUserFontSet* GetUserFontSet() const;
 
   int32_t AppUnitsPerDevPixel() const { return mP2A; }
 
  private:
   // Private destructor, to discourage deletion outside of Release():
@@ -253,12 +255,12 @@ class nsFontMetrics final {
   // descent) they will return.
   FontOrientation mOrientation;
 
   // These fields may be set by clients to control the behavior of methods
   // like GetWidth and DrawString according to the writing mode, direction
   // and text-orientation desired.
   bool mTextRunRTL;
   bool mVertical;
-  uint8_t mTextOrientation;
+  mozilla::StyleTextOrientation mTextOrientation;
 };
 
 #endif /* NSFONTMETRICS__H__ */
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -73,17 +73,17 @@ static bool IsIsolateControl(char16_t aC
 // unicode-bidi:bidi-override, or text-orientation:upright in vertical
 // writing mode) when applying the bidi algorithm.
 //
 // Returns 0 if no override control character is implied by this style.
 static char16_t GetBidiOverride(ComputedStyle* aComputedStyle) {
   const nsStyleVisibility* vis = aComputedStyle->StyleVisibility();
   if ((vis->mWritingMode == NS_STYLE_WRITING_MODE_VERTICAL_RL ||
        vis->mWritingMode == NS_STYLE_WRITING_MODE_VERTICAL_LR) &&
-      vis->mTextOrientation == NS_STYLE_TEXT_ORIENTATION_UPRIGHT) {
+      vis->mTextOrientation == StyleTextOrientation::Upright) {
     return kLRO;
   }
   const nsStyleTextReset* text = aComputedStyle->StyleTextReset();
   if (text->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_BIDI_OVERRIDE) {
     return NS_STYLE_DIRECTION_RTL == vis->mDirection ? kRLO : kLRO;
   }
   return 0;
 }
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -7356,21 +7356,21 @@ nsIFrame* nsLayoutUtils::GetReferenceFra
   uint8_t writingMode = aComputedStyle->StyleVisibility()->mWritingMode;
   switch (writingMode) {
     case NS_STYLE_WRITING_MODE_HORIZONTAL_TB:
       return gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL;
 
     case NS_STYLE_WRITING_MODE_VERTICAL_LR:
     case NS_STYLE_WRITING_MODE_VERTICAL_RL:
       switch (aComputedStyle->StyleVisibility()->mTextOrientation) {
-        case NS_STYLE_TEXT_ORIENTATION_MIXED:
+        case StyleTextOrientation::Mixed:
           return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED;
-        case NS_STYLE_TEXT_ORIENTATION_UPRIGHT:
+        case StyleTextOrientation::Upright:
           return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
-        case NS_STYLE_TEXT_ORIENTATION_SIDEWAYS:
+        case StyleTextOrientation::Sideways:
           return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
         default:
           MOZ_ASSERT_UNREACHABLE("unknown text-orientation");
           return gfx::ShapedTextFlags();
       }
 
     case NS_STYLE_WRITING_MODE_SIDEWAYS_LR:
       return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -129,16 +129,17 @@ rusty-enums = [
     "mozilla::StyleFlexDirection",
     "mozilla::StyleStrokeLinecap",
     "mozilla::StyleFlexWrap",
     "mozilla::StyleTextDecorationSkipInk",
     "mozilla::StyleTextDecorationLength",
     "mozilla::StyleShapeRendering",
     "mozilla::StyleTextAnchor",
     "mozilla::StyleObjectFit",
+    "mozilla::StyleTextOrientation",
     "nsStyleImageType",
     "nsINode_BooleanFlag",
     "mozilla::PseudoStyleType",
     "mozilla::LookAndFeel_ColorID",
     "mozilla::LookAndFeel_FontID",
     "nsStyleTransformMatrix::MatrixTransformOperator",
     "mozilla::StyleGeometryBox",
     "mozilla::SystemColor",
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -662,19 +662,21 @@ enum class StyleWhiteSpace : uint8_t {
 #define NS_STYLE_RUBY_POSITION_UNDER 1
 #define NS_STYLE_RUBY_POSITION_INTER_CHARACTER 2  // placeholder, not yet parsed
 
 // See nsStyleText
 #define NS_STYLE_TEXT_SIZE_ADJUST_NONE 0
 #define NS_STYLE_TEXT_SIZE_ADJUST_AUTO 1
 
 // See nsStyleText
-#define NS_STYLE_TEXT_ORIENTATION_MIXED 0
-#define NS_STYLE_TEXT_ORIENTATION_UPRIGHT 1
-#define NS_STYLE_TEXT_ORIENTATION_SIDEWAYS 2
+enum class StyleTextOrientation : uint8_t {
+  Mixed,
+  Upright,
+  Sideways,
+};
 
 // See nsStyleText
 #define NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE 0
 #define NS_STYLE_TEXT_COMBINE_UPRIGHT_ALL 1
 
 // See nsStyleText
 #define NS_STYLE_UNICODE_BIDI_NORMAL 0x0
 #define NS_STYLE_UNICODE_BIDI_EMBED 0x1
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3127,17 +3127,17 @@ nsChangeHint nsStyleDisplay::CalcDiffere
 
 nsStyleVisibility::nsStyleVisibility(const Document& aDocument)
     : mDirection(aDocument.GetBidiOptions() == IBMBIDI_TEXTDIRECTION_RTL
                      ? NS_STYLE_DIRECTION_RTL
                      : NS_STYLE_DIRECTION_LTR),
       mVisible(NS_STYLE_VISIBILITY_VISIBLE),
       mImageRendering(NS_STYLE_IMAGE_RENDERING_AUTO),
       mWritingMode(NS_STYLE_WRITING_MODE_HORIZONTAL_TB),
-      mTextOrientation(NS_STYLE_TEXT_ORIENTATION_MIXED),
+      mTextOrientation(StyleTextOrientation::Mixed),
       mColorAdjust(StyleColorAdjust::Economy) {
   MOZ_COUNT_CTOR(nsStyleVisibility);
 }
 
 nsStyleVisibility::nsStyleVisibility(const nsStyleVisibility& aSource)
     : mImageOrientation(aSource.mImageOrientation),
       mDirection(aSource.mDirection),
       mVisible(aSource.mVisible),
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1261,21 +1261,21 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   nsStyleVisibility(const nsStyleVisibility& aVisibility);
   ~nsStyleVisibility() { MOZ_COUNT_DTOR(nsStyleVisibility); }
   void TriggerImageLoads(mozilla::dom::Document&, const nsStyleVisibility*) {}
   const static bool kHasTriggerImageLoads = false;
 
   nsChangeHint CalcDifference(const nsStyleVisibility& aNewData) const;
 
   mozilla::StyleImageOrientation mImageOrientation;
-  uint8_t mDirection;        // NS_STYLE_DIRECTION_*
-  uint8_t mVisible;          // NS_STYLE_VISIBILITY_VISIBLE_*
-  uint8_t mImageRendering;   // NS_STYLE_IMAGE_RENDERING_*
-  uint8_t mWritingMode;      // NS_STYLE_WRITING_MODE_*
-  uint8_t mTextOrientation;  // NS_STYLE_TEXT_ORIENTATION_MIXED_*
+  uint8_t mDirection;       // NS_STYLE_DIRECTION_*
+  uint8_t mVisible;         // NS_STYLE_VISIBILITY_VISIBLE_*
+  uint8_t mImageRendering;  // NS_STYLE_IMAGE_RENDERING_*
+  uint8_t mWritingMode;     // NS_STYLE_WRITING_MODE_*
+  mozilla::StyleTextOrientation mTextOrientation;
   mozilla::StyleColorAdjust mColorAdjust;
 
   bool IsVisible() const { return (mVisible == NS_STYLE_VISIBILITY_VISIBLE); }
 
   bool IsVisibleOrCollapsed() const {
     return ((mVisible == NS_STYLE_VISIBILITY_VISIBLE) ||
             (mVisible == NS_STYLE_VISIBILITY_COLLAPSE));
   }
--- a/servo/components/style/properties/longhands/inherited_box.mako.rs
+++ b/servo/components/style/properties/longhands/inherited_box.mako.rs
@@ -46,16 +46,17 @@
     servo_restyle_damage="rebuild_and_reflow",
 )}
 
 ${helpers.single_keyword(
     "text-orientation",
     "mixed upright sideways",
     engines="gecko",
     gecko_aliases="sideways-right=sideways",
+    gecko_enum_prefix="StyleTextOrientation",
     animation_value_type="none",
     spec="https://drafts.csswg.org/css-writing-modes/#propdef-text-orientation",
 )}
 
 // CSS Color Module Level 4
 // https://drafts.csswg.org/css-color/
 ${helpers.single_keyword(
     "color-adjust",