Bug 1277756 part.1 Make anonymous enum for NS_TEXTRANGE_* to an enum class named "TextRangeType" r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 04 Jun 2016 09:49:21 +0900
changeset 341525 ccdb440b7b7e8e680f6c2b561fbd9db0a1214f14
parent 341524 9d34386dec390f98671e29fe4de7b768a097b27a
child 341526 93278105babfbc4ad72a55fd421df8fbc47f4dc5
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1277756
milestone49.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 1277756 part.1 Make anonymous enum for NS_TEXTRANGE_* to an enum class named "TextRangeType" r=smaug For making our code clearer by the stronger type check, we should change the anonymous enum for NS_TEXTRANGE_* to enum class whose name is "TextRangeType" and whose type is "RawTextRangeType" which is an alias of uint8_t. Additionally, this also adds some utility methods for them. Note that some lines which are changed by this patch become over 80 characters but it will be fixed by the following patches. MozReview-Commit-ID: 76izA1WqTkp
dom/base/TextInputProcessor.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
editor/libeditor/IMETextTxn.cpp
editor/libeditor/nsEditor.cpp
widget/EventForwards.h
widget/TextEventDispatcher.cpp
widget/TextEventDispatcher.h
widget/TextRange.h
widget/WidgetEventImpl.cpp
widget/android/nsWindow.cpp
widget/cocoa/TextInputHandler.h
widget/cocoa/TextInputHandler.mm
widget/gtk/IMContextWrapper.cpp
widget/nsGUIEventIPC.h
widget/windows/IMMHandler.cpp
widget/windows/TSFTextStore.cpp
--- a/dom/base/TextInputProcessor.cpp
+++ b/dom/base/TextInputProcessor.cpp
@@ -417,30 +417,32 @@ TextInputProcessor::SetPendingCompositio
 }
 
 NS_IMETHODIMP
 TextInputProcessor::AppendClauseToPendingComposition(uint32_t aLength,
                                                      uint32_t aAttribute)
 {
   MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
   RefPtr<TextEventDispatcher> kungfuDeathGrip(mDispatcher);
+  TextRangeType textRangeType;
   switch (aAttribute) {
     case ATTR_RAW_CLAUSE:
     case ATTR_SELECTED_RAW_CLAUSE:
     case ATTR_CONVERTED_CLAUSE:
     case ATTR_SELECTED_CLAUSE:
+      textRangeType = ToTextRangeType(aAttribute);
       break;
     default:
       return NS_ERROR_INVALID_ARG;
   }
   nsresult rv = IsValidStateForComposition();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
-  return mDispatcher->AppendClauseToPendingComposition(aLength, aAttribute);
+  return mDispatcher->AppendClauseToPendingComposition(aLength, textRangeType);
 }
 
 NS_IMETHODIMP
 TextInputProcessor::SetCaretInPendingComposition(uint32_t aOffset)
 {
   MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
   RefPtr<TextEventDispatcher> kungfuDeathGrip(mDispatcher);
   nsresult rv = IsValidStateForComposition();
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -881,26 +881,26 @@ nsPluginInstanceOwner::GetCompositionStr
       }
 
       aDist->SetLength(composition->LastData().Length());
       memset(aDist->Elements(), ATTR_INPUT, aDist->Length());
 
       for (TextRange& range : *ranges) {
         uint8_t type = ATTR_INPUT;
         switch(range.mRangeType) {
-          case NS_TEXTRANGE_RAWINPUT:
+          case TextRangeType::NS_TEXTRANGE_RAWINPUT:
             type = ATTR_INPUT;
             break;
-          case NS_TEXTRANGE_SELECTEDRAWTEXT:
+          case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
             type = ATTR_TARGET_NOTCONVERTED;
             break;
-          case NS_TEXTRANGE_CONVERTEDTEXT:
+          case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
             type = ATTR_CONVERTED;
             break;
-          case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
+          case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
             type = ATTR_TARGET_CONVERTED;
             break;
           default:
             continue;
         }
 
         size_t minLen = std::min<size_t>(range.mEndOffset, aDist->Length());
         for (size_t i = range.mStartOffset; i < minLen; i++) {
--- a/editor/libeditor/IMETextTxn.cpp
+++ b/editor/libeditor/IMETextTxn.cpp
@@ -130,26 +130,26 @@ IMETextTxn::GetTxnDescription(nsAString&
 {
   aString.AssignLiteral("IMETextTxn: ");
   aString += mStringToInsert;
   return NS_OK;
 }
 
 /* ============ private methods ================== */
 static SelectionType
-ToSelectionType(uint32_t aTextRangeType)
+ToSelectionType(TextRangeType aTextRangeType)
 {
-  switch(aTextRangeType) {
-    case NS_TEXTRANGE_RAWINPUT:
+  switch (aTextRangeType) {
+    case TextRangeType::NS_TEXTRANGE_RAWINPUT:
       return nsISelectionController::SELECTION_IME_RAWINPUT;
-    case NS_TEXTRANGE_SELECTEDRAWTEXT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
       return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
-    case NS_TEXTRANGE_CONVERTEDTEXT:
+    case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
       return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
-    case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
       return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;
     default:
       MOZ_CRASH("Selection type is invalid");
       return nsISelectionController::SELECTION_NORMAL;
   }
 }
 
 nsresult
@@ -208,17 +208,17 @@ IMETextTxn::SetIMESelection(nsEditor& aE
   // NOTE: composition string may be truncated when it's committed and
   //       maxlength attribute value doesn't allow input of all text of this
   //       composition.
   for (uint32_t i = 0; i < countOfRanges; ++i) {
     const TextRange& textRange = aRanges->ElementAt(i);
 
     // Caret needs special handling since its length may be 0 and if it's not
     // specified explicitly, we need to handle it ourselves later.
-    if (textRange.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
+    if (textRange.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
       NS_ASSERTION(!setCaret, "The ranges already has caret position");
       NS_ASSERTION(!textRange.Length(), "nsEditor doesn't support wide caret");
       int32_t caretOffset = static_cast<int32_t>(
         aOffsetInNode +
           std::min(textRange.mStartOffset, aLengthOfCompositionString));
       MOZ_ASSERT(caretOffset >= 0 &&
                  static_cast<uint32_t>(caretOffset) <= maxOffset);
       rv = selection->Collapse(aTextNode, caretOffset);
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -2417,17 +2417,17 @@ nsEditor::InsertTextIntoTextNodeImpl(con
       mIMETextNode = &aTextNode;
       mIMETextOffset = aOffset;
     }
     // Modify mPhonetic with raw text input clauses.
     const TextRangeArray* ranges = mComposition->GetRanges();
     for (uint32_t i = 0; i < (ranges ? ranges->Length() : 0); ++i) {
       const TextRange& textRange = ranges->ElementAt(i);
       if (!textRange.Length() ||
-          textRange.mRangeType != NS_TEXTRANGE_RAWINPUT) {
+          textRange.mRangeType != TextRangeType::NS_TEXTRANGE_RAWINPUT) {
         continue;
       }
       if (!mPhonetic) {
         mPhonetic = new nsString();
       }
       nsAutoString stringToInsert(aStringToInsert);
       stringToInsert.Mid(*mPhonetic,
                          textRange.mStartOffset, textRange.Length());
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -146,16 +146,19 @@ class NativeEventData;
 // TextEvents.h
 struct AlternativeCharCode;
 struct ShortcutKeyCandidate;
 
 typedef nsTArray<ShortcutKeyCandidate> ShortcutKeyCandidateArray;
 typedef AutoTArray<ShortcutKeyCandidate, 10> AutoShortcutKeyCandidateArray;
 
 // TextRange.h
+typedef uint8_t RawTextRangeType;
+enum class TextRangeType : RawTextRangeType;
+
 struct TextRangeStyle;
 struct TextRange;
 
 class TextRangeArray;
 
 // FontRange.h
 struct FontRange;
 
--- a/widget/TextEventDispatcher.cpp
+++ b/widget/TextEventDispatcher.cpp
@@ -590,17 +590,17 @@ TextEventDispatcher::PendingComposition:
   Clear();
 }
 
 void
 TextEventDispatcher::PendingComposition::Clear()
 {
   mString.Truncate();
   mClauses = nullptr;
-  mCaret.mRangeType = 0;
+  mCaret.mRangeType = TextRangeType::NS_TEXTRANGE_UNDEFINED;
 }
 
 void
 TextEventDispatcher::PendingComposition::EnsureClauseArray()
 {
   if (mClauses) {
     return;
   }
@@ -610,49 +610,50 @@ TextEventDispatcher::PendingComposition:
 nsresult
 TextEventDispatcher::PendingComposition::SetString(const nsAString& aString)
 {
   mString = aString;
   return NS_OK;
 }
 
 nsresult
-TextEventDispatcher::PendingComposition::AppendClause(uint32_t aLength,
-                                                      uint32_t aAttribute)
+TextEventDispatcher::PendingComposition::AppendClause(
+                                           uint32_t aLength,
+                                           TextRangeType aTextRangeType)
 {
   if (NS_WARN_IF(!aLength)) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  switch (aAttribute) {
-    case NS_TEXTRANGE_RAWINPUT:
-    case NS_TEXTRANGE_SELECTEDRAWTEXT:
-    case NS_TEXTRANGE_CONVERTEDTEXT:
-    case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT: {
+  switch (aTextRangeType) {
+    case TextRangeType::NS_TEXTRANGE_RAWINPUT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
+    case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT: {
       EnsureClauseArray();
       TextRange textRange;
       textRange.mStartOffset =
         mClauses->IsEmpty() ? 0 : mClauses->LastElement().mEndOffset;
       textRange.mEndOffset = textRange.mStartOffset + aLength;
-      textRange.mRangeType = aAttribute;
+      textRange.mRangeType = aTextRangeType;
       mClauses->AppendElement(textRange);
       return NS_OK;
     }
     default:
       return NS_ERROR_INVALID_ARG;
   }
 }
 
 nsresult
 TextEventDispatcher::PendingComposition::SetCaret(uint32_t aOffset,
                                                   uint32_t aLength)
 {
   mCaret.mStartOffset = aOffset;
   mCaret.mEndOffset = mCaret.mStartOffset + aLength;
-  mCaret.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+  mCaret.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
   return NS_OK;
 }
 
 nsresult
 TextEventDispatcher::PendingComposition::Set(const nsAString& aString,
                                              const TextRangeArray* aRanges)
 {
   Clear();
@@ -663,17 +664,17 @@ TextEventDispatcher::PendingComposition:
   nsresult rv = SetString(str);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (!aRanges || aRanges->IsEmpty()) {
     // Create dummy range if aString isn't empty.
     if (!aString.IsEmpty()) {
-      rv = AppendClause(str.Length(), NS_TEXTRANGE_RAWINPUT);
+      rv = AppendClause(str.Length(), TextRangeType::NS_TEXTRANGE_RAWINPUT);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
     return NS_OK;
   }
 
   // Adjust offsets in the ranges for XP linefeed character (only \n).
@@ -693,17 +694,17 @@ TextEventDispatcher::PendingComposition:
       range.mEndOffset = range.mStartOffset;
     } else {
       nsAutoString clause(
         Substring(aString, nativeRange.mStartOffset, nativeRange.Length()));
       clause.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
                               NS_LITERAL_STRING("\n"));
       range.mEndOffset = range.mStartOffset + clause.Length();
     }
-    if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
+    if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
       mCaret = range;
     } else {
       EnsureClauseArray();
       mClauses->AppendElement(range);
     }
   }
   return NS_OK;
 }
@@ -723,17 +724,17 @@ TextEventDispatcher::PendingComposition:
 
   if (mClauses && !mClauses->IsEmpty() &&
       mClauses->LastElement().mEndOffset != mString.Length()) {
     NS_WARNING("Sum of length of the all clauses must be same as the string "
                "length");
     Clear();
     return NS_ERROR_ILLEGAL_VALUE;
   }
-  if (mCaret.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
+  if (mCaret.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
     if (mCaret.mEndOffset > mString.Length()) {
       NS_WARNING("Caret position is out of the composition string");
       Clear();
       return NS_ERROR_ILLEGAL_VALUE;
     }
     EnsureClauseArray();
     mClauses->AppendElement(mCaret);
   }
--- a/widget/TextEventDispatcher.h
+++ b/widget/TextEventDispatcher.h
@@ -147,25 +147,25 @@ public:
     return mPendingComposition.SetString(aString);
   }
 
   /**
    * AppendClauseToPendingComposition() appends a clause information to
    * the pending composition string.
    *
    * @param aLength         Length of the clause.
-   * @param aAttribute      One of NS_TEXTRANGE_RAWINPUT,
+   * @param aTextRangeType  One of NS_TEXTRANGE_RAWINPUT,
    *                        NS_TEXTRANGE_SELECTEDRAWTEXT,
    *                        NS_TEXTRANGE_CONVERTEDTEXT or
    *                        NS_TEXTRANGE_SELECTEDCONVERTEDTEXT.
    */
   nsresult AppendClauseToPendingComposition(uint32_t aLength,
-                                            uint32_t aAttribute)
+                                            TextRangeType aTextRangeType)
   {
-    return mPendingComposition.AppendClause(aLength, aAttribute);
+    return mPendingComposition.AppendClause(aLength, aTextRangeType);
   }
 
   /**
    * SetCaretInPendingComposition() sets caret position in the pending
    * composition string and its length.  This is optional.  If IME doesn't
    * want to show caret, it shouldn't need to call this.
    *
    * @param aOffset         Offset of the caret in the pending composition
@@ -299,17 +299,17 @@ private:
   // These values will be used for dispatching eCompositionChange event
   // in Flush().  When Flush() is called, the members will be cleared
   // automatically.
   class PendingComposition
   {
   public:
     PendingComposition();
     nsresult SetString(const nsAString& aString);
-    nsresult AppendClause(uint32_t aLength, uint32_t aAttribute);
+    nsresult AppendClause(uint32_t aLength, TextRangeType aTextRangeType);
     nsresult SetCaret(uint32_t aOffset, uint32_t aLength);
     nsresult Set(const nsAString& aString, const TextRangeArray* aRanges);
     nsresult Flush(TextEventDispatcher* aDispatcher,
                    nsEventStatus& aStatus,
                    const WidgetEventTime* aEventTime);
     const TextRangeArray* GetClauses() const { return mClauses; }
     void Clear();
 
--- a/widget/TextRange.h
+++ b/widget/TextRange.h
@@ -3,16 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_TextRage_h_
 #define mozilla_TextRage_h_
 
 #include <stdint.h>
 
+#include "mozilla/EventForwards.h"
+
 #include "nsColor.h"
 #include "nsITextInputProcessor.h"
 #include "nsStyleConsts.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
 /******************************************************************************
@@ -121,54 +123,58 @@ struct TextRangeStyle
   nscolor mBackgroundColor;  // DEFINED_BACKGROUND_COLOR
   nscolor mUnderlineColor;   // DEFINED_UNDERLINE_COLOR
 };
 
 /******************************************************************************
  * mozilla::TextRange
  ******************************************************************************/
 
-// XXX NS_TEXTRANGE_* should be moved into TextRange as an typed enum.
-enum
+enum class TextRangeType : RawTextRangeType
 {
   NS_TEXTRANGE_UNDEFINED = 0x00,
   NS_TEXTRANGE_CARETPOSITION = 0x01,
   NS_TEXTRANGE_RAWINPUT =
     nsITextInputProcessor::ATTR_RAW_CLAUSE,
   NS_TEXTRANGE_SELECTEDRAWTEXT =
     nsITextInputProcessor::ATTR_SELECTED_RAW_CLAUSE,
   NS_TEXTRANGE_CONVERTEDTEXT =
     nsITextInputProcessor::ATTR_CONVERTED_CLAUSE,
   NS_TEXTRANGE_SELECTEDCONVERTEDTEXT =
     nsITextInputProcessor::ATTR_SELECTED_CLAUSE
 };
 
+bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeValue);
+RawTextRangeType ToRawTextRangeType(TextRangeType aTextRangeType);
+TextRangeType ToTextRangeType(RawTextRangeType aRawTextRangeType);
+const char* ToChar(TextRangeType aTextRangeType);
+
 struct TextRange
 {
-  TextRange() :
-    mStartOffset(0), mEndOffset(0), mRangeType(NS_TEXTRANGE_UNDEFINED)
+  TextRange()
+    : mStartOffset(0)
+    , mEndOffset(0)
+    , mRangeType(TextRangeType::NS_TEXTRANGE_UNDEFINED)
   {
   }
 
   uint32_t mStartOffset;
   // XXX Storing end offset makes the initializing code very complicated.
   //     We should replace it with mLength.
   uint32_t mEndOffset;
-  uint32_t mRangeType;
 
   TextRangeStyle mRangeStyle;
 
+  TextRangeType mRangeType;
+
   uint32_t Length() const { return mEndOffset - mStartOffset; }
 
   bool IsClause() const
   {
-    MOZ_ASSERT(mRangeType >= NS_TEXTRANGE_CARETPOSITION &&
-                 mRangeType <= NS_TEXTRANGE_SELECTEDCONVERTEDTEXT,
-               "Invalid range type");
-    return mRangeType != NS_TEXTRANGE_CARETPOSITION;
+    return mRangeType != TextRangeType::NS_TEXTRANGE_CARETPOSITION;
   }
 
   bool Equals(const TextRange& aOther) const
   {
     return mStartOffset == aOther.mStartOffset &&
            mEndOffset == aOther.mEndOffset &&
            mRangeType == aOther.mRangeType &&
            mRangeStyle == aOther.mRangeStyle;
@@ -195,18 +201,18 @@ class TextRangeArray final : public Auto
   ~TextRangeArray() {}
 
   NS_INLINE_DECL_REFCOUNTING(TextRangeArray)
 
   const TextRange* GetTargetClause() const
   {
     for (uint32_t i = 0; i < Length(); ++i) {
       const TextRange& range = ElementAt(i);
-      if (range.mRangeType == NS_TEXTRANGE_SELECTEDRAWTEXT ||
-          range.mRangeType == NS_TEXTRANGE_SELECTEDCONVERTEDTEXT) {
+      if (range.mRangeType == TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT ||
+          range.mRangeType == TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT) {
         return &range;
       }
     }
     return nullptr;
   }
 
   // Returns target clause offset.  If there are selected clauses, this returns
   // the first selected clause offset.  Otherwise, 0.
@@ -254,27 +260,27 @@ public:
     for (size_t i = 0, len = Length(); i < len; i++) {
       ElementAt(i).RemoveCharacter(aOffset);
     }
   }
 
   bool HasCaret() const
   {
     for (const TextRange& range : *this) {
-      if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
+      if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
         return true;
       }
     }
     return false;
   }
 
   uint32_t GetCaretPosition() const
   {
     for (const TextRange& range : *this) {
-      if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
+      if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
         return range.mStartOffset;
       }
     }
     return UINT32_MAX;
   }
 };
 
 } // namespace mozilla
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -52,16 +52,66 @@ ToChar(EventClassID aEventClassID)
 
 #undef NS_EVENT_CLASS
 #undef NS_ROOT_EVENT_CLASS
     default:
       return "illegal event class ID";
   }
 }
 
+bool
+IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType)
+{
+  switch (static_cast<TextRangeType>(aRawTextRangeType)) {
+    case TextRangeType::NS_TEXTRANGE_UNDEFINED:
+    case TextRangeType::NS_TEXTRANGE_CARETPOSITION:
+    case TextRangeType::NS_TEXTRANGE_RAWINPUT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
+    case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
+    case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
+      return true;
+    default:
+      return false;
+  }
+}
+
+RawTextRangeType
+ToRawTextRangeType(TextRangeType aTextRangeType)
+{
+  return static_cast<RawTextRangeType>(aTextRangeType);
+}
+
+TextRangeType
+ToTextRangeType(RawTextRangeType aRawTextRangeType)
+{
+  MOZ_ASSERT(IsValidRawTextRangeValue(aRawTextRangeType));
+  return static_cast<TextRangeType>(aRawTextRangeType);
+}
+
+const char*
+ToChar(TextRangeType aTextRangeType)
+{
+  switch (aTextRangeType) {
+    case TextRangeType::NS_TEXTRANGE_UNDEFINED:
+      return "NS_TEXTRANGE_UNDEFINED";
+    case TextRangeType::NS_TEXTRANGE_CARETPOSITION:
+      return "NS_TEXTRANGE_CARETPOSITION";
+    case TextRangeType::NS_TEXTRANGE_RAWINPUT:
+      return "NS_TEXTRANGE_RAWINPUT";
+    case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
+      return "NS_TEXTRANGE_SELECTEDRAWTEXT";
+    case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
+      return "NS_TEXTRANGE_CONVERTEDTEXT";
+    case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
+      return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
+    default:
+      return "Invalid TextRangeType";
+  }
+}
+
 /******************************************************************************
  * As*Event() implementation
  ******************************************************************************/
 
 #define NS_ROOT_EVENT_CLASS(aPrefix, aName)
 #define NS_EVENT_CLASS(aPrefix, aName) \
 aPrefix##aName* \
 WidgetEvent::As##aName() \
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -3142,17 +3142,17 @@ nsWindow::GeckoViewSupport::OnImeReplace
             event.mRanges = new TextRangeArray();
             mIMERanges.swap(event.mRanges);
 
         } else if (event.mData.Length()) {
             // Include proper text ranges to make the editor happy.
             TextRange range;
             range.mStartOffset = 0;
             range.mEndOffset = event.mData.Length();
-            range.mRangeType = NS_TEXTRANGE_RAWINPUT;
+            range.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
             event.mRanges = new TextRangeArray();
             event.mRanges->AppendElement(range);
         }
 
         window.DispatchEvent(&event);
 
     } else if (composing) {
         // Ensure IME ranges are empty.
@@ -3178,17 +3178,17 @@ nsWindow::GeckoViewSupport::OnImeAddComp
     if (mIMEMaskEventsCount > 0) {
         // Not focused.
         return;
     }
 
     TextRange range;
     range.mStartOffset = aStart;
     range.mEndOffset = aEnd;
-    range.mRangeType = aRangeType;
+    range.mRangeType = ToTextRangeType(aRangeType);
     range.mRangeStyle.mDefinedStyles = aRangeStyle;
     range.mRangeStyle.mLineStyle = aRangeLineStyle;
     range.mRangeStyle.mIsBoldLine = aRangeBoldLine;
     range.mRangeStyle.mForegroundColor =
             ConvertAndroidColor(uint32_t(aRangeForeColor));
     range.mRangeStyle.mBackgroundColor =
             ConvertAndroidColor(uint32_t(aRangeBackColor));
     range.mRangeStyle.mUnderlineColor =
--- a/widget/cocoa/TextInputHandler.h
+++ b/widget/cocoa/TextInputHandler.h
@@ -961,18 +961,18 @@ private:
    * ConvertToTextRangeStyle converts the given native underline style to
    * our defined text range type.
    *
    * @param aUnderlineStyle       NSUnderlineStyleSingle or
    *                              NSUnderlineStyleThick.
    * @param aSelectedRange        Current selected range (or caret position).
    * @return                      NS_TEXTRANGE_*.
    */
-  uint32_t ConvertToTextRangeType(uint32_t aUnderlineStyle,
-                                  NSRange& aSelectedRange);
+  TextRangeType ConvertToTextRangeType(uint32_t aUnderlineStyle,
+                                       NSRange& aSelectedRange);
 
   /**
    * GetRangeCount() computes the range count of aAttrString.
    *
    * @param aAttrString           An NSAttributedString instance whose number of
    *                              NSUnderlineStyleAttributeName ranges you with
    *                              to know.
    * @return                      The count of NSUnderlineStyleAttributeName
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -228,35 +228,16 @@ GetGeckoKeyEventType(const WidgetEvent& 
     case eKeyDown:       return "eKeyDown";
     case eKeyUp:         return "eKeyUp";
     case eKeyPress:      return "eKeyPress";
     default:             return "not key event";
   }
 }
 
 static const char*
-GetRangeTypeName(uint32_t aRangeType)
-{
-  switch (aRangeType) {
-    case NS_TEXTRANGE_RAWINPUT:
-      return "NS_TEXTRANGE_RAWINPUT";
-    case NS_TEXTRANGE_CONVERTEDTEXT:
-      return "NS_TEXTRANGE_CONVERTEDTEXT";
-    case NS_TEXTRANGE_SELECTEDRAWTEXT:
-      return "NS_TEXTRANGE_SELECTEDRAWTEXT";
-    case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
-      return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
-    case NS_TEXTRANGE_CARETPOSITION:
-      return "NS_TEXTRANGE_CARETPOSITION";
-    default:
-      return "invalid range type";
-  }
-}
-
-static const char*
 GetWindowLevelName(NSInteger aWindowLevel)
 {
   switch (aWindowLevel) {
     case kCGBaseWindowLevelKey:
       return "kCGBaseWindowLevelKey (NSNormalWindowLevel)";
     case kCGMinimumWindowLevelKey:
       return "kCGMinimumWindowLevelKey";
     case kCGDesktopWindowLevelKey:
@@ -2738,49 +2719,49 @@ IMEInputHandler::ExecutePendingMethods()
 
 
 /******************************************************************************
  *
  * IMEInputHandler implementation (native event handlers)
  *
  ******************************************************************************/
 
-uint32_t
+TextRangeType
 IMEInputHandler::ConvertToTextRangeType(uint32_t aUnderlineStyle,
                                         NSRange& aSelectedRange)
 {
   MOZ_LOG(gLog, LogLevel::Info,
     ("%p IMEInputHandler::ConvertToTextRangeType, "
      "aUnderlineStyle=%llu, aSelectedRange.length=%llu,",
      this, aUnderlineStyle, aSelectedRange.length));
 
   // We assume that aUnderlineStyle is NSUnderlineStyleSingle or
   // NSUnderlineStyleThick.  NSUnderlineStyleThick should indicate a selected
   // clause.  Otherwise, should indicate non-selected clause.
 
   if (aSelectedRange.length == 0) {
     switch (aUnderlineStyle) {
       case NSUnderlineStyleSingle:
-        return NS_TEXTRANGE_RAWINPUT;
+        return TextRangeType::NS_TEXTRANGE_RAWINPUT;
       case NSUnderlineStyleThick:
-        return NS_TEXTRANGE_SELECTEDRAWTEXT;
+        return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
       default:
         NS_WARNING("Unexpected line style");
-        return NS_TEXTRANGE_SELECTEDRAWTEXT;
+        return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
     }
   }
 
   switch (aUnderlineStyle) {
     case NSUnderlineStyleSingle:
-      return NS_TEXTRANGE_CONVERTEDTEXT;
+      return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
     case NSUnderlineStyleThick:
-      return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
     default:
       NS_WARNING("Unexpected line style");
-      return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
   }
 }
 
 uint32_t
 IMEInputHandler::GetRangeCount(NSAttributedString *aAttrString)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
@@ -2836,35 +2817,35 @@ IMEInputHandler::CreateTextRangeArray(NS
     range.mRangeType =
       ConvertToTextRangeType([attributeValue intValue], aSelectedRange);
     textRangeArray->AppendElement(range);
 
     MOZ_LOG(gLog, LogLevel::Info,
       ("%p IMEInputHandler::CreateTextRangeArray, "
        "range={ mStartOffset=%llu, mEndOffset=%llu, mRangeType=%s }",
        this, range.mStartOffset, range.mEndOffset,
-       GetRangeTypeName(range.mRangeType)));
+       ToChar(range.mRangeType)));
 
     limitRange =
       NSMakeRange(NSMaxRange(effectiveRange), 
                   NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
   }
 
   // Get current caret position.
   TextRange range;
   range.mStartOffset = aSelectedRange.location + aSelectedRange.length;
   range.mEndOffset = range.mStartOffset;
-  range.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+  range.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
   textRangeArray->AppendElement(range);
 
   MOZ_LOG(gLog, LogLevel::Info,
     ("%p IMEInputHandler::CreateTextRangeArray, "
      "range={ mStartOffset=%llu, mEndOffset=%llu, mRangeType=%s }",
      this, range.mStartOffset, range.mEndOffset,
-     GetRangeTypeName(range.mRangeType)));
+     ToChar(range.mRangeType)));
 
   return textRangeArray.forget();
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
 }
 
 bool
 IMEInputHandler::DispatchCompositionStartEvent()
--- a/widget/gtk/IMContextWrapper.cpp
+++ b/widget/gtk/IMContextWrapper.cpp
@@ -25,35 +25,16 @@ PRLogModuleInfo* gGtkIMLog = nullptr;
 
 static inline const char*
 ToChar(bool aBool)
 {
     return aBool ? "true" : "false";
 }
 
 static const char*
-GetRangeTypeName(uint32_t aRangeType)
-{
-    switch (aRangeType) {
-        case NS_TEXTRANGE_RAWINPUT:
-            return "NS_TEXTRANGE_RAWINPUT";
-        case NS_TEXTRANGE_CONVERTEDTEXT:
-            return "NS_TEXTRANGE_CONVERTEDTEXT";
-        case NS_TEXTRANGE_SELECTEDRAWTEXT:
-            return "NS_TEXTRANGE_SELECTEDRAWTEXT";
-        case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
-            return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
-        case NS_TEXTRANGE_CARETPOSITION:
-            return "NS_TEXTRANGE_CARETPOSITION";
-        default:
-            return "UNKNOWN SELECTION TYPE!!";
-    }
-}
-
-static const char*
 GetEnabledStateName(uint32_t aState)
 {
     switch (aState) {
         case IMEState::DISABLED:
             return "DISABLED";
         case IMEState::ENABLED:
             return "ENABLED";
         case IMEState::PASSWORD:
@@ -1686,23 +1667,23 @@ IMContextWrapper::CreateTextRangeArray(G
         if (!SetTextRange(iter, preedit_string, caretOffsetInUTF16, range)) {
             continue;
         }
         textRangeArray->AppendElement(range);
     } while (pango_attr_iterator_next(iter));
 
     TextRange range;
     range.mStartOffset = range.mEndOffset = caretOffsetInUTF16;
-    range.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+    range.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
     textRangeArray->AppendElement(range);
     MOZ_LOG(gGtkIMLog, LogLevel::Debug,
         ("GTKIM: %p   CreateTextRangeArray(), mStartOffset=%u, "
          "mEndOffset=%u, mRangeType=%s",
          this, range.mStartOffset, range.mEndOffset,
-         GetRangeTypeName(range.mRangeType)));
+         ToChar(range.mRangeType)));
 
     pango_attr_iterator_destroy(iter);
     pango_attr_list_unref(feedback_list);
     g_free(preedit_string);
 
     return textRangeArray.forget();
 }
 
@@ -1866,36 +1847,36 @@ IMContextWrapper::SetTextRange(PangoAttr
         return false;
     }
 
     // If the range covers whole of composition string and the caret is at
     // the end of the composition string, the range is probably not converted.
     if (!utf8ClauseStart &&
         utf8ClauseEnd == static_cast<gint>(strlen(aUTF8CompositionString)) &&
         aTextRange.mEndOffset == aUTF16CaretOffset) {
-        aTextRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
+        aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
     }
     // Typically, the caret is set at the start of the selected clause.
     // So, if the caret is in the clause, we can assume that the clause is
     // selected.
     else if (aTextRange.mStartOffset <= aUTF16CaretOffset &&
              aTextRange.mEndOffset > aUTF16CaretOffset) {
-        aTextRange.mRangeType = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
+        aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
     }
     // Otherwise, we should assume that the clause is converted but not
     // selected.
     else {
-        aTextRange.mRangeType = NS_TEXTRANGE_CONVERTEDTEXT;
+        aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
     }
 
     MOZ_LOG(gGtkIMLog, LogLevel::Debug,
         ("GTKIM: %p   SetTextRange(), succeeded, aTextRange= { "
          "mStartOffset=%u, mEndOffset=%u, mRangeType=%s, mRangeStyle=%s }",
          this, aTextRange.mStartOffset, aTextRange.mEndOffset,
-         GetRangeTypeName(aTextRange.mRangeType),
+         ToChar(aTextRange.mRangeType),
          GetTextRangeStyleText(aTextRange.mRangeStyle).get()));
 
     return true;
 }
 
 void
 IMContextWrapper::SetCursorPosition(GtkIMContext* aContext)
 {
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -521,26 +521,31 @@ template<>
 struct ParamTraits<mozilla::TextRange>
 {
   typedef mozilla::TextRange paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.mStartOffset);
     WriteParam(aMsg, aParam.mEndOffset);
-    WriteParam(aMsg, aParam.mRangeType);
+    WriteParam(aMsg, mozilla::ToRawTextRangeType(aParam.mRangeType));
     WriteParam(aMsg, aParam.mRangeStyle);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
-    return ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
-           ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
-           ReadParam(aMsg, aIter, &aResult->mRangeType) &&
-           ReadParam(aMsg, aIter, &aResult->mRangeStyle);
+    mozilla::RawTextRangeType rawTextRangeType;
+    if (ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
+        ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
+        ReadParam(aMsg, aIter, &rawTextRangeType) &&
+        ReadParam(aMsg, aIter, &aResult->mRangeStyle)) {
+      aResult->mRangeType = mozilla::ToTextRangeType(rawTextRangeType);
+      return true;
+    }
+    return false;
   }
 };
 
 template<>
 struct ParamTraits<mozilla::TextRangeArray>
 {
   typedef mozilla::TextRangeArray paramType;
 
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -1883,53 +1883,34 @@ IMMHandler::CommitCompositionOnPreviousW
 
     HandleEndComposition(mComposingWindow);
     return true;
   }
 
   return false;
 }
 
-static uint32_t
+static TextRangeType
 PlatformToNSAttr(uint8_t aAttr)
 {
   switch (aAttr)
   {
     case ATTR_INPUT_ERROR:
     // case ATTR_FIXEDCONVERTED:
     case ATTR_INPUT:
-      return NS_TEXTRANGE_RAWINPUT;
+      return TextRangeType::NS_TEXTRANGE_RAWINPUT;
     case ATTR_CONVERTED:
-      return NS_TEXTRANGE_CONVERTEDTEXT;
+      return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
     case ATTR_TARGET_NOTCONVERTED:
-      return NS_TEXTRANGE_SELECTEDRAWTEXT;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
     case ATTR_TARGET_CONVERTED:
-      return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
     default:
       NS_ASSERTION(false, "unknown attribute");
-      return NS_TEXTRANGE_CARETPOSITION;
-  }
-}
-
-static const char*
-GetRangeTypeName(uint32_t aRangeType)
-{
-  switch (aRangeType) {
-    case NS_TEXTRANGE_RAWINPUT:
-      return "NS_TEXTRANGE_RAWINPUT";
-    case NS_TEXTRANGE_CONVERTEDTEXT:
-      return "NS_TEXTRANGE_CONVERTEDTEXT";
-    case NS_TEXTRANGE_SELECTEDRAWTEXT:
-      return "NS_TEXTRANGE_SELECTEDRAWTEXT";
-    case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
-      return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
-    case NS_TEXTRANGE_CARETPOSITION:
-      return "NS_TEXTRANGE_CARETPOSITION";
-    default:
-      return "UNKNOWN SELECTION TYPE!!";
+      return TextRangeType::NS_TEXTRANGE_CARETPOSITION;
   }
 }
 
 // static
 void
 IMMHandler::DispatchEvent(nsWindow* aWindow, WidgetGUIEvent& aEvent)
 {
   MOZ_LOG(gIMMLog, LogLevel::Info,
@@ -2009,31 +1990,32 @@ IMMHandler::DispatchCompositionChangeEve
         MOZ_LOG(gIMMLog, LogLevel::Info,
           ("IMM: DispatchCompositionChangeEvent, mClauseArray[%ld]=%lu. "
            "This is larger than mCompositionString.Length()=%lu",
            i + 1, current, mCompositionString.Length()));
         current = int32_t(mCompositionString.Length());
       }
 
       uint32_t length = current - lastOffset;
-      uint32_t attr = PlatformToNSAttr(mAttributeArray[lastOffset]);
-      rv = dispatcher->AppendClauseToPendingComposition(length, attr);
+      TextRangeType textRangeType =
+        PlatformToNSAttr(mAttributeArray[lastOffset]);
+      rv = dispatcher->AppendClauseToPendingComposition(length, textRangeType);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         MOZ_LOG(gIMMLog, LogLevel::Error,
           ("IMM: DispatchCompositionChangeEvent, FAILED due to"
            "TextEventDispatcher::AppendClauseToPendingComposition() failure"));
         return;
       }
 
       lastOffset = current;
 
       MOZ_LOG(gIMMLog, LogLevel::Info,
         ("IMM: DispatchCompositionChangeEvent, index=%ld, rangeType=%s, "
          "range length=%lu",
-         i, GetRangeTypeName(attr), length));
+         i, ToChar(textRangeType), length));
     }
   }
 
   if (mCursorPosition == NO_IME_CARET) {
     MOZ_LOG(gIMMLog, LogLevel::Info,
       ("IMM: DispatchCompositionChangeEvent, no caret"));
   } else {
     uint32_t cursor = static_cast<uint32_t>(mCursorPosition);
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -2040,35 +2040,29 @@ static HRESULT
 GetRangeExtent(ITfRange* aRange, LONG* aStart, LONG* aLength)
 {
   RefPtr<ITfRangeACP> rangeACP;
   aRange->QueryInterface(IID_ITfRangeACP, getter_AddRefs(rangeACP));
   NS_ENSURE_TRUE(rangeACP, E_FAIL);
   return rangeACP->GetExtent(aStart, aLength);
 }
 
-static uint32_t
+static TextRangeType
 GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE& aDisplayAttr)
 {
-  uint32_t result;
   switch (aDisplayAttr.bAttr) {
     case TF_ATTR_TARGET_CONVERTED:
-      result = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
-      break;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
     case TF_ATTR_CONVERTED:
-      result = NS_TEXTRANGE_CONVERTEDTEXT;
-      break;
+      return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
     case TF_ATTR_TARGET_NOTCONVERTED:
-      result = NS_TEXTRANGE_SELECTEDRAWTEXT;
-      break;
+      return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
     default:
-      result = NS_TEXTRANGE_RAWINPUT;
-      break;
-  }
-  return result;
+      return TextRangeType::NS_TEXTRANGE_RAWINPUT;
+  }
 }
 
 HRESULT
 TSFTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty,
                                   ITfRange* aRange,
                                   TF_DISPLAYATTRIBUTE* aResult)
 {
   NS_ENSURE_TRUE(aAttrProperty, E_FAIL);
@@ -2280,17 +2274,17 @@ TSFTextStore::RestartComposition(ITfComp
                                 commitString);
   // Record a compositionupdate action for commit the part of composing string.
   PendingAction* action = LastOrNewPendingCompositionUpdate();
   action->mData = mComposition.mString;
   action->mRanges->Clear();
   TextRange caretRange;
   caretRange.mStartOffset = caretRange.mEndOffset =
     uint32_t(oldComposition.mStart + commitString.Length());
-  caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+  caretRange.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
   action->mRanges->AppendElement(caretRange);
   action->mIncomplete = false;
 
   // Record compositionend action.
   RecordCompositionEndAction();
 
   // Record compositionstart action only with the new start since this method
   // hasn't restored composing string yet.
@@ -2429,17 +2423,17 @@ TSFTextStore::RecordCompositionUpdateAct
   // information.
   action->mRanges->Clear();
 
   TextRange newRange;
   // No matter if we have display attribute info or not,
   // we always pass in at least one range to eCompositionChange
   newRange.mStartOffset = 0;
   newRange.mEndOffset = action->mData.Length();
-  newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
+  newRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
   action->mRanges->AppendElement(newRange);
 
   RefPtr<ITfRange> range;
   while (S_OK == enumRanges->Next(1, getter_AddRefs(range), nullptr) && range) {
 
     LONG rangeStart = 0, rangeLength = 0;
     if (FAILED(GetRangeExtent(range, &rangeStart, &rangeLength))) {
       continue;
@@ -2474,17 +2468,17 @@ TSFTextStore::RecordCompositionUpdateAct
     newRange.mStartOffset = uint32_t(start - mComposition.mStart);
     // The end of the last range in the array is
     // always kept at the end of composition
     newRange.mEndOffset = mComposition.mString.Length();
 
     TF_DISPLAYATTRIBUTE attr;
     hr = GetDisplayAttribute(attrPropetry, range, &attr);
     if (FAILED(hr)) {
-      newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
+      newRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
     } else {
       newRange.mRangeType = GetGeckoSelectionValue(attr);
       if (GetColor(attr.crText, newRange.mRangeStyle.mForegroundColor)) {
         newRange.mRangeStyle.mDefinedStyles |=
                                TextRangeStyle::DEFINED_FOREGROUND_COLOR;
       }
       if (GetColor(attr.crBk, newRange.mRangeStyle.mBackgroundColor)) {
         newRange.mRangeStyle.mDefinedStyles |=
@@ -2524,17 +2518,17 @@ TSFTextStore::RecordCompositionUpdateAct
     TextRange& range = action->mRanges->ElementAt(0);
     LONG start = currentSel.MinOffset();
     LONG end = currentSel.MaxOffset();
     if ((LONG)range.mStartOffset == start - mComposition.mStart &&
         (LONG)range.mEndOffset == end - mComposition.mStart &&
         range.mRangeStyle.IsNoChangeStyle()) {
       range.mRangeStyle.Clear();
       // The looks of selected type is better than others.
-      range.mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT;
+      range.mRangeType = TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
     }
   }
 
   // The caret position has to be collapsed.
   uint32_t caretPosition =
     static_cast<uint32_t>(currentSel.MaxOffset() - mComposition.mStart);
 
   // If caret is in the target clause and it doesn't have specific style,
@@ -2542,17 +2536,17 @@ TSFTextStore::RecordCompositionUpdateAct
   // shouldn't be in selection range on Windows, we shouldn't append caret
   // range in such case.
   const TextRange* targetClause = action->mRanges->GetTargetClause();
   if (!targetClause || targetClause->mRangeStyle.IsDefined() ||
       caretPosition < targetClause->mStartOffset ||
       caretPosition > targetClause->mEndOffset) {
     TextRange caretRange;
     caretRange.mStartOffset = caretRange.mEndOffset = caretPosition;
-    caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+    caretRange.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
     action->mRanges->AppendElement(caretRange);
   }
 
   action->mIncomplete = false;
 
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
          ("TSF: 0x%p   TSFTextStore::RecordCompositionUpdateAction() "
           "succeeded", this));