Bug 1216043 - Rename nsStyleSheet::sheetType and make it an enum class. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Tue, 20 Oct 2015 10:16:20 +1100
changeset 268440 240c0cff264b63cd246e63d0c266f0328b1c18e3
parent 268439 c3e202bf0f25772c0eb34078db586449e51ccd00
child 268441 19c3ba35bcaefc29534fade508fd077e509ed194
push id29551
push usercbook@mozilla.com
push dateTue, 20 Oct 2015 10:01:15 +0000
treeherdermozilla-central@f7b746b4e913 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1216043
milestone44.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 1216043 - Rename nsStyleSheet::sheetType and make it an enum class. r=dbaron The only substantive change here, apart from a few variables changing in size from uint16_t to uint8_t, is FontFaceSet's use of SheetType::Unknown (0xFF) instead of 0 for FontFaceRecords for script-created FontFaces.
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
dom/xbl/nsXBLPrototypeResources.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresShell.cpp
layout/base/nsPresShell.h
layout/inspector/inDOMUtils.cpp
layout/style/FontFaceSet.cpp
layout/style/FontFaceSet.h
layout/style/SheetType.h
layout/style/moz.build
layout/style/nsCSSDataBlock.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRuleProcessor.h
layout/style/nsCSSRules.h
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleData.h
layout/style/nsRuleNode.cpp
layout/style/nsRuleNode.h
layout/style/nsRuleWalker.h
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
layout/style/nsStyleStruct.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3191,17 +3191,17 @@ convertSheetType(uint32_t aSheetType)
       return nsIDocument::eAgentSheet;
     case nsDOMWindowUtils::USER_SHEET:
       return nsIDocument::eUserSheet;
     case nsDOMWindowUtils::AUTHOR_SHEET:
       return nsIDocument::eAuthorSheet;
     default:
       NS_ASSERTION(false, "wrong type");
       // we must return something although this should never happen
-      return nsIDocument::SheetTypeCount;
+      return nsIDocument::AdditionalSheetTypeCount;
   }
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::LoadSheet(nsIURI *aSheetURI, uint32_t aSheetType)
 {
   NS_ENSURE_ARG_POINTER(aSheetURI);
   NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2408,17 +2408,17 @@ nsDocument::RemoveDocStyleSheetsFromStyl
         shell->StyleSet()->RemoveDocStyleSheet(sheet);
       }
     }
     // XXX Tell observers?
   }
 }
 
 void
-nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets, nsStyleSet::sheetType aType)
+nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets, SheetType aType)
 {
   // The stylesheets should forget us
   int32_t indx = aSheets.Count();
   while (--indx >= 0) {
     nsIStyleSheet* sheet = aSheets[indx];
     sheet->SetOwningDocument(nullptr);
 
     if (sheet->IsApplicable()) {
@@ -2435,26 +2435,27 @@ nsDocument::RemoveStyleSheetsFromStyleSe
 
 void
 nsDocument::ResetStylesheetsToURI(nsIURI* aURI)
 {
   MOZ_ASSERT(aURI);
 
   mozAutoDocUpdate upd(this, UPDATE_STYLE, true);
   RemoveDocStyleSheetsFromStyleSets();
-  RemoveStyleSheetsFromStyleSets(mOnDemandBuiltInUASheets, nsStyleSet::eAgentSheet);
-  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAgentSheet], nsStyleSet::eAgentSheet);
-  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eUserSheet], nsStyleSet::eUserSheet);
-  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAuthorSheet], nsStyleSet::eDocSheet);
+  RemoveStyleSheetsFromStyleSets(mOnDemandBuiltInUASheets, SheetType::Agent);
+  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAgentSheet], SheetType::Agent);
+  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eUserSheet], SheetType::User);
+  RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAuthorSheet], SheetType::Doc);
 
   // Release all the sheets
   mStyleSheets.Clear();
   mOnDemandBuiltInUASheets.Clear();
-  for (uint32_t i = 0; i < SheetTypeCount; ++i)
-    mAdditionalSheets[i].Clear();
+  for (auto& sheets : mAdditionalSheets) {
+    sheets.Clear();
+  }
 
   // NOTE:  We don't release the catalog sheets.  It doesn't really matter
   // now, but it could in the future -- in which case not releasing them
   // is probably the right thing to do.
 
   // Now reset our inline style and attribute sheets.
   if (mAttrStyleSheet) {
     mAttrStyleSheet->Reset();
@@ -2478,42 +2479,42 @@ nsDocument::ResetStylesheetsToURI(nsIURI
     FillStyleSet(shell->StyleSet());
   }
 }
 
 static bool
 AppendAuthorSheet(nsIStyleSheet *aSheet, void *aData)
 {
   nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
-  styleSet->AppendStyleSheet(nsStyleSet::eDocSheet, aSheet);
+  styleSet->AppendStyleSheet(SheetType::Doc, aSheet);
   return true;
 }
 
 static void
 AppendSheetsToStyleSet(nsStyleSet* aStyleSet,
                        const nsCOMArray<nsIStyleSheet>& aSheets,
-                       nsStyleSet::sheetType aType)
+                       SheetType aType)
 {
   for (int32_t i = aSheets.Count() - 1; i >= 0; --i) {
     aStyleSet->AppendStyleSheet(aType, aSheets[i]);
   }
 }
 
 
 void
 nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
 {
   NS_PRECONDITION(aStyleSet, "Must have a style set");
-  NS_PRECONDITION(aStyleSet->SheetCount(nsStyleSet::eDocSheet) == 0,
+  NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0,
                   "Style set already has document sheets?");
 
   // We could consider moving this to nsStyleSet::Init, to match its
   // handling of the eAnimationSheet and eTransitionSheet levels.
-  aStyleSet->DirtyRuleProcessors(nsStyleSet::ePresHintSheet);
-  aStyleSet->DirtyRuleProcessors(nsStyleSet::eStyleAttrSheet);
+  aStyleSet->DirtyRuleProcessors(SheetType::PresHint);
+  aStyleSet->DirtyRuleProcessors(SheetType::StyleAttr);
 
   int32_t i;
   for (i = mStyleSheets.Count() - 1; i >= 0; --i) {
     nsIStyleSheet* sheet = mStyleSheets[i];
     if (sheet->IsApplicable()) {
       aStyleSet->AddDocStyleSheet(sheet, this);
     }
   }
@@ -2523,26 +2524,26 @@ nsDocument::FillStyleSet(nsStyleSet* aSt
     sheetService->AuthorStyleSheets()->EnumerateForwards(AppendAuthorSheet,
                                                          aStyleSet);
   }
 
   // Iterate backwards to maintain order
   for (i = mOnDemandBuiltInUASheets.Count() - 1; i >= 0; --i) {
     nsIStyleSheet* sheet = mOnDemandBuiltInUASheets[i];
     if (sheet->IsApplicable()) {
-      aStyleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      aStyleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
   }
 
   AppendSheetsToStyleSet(aStyleSet, mAdditionalSheets[eAgentSheet],
-                         nsStyleSet::eAgentSheet);
+                         SheetType::Agent);
   AppendSheetsToStyleSet(aStyleSet, mAdditionalSheets[eUserSheet],
-                         nsStyleSet::eUserSheet);
+                         SheetType::User);
   AppendSheetsToStyleSet(aStyleSet, mAdditionalSheets[eAuthorSheet],
-                         nsStyleSet::eDocSheet);
+                         SheetType::Doc);
 }
 
 static void
 WarnIfSandboxIneffective(nsIDocShell* aDocShell,
                          uint32_t aSandboxFlags,
                          nsIChannel* aChannel)
 {
   // If the document is sandboxed (via the HTML5 iframe sandbox
@@ -4136,17 +4137,17 @@ nsDocument::AddOnDemandBuiltInUASheet(CS
   if (aSheet->IsApplicable()) {
     // This is like |AddStyleSheetToStyleSets|, but for an agent sheet.
     nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       // Note that prepending here is necessary to make sure that html.css etc.
       // do not override Firefox OS/Mobile's content.css sheet. Maybe we should
       // have an insertion point to match the order of
       // nsDocumentViewer::CreateStyleSet though?
-      shell->StyleSet()->PrependStyleSheet(nsStyleSet::eAgentSheet, aSheet);
+      shell->StyleSet()->PrependStyleSheet(SheetType::Agent, aSheet);
     }
   }
 
   NotifyStyleSheetAdded(aSheet, false);
 }
 
 int32_t
 nsDocument::GetNumberOfStyleSheets() const
@@ -4368,30 +4369,30 @@ nsDocument::NotifyStyleSheetApplicableSt
     mozilla::services::GetObserverService();
   if (observerService) {
     observerService->NotifyObservers(static_cast<nsIDocument*>(this),
                                      "style-sheet-applicable-state-changed",
                                      nullptr);
   }
 }
 
-static nsStyleSet::sheetType
+static SheetType
 ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType)
 {
   switch(aType) {
     case nsIDocument::eAgentSheet:
-      return nsStyleSet::eAgentSheet;
+      return SheetType::Agent;
     case nsIDocument::eUserSheet:
-      return nsStyleSet::eUserSheet;
+      return SheetType::User;
     case nsIDocument::eAuthorSheet:
-      return nsStyleSet::eDocSheet;
+      return SheetType::Doc;
     default:
-      NS_ASSERTION(false, "wrong type");
+      MOZ_ASSERT(false, "wrong type");
       // we must return something although this should never happen
-      return nsStyleSet::eSheetTypeCount;
+      return SheetType::Count;
   }
 }
 
 static int32_t
 FindSheet(const nsCOMArray<nsIStyleSheet>& aSheets, nsIURI* aSheetURI)
 {
   for (int32_t i = aSheets.Count() - 1; i >= 0; i-- ) {
     bool bEqual;
@@ -4455,17 +4456,17 @@ nsDocument::AddAdditionalStyleSheet(addi
   if (!aSheet->IsApplicable())
     return NS_ERROR_INVALID_ARG;
 
   mAdditionalSheets[aType].AppendObject(aSheet);
 
   BeginUpdate(UPDATE_STYLE);
   nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
-    nsStyleSet::sheetType type = ConvertAdditionalSheetType(aType);
+    SheetType type = ConvertAdditionalSheetType(aType);
     shell->StyleSet()->AppendStyleSheet(type, aSheet);
   }
 
   // Passing false, so documet.styleSheets.length will not be affected by
   // these additional sheets.
   NotifyStyleSheetAdded(aSheet, false);
   EndUpdate(UPDATE_STYLE);
   return NS_OK;
@@ -4483,17 +4484,17 @@ nsDocument::RemoveAdditionalStyleSheet(a
     nsCOMPtr<nsIStyleSheet> sheetRef = sheets[i];
     sheets.RemoveObjectAt(i);
 
     BeginUpdate(UPDATE_STYLE);
     if (!mIsGoingAway) {
       MOZ_ASSERT(sheetRef->IsApplicable());
       nsCOMPtr<nsIPresShell> shell = GetShell();
       if (shell) {
-        nsStyleSet::sheetType type = ConvertAdditionalSheetType(aType);
+        SheetType type = ConvertAdditionalSheetType(aType);
         shell->StyleSet()->RemoveStyleSheet(type, sheetRef);
       }
     }
 
     // Passing false, so documet.styleSheets.length will not be affected by
     // these additional sheets.
     NotifyStyleSheetRemoved(sheetRef, false);
     EndUpdate(UPDATE_STYLE);
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1511,17 +1511,17 @@ public:
 protected:
   already_AddRefed<nsIPresShell> doCreateShell(nsPresContext* aContext,
                                                nsViewManager* aViewManager,
                                                nsStyleSet* aStyleSet,
                                                nsCompatibility aCompatMode);
 
   void RemoveDocStyleSheetsFromStyleSets();
   void RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets, 
-                                      nsStyleSet::sheetType aType);
+                                      mozilla::SheetType aType);
   void ResetStylesheetsToURI(nsIURI* aURI);
   void FillStyleSet(nsStyleSet* aStyleSet);
 
   // Return whether all the presshells for this document are safe to flush
   bool IsSafeToFlush() const;
 
   void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
                               const nsAString& aType,
@@ -1566,17 +1566,17 @@ protected:
 
   // Weak reference to our sink for in case we no longer have a parser.  This
   // will allow us to flush out any pending stuff from the sink even if
   // EndLoad() has already happened.
   nsWeakPtr mWeakSink;
 
   nsCOMArray<nsIStyleSheet> mStyleSheets;
   nsCOMArray<nsIStyleSheet> mOnDemandBuiltInUASheets;
-  nsCOMArray<nsIStyleSheet> mAdditionalSheets[SheetTypeCount];
+  nsCOMArray<nsIStyleSheet> mAdditionalSheets[AdditionalSheetTypeCount];
 
   // Array of observers
   nsTObserverArray<nsIDocumentObserver*> mObservers;
 
   // Tracker for animations that are waiting to start.
   // nullptr until GetOrCreatePendingAnimationTracker is called.
   RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker;
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -939,17 +939,17 @@ public:
    */
   virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
                                             bool aApplicable) = 0;
 
   enum additionalSheetType {
     eAgentSheet,
     eUserSheet,
     eAuthorSheet,
-    SheetTypeCount
+    AdditionalSheetTypeCount
   };
 
   virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0;
   virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) = 0;
   virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) = 0;
   virtual nsIStyleSheet* FirstAdditionalAuthorSheet() = 0;
 
   /**
--- a/dom/xbl/nsXBLPrototypeResources.cpp
+++ b/dom/xbl/nsXBLPrototypeResources.cpp
@@ -138,17 +138,17 @@ nsXBLPrototypeResources::ClearLoader()
 {
   mLoader = nullptr;
 }
 
 void
 nsXBLPrototypeResources::GatherRuleProcessor()
 {
   mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList,
-                                          nsStyleSet::eDocSheet,
+                                          SheetType::Doc,
                                           nullptr,
                                           mRuleProcessor);
 }
 
 void
 nsXBLPrototypeResources::AppendStyleSheet(CSSStyleSheet* aSheet)
 {
   mStyleSheetList.AppendElement(aSheet);
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2171,25 +2171,25 @@ nsDocumentViewer::RequestWindowClose(boo
 
   return NS_OK;
 }
 
 static bool
 AppendAgentSheet(nsIStyleSheet *aSheet, void *aData)
 {
   nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
-  styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, aSheet);
+  styleSet->AppendStyleSheet(SheetType::Agent, aSheet);
   return true;
 }
 
 static bool
 PrependUserSheet(nsIStyleSheet *aSheet, void *aData)
 {
   nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
-  styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, aSheet);
+  styleSet->PrependStyleSheet(SheetType::User, aSheet);
   return true;
 }
 
 nsresult
 nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
                                    nsStyleSet** aStyleSet)
 {
   // Make sure this does the same thing as PresShell::AddSheet wrt ordering.
@@ -2222,17 +2222,17 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
   if (nsContentUtils::IsInChromeDocshell(aDocument)) {
     sheet = nsLayoutStylesheetCache::UserChromeSheet();
   }
   else {
     sheet = nsLayoutStylesheetCache::UserContentSheet();
   }
 
   if (sheet)
-    styleSet->AppendStyleSheet(nsStyleSet::eUserSheet, sheet);
+    styleSet->AppendStyleSheet(SheetType::User, sheet);
 
   // Append chrome sheets (scrollbars + forms).
   bool shouldOverride = false;
   // We don't want a docshell here for external resource docs, so just
   // look at mContainer.
   nsCOMPtr<nsIDocShell> ds(mContainer);
   nsCOMPtr<nsIDOMEventTarget> chromeHandler;
   nsCOMPtr<nsIURI> uri;
@@ -2258,101 +2258,101 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
         while ( (token = nsCRT::strtok(newStr, ", ", &newStr)) ) {
           NS_NewURI(getter_AddRefs(uri), nsDependentCString(token), nullptr,
                     baseURI);
           if (!uri) continue;
 
           cssLoader->LoadSheetSync(uri, getter_AddRefs(csssheet));
           if (!csssheet) continue;
 
-          styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, csssheet);
+          styleSet->PrependStyleSheet(SheetType::Agent, csssheet);
           shouldOverride = true;
         }
         free(str);
       }
     }
   }
 
   if (!shouldOverride) {
     sheet = nsLayoutStylesheetCache::ScrollbarsSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
   }
 
   if (!aDocument->IsSVGDocument()) {
     // !!! IMPORTANT - KEEP THIS BLOCK IN SYNC WITH
     // !!! SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded.
 
     // SVGForeignObjectElement::BindToTree calls SVGDocument::
     // EnsureNonSVGUserAgentStyleSheetsLoaded to loads these UA sheet
     // on-demand. (Excluding the quirks sheet, which should never be loaded for
     // an SVG document, and excluding xul.css which will be loaded on demand by
     // nsXULElement::BindToTree.)
 
     sheet = nsLayoutStylesheetCache::NumberControlSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
 
     sheet = nsLayoutStylesheetCache::FormsSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
 
     if (aDocument->LoadsFullXULStyleSheetUpFront()) {
       // nsXULElement::BindToTree loads xul.css on-demand if we don't load it
       // up-front here.
       sheet = nsLayoutStylesheetCache::XULSheet();
       if (sheet) {
-        styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+        styleSet->PrependStyleSheet(SheetType::Agent, sheet);
       }
     }
 
     sheet = nsLayoutStylesheetCache::MinimalXULSheet();
     if (sheet) {
       // Load the minimal XUL rules for scrollbars and a few other XUL things
       // that non-XUL (typically HTML) documents commonly use.
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
 
     sheet = nsLayoutStylesheetCache::CounterStylesSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
 
     if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
       sheet = nsLayoutStylesheetCache::NoScriptSheet();
       if (sheet) {
-        styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+        styleSet->PrependStyleSheet(SheetType::Agent, sheet);
       }
     }
 
     if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) {
       sheet = nsLayoutStylesheetCache::NoFramesSheet();
       if (sheet) {
-        styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+        styleSet->PrependStyleSheet(SheetType::Agent, sheet);
       }
     }
 
     // We don't add quirk.css here; nsPresContext::CompatibilityModeChanged will
     // append it if needed.
 
     sheet = nsLayoutStylesheetCache::HTMLSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
 
-    styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet,
+    styleSet->PrependStyleSheet(SheetType::Agent,
                                 nsLayoutStylesheetCache::UASheet());
   } else {
     // SVG documents may have scrollbars and need the scrollbar styling.
     sheet = nsLayoutStylesheetCache::MinimalXULSheet();
     if (sheet) {
-      styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
     }
   }
 
   nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
   if (sheetService) {
     sheetService->AgentStyleSheets()->EnumerateForwards(AppendAgentSheet,
                                                         styleSet);
     sheetService->UserStyleSheets()->EnumerateBackwards(PrependUserSheet,
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1376,21 +1376,21 @@ nsPresContext::CompatibilityModeChanged(
   }
 
   nsStyleSet* styleSet = mShell->StyleSet();
   CSSStyleSheet* sheet = nsLayoutStylesheetCache::QuirkSheet();
 
   if (needsQuirkSheet) {
     // quirk.css needs to come after html.css; we just keep it at the end.
     DebugOnly<nsresult> rv =
-      styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->AppendStyleSheet(SheetType::Agent, sheet);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to insert quirk.css");
   } else {
     DebugOnly<nsresult> rv =
-      styleSet->RemoveStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      styleSet->RemoveStyleSheet(SheetType::Agent, sheet);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to remove quirk.css");
   }
 
   mQuirkSheetAdded = needsQuirkSheet;
 }
 
 // Helper function for setting Anim Mode on image
 static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, uint16_t aMode)
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1404,27 +1404,27 @@ PresShell::UpdatePreferenceStyles()
   if (mPrefStyleSheet == newPrefSheet) {
     return;
   }
 
   mStyleSet->BeginUpdate();
 
   RemovePreferenceStyles();
 
-  mStyleSet->AppendStyleSheet(nsStyleSet::eUserSheet, newPrefSheet);
+  mStyleSet->AppendStyleSheet(SheetType::User, newPrefSheet);
   mPrefStyleSheet = newPrefSheet;
 
   mStyleSet->EndUpdate();
 }
 
 void
 PresShell::RemovePreferenceStyles()
 {
   if (mPrefStyleSheet) {
-    mStyleSet->RemoveStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
+    mStyleSet->RemoveStyleSheet(SheetType::User, mPrefStyleSheet);
     mPrefStyleSheet = nullptr;
   }
 }
 
 void
 PresShell::AddUserSheet(nsISupports* aSheet)
 {
   // Make sure this does what nsDocumentViewer::CreateStyleSet does wrt
@@ -1438,23 +1438,23 @@ PresShell::AddUserSheet(nsISupports* aSh
   mStyleSet->BeginUpdate();
 
   nsStyleSheetService *sheetService = nsStyleSheetService::gInstance;
   nsCOMArray<nsIStyleSheet> & userSheets = *sheetService->UserStyleSheets();
   int32_t i;
   // Iterate forwards when removing so the searches for RemoveStyleSheet are as
   // short as possible.
   for (i = 0; i < userSheets.Count(); ++i) {
-    mStyleSet->RemoveStyleSheet(nsStyleSet::eUserSheet, userSheets[i]);
+    mStyleSet->RemoveStyleSheet(SheetType::User, userSheets[i]);
   }
 
   // Now iterate backwards, so that the order of userSheets will be the same as
   // the order of sheets from it in the style set.
   for (i = userSheets.Count() - 1; i >= 0; --i) {
-    mStyleSet->PrependStyleSheet(nsStyleSet::eUserSheet, userSheets[i]);
+    mStyleSet->PrependStyleSheet(SheetType::User, userSheets[i]);
   }
 
   mStyleSet->EndUpdate();
 
   ReconstructStyleData();
 }
 
 void
@@ -1462,42 +1462,42 @@ PresShell::AddAgentSheet(nsISupports* aS
 {
   // Make sure this does what nsDocumentViewer::CreateStyleSet does
   // wrt ordering.
   nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
   if (!sheet) {
     return;
   }
 
-  mStyleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
+  mStyleSet->AppendStyleSheet(SheetType::Agent, sheet);
   ReconstructStyleData();
 }
 
 void
 PresShell::AddAuthorSheet(nsISupports* aSheet)
 {
   nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
   if (!sheet) {
     return;
   }
 
   // Document specific "additional" Author sheets should be stronger than the ones
   // added with the StyleSheetService.
   nsIStyleSheet* firstAuthorSheet = mDocument->FirstAdditionalAuthorSheet();
   if (firstAuthorSheet) {
-    mStyleSet->InsertStyleSheetBefore(nsStyleSet::eDocSheet, sheet, firstAuthorSheet);
+    mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet, firstAuthorSheet);
   } else {
-    mStyleSet->AppendStyleSheet(nsStyleSet::eDocSheet, sheet);
+    mStyleSet->AppendStyleSheet(SheetType::Doc, sheet);
   }
 
   ReconstructStyleData();
 }
 
 void
-PresShell::RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet)
+PresShell::RemoveSheet(SheetType aType, nsISupports* aSheet)
 {
   nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
   if (!sheet) {
     return;
   }
 
   mStyleSet->RemoveStyleSheet(aType, sheet);
   ReconstructStyleData();
@@ -8660,43 +8660,43 @@ PresShell::IsVisible()
 
   return frame->IsVisibleConsideringAncestors(nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY);
 }
 
 nsresult
 PresShell::GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets)
 {
   aSheets.Clear();
-  int32_t sheetCount = mStyleSet->SheetCount(nsStyleSet::eAgentSheet);
+  int32_t sheetCount = mStyleSet->SheetCount(SheetType::Agent);
 
   for (int32_t i = 0; i < sheetCount; ++i) {
-    nsIStyleSheet *sheet = mStyleSet->StyleSheetAt(nsStyleSet::eAgentSheet, i);
+    nsIStyleSheet *sheet = mStyleSet->StyleSheetAt(SheetType::Agent, i);
     if (!aSheets.AppendObject(sheet))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
 nsresult
 PresShell::SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets)
 {
-  return mStyleSet->ReplaceSheets(nsStyleSet::eAgentSheet, aSheets);
+  return mStyleSet->ReplaceSheets(SheetType::Agent, aSheets);
 }
 
 nsresult
 PresShell::AddOverrideStyleSheet(nsIStyleSheet *aSheet)
 {
-  return mStyleSet->PrependStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
+  return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet);
 }
 
 nsresult
 PresShell::RemoveOverrideStyleSheet(nsIStyleSheet *aSheet)
 {
-  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
+  return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet);
 }
 
 static void
 FreezeElement(nsISupports *aSupports, void * /* unused */)
 {
   nsCOMPtr<nsIObjectLoadingContent> olc(do_QueryInterface(aSupports));
   if (olc) {
     olc->StopPluginInstance();
@@ -9432,27 +9432,27 @@ PresShell::Observe(nsISupports* aSubject
   }
 
   if (!nsCRT::strcmp(aTopic, "author-sheet-added") && mStyleSet) {
     AddAuthorSheet(aSubject);
     return NS_OK;
   }
 
   if (!nsCRT::strcmp(aTopic, "agent-sheet-removed") && mStyleSet) {
-    RemoveSheet(nsStyleSet::eAgentSheet, aSubject);
+    RemoveSheet(SheetType::Agent, aSubject);
     return NS_OK;
   }
 
   if (!nsCRT::strcmp(aTopic, "user-sheet-removed") && mStyleSet) {
-    RemoveSheet(nsStyleSet::eUserSheet, aSubject);
+    RemoveSheet(SheetType::User, aSubject);
     return NS_OK;
   }
 
   if (!nsCRT::strcmp(aTopic, "author-sheet-removed") && mStyleSet) {
-    RemoveSheet(nsStyleSet::eDocSheet, aSubject);
+    RemoveSheet(SheetType::Doc, aSubject);
     return NS_OK;
   }
 
   NS_WARNING("unrecognized topic in PresShell::Observe");
   return NS_ERROR_FAILURE;
 }
 
 bool
@@ -9785,45 +9785,45 @@ FindTopFrame(nsIFrame* aRoot)
 
 #ifdef DEBUG
 
 nsStyleSet*
 PresShell::CloneStyleSet(nsStyleSet* aSet)
 {
   nsStyleSet *clone = new nsStyleSet();
 
-  int32_t i, n = aSet->SheetCount(nsStyleSet::eOverrideSheet);
+  int32_t i, n = aSet->SheetCount(SheetType::Override);
   for (i = 0; i < n; i++) {
-    nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eOverrideSheet, i);
+    nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Override, i);
     if (ss)
-      clone->AppendStyleSheet(nsStyleSet::eOverrideSheet, ss);
+      clone->AppendStyleSheet(SheetType::Override, ss);
   }
 
   // The document expects to insert document stylesheets itself
 #if 0
-  n = aSet->SheetCount(nsStyleSet::eDocSheet);
+  n = aSet->SheetCount(SheetType::Doc);
   for (i = 0; i < n; i++) {
-    nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eDocSheet, i);
+    nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Doc, i);
     if (ss)
       clone->AddDocStyleSheet(ss, mDocument);
   }
 #endif
 
-  n = aSet->SheetCount(nsStyleSet::eUserSheet);
+  n = aSet->SheetCount(SheetType::User);
   for (i = 0; i < n; i++) {
-    nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eUserSheet, i);
+    nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::User, i);
     if (ss)
-      clone->AppendStyleSheet(nsStyleSet::eUserSheet, ss);
-  }
-
-  n = aSet->SheetCount(nsStyleSet::eAgentSheet);
+      clone->AppendStyleSheet(SheetType::User, ss);
+  }
+
+  n = aSet->SheetCount(SheetType::Agent);
   for (i = 0; i < n; i++) {
-    nsIStyleSheet* ss = aSet->StyleSheetAt(nsStyleSet::eAgentSheet, i);
+    nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Agent, i);
     if (ss)
-      clone->AppendStyleSheet(nsStyleSet::eAgentSheet, ss);
+      clone->AppendStyleSheet(SheetType::Agent, ss);
   }
   return clone;
 }
 
 // After an incremental reflow, we verify the correctness by doing a
 // full reflow into a fresh frame tree.
 bool
 PresShell::VerifyIncrementalReflow()
@@ -9942,19 +9942,19 @@ PresShell::ListStyleContexts(nsIFrame *a
   nsStyleContext *sc = aRootFrame->StyleContext();
   if (sc)
     sc->List(out, aIndent);
 }
 
 void
 PresShell::ListStyleSheets(FILE *out, int32_t aIndent)
 {
-  int32_t sheetCount = mStyleSet->SheetCount(nsStyleSet::eDocSheet);
+  int32_t sheetCount = mStyleSet->SheetCount(SheetType::Doc);
   for (int32_t i = 0; i < sheetCount; ++i) {
-    mStyleSet->StyleSheetAt(nsStyleSet::eDocSheet, i)->List(out, aIndent);
+    mStyleSet->StyleSheetAt(SheetType::Doc, i)->List(out, aIndent);
     fputs("\n", out);
   }
 }
 
 void
 PresShell::VerifyStyleTree()
 {
   VERIFY_STYLE_TREE;
@@ -10925,26 +10925,26 @@ nsIPresShell::SyncWindowProperties(nsVie
     nsContainerFrame::SyncWindowProperties(mPresContext, frame, aView, &rcx, 0);
   }
 }
 
 nsresult
 nsIPresShell::HasRuleProcessorUsedByMultipleStyleSets(uint32_t aSheetType,
                                                       bool* aRetVal)
 {
-  nsStyleSet::sheetType type;
+  SheetType type;
   switch (aSheetType) {
     case nsIStyleSheetService::AGENT_SHEET:
-      type = nsStyleSet::eAgentSheet;
+      type = SheetType::Agent;
       break;
     case nsIStyleSheetService::USER_SHEET:
-      type = nsStyleSet::eUserSheet;
+      type = SheetType::User;
       break;
     case nsIStyleSheetService::AUTHOR_SHEET:
-      type = nsStyleSet::eDocSheet;
+      type = SheetType::Doc;
       break;
     default:
       MOZ_ASSERT(false, "unexpected aSheetType value");
       return NS_ERROR_ILLEGAL_VALUE;
   }
 
   *aRetVal = mStyleSet->HasRuleProcessorUsedByMultipleStyleSets(type);
   return NS_OK;
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -559,17 +559,17 @@ protected:
 
   /**
    * Methods to handle changes to user and UA sheet lists that we get
    * notified about.
    */
   void AddUserSheet(nsISupports* aSheet);
   void AddAgentSheet(nsISupports* aSheet);
   void AddAuthorSheet(nsISupports* aSheet);
-  void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet);
+  void RemoveSheet(mozilla::SheetType aType, nsISupports* aSheet);
 
   // Hide a view if it is a popup
   void HideViewIfPopup(nsView* aView);
 
   // Utility method to restore the root scrollframe state
   void RestoreRootScrollPosition();
 
   void MaybeReleaseCapturingContent();
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -78,21 +78,21 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocu
 
   nsCOMPtr<nsIDocument> document = do_QueryInterface(aDocument);
   MOZ_ASSERT(document);
 
   // Get the agent, then user and finally xbl sheets in the style set.
   nsIPresShell* presShell = document->GetShell();
   if (presShell) {
     nsStyleSet* styleSet = presShell->StyleSet();
-    nsStyleSet::sheetType sheetType = nsStyleSet::eAgentSheet;
+    SheetType sheetType = SheetType::Agent;
     for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
       sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
     }
-    sheetType = nsStyleSet::eUserSheet;
+    sheetType = SheetType::User;
     for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
       sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
     }
     nsAutoTArray<CSSStyleSheet*, 32> xblSheetArray;
     styleSet->AppendAllXBLStyleSheets(xblSheetArray);
 
     // The XBL stylesheet array will quite often be full of duplicates. Cope:
     nsTHashtable<nsPtrHashKey<CSSStyleSheet>> sheetSet;
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -414,17 +414,17 @@ FontFaceSet::Add(FontFace& aFontFace, Er
   for (const FontFaceRecord& rec : mNonRuleFaces) {
     MOZ_ASSERT(rec.mFontFace != &aFontFace,
                "FontFace should not occur in mNonRuleFaces twice");
   }
 #endif
 
   FontFaceRecord* rec = mNonRuleFaces.AppendElement();
   rec->mFontFace = &aFontFace;
-  rec->mSheetType = 0;  // unused for mNonRuleFaces
+  rec->mSheetType = SheetType::Unknown;  // unused for mNonRuleFaces
   rec->mLoadEventShouldFire =
     aFontFace.Status() == FontFaceLoadStatus::Unloaded ||
     aFontFace.Status() == FontFaceLoadStatus::Loading;
 
   mNonRuleFacesDirty = true;
   RebuildUserFontSet();
   mHasLoadingFontFacesIsDirty = true;
   CheckLoadingStarted();
@@ -823,29 +823,29 @@ FontFaceSet::InsertNonRuleFontFace(FontF
   }
 
   // Just create a new font entry if we haven't got one already.
   if (!aFontFace->GetUserFontEntry()) {
     // XXX Should we be checking mUserFontSet->mLocalRulesUsed like
     // InsertRuleFontFace does?
     RefPtr<gfxUserFontEntry> entry =
       FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
-                                            nsStyleSet::eDocSheet);
+                                            SheetType::Doc);
     if (!entry) {
       return;
     }
     aFontFace->SetUserFontEntry(entry);
   }
 
   aFontSetModified = true;
   mUserFontSet->AddUserFontEntry(fontfamily, aFontFace->GetUserFontEntry());
 }
 
 void
-FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, uint8_t aSheetType,
+FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
                                 nsTArray<FontFaceRecord>& aOldRecords,
                                 bool& aFontSetModified)
 {
   nsAutoString fontfamily;
   if (!aFontFace->GetFamilyName(fontfamily)) {
     // If there is no family name, this rule cannot contribute a
     // usable font, so there is no point in processing it further.
     return;
@@ -946,23 +946,23 @@ FontFaceSet::FindOrCreateUserFontEntryFr
   nsAutoString fontfamily;
   if (!aFontFace->GetFamilyName(fontfamily)) {
     // If there is no family name, this rule cannot contribute a
     // usable font, so there is no point in processing it further.
     return nullptr;
   }
 
   return FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
-                                               nsStyleSet::eDocSheet);
+                                               SheetType::Doc);
 }
 
 already_AddRefed<gfxUserFontEntry>
 FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
                                                    FontFace* aFontFace,
-                                                   uint8_t aSheetType)
+                                                   SheetType aSheetType)
 {
   nsCSSValue val;
   nsCSSUnit unit;
 
   uint32_t weight = NS_STYLE_FONT_WEIGHT_NORMAL;
   int32_t stretch = NS_STYLE_FONT_STRETCH_NORMAL;
   uint8_t italicStyle = NS_STYLE_FONT_STYLE_NORMAL;
   uint32_t languageOverride = NO_FONT_LANGUAGE_OVERRIDE;
@@ -1089,18 +1089,18 @@ FontFaceSet::FindOrCreateUserFontEntryFr
           face->mReferrerPolicy = mDocument->GetReferrerPolicy();
           face->mOriginPrincipal = val.GetURLStructValue()->mOriginPrincipal;
           NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule");
 
           // agent and user stylesheets are treated slightly differently,
           // the same-site origin check and access control headers are
           // enforced against the sheet principal rather than the document
           // principal to allow user stylesheets to include @font-face rules
-          face->mUseOriginPrincipal = (aSheetType == nsStyleSet::eUserSheet ||
-                                       aSheetType == nsStyleSet::eAgentSheet);
+          face->mUseOriginPrincipal = (aSheetType == SheetType::User ||
+                                       aSheetType == SheetType::Agent);
 
           face->mLocalName.Truncate();
           face->mFormatFlags = 0;
           while (i + 1 < numSrc && (val = srcArr->Item(i+1),
                    val.GetUnit() == eCSSUnit_Font_Format)) {
             nsDependentString valueString(val.GetStringBufferValue());
             if (valueString.LowerCaseEqualsASCII("woff")) {
               face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF;
--- a/layout/style/FontFaceSet.h
+++ b/layout/style/FontFaceSet.h
@@ -227,28 +227,28 @@ private:
                                 const nsAString& aType,
                                 const nsTArray<FontFace*>& aFontFaces);
 
   // Note: if you add new cycle collected objects to FontFaceRecord,
   // make sure to update FontFaceSet's cycle collection macros
   // accordingly.
   struct FontFaceRecord {
     RefPtr<FontFace> mFontFace;
-    uint8_t mSheetType;  // only relevant for mRuleFaces entries
+    SheetType mSheetType;  // only relevant for mRuleFaces entries
 
     // When true, indicates that when finished loading, the FontFace should be
     // included in the subsequent loadingdone/loadingerror event fired at the
     // FontFaceSet.
     bool mLoadEventShouldFire;
   };
 
   already_AddRefed<gfxUserFontEntry> FindOrCreateUserFontEntryFromFontFace(
                                                    const nsAString& aFamilyName,
                                                    FontFace* aFontFace,
-                                                   uint8_t aSheetType);
+                                                   SheetType aSheetType);
 
   // search for @font-face rule that matches a userfont font entry
   nsCSSFontFaceRule* FindRuleForUserFontEntry(gfxUserFontEntry* aUserFontEntry);
 
   nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
                      const gfxFontFaceSrc* aFontFaceSrc);
   nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
                          nsIPrincipal** aPrincipal,
@@ -259,17 +259,17 @@ private:
                             uint8_t*& aBuffer,
                             uint32_t& aBufferLength);
   nsresult LogMessage(gfxUserFontEntry* aUserFontEntry,
                       const char* aMessage,
                       uint32_t aFlags,
                       nsresult aStatus);
   void RebuildUserFontSet();
 
-  void InsertRuleFontFace(FontFace* aFontFace, uint8_t aSheetType,
+  void InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
                           nsTArray<FontFaceRecord>& aOldRecords,
                           bool& aFontSetModified);
   void InsertNonRuleFontFace(FontFace* aFontFace, bool& aFontSetModified);
 
 #ifdef DEBUG
   bool HasRuleFontFace(FontFace* aFontFace);
 #endif
 
new file mode 100644
--- /dev/null
+++ b/layout/style/SheetType.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+/* enum to represent a level in the cascade */
+
+#ifndef mozilla_SheetType_h
+#define mozilla_SheetType_h
+
+namespace mozilla {
+
+// The "origins" of the CSS cascade, from lowest precedence to
+// highest (for non-!important rules).
+//
+// Be sure to update NS_RULE_NODE_LEVEL_MASK when changing the number
+// of sheet types; static assertions enforce this.
+enum class SheetType : uint8_t {
+  Agent, // CSS
+  User, // CSS
+  PresHint,
+  SVGAttrAnimation,
+  Doc, // CSS
+  ScopedDoc,
+  StyleAttr,
+  Override, // CSS
+  Animation,
+  Transition,
+
+  Count,
+  Unknown = 0xff
+};
+
+} // namespace mozilla
+
+#endif // mozilla_SheetType_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -83,16 +83,17 @@ EXPORTS.mozilla += [
     'CSSStyleSheet.h',
     'CSSVariableDeclarations.h',
     'CSSVariableResolver.h',
     'CSSVariableValues.h',
     'IncrementalClearCOMRuleArray.h',
     'LayerAnimationInfo.h',
     'RuleNodeCacheConditions.h',
     'RuleProcessorCache.h',
+    'SheetType.h',
     'StyleAnimationValue.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'CSS.h',
     'CSSLexer.h',
     'CSSRuleList.h',
     'CSSValue.h',
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -37,18 +37,18 @@ MoveValue(nsCSSValue* aSource, nsCSSValu
     memcpy(aDest, aSource, sizeof(nsCSSValue));
     new (aSource) nsCSSValue();
     return changed;
 }
 
 static bool
 ShouldIgnoreColors(nsRuleData *aRuleData)
 {
-    return aRuleData->mLevel != nsStyleSet::eAgentSheet &&
-           aRuleData->mLevel != nsStyleSet::eUserSheet &&
+    return aRuleData->mLevel != SheetType::Agent &&
+           aRuleData->mLevel != SheetType::User &&
            !aRuleData->mPresContext->UseDocumentColors();
 }
 
 /**
  * Tries to call |nsCSSValue::StartImageLoad()| on an image source.
  * Image sources are specified by |url()| or |-moz-image-rect()| function.
  */
 static void
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -1009,17 +1009,17 @@ RuleCascadeData::AttributeListFor(nsIAto
   return &entry->mSelectors;
 }
 
 // -------------------------------
 // CSS Style rule processor implementation
 //
 
 nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
-                                       uint8_t aSheetType,
+                                       SheetType aSheetType,
                                        Element* aScopeElement,
                                        nsCSSRuleProcessor*
                                          aPreviousCSSRuleProcessor,
                                        bool aIsShared)
   : mSheets(aSheets)
   , mRuleCascades(nullptr)
   , mPreviousCacheKey(aPreviousCSSRuleProcessor
                        ? aPreviousCSSRuleProcessor->CloneMQCacheKey()
@@ -1030,17 +1030,17 @@ nsCSSRuleProcessor::nsCSSRuleProcessor(c
   , mSheetType(aSheetType)
   , mIsShared(aIsShared)
   , mMustGatherDocumentRules(aIsShared)
   , mInRuleProcessorCache(false)
 #ifdef DEBUG
   , mDocumentRulesAndCacheKeyValid(false)
 #endif
 {
-  NS_ASSERTION(!!mScopeElement == (aSheetType == nsStyleSet::eScopedDocSheet),
+  NS_ASSERTION(!!mScopeElement == (aSheetType == SheetType::ScopedDoc),
                "aScopeElement must be specified iff aSheetType is "
                "eScopedDocSheet");
   for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
     mSheets[i]->AddRuleProcessor(this);
   }
 }
 
 nsCSSRuleProcessor::~nsCSSRuleProcessor()
@@ -3546,17 +3546,17 @@ struct CascadeEnumData {
                   nsTArray<nsFontFaceRuleContainer>& aFontFaceRules,
                   nsTArray<nsCSSKeyframesRule*>& aKeyframesRules,
                   nsTArray<nsCSSFontFeatureValuesRule*>& aFontFeatureValuesRules,
                   nsTArray<nsCSSPageRule*>& aPageRules,
                   nsTArray<nsCSSCounterStyleRule*>& aCounterStyleRules,
                   nsTArray<css::DocumentRule*>& aDocumentRules,
                   nsMediaQueryResultCacheKey& aKey,
                   nsDocumentRuleResultCacheKey& aDocumentKey,
-                  uint8_t aSheetType,
+                  SheetType aSheetType,
                   bool aMustGatherDocumentRules)
     : mPresContext(aPresContext),
       mFontFaceRules(aFontFaceRules),
       mKeyframesRules(aKeyframesRules),
       mFontFeatureValuesRules(aFontFeatureValuesRules),
       mPageRules(aPageRules),
       mCounterStyleRules(aCounterStyleRules),
       mDocumentRules(aDocumentRules),
@@ -3584,17 +3584,17 @@ struct CascadeEnumData {
   nsTArray<nsCSSCounterStyleRule*>& mCounterStyleRules;
   nsTArray<css::DocumentRule*>& mDocumentRules;
   nsMediaQueryResultCacheKey& mCacheKey;
   nsDocumentRuleResultCacheKey& mDocumentCacheKey;
   PLArenaPool mArena;
   // Hooray, a manual PLDHashTable since nsClassHashtable doesn't
   // provide a getter that gives me a *reference* to the value.
   PLDHashTable mRulesByWeight; // of PerWeightDataListItem linked lists
-  uint8_t mSheetType;
+  SheetType mSheetType;
   bool mMustGatherDocumentRules;
 };
 
 /**
  * Recursively traverses rules in order to:
  *  (1) add any @-moz-document rules into data->mDocumentRules.
  *  (2) record any @-moz-document rules whose conditions evaluate to true
  *      on data->mDocumentCacheKey.
--- a/layout/style/nsCSSRuleProcessor.h
+++ b/layout/style/nsCSSRuleProcessor.h
@@ -10,24 +10,25 @@
  */
 
 #ifndef nsCSSRuleProcessor_h_
 #define nsCSSRuleProcessor_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MemoryReporting.h"
-#include "nsIStyleRuleProcessor.h"
-#include "nsIMediaList.h"
-#include "nsTArray.h"
+#include "mozilla/RefCountType.h"
+#include "mozilla/SheetType.h"
+#include "mozilla/UniquePtr.h"
 #include "nsAutoPtr.h"
 #include "nsExpirationTracker.h"
+#include "nsIMediaList.h"
+#include "nsIStyleRuleProcessor.h"
 #include "nsRuleWalker.h"
-#include "mozilla/RefCountType.h"
-#include "mozilla/UniquePtr.h"
+#include "nsTArray.h"
 
 struct CascadeEnumData;
 struct ElementDependentRuleProcessorData;
 struct nsCSSSelector;
 struct nsCSSSelectorList;
 struct nsFontFaceRuleContainer;
 struct RuleCascadeData;
 struct TreeMatchContext;
@@ -54,21 +55,21 @@ class DocumentRule;
  * is told when the rule processor is going away (via DropRuleProcessor).
  */
 
 class nsCSSRuleProcessor: public nsIStyleRuleProcessor {
 public:
   typedef nsTArray<RefPtr<mozilla::CSSStyleSheet>> sheet_array_type;
 
   // aScopeElement must be non-null iff aSheetType is
-  // nsStyleSet::eScopedDocSheet.
+  // SheetType::ScopedDoc.
   // aPreviousCSSRuleProcessor is the rule processor (if any) that this
   // one is replacing.
   nsCSSRuleProcessor(const sheet_array_type& aSheets,
-                     uint8_t aSheetType,
+                     mozilla::SheetType aSheetType,
                      mozilla::dom::Element* aScopeElement,
                      nsCSSRuleProcessor* aPreviousCSSRuleProcessor,
                      bool aIsShared = false);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsCSSRuleProcessor)
 
 public:
@@ -257,17 +258,17 @@ private:
 
   nsTArray<mozilla::css::DocumentRule*> mDocumentRules;
   nsDocumentRuleResultCacheKey mDocumentCacheKey;
 
   nsExpirationState mExpirationState;
   MozRefCountType mStyleSetRefCnt;
 
   // type of stylesheet using this processor
-  uint8_t mSheetType;  // == nsStyleSet::sheetType
+  mozilla::SheetType mSheetType;
 
   const bool mIsShared;
 
   // Whether we need to build up mDocumentCacheKey and mDocumentRules as
   // we build a RuleCascadeData.  Is true only for shared rule processors
   // and only before we build the first RuleCascadeData.  See comment in
   // RefreshRuleCascade for why.
   bool mMustGatherDocumentRules;
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -4,41 +4,41 @@
  * 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/. */
 
 /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
 
 #ifndef nsCSSRules_h_
 #define nsCSSRules_h_
 
+#include "Declaration.h"
+#include "StyleRule.h"
+#include "gfxFontFeatures.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
-
-#include "mozilla/MemoryReporting.h"
+#include "mozilla/SheetType.h"
 #include "mozilla/css/GroupRule.h"
 #include "mozilla/dom/FontFace.h"
+#include "nsAutoPtr.h"
+#include "nsCSSProperty.h"
+#include "nsCSSValue.h"
+#include "nsDOMCSSDeclaration.h"
 #include "nsIDOMCSSConditionRule.h"
 #include "nsIDOMCSSCounterStyleRule.h"
 #include "nsIDOMCSSFontFaceRule.h"
 #include "nsIDOMCSSFontFeatureValuesRule.h"
 #include "nsIDOMCSSGroupingRule.h"
 #include "nsIDOMCSSMediaRule.h"
 #include "nsIDOMCSSMozDocumentRule.h"
+#include "nsIDOMCSSPageRule.h"
 #include "nsIDOMCSSSupportsRule.h"
 #include "nsIDOMMozCSSKeyframeRule.h"
 #include "nsIDOMMozCSSKeyframesRule.h"
-#include "nsAutoPtr.h"
-#include "nsCSSProperty.h"
-#include "nsCSSValue.h"
 #include "nsTArray.h"
-#include "nsDOMCSSDeclaration.h"
-#include "Declaration.h"
-#include "nsIDOMCSSPageRule.h"
-#include "StyleRule.h"
-#include "gfxFontFeatures.h"
 
 class nsMediaList;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace css {
@@ -282,17 +282,17 @@ protected:
   friend class nsCSSFontFaceStyleDecl;
   nsCSSFontFaceStyleDecl mDecl;
 };
 
 // nsFontFaceRuleContainer - used for associating sheet type with
 // specific @font-face rules
 struct nsFontFaceRuleContainer {
   RefPtr<nsCSSFontFaceRule> mRule;
-  uint8_t mSheetType;
+  mozilla::SheetType mSheetType;
 };
 
 inline nsCSSFontFaceRule*
 nsCSSFontFaceStyleDecl::ContainingRule()
 {
   return reinterpret_cast<nsCSSFontFaceRule*>
     (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
 }
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2533,17 +2533,17 @@ nsCSSValueGradient::SizeOfIncludingThis(
   return n;
 }
 
 // --- nsCSSValueTokenStream ------------
 
 nsCSSValueTokenStream::nsCSSValueTokenStream()
   : mPropertyID(eCSSProperty_UNKNOWN)
   , mShorthandPropertyID(eCSSProperty_UNKNOWN)
-  , mLevel(nsStyleSet::eSheetTypeCount)
+  , mLevel(SheetType::Count)
 {
   MOZ_COUNT_CTOR(nsCSSValueTokenStream);
 }
 
 nsCSSValueTokenStream::~nsCSSValueTokenStream()
 {
   MOZ_COUNT_DTOR(nsCSSValueTokenStream);
 }
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -5,16 +5,17 @@
 
 /* representation of simple property values within CSS declarations */
 
 #ifndef nsCSSValue_h___
 #define nsCSSValue_h___
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/SheetType.h"
 
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
 #include "nsCOMPtr.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCoord.h"
@@ -1537,17 +1538,17 @@ public:
 
   nsCOMPtr<nsIURI> mBaseURI;
   nsCOMPtr<nsIURI> mSheetURI;
   nsCOMPtr<nsIPrincipal> mSheetPrincipal;
   // XXX Should store sheet here (see Bug 952338)
   // mozilla::CSSStyleSheet* mSheet;
   uint32_t mLineNumber;
   uint32_t mLineOffset;
-  uint16_t mLevel; // an nsStyleSet::sheetType
+  mozilla::SheetType mLevel;
 
 private:
   nsCSSValueTokenStream(const nsCSSValueTokenStream& aOther) = delete;
   nsCSSValueTokenStream& operator=(const nsCSSValueTokenStream& aOther) = delete;
 };
 
 class nsCSSValueFloatColor final {
 public:
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -498,18 +498,18 @@ nsComputedDOMStyle::GetStyleContextForEl
   }
 
   if (aStyleType == eDefaultOnly) {
     // We really only want the user and UA rules.  Filter out the other ones.
     nsTArray< nsCOMPtr<nsIStyleRule> > rules;
     for (nsRuleNode* ruleNode = sc->RuleNode();
          !ruleNode->IsRoot();
          ruleNode = ruleNode->GetParent()) {
-      if (ruleNode->GetLevel() == nsStyleSet::eAgentSheet ||
-          ruleNode->GetLevel() == nsStyleSet::eUserSheet) {
+      if (ruleNode->GetLevel() == SheetType::Agent ||
+          ruleNode->GetLevel() == SheetType::User) {
         rules.AppendElement(ruleNode->GetRule());
       }
     }
 
     // We want to build a list of user/ua rules that is in order from least to
     // most important, so we have to reverse the list.
     // Integer division to get "stop" is purposeful here: if length is odd, we
     // don't have to do anything with the middle element of the array.
--- a/layout/style/nsRuleData.h
+++ b/layout/style/nsRuleData.h
@@ -8,32 +8,33 @@
  * hold data from matched rules during style data computation.
  */
 
 #ifndef nsRuleData_h_
 #define nsRuleData_h_
 
 #include "mozilla/CSSVariableDeclarations.h"
 #include "mozilla/RuleNodeCacheConditions.h"
+#include "mozilla/SheetType.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsStyleStructFwd.h"
 
 class nsPresContext;
 class nsStyleContext;
 struct nsRuleData;
 
 typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
 
 struct nsRuleData
 {
   const uint32_t mSIDs;
   mozilla::RuleNodeCacheConditions mConditions;
   bool mIsImportantRule;
-  uint16_t mLevel; // an nsStyleSet::sheetType
+  mozilla::SheetType mLevel;
   nsPresContext* const mPresContext;
   nsStyleContext* const mStyleContext;
 
   // We store nsCSSValues needed to compute the data for one or more
   // style structs (specified by the bitfield mSIDs).  These are stored
   // in a single array allocation (which our caller allocates; see
   // AutoCSSValueArray)   The offset of each property |prop| in
   // mValueStorage is the sum of
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1461,21 +1461,21 @@ nsRuleNode::DestroyInternal(nsRuleNode *
   // Don't let the memory be freed, since it will be recycled
   // instead. Don't call the global operator delete.
   mPresContext->PresShell()->FreeByObjectID(eArenaObjectID_nsRuleNode, this);
 }
 
 nsRuleNode* nsRuleNode::CreateRootNode(nsPresContext* aPresContext)
 {
   return new (aPresContext)
-    nsRuleNode(aPresContext, nullptr, nullptr, 0xff, false);
+    nsRuleNode(aPresContext, nullptr, nullptr, SheetType::Unknown, false);
 }
 
 nsRuleNode::nsRuleNode(nsPresContext* aContext, nsRuleNode* aParent,
-                       nsIStyleRule* aRule, uint8_t aLevel,
+                       nsIStyleRule* aRule, SheetType aLevel,
                        bool aIsImportant)
   : mPresContext(aContext),
     mParent(aParent),
     mRule(aRule),
     mNextSibling(nullptr),
     mDependentBits((uint32_t(aLevel) << NS_RULE_NODE_LEVEL_SHIFT) |
                    (aIsImportant ? NS_RULE_NODE_IS_IMPORTANT : 0)),
     mNoneBits(aParent ? aParent->mNoneBits & NS_RULE_NODE_HAS_ANIMATION_DATA :
@@ -1500,34 +1500,34 @@ nsRuleNode::nsRuleNode(nsPresContext* aC
      unused.  */
   if (!IsRoot()) {
     mParent->AddRef();
     aContext->StyleSet()->RuleNodeUnused();
   }
 
   // nsStyleSet::GetContext depends on there being only one animation
   // rule.
-  MOZ_ASSERT(IsRoot() || GetLevel() != nsStyleSet::eAnimationSheet ||
+  MOZ_ASSERT(IsRoot() || GetLevel() != SheetType::Animation ||
              mParent->IsRoot() ||
-             mParent->GetLevel() != nsStyleSet::eAnimationSheet,
+             mParent->GetLevel() != SheetType::Animation,
              "must be only one rule at animation level");
 }
 
 nsRuleNode::~nsRuleNode()
 {
   MOZ_COUNT_DTOR(nsRuleNode);
   if (mStyleData.mResetData || mStyleData.mInheritedData)
     mStyleData.Destroy(mDependentBits, mPresContext);
   if (mRule) {
     mRule->Release();
   }
 }
 
 nsRuleNode*
-nsRuleNode::Transition(nsIStyleRule* aRule, uint8_t aLevel,
+nsRuleNode::Transition(nsIStyleRule* aRule, SheetType aLevel,
                        bool aIsImportantRule)
 {
   nsRuleNode* next = nullptr;
   nsRuleNode::Key key(aRule, aLevel, aIsImportantRule);
 
   if (HaveChildren() && !ChildrenAreHashed()) {
     int32_t numKids = 0;
     nsRuleNode* curr = ChildrenList();
@@ -2175,20 +2175,20 @@ nsRuleNode::ResolveVariableReferences(co
     if (value->GetUnit() != eCSSUnit_TokenStream) {
       continue;
     }
 
     const CSSVariableValues* variables =
       &aContext->StyleVariables()->mVariables;
     nsCSSValueTokenStream* tokenStream = value->GetTokenStreamValue();
 
-    MOZ_ASSERT(tokenStream->mLevel != nsStyleSet::eSheetTypeCount,
+    MOZ_ASSERT(tokenStream->mLevel != SheetType::Count,
                "Token stream should have a defined level");
 
-    AutoRestore<uint16_t> saveLevel(aRuleData->mLevel);
+    AutoRestore<SheetType> saveLevel(aRuleData->mLevel);
     aRuleData->mLevel = tokenStream->mLevel;
 
     // Note that ParsePropertyWithVariableReferences relies on the fact
     // that the nsCSSValue in aRuleData for the property we are re-parsing
     // is still the token stream value.  When
     // ParsePropertyWithVariableReferences calls
     // nsCSSExpandedDataBlock::MapRuleInfoInto, that function will add
     // the ImageValue that is created into the token stream object's
@@ -9687,18 +9687,18 @@ nsRuleNode::HasAuthorSpecifiedRules(nsSt
          ruleNode = ruleNode->GetParent()) {
       nsIStyleRule *rule = ruleNode->GetRule();
       if (rule) {
         ruleData.mLevel = ruleNode->GetLevel();
         ruleData.mIsImportantRule = ruleNode->IsImportantRule();
 
         rule->MapRuleInfoInto(&ruleData);
 
-        if (ruleData.mLevel == nsStyleSet::eAgentSheet ||
-            ruleData.mLevel == nsStyleSet::eUserSheet) {
+        if (ruleData.mLevel == SheetType::Agent ||
+            ruleData.mLevel == SheetType::User) {
           // This is a rule whose effect we want to ignore, so if any of
           // the properties we care about were set, set them to the dummy
           // value that they'll never otherwise get.
           for (uint32_t i = 0; i < nValues; ++i) {
             nsCSSUnit unit = values[i]->GetUnit();
             if (unit != eCSSUnit_Null &&
                 unit != eCSSUnit_Dummy &&
                 unit != eCSSUnit_DummyInherit) {
@@ -9810,17 +9810,17 @@ nsRuleNode::ComputePropertiesOverridingA
       // animations in the cascade ordering.  They also don't actually
       // override animations, since transitions are suppressed when both
       // are present.  And since we might not have called
       // UpdateCascadeResults (which updates when they are suppressed
       // due to the presence of animations for the same element and
       // property) for transitions yet (which will make their
       // MapRuleInfoInto skip the properties that are currently
       // animating), we should skip them explicitly.
-      if (ruleData.mLevel == nsStyleSet::eTransitionSheet) {
+      if (ruleData.mLevel == SheetType::Transition) {
         continue;
       }
 
       if (!ruleData.mIsImportantRule) {
         // We're now equal to or less than the animation level; stop.
         break;
       }
 
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -10,16 +10,17 @@
 
 #ifndef nsRuleNode_h___
 #define nsRuleNode_h___
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/RangedArray.h"
 #include "mozilla/RuleNodeCacheConditions.h"
+#include "mozilla/SheetType.h"
 #include "nsPresContext.h"
 #include "nsStyleStruct.h"
 
 class nsCSSPropertySet;
 class nsCSSValue;
 class nsIStyleRule;
 class nsStyleContext;
 class nsStyleCoord;
@@ -413,20 +414,20 @@ private:
   nsRuleNode* mNextSibling; // This value should be used only by the
                             // parent, since the parent may store
                             // children in a hash, which means this
                             // pointer is not meaningful.  Order of
                             // siblings is also not meaningful.
 
   struct Key {
     nsIStyleRule* mRule;
-    uint8_t mLevel;
+    mozilla::SheetType mLevel;
     bool mIsImportantRule;
 
-    Key(nsIStyleRule* aRule, uint8_t aLevel, bool aIsImportantRule)
+    Key(nsIStyleRule* aRule, mozilla::SheetType aLevel, bool aIsImportantRule)
       : mRule(aRule), mLevel(aLevel), mIsImportantRule(aIsImportantRule)
     {}
 
     bool operator==(const Key& aOther) const
     {
       return mRule == aOther.mRule &&
              mLevel == aOther.mLevel &&
              mIsImportantRule == aOther.mIsImportantRule;
@@ -795,44 +796,44 @@ protected:
   void SetStyleClipPathToCSSValue(nsStyleClipPath* aStyleClipPath,
                                   const nsCSSValue* aValue,
                                   nsStyleContext* aStyleContext,
                                   nsPresContext* aPresContext,
                                   mozilla::RuleNodeCacheConditions& aConditions);
 
 private:
   nsRuleNode(nsPresContext* aPresContext, nsRuleNode* aParent,
-             nsIStyleRule* aRule, uint8_t aLevel, bool aIsImportant);
+             nsIStyleRule* aRule, mozilla::SheetType aLevel, bool aIsImportant);
   ~nsRuleNode();
 
 public:
   // This is infallible; it will never return nullptr.
   static nsRuleNode* CreateRootNode(nsPresContext* aPresContext);
 
   static void EnsureBlockDisplay(uint8_t& display,
                                  bool aConvertListItem = false);
   static void EnsureInlineDisplay(uint8_t& display);
 
   // Transition never returns null; on out of memory it'll just return |this|.
-  nsRuleNode* Transition(nsIStyleRule* aRule, uint8_t aLevel,
+  nsRuleNode* Transition(nsIStyleRule* aRule, mozilla::SheetType aLevel,
                          bool aIsImportantRule);
   nsRuleNode* GetParent() const { return mParent; }
   bool IsRoot() const { return mParent == nullptr; }
 
   // Return the root of the rule tree that this rule node is in.
   nsRuleNode* RuleTree();
   const nsRuleNode* RuleTree() const {
     return const_cast<nsRuleNode*>(this)->RuleTree();
   }
 
-  // These uint8_ts are really nsStyleSet::sheetType values.
-  uint8_t GetLevel() const {
+  mozilla::SheetType GetLevel() const {
     NS_ASSERTION(!IsRoot(), "can't call on root");
-    return (mDependentBits & NS_RULE_NODE_LEVEL_MASK) >>
-             NS_RULE_NODE_LEVEL_SHIFT;
+    return mozilla::SheetType(
+        (mDependentBits & NS_RULE_NODE_LEVEL_MASK) >>
+          NS_RULE_NODE_LEVEL_SHIFT);
   }
   bool IsImportantRule() const {
     NS_ASSERTION(!IsRoot(), "can't call on root");
     return (mDependentBits & NS_RULE_NODE_IS_IMPORTANT) != 0;
   }
 
   /**
    * Has this rule node at some time in its lifetime been the mRuleNode
--- a/layout/style/nsRuleWalker.h
+++ b/layout/style/nsRuleWalker.h
@@ -49,26 +49,26 @@ public:
   void ForwardOnPossiblyCSSRule(nsIStyleRule* aRule) {
     DoForward(aRule);
   }
 
   void Reset() { mCurrent = mRoot; }
 
   bool AtRoot() { return mCurrent == mRoot; }
 
-  void SetLevel(uint8_t aLevel, bool aImportance,
+  void SetLevel(mozilla::SheetType aLevel, bool aImportance,
                 bool aCheckForImportantRules) {
     NS_ASSERTION(!aCheckForImportantRules || !aImportance,
                  "Shouldn't be checking for important rules while walking "
                  "important rules");
     mLevel = aLevel;
     mImportance = aImportance;
     mCheckForImportantRules = aCheckForImportantRules;
   }
-  uint8_t GetLevel() const { return mLevel; }
+  mozilla::SheetType GetLevel() const { return mLevel; }
   bool GetImportance() const { return mImportance; }
   bool GetCheckForImportantRules() const { return mCheckForImportantRules; }
 
   bool AuthorStyleDisabled() const { return mAuthorStyleDisabled; }
 
   // We define the visited-relevant link to be the link that is the
   // nearest self-or-ancestor to the node being matched.
   enum VisitedHandlingType {
@@ -81,17 +81,17 @@ public:
     // given any set of visitedness states.  (used by users other than
     // nsRuleWalker)
     eLinksVisitedOrUnvisited
   };
 
 private:
   nsRuleNode* mCurrent; // Our current position.  Never null.
   nsRuleNode* mRoot; // The root of the tree we're walking.
-  uint8_t mLevel; // an nsStyleSet::sheetType
+  mozilla::SheetType mLevel;
   bool mImportance;
   bool mCheckForImportantRules; // If true, check for important rules as
                                 // we walk and set to false if we find
                                 // one.
   bool mAuthorStyleDisabled;
 
 public:
   nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled)
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -8,16 +8,17 @@
  * the internal API that the style system exposes for creating (and
  * potentially re-creating) style contexts
  */
 
 #include "nsStyleSet.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/CSSStyleSheet.h"
+#include "mozilla/EnumeratedRange.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/RuleProcessorCache.h"
 #include "nsIDocumentInlines.h"
 #include "nsRuleWalker.h"
 #include "nsStyleContext.h"
 #include "mozilla/css/StyleRule.h"
 #include "nsCSSAnonBoxes.h"
@@ -138,28 +139,28 @@ nsDisableTextZoomStyleRule::List(FILE* o
   nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
     indentStr.AppendLiteral("  ");
   }
   fprintf_stderr(out, "%s[disable text zoom style rule] {}\n", indentStr.get());
 }
 #endif
 
-static const nsStyleSet::sheetType gCSSSheetTypes[] = {
+static const SheetType gCSSSheetTypes[] = {
   // From lowest to highest in cascading order.
-  nsStyleSet::eAgentSheet,
-  nsStyleSet::eUserSheet,
-  nsStyleSet::eDocSheet,
-  nsStyleSet::eScopedDocSheet,
-  nsStyleSet::eOverrideSheet
+  SheetType::Agent,
+  SheetType::User,
+  SheetType::Doc,
+  SheetType::ScopedDoc,
+  SheetType::Override
 };
 
-static bool IsCSSSheetType(nsStyleSet::sheetType aSheetType)
+static bool IsCSSSheetType(SheetType aSheetType)
 {
-  for (nsStyleSet::sheetType type : gCSSSheetTypes) {
+  for (SheetType type : gCSSSheetTypes) {
     if (type == aSheetType) {
       return true;
     }
   }
   return false;
 }
 
 nsStyleSet::nsStyleSet()
@@ -172,60 +173,60 @@ nsStyleSet::nsStyleSet()
     mNeedsRestyleAfterEnsureUniqueInner(false),
     mDirty(0),
     mUnusedRuleNodeCount(0)
 {
 }
 
 nsStyleSet::~nsStyleSet()
 {
-  for (sheetType type : gCSSSheetTypes) {
+  for (SheetType type : gCSSSheetTypes) {
     for (uint32_t i = 0, n = mSheets[type].Length(); i < n; i++) {
       static_cast<CSSStyleSheet*>(mSheets[type][i])->DropStyleSet(this);
     }
   }
 
   // drop reference to cached rule processors
   nsCSSRuleProcessor* rp;
-  rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[eAgentSheet].get());
+  rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[SheetType::Agent].get());
   if (rp) {
     MOZ_ASSERT(rp->IsShared());
     rp->ReleaseStyleSetRef();
   }
-  rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[eUserSheet].get());
+  rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[SheetType::User].get());
   if (rp) {
     MOZ_ASSERT(rp->IsShared());
     rp->ReleaseStyleSetRef();
   }
 }
 
 size_t
 nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t n = aMallocSizeOf(this);
 
-  for (int i = 0; i < eSheetTypeCount; i++) {
-    if (mRuleProcessors[i]) {
+  for (SheetType type : MakeEnumeratedRange(SheetType::Count)) {
+    if (mRuleProcessors[type]) {
       bool shared = false;
-      if (i == eAgentSheet || i == eUserSheet) {
+      if (type == SheetType::Agent || type == SheetType::User) {
         // The only two origins we consider caching rule processors for.
         nsCSSRuleProcessor* rp =
-          static_cast<nsCSSRuleProcessor*>(mRuleProcessors[i].get());
+          static_cast<nsCSSRuleProcessor*>(mRuleProcessors[type].get());
         shared = rp->IsShared();
       }
       if (!shared) {
-        n += mRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
+        n += mRuleProcessors[type]->SizeOfIncludingThis(aMallocSizeOf);
       }
     }
     // mSheets is a C-style array of nsCOMArrays.  We do not own the sheets in
     // the nsCOMArrays (either the nsLayoutStyleSheetCache singleton or our
     // document owns them) so we do not count the sheets here (we pass nullptr
     // as the aSizeOfElementIncludingThis argument).  All we're doing here is
     // counting the size of the nsCOMArrays' buffers.
-    n += mSheets[i].SizeOfExcludingThis(nullptr, aMallocSizeOf);
+    n += mSheets[type].SizeOfExcludingThis(nullptr, aMallocSizeOf);
   }
 
   for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
     n += mScopedDocSheetRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
   }
   n += mScopedDocSheetRuleProcessors.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
   n += mRoots.ShallowSizeOfExcludingThis(aMallocSizeOf);
@@ -242,21 +243,21 @@ nsStyleSet::Init(nsPresContext *aPresCon
   mPlaceholderRule = new nsEmptyStyleRule;
   mDisableTextZoomStyleRule = new nsDisableTextZoomStyleRule;
 
   mRuleTree = nsRuleNode::CreateRootNode(aPresContext);
 
   // Make an explicit GatherRuleProcessors call for the levels that
   // don't have style sheets.  The other levels will have their calls
   // triggered by DirtyRuleProcessors.  (We should probably convert the
-  // ePresHintSheet and eStyleAttrSheet levels to work like this as
-  // well, and not implement nsIStyleSheet.)
-  GatherRuleProcessors(eAnimationSheet);
-  GatherRuleProcessors(eTransitionSheet);
-  GatherRuleProcessors(eSVGAttrAnimationSheet);
+  // SheetType::PresHint and SheetType::StyleAttr levels to work like
+  // this as well, and not implement nsIStyleSheet.)
+  GatherRuleProcessors(SheetType::Animation);
+  GatherRuleProcessors(SheetType::Transition);
+  GatherRuleProcessors(SheetType::SVGAttrAnimation);
 }
 
 nsresult
 nsStyleSet::BeginReconstruct()
 {
   NS_ASSERTION(!mInReconstruct, "Unmatched begin/end?");
   NS_ASSERTION(mRuleTree, "Reconstructing before first construction?");
 
@@ -382,99 +383,99 @@ SortStyleSheetsByScope(nsTArray<CSSStyle
   sheets.Sort();
 
   for (uint32_t i = 0; i < n; i++) {
     aSheets[i] = sheets[i].mSheet;
   }
 }
 
 nsresult
-nsStyleSet::GatherRuleProcessors(sheetType aType)
+nsStyleSet::GatherRuleProcessors(SheetType aType)
 {
   NS_ENSURE_FALSE(mInShutdown, NS_ERROR_FAILURE);
 
   // We might be in GatherRuleProcessors because we are dropping a sheet,
   // resulting in an nsCSSSelector being destroyed.  Tell the
   // RestyleManager for each document we're used in so that they can
   // drop any nsCSSSelector pointers (used for eRestyle_SomeDescendants)
   // in their mPendingRestyles.
   if (IsCSSSheetType(aType)) {
     ClearSelectors();
   }
   nsCOMPtr<nsIStyleRuleProcessor> oldRuleProcessor(mRuleProcessors[aType]);
   nsTArray<nsCOMPtr<nsIStyleRuleProcessor>> oldScopedDocRuleProcessors;
-  if (aType == eAgentSheet || aType == eUserSheet) {
+  if (aType == SheetType::Agent || aType == SheetType::User) {
     // drop reference to cached rule processor
     nsCSSRuleProcessor* rp =
       static_cast<nsCSSRuleProcessor*>(mRuleProcessors[aType].get());
     if (rp) {
       MOZ_ASSERT(rp->IsShared());
       rp->ReleaseStyleSetRef();
     }
   }
   mRuleProcessors[aType] = nullptr;
-  if (aType == eScopedDocSheet) {
+  if (aType == SheetType::ScopedDoc) {
     for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
       nsIStyleRuleProcessor* processor = mScopedDocSheetRuleProcessors[i].get();
       Element* scope =
         static_cast<nsCSSRuleProcessor*>(processor)->GetScopeElement();
       scope->ClearIsScopedStyleRoot();
     }
 
     // Clear mScopedDocSheetRuleProcessors, but save it.
     oldScopedDocRuleProcessors.SwapElements(mScopedDocSheetRuleProcessors);
   }
-  if (mAuthorStyleDisabled && (aType == eDocSheet || 
-                               aType == eScopedDocSheet ||
-                               aType == eStyleAttrSheet)) {
+  if (mAuthorStyleDisabled && (aType == SheetType::Doc || 
+                               aType == SheetType::ScopedDoc ||
+                               aType == SheetType::StyleAttr)) {
     // Don't regather if this level is disabled.  Note that we gather
     // preshint sheets no matter what, but then skip them for some
     // elements later if mAuthorStyleDisabled.
     return NS_OK;
   }
   switch (aType) {
     // handle the types for which have a rule processor that does not
     // implement the style sheet interface.
-    case eAnimationSheet:
+    case SheetType::Animation:
       MOZ_ASSERT(mSheets[aType].IsEmpty());
       mRuleProcessors[aType] = PresContext()->AnimationManager();
       return NS_OK;
-    case eTransitionSheet:
+    case SheetType::Transition:
       MOZ_ASSERT(mSheets[aType].IsEmpty());
       mRuleProcessors[aType] = PresContext()->TransitionManager();
       return NS_OK;
-    case eStyleAttrSheet:
+    case SheetType::StyleAttr:
       MOZ_ASSERT(mSheets[aType].IsEmpty());
       mRuleProcessors[aType] = PresContext()->Document()->GetInlineStyleSheet();
       return NS_OK;
-    case ePresHintSheet:
+    case SheetType::PresHint:
       MOZ_ASSERT(mSheets[aType].IsEmpty());
       mRuleProcessors[aType] =
         PresContext()->Document()->GetAttributeStyleSheet();
       return NS_OK;
-    case eSVGAttrAnimationSheet:
+    case SheetType::SVGAttrAnimation:
       MOZ_ASSERT(mSheets[aType].IsEmpty());
       mRuleProcessors[aType] =
         PresContext()->Document()->GetSVGAttrAnimationRuleProcessor();
       return NS_OK;
     default:
       // keep going
       break;
   }
-  if (aType == eScopedDocSheet) {
+  if (aType == SheetType::ScopedDoc) {
     // Create a rule processor for each scope.
-    uint32_t count = mSheets[eScopedDocSheet].Count();
+    uint32_t count = mSheets[SheetType::ScopedDoc].Count();
     if (count) {
       // Gather the scoped style sheets into an array as
       // CSSStyleSheets, and mark all of their scope elements
       // as scoped style roots.
       nsTArray<CSSStyleSheet*> sheets(count);
       for (uint32_t i = 0; i < count; i++) {
         RefPtr<CSSStyleSheet> sheet =
-          do_QueryObject(mSheets[eScopedDocSheet].ObjectAt(i));
+          do_QueryObject(mSheets[SheetType::ScopedDoc].ObjectAt(i));
         sheets.AppendElement(sheet);
 
         Element* scope = sheet->GetScopeElement();
         scope->SetIsScopedStyleRoot();
       }
 
       // Sort the scoped style sheets so that those for the same scope are
       // adjacent and that ancestor scopes come before descendent scopes.
@@ -506,73 +507,72 @@ nsStyleSet::GatherRuleProcessors(sheetTy
 
         scope->SetIsScopedStyleRoot();
 
         // Create a rule processor for the scope.
         nsTArray<RefPtr<CSSStyleSheet>> sheetsForScope;
         sheetsForScope.AppendElements(sheets.Elements() + start, end - start);
         nsCSSRuleProcessor* oldRP = oldScopedRuleProcessorHash.Get(scope);
         mScopedDocSheetRuleProcessors.AppendElement
-          (new nsCSSRuleProcessor(sheetsForScope, uint8_t(aType), scope,
-                                  oldRP));
+          (new nsCSSRuleProcessor(sheetsForScope, aType, scope, oldRP));
 
         start = end;
       } while (start < count);
     }
     return NS_OK;
   }
   if (mSheets[aType].Count()) {
     switch (aType) {
-      case eAgentSheet:
-      case eUserSheet: {
+      case SheetType::Agent:
+      case SheetType::User: {
         // levels containing non-scoped CSS style sheets whose rule processors
         // we want to re-use
         nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
         nsTArray<RefPtr<CSSStyleSheet>> cssSheets(sheets.Count());
         for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) {
           RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
           NS_ASSERTION(cssSheet, "not a CSS sheet");
           cssSheets.AppendElement(cssSheet);
         }
         nsTArray<CSSStyleSheet*> cssSheetsRaw(cssSheets.Length());
         for (int32_t i = 0, i_end = cssSheets.Length(); i < i_end; ++i) {
           cssSheetsRaw.AppendElement(cssSheets[i]);
         }
         nsCSSRuleProcessor* rp =
           RuleProcessorCache::GetRuleProcessor(cssSheetsRaw, PresContext());
         if (!rp) {
-          rp = new nsCSSRuleProcessor(cssSheets, uint8_t(aType), nullptr,
+          rp = new nsCSSRuleProcessor(cssSheets, aType, nullptr,
                                       static_cast<nsCSSRuleProcessor*>(
                                        oldRuleProcessor.get()),
                                       true /* aIsShared */);
           nsTArray<css::DocumentRule*> documentRules;
           nsDocumentRuleResultCacheKey cacheKey;
           rp->TakeDocumentRulesAndCacheKey(PresContext(),
                                            documentRules, cacheKey);
           RuleProcessorCache::PutRuleProcessor(cssSheetsRaw,
                                                Move(documentRules),
                                                cacheKey, rp);
         }
         mRuleProcessors[aType] = rp;
         rp->AddStyleSetRef();
         break;
       }
-      case eDocSheet:
-      case eOverrideSheet: {
+      case SheetType::Doc:
+      case SheetType::Override: {
         // levels containing non-scoped CSS stylesheets whose rule processors
         // we don't want to re-use
         nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
         nsTArray<RefPtr<CSSStyleSheet>> cssSheets(sheets.Count());
         for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) {
           RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
           NS_ASSERTION(cssSheet, "not a CSS sheet");
           cssSheets.AppendElement(cssSheet);
         }
         mRuleProcessors[aType] =
-          new nsCSSRuleProcessor(cssSheets, uint8_t(aType), nullptr,
+          new nsCSSRuleProcessor(cssSheets, aType, nullptr,
                                  static_cast<nsCSSRuleProcessor*>(
                                    oldRuleProcessor.get()));
       } break;
 
       default:
         // levels containing non-CSS stylesheets
         NS_ASSERTION(mSheets[aType].Count() == 1, "only one sheet per level");
         mRuleProcessors[aType] = do_QueryInterface(mSheets[aType][0]);
@@ -588,66 +588,66 @@ IsScopedStyleSheet(nsIStyleSheet* aSheet
 {
   RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(aSheet);
   NS_ASSERTION(cssSheet, "expected aSheet to be a CSSStyleSheet");
 
   return cssSheet->GetScopeElement();
 }
 
 nsresult
-nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
+nsStyleSet::AppendStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
   NS_ASSERTION(aSheet->IsApplicable(),
                "Inapplicable sheet being placed in style set");
   bool present = mSheets[aType].RemoveObject(aSheet);
   if (!mSheets[aType].AppendObject(aSheet))
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (!present && IsCSSSheetType(aType)) {
     static_cast<CSSStyleSheet*>(aSheet)->AddStyleSet(this);
   }
 
   return DirtyRuleProcessors(aType);
 }
 
 nsresult
-nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
+nsStyleSet::PrependStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
   NS_ASSERTION(aSheet->IsApplicable(),
                "Inapplicable sheet being placed in style set");
   bool present = mSheets[aType].RemoveObject(aSheet);
   if (!mSheets[aType].InsertObjectAt(aSheet, 0))
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (!present && IsCSSSheetType(aType)) {
     static_cast<CSSStyleSheet*>(aSheet)->AddStyleSet(this);
   }
 
   return DirtyRuleProcessors(aType);
 }
 
 nsresult
-nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
+nsStyleSet::RemoveStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
   NS_ASSERTION(aSheet->IsComplete(),
                "Incomplete sheet being removed from style set");
   if (mSheets[aType].RemoveObject(aSheet)) {
     if (IsCSSSheetType(aType)) {
       static_cast<CSSStyleSheet*>(aSheet)->DropStyleSet(this);
     }
   }
 
   return DirtyRuleProcessors(aType);
 }
 
 nsresult
-nsStyleSet::ReplaceSheets(sheetType aType,
+nsStyleSet::ReplaceSheets(SheetType aType,
                           const nsCOMArray<nsIStyleSheet> &aNewSheets)
 {
   bool cssSheetType = IsCSSSheetType(aType);
   if (cssSheetType) {
     for (uint32_t i = 0, n = mSheets[aType].Length(); i < n; i++) {
       static_cast<CSSStyleSheet*>(mSheets[aType][i])->DropStyleSet(this);
     }
   }
@@ -661,17 +661,17 @@ nsStyleSet::ReplaceSheets(sheetType aTyp
       static_cast<CSSStyleSheet*>(mSheets[aType][i])->AddStyleSet(this);
     }
   }
 
   return DirtyRuleProcessors(aType);
 }
 
 nsresult
-nsStyleSet::InsertStyleSheetBefore(sheetType aType, nsIStyleSheet *aNewSheet,
+nsStyleSet::InsertStyleSheetBefore(SheetType aType, nsIStyleSheet *aNewSheet,
                                    nsIStyleSheet *aReferenceSheet)
 {
   NS_PRECONDITION(aNewSheet && aReferenceSheet, "null arg");
   NS_ASSERTION(aNewSheet->IsApplicable(),
                "Inapplicable sheet being placed in style set");
 
   bool present = mSheets[aType].RemoveObject(aNewSheet);
   int32_t idx = mSheets[aType].IndexOf(aReferenceSheet);
@@ -683,58 +683,64 @@ nsStyleSet::InsertStyleSheetBefore(sheet
 
   if (!present && IsCSSSheetType(aType)) {
     static_cast<CSSStyleSheet*>(aNewSheet)->AddStyleSet(this);
   }
 
   return DirtyRuleProcessors(aType);
 }
 
+static inline uint32_t
+DirtyBit(SheetType aType)
+{
+  return 1 << uint32_t(aType);
+}
+
 nsresult
-nsStyleSet::DirtyRuleProcessors(sheetType aType)
+nsStyleSet::DirtyRuleProcessors(SheetType aType)
 {
   if (!mBatching)
     return GatherRuleProcessors(aType);
 
-  mDirty |= 1 << aType;
+  mDirty |= DirtyBit(aType);
   return NS_OK;
 }
 
 bool
 nsStyleSet::GetAuthorStyleDisabled()
 {
   return mAuthorStyleDisabled;
 }
 
 nsresult
 nsStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
 {
   if (aStyleDisabled == !mAuthorStyleDisabled) {
     mAuthorStyleDisabled = aStyleDisabled;
     BeginUpdate();
-    mDirty |= 1 << eDocSheet |
-              1 << eScopedDocSheet |
-              1 << eStyleAttrSheet;
+    mDirty |= DirtyBit(SheetType::Doc) |
+              DirtyBit(SheetType::ScopedDoc) |
+              DirtyBit(SheetType::StyleAttr);
     return EndUpdate();
   }
   return NS_OK;
 }
 
 // -------- Doc Sheets
 
 nsresult
 nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
 {
   NS_PRECONDITION(aSheet && aDocument, "null arg");
   NS_ASSERTION(aSheet->IsApplicable(),
                "Inapplicable sheet being placed in style set");
 
-  sheetType type = IsScopedStyleSheet(aSheet) ?
-                     eScopedDocSheet :
-                     eDocSheet;
+  SheetType type = IsScopedStyleSheet(aSheet) ?
+                     SheetType::ScopedDoc :
+                     SheetType::Doc;
   nsCOMArray<nsIStyleSheet>& sheets = mSheets[type];
 
   bool present = sheets.RemoveObject(aSheet);
   nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
 
   // lowest index first
   int32_t newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
 
@@ -766,17 +772,18 @@ nsStyleSet::AddDocStyleSheet(nsIStyleShe
   return DirtyRuleProcessors(type);
 }
 
 nsresult
 nsStyleSet::RemoveDocStyleSheet(nsIStyleSheet *aSheet)
 {
   RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(aSheet);
   bool isScoped = cssSheet && cssSheet->GetScopeElement();
-  return RemoveStyleSheet(isScoped ? eScopedDocSheet : eDocSheet, aSheet);
+  return RemoveStyleSheet(isScoped ? SheetType::ScopedDoc : SheetType::Doc,
+                          aSheet);
 }
 
 // Batching
 void
 nsStyleSet::BeginUpdate()
 {
   ++mBatching;
 }
@@ -785,19 +792,19 @@ nsresult
 nsStyleSet::EndUpdate()
 {
   NS_ASSERTION(mBatching > 0, "Unbalanced EndUpdate");
   if (--mBatching) {
     // We're not completely done yet.
     return NS_OK;
   }
 
-  for (int i = 0; i < eSheetTypeCount; ++i) {
-    if (mDirty & (1 << i)) {
-      nsresult rv = GatherRuleProcessors(sheetType(i));
+  for (SheetType type : MakeEnumeratedRange(SheetType::Count)) {
+    if (mDirty & DirtyBit(type)) {
+      nsresult rv = GatherRuleProcessors(type);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   mDirty = 0;
   return NS_OK;
 }
 
@@ -809,29 +816,29 @@ EnumRulesMatching(nsIStyleRuleProcessor*
   aProcessor->RulesMatching(data);
   return true;
 }
 
 static inline bool
 IsMoreSpecificThanAnimation(nsRuleNode *aRuleNode)
 {
   return !aRuleNode->IsRoot() &&
-         (aRuleNode->GetLevel() == nsStyleSet::eTransitionSheet ||
+         (aRuleNode->GetLevel() == SheetType::Transition ||
           aRuleNode->IsImportantRule());
 }
 
 static nsIStyleRule*
 GetAnimationRule(nsRuleNode *aRuleNode)
 {
   nsRuleNode *n = aRuleNode;
   while (IsMoreSpecificThanAnimation(n)) {
     n = n->GetParent();
   }
 
-  if (n->IsRoot() || n->GetLevel() != nsStyleSet::eAnimationSheet) {
+  if (n->IsRoot() || n->GetLevel() != SheetType::Animation) {
     return nullptr;
   }
 
   return n->GetRule();
 }
 
 static nsRuleNode*
 ReplaceAnimationRule(nsRuleNode *aOldRuleNode,
@@ -843,27 +850,27 @@ ReplaceAnimationRule(nsRuleNode *aOldRul
   nsRuleNode *n = aOldRuleNode;
   while (IsMoreSpecificThanAnimation(n)) {
     moreSpecificNodes.AppendElement(n);
     n = n->GetParent();
   }
 
   if (aOldAnimRule) {
     MOZ_ASSERT(n->GetRule() == aOldAnimRule, "wrong rule");
-    MOZ_ASSERT(n->GetLevel() == nsStyleSet::eAnimationSheet,
+    MOZ_ASSERT(n->GetLevel() == SheetType::Animation,
                "wrong level");
     n = n->GetParent();
   }
 
   MOZ_ASSERT(!IsMoreSpecificThanAnimation(n) &&
-             (n->IsRoot() || n->GetLevel() != nsStyleSet::eAnimationSheet),
+             (n->IsRoot() || n->GetLevel() != SheetType::Animation),
              "wrong level");
 
   if (aNewAnimRule) {
-    n = n->Transition(aNewAnimRule, nsStyleSet::eAnimationSheet, false);
+    n = n->Transition(aNewAnimRule, SheetType::Animation, false);
     n->SetIsAnimationRule();
   }
 
   for (uint32_t i = moreSpecificNodes.Length(); i-- != 0; ) {
     nsRuleNode *oldNode = moreSpecificNodes[i];
     n = n->Transition(oldNode->GetRule(), oldNode->GetLevel(),
                       oldNode->IsImportantRule());
   }
@@ -1108,91 +1115,91 @@ nsStyleSet::FileRules(nsIStyleRuleProces
   //  - UA !important rules                = Agent        !important
   //  - transition rules                   = Transition   normal
   // [most important]
 
   // Save off the last rule before we start walking our agent sheets;
   // this will be either the root or one of the restriction rules.
   nsRuleNode* lastRestrictionRN = aRuleWalker->CurrentNode();
 
-  aRuleWalker->SetLevel(eAgentSheet, false, true);
-  if (mRuleProcessors[eAgentSheet])
-    (*aCollectorFunc)(mRuleProcessors[eAgentSheet], aData);
+  aRuleWalker->SetLevel(SheetType::Agent, false, true);
+  if (mRuleProcessors[SheetType::Agent])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::Agent], aData);
   nsRuleNode* lastAgentRN = aRuleWalker->CurrentNode();
   bool haveImportantUARules = !aRuleWalker->GetCheckForImportantRules();
 
-  aRuleWalker->SetLevel(eUserSheet, false, true);
+  aRuleWalker->SetLevel(SheetType::User, false, true);
   bool skipUserStyles =
     aElement && aElement->IsInNativeAnonymousSubtree();
-  if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
-    (*aCollectorFunc)(mRuleProcessors[eUserSheet], aData);
+  if (!skipUserStyles && mRuleProcessors[SheetType::User]) // NOTE: different
+    (*aCollectorFunc)(mRuleProcessors[SheetType::User], aData);
   nsRuleNode* lastUserRN = aRuleWalker->CurrentNode();
   bool haveImportantUserRules = !aRuleWalker->GetCheckForImportantRules();
 
-  aRuleWalker->SetLevel(ePresHintSheet, false, false);
-  if (mRuleProcessors[ePresHintSheet])
-    (*aCollectorFunc)(mRuleProcessors[ePresHintSheet], aData);
+  aRuleWalker->SetLevel(SheetType::PresHint, false, false);
+  if (mRuleProcessors[SheetType::PresHint])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::PresHint], aData);
 
-  aRuleWalker->SetLevel(eSVGAttrAnimationSheet, false, false);
-  if (mRuleProcessors[eSVGAttrAnimationSheet])
-    (*aCollectorFunc)(mRuleProcessors[eSVGAttrAnimationSheet], aData);
+  aRuleWalker->SetLevel(SheetType::SVGAttrAnimation, false, false);
+  if (mRuleProcessors[SheetType::SVGAttrAnimation])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::SVGAttrAnimation], aData);
   nsRuleNode* lastSVGAttrAnimationRN = aRuleWalker->CurrentNode();
 
-  aRuleWalker->SetLevel(eDocSheet, false, true);
+  aRuleWalker->SetLevel(SheetType::Doc, false, true);
   bool cutOffInheritance = false;
   if (mBindingManager && aElement) {
     // We can supply additional document-level sheets that should be walked.
     mBindingManager->WalkRules(aCollectorFunc,
                                static_cast<ElementDependentRuleProcessorData*>(aData),
                                &cutOffInheritance);
   }
   if (!skipUserStyles && !cutOffInheritance && // NOTE: different
-      mRuleProcessors[eDocSheet])
-    (*aCollectorFunc)(mRuleProcessors[eDocSheet], aData);
+      mRuleProcessors[SheetType::Doc])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::Doc], aData);
   nsRuleNode* lastDocRN = aRuleWalker->CurrentNode();
   bool haveImportantDocRules = !aRuleWalker->GetCheckForImportantRules();
   nsTArray<nsRuleNode*> lastScopedRNs;
   nsTArray<bool> haveImportantScopedRules;
   bool haveAnyImportantScopedRules = false;
   if (!skipUserStyles && !cutOffInheritance &&
       aElement && aElement->IsElementInStyleScope()) {
     lastScopedRNs.SetLength(mScopedDocSheetRuleProcessors.Length());
     haveImportantScopedRules.SetLength(mScopedDocSheetRuleProcessors.Length());
     for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
-      aRuleWalker->SetLevel(eScopedDocSheet, false, true);
+      aRuleWalker->SetLevel(SheetType::ScopedDoc, false, true);
       nsCSSRuleProcessor* processor =
         static_cast<nsCSSRuleProcessor*>(mScopedDocSheetRuleProcessors[i].get());
       aData->mScope = processor->GetScopeElement();
       (*aCollectorFunc)(mScopedDocSheetRuleProcessors[i], aData);
       lastScopedRNs[i] = aRuleWalker->CurrentNode();
       haveImportantScopedRules[i] = !aRuleWalker->GetCheckForImportantRules();
       haveAnyImportantScopedRules = haveAnyImportantScopedRules || haveImportantScopedRules[i];
     }
     aData->mScope = nullptr;
   }
   nsRuleNode* lastScopedRN = aRuleWalker->CurrentNode();
-  aRuleWalker->SetLevel(eStyleAttrSheet, false, true);
-  if (mRuleProcessors[eStyleAttrSheet])
-    (*aCollectorFunc)(mRuleProcessors[eStyleAttrSheet], aData);
+  aRuleWalker->SetLevel(SheetType::StyleAttr, false, true);
+  if (mRuleProcessors[SheetType::StyleAttr])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::StyleAttr], aData);
   nsRuleNode* lastStyleAttrRN = aRuleWalker->CurrentNode();
   bool haveImportantStyleAttrRules = !aRuleWalker->GetCheckForImportantRules();
 
-  aRuleWalker->SetLevel(eOverrideSheet, false, true);
-  if (mRuleProcessors[eOverrideSheet])
-    (*aCollectorFunc)(mRuleProcessors[eOverrideSheet], aData);
+  aRuleWalker->SetLevel(SheetType::Override, false, true);
+  if (mRuleProcessors[SheetType::Override])
+    (*aCollectorFunc)(mRuleProcessors[SheetType::Override], aData);
   nsRuleNode* lastOvrRN = aRuleWalker->CurrentNode();
   bool haveImportantOverrideRules = !aRuleWalker->GetCheckForImportantRules();
 
   // This needs to match IsMoreSpecificThanAnimation() above.
-  aRuleWalker->SetLevel(eAnimationSheet, false, false);
-  (*aCollectorFunc)(mRuleProcessors[eAnimationSheet], aData);
+  aRuleWalker->SetLevel(SheetType::Animation, false, false);
+  (*aCollectorFunc)(mRuleProcessors[SheetType::Animation], aData);
 
   if (haveAnyImportantScopedRules) {
     for (uint32_t i = lastScopedRNs.Length(); i-- != 0; ) {
-      aRuleWalker->SetLevel(eScopedDocSheet, true, false);
+      aRuleWalker->SetLevel(SheetType::ScopedDoc, true, false);
       nsRuleNode* startRN = lastScopedRNs[i];
       nsRuleNode* endRN = i == 0 ? lastDocRN : lastScopedRNs[i - 1];
       if (haveImportantScopedRules[i]) {
         AddImportantRules(startRN, endRN, aRuleWalker);  // scoped
       }
 #ifdef DEBUG
       else {
         AssertNoImportantRules(startRN, endRN);
@@ -1202,129 +1209,129 @@ nsStyleSet::FileRules(nsIStyleRuleProces
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastScopedRN, lastDocRN);
   }
 #endif
 
   if (haveImportantDocRules) {
-    aRuleWalker->SetLevel(eDocSheet, true, false);
+    aRuleWalker->SetLevel(SheetType::Doc, true, false);
     AddImportantRules(lastDocRN, lastSVGAttrAnimationRN, aRuleWalker);  // doc
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastDocRN, lastSVGAttrAnimationRN);
   }
 #endif
 
   if (haveImportantStyleAttrRules) {
-    aRuleWalker->SetLevel(eStyleAttrSheet, true, false);
+    aRuleWalker->SetLevel(SheetType::StyleAttr, true, false);
     AddImportantRules(lastStyleAttrRN, lastScopedRN, aRuleWalker);  // style attr
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastStyleAttrRN, lastScopedRN);
   }
 #endif
 
   if (haveImportantOverrideRules) {
-    aRuleWalker->SetLevel(eOverrideSheet, true, false);
+    aRuleWalker->SetLevel(SheetType::Override, true, false);
     AddImportantRules(lastOvrRN, lastStyleAttrRN, aRuleWalker);  // override
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastOvrRN, lastStyleAttrRN);
   }
 #endif
 
 #ifdef DEBUG
   AssertNoCSSRules(lastSVGAttrAnimationRN, lastUserRN);
 #endif
 
   if (haveImportantUserRules) {
-    aRuleWalker->SetLevel(eUserSheet, true, false);
+    aRuleWalker->SetLevel(SheetType::User, true, false);
     AddImportantRules(lastUserRN, lastAgentRN, aRuleWalker); //user
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastUserRN, lastAgentRN);
   }
 #endif
 
   if (haveImportantUARules) {
-    aRuleWalker->SetLevel(eAgentSheet, true, false);
+    aRuleWalker->SetLevel(SheetType::Agent, true, false);
     AddImportantRules(lastAgentRN, lastRestrictionRN, aRuleWalker); //agent
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastAgentRN, lastRestrictionRN);
   }
 #endif
 
 #ifdef DEBUG
   AssertNoCSSRules(lastRestrictionRN, mRuleTree);
 #endif
 
 #ifdef DEBUG
   nsRuleNode *lastImportantRN = aRuleWalker->CurrentNode();
 #endif
-  aRuleWalker->SetLevel(eTransitionSheet, false, false);
-  (*aCollectorFunc)(mRuleProcessors[eTransitionSheet], aData);
+  aRuleWalker->SetLevel(SheetType::Transition, false, false);
+  (*aCollectorFunc)(mRuleProcessors[SheetType::Transition], aData);
 #ifdef DEBUG
   AssertNoCSSRules(aRuleWalker->CurrentNode(), lastImportantRN);
 #endif
 
 }
 
 // Enumerate all the rules in a way that doesn't care about the order
 // of the rules and doesn't walk !important-rules.
 void
 nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
                                ElementDependentRuleProcessorData* aData,
                                bool aWalkAllXBLStylesheets)
 {
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
-  if (mRuleProcessors[eAgentSheet])
-    (*aFunc)(mRuleProcessors[eAgentSheet], aData);
+  if (mRuleProcessors[SheetType::Agent])
+    (*aFunc)(mRuleProcessors[SheetType::Agent], aData);
 
   bool skipUserStyles = aData->mElement->IsInNativeAnonymousSubtree();
-  if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
-    (*aFunc)(mRuleProcessors[eUserSheet], aData);
+  if (!skipUserStyles && mRuleProcessors[SheetType::User]) // NOTE: different
+    (*aFunc)(mRuleProcessors[SheetType::User], aData);
 
-  if (mRuleProcessors[ePresHintSheet])
-    (*aFunc)(mRuleProcessors[ePresHintSheet], aData);
+  if (mRuleProcessors[SheetType::PresHint])
+    (*aFunc)(mRuleProcessors[SheetType::PresHint], aData);
 
-  if (mRuleProcessors[eSVGAttrAnimationSheet])
-    (*aFunc)(mRuleProcessors[eSVGAttrAnimationSheet], aData);
+  if (mRuleProcessors[SheetType::SVGAttrAnimation])
+    (*aFunc)(mRuleProcessors[SheetType::SVGAttrAnimation], aData);
 
   bool cutOffInheritance = false;
   if (mBindingManager) {
     // We can supply additional document-level sheets that should be walked.
     if (aWalkAllXBLStylesheets) {
       mBindingManager->WalkAllRules(aFunc, aData);
     } else {
       mBindingManager->WalkRules(aFunc, aData, &cutOffInheritance);
     }
   }
   if (!skipUserStyles && !cutOffInheritance) {
-    if (mRuleProcessors[eDocSheet]) // NOTE: different
-      (*aFunc)(mRuleProcessors[eDocSheet], aData);
+    if (mRuleProcessors[SheetType::Doc]) // NOTE: different
+      (*aFunc)(mRuleProcessors[SheetType::Doc], aData);
     if (aData->mElement->IsElementInStyleScope()) {
       for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++)
         (*aFunc)(mScopedDocSheetRuleProcessors[i], aData);
     }
   }
-  if (mRuleProcessors[eStyleAttrSheet])
-    (*aFunc)(mRuleProcessors[eStyleAttrSheet], aData);
-  if (mRuleProcessors[eOverrideSheet])
-    (*aFunc)(mRuleProcessors[eOverrideSheet], aData);
-  (*aFunc)(mRuleProcessors[eAnimationSheet], aData);
-  (*aFunc)(mRuleProcessors[eTransitionSheet], aData);
+  if (mRuleProcessors[SheetType::StyleAttr])
+    (*aFunc)(mRuleProcessors[SheetType::StyleAttr], aData);
+  if (mRuleProcessors[SheetType::Override])
+    (*aFunc)(mRuleProcessors[SheetType::Override], aData);
+  (*aFunc)(mRuleProcessors[SheetType::Animation], aData);
+  (*aFunc)(mRuleProcessors[SheetType::Transition], aData);
 }
 
 static void
 InitStyleScopes(TreeMatchContext& aTreeContext, Element* aElement)
 {
   if (aElement->IsElementInStyleScope()) {
     aTreeContext.InitStyleScopes(aElement->GetParentElementCrossingShadowRoot());
   }
@@ -1388,17 +1395,17 @@ already_AddRefed<nsStyleContext>
 nsStyleSet::ResolveStyleForRules(nsStyleContext* aParentContext,
                                  const nsTArray< nsCOMPtr<nsIStyleRule> > &aRules)
 {
   NS_ENSURE_FALSE(mInShutdown, nullptr);
 
   nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
   // FIXME: Perhaps this should be passed in, but it probably doesn't
   // matter.
-  ruleWalker.SetLevel(eDocSheet, false, false);
+  ruleWalker.SetLevel(SheetType::Doc, false, false);
   for (uint32_t i = 0; i < aRules.Length(); i++) {
     ruleWalker.ForwardOnPossiblyCSSRule(aRules.ElementAt(i));
   }
 
   return GetContext(aParentContext, ruleWalker.CurrentNode(), nullptr,
                     nullptr, nsCSSPseudoElements::ePseudo_NotPseudoElement,
                     nullptr, eNoFlags);
 }
@@ -1412,17 +1419,17 @@ nsStyleSet::ResolveStyleByAddingRules(ns
   nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
   ruleWalker.SetCurrentNode(aBaseContext->RuleNode());
   // This needs to be the transition sheet because that is the highest
   // level of the cascade, and thus the only thing that makes sense if
   // we are ever going to call ResolveStyleWithReplacement on the
   // resulting context.  It's also the right thing for the one case (the
   // transition manager's cover rule) where we put the result of this
   // function in the style context tree.
-  ruleWalker.SetLevel(eTransitionSheet, false, false);
+  ruleWalker.SetLevel(SheetType::Transition, false, false);
   for (int32_t i = 0; i < aRules.Count(); i++) {
     ruleWalker.ForwardOnPossiblyCSSRule(aRules.ObjectAt(i));
   }
 
   nsRuleNode *ruleNode = ruleWalker.CurrentNode();
   nsRuleNode *visitedRuleNode = nullptr;
 
   if (aBaseContext->GetStyleIfVisited()) {
@@ -1447,47 +1454,47 @@ nsStyleSet::ResolveStyleByAddingRules(ns
   return GetContext(aBaseContext->GetParent(), ruleNode, visitedRuleNode,
                     aBaseContext->GetPseudo(),
                     aBaseContext->GetPseudoType(),
                     nullptr, flags);
 }
 
 struct RuleNodeInfo {
   nsIStyleRule* mRule;
-  uint8_t mLevel;
+  SheetType mLevel;
   bool mIsImportant;
   bool mIsAnimationRule;
 };
 
 struct CascadeLevel {
-  uint8_t mLevel;
+  SheetType mLevel;
   bool mIsImportant;
   bool mCheckForImportantRules;
   nsRestyleHint mLevelReplacementHint;
 };
 
 static const CascadeLevel gCascadeLevels[] = {
-  { nsStyleSet::eAgentSheet,            false, false, nsRestyleHint(0) },
-  { nsStyleSet::eUserSheet,             false, false, nsRestyleHint(0) },
-  { nsStyleSet::ePresHintSheet,         false, false, nsRestyleHint(0) },
-  { nsStyleSet::eSVGAttrAnimationSheet, false, false, eRestyle_SVGAttrAnimations },
-  { nsStyleSet::eDocSheet,              false, false, nsRestyleHint(0) },
-  { nsStyleSet::eScopedDocSheet,        false, false, nsRestyleHint(0) },
-  { nsStyleSet::eStyleAttrSheet,        false, true,  eRestyle_StyleAttribute |
-                                                      eRestyle_StyleAttribute_Animations },
-  { nsStyleSet::eOverrideSheet,         false, false, nsRestyleHint(0) },
-  { nsStyleSet::eAnimationSheet,        false, false, eRestyle_CSSAnimations },
-  { nsStyleSet::eScopedDocSheet,        true,  false, nsRestyleHint(0) },
-  { nsStyleSet::eDocSheet,              true,  false, nsRestyleHint(0) },
-  { nsStyleSet::eStyleAttrSheet,        true,  false, eRestyle_StyleAttribute |
-                                                      eRestyle_StyleAttribute_Animations },
-  { nsStyleSet::eOverrideSheet,         true,  false, nsRestyleHint(0) },
-  { nsStyleSet::eUserSheet,             true,  false, nsRestyleHint(0) },
-  { nsStyleSet::eAgentSheet,            true,  false, nsRestyleHint(0) },
-  { nsStyleSet::eTransitionSheet,       false, false, eRestyle_CSSTransitions },
+  { SheetType::Agent,            false, false, nsRestyleHint(0) },
+  { SheetType::User,             false, false, nsRestyleHint(0) },
+  { SheetType::PresHint,         false, false, nsRestyleHint(0) },
+  { SheetType::SVGAttrAnimation, false, false, eRestyle_SVGAttrAnimations },
+  { SheetType::Doc,              false, false, nsRestyleHint(0) },
+  { SheetType::ScopedDoc,        false, false, nsRestyleHint(0) },
+  { SheetType::StyleAttr,        false, true,  eRestyle_StyleAttribute |
+                                               eRestyle_StyleAttribute_Animations },
+  { SheetType::Override,         false, false, nsRestyleHint(0) },
+  { SheetType::Animation,        false, false, eRestyle_CSSAnimations },
+  { SheetType::ScopedDoc,        true,  false, nsRestyleHint(0) },
+  { SheetType::Doc,              true,  false, nsRestyleHint(0) },
+  { SheetType::StyleAttr,        true,  false, eRestyle_StyleAttribute |
+                                               eRestyle_StyleAttribute_Animations },
+  { SheetType::Override,         true,  false, nsRestyleHint(0) },
+  { SheetType::User,             true,  false, nsRestyleHint(0) },
+  { SheetType::Agent,            true,  false, nsRestyleHint(0) },
+  { SheetType::Transition,       false, false, eRestyle_CSSTransitions },
 };
 
 nsRuleNode*
 nsStyleSet::RuleNodeWithReplacement(Element* aElement,
                                     Element* aPseudoElement,
                                     nsRuleNode* aOldRuleNode,
                                     nsCSSPseudoElements::Type aPseudoType,
                                     nsRestyleHint aReplacements)
@@ -1542,58 +1549,58 @@ nsStyleSet::RuleNodeWithReplacement(Elem
 
     bool doReplace = level->mLevelReplacementHint & aReplacements;
 
     ruleWalker.SetLevel(level->mLevel, level->mIsImportant,
                         level->mCheckForImportantRules && doReplace);
 
     if (doReplace) {
       switch (level->mLevel) {
-        case nsStyleSet::eAnimationSheet: {
+        case SheetType::Animation: {
           if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
               aPseudoType == nsCSSPseudoElements::ePseudo_before ||
               aPseudoType == nsCSSPseudoElements::ePseudo_after) {
             nsIStyleRule* rule = PresContext()->AnimationManager()->
               GetAnimationRule(aElement, aPseudoType);
             if (rule) {
               ruleWalker.ForwardOnPossiblyCSSRule(rule);
               ruleWalker.CurrentNode()->SetIsAnimationRule();
             }
           }
           break;
         }
-        case nsStyleSet::eTransitionSheet: {
+        case SheetType::Transition: {
           if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
               aPseudoType == nsCSSPseudoElements::ePseudo_before ||
               aPseudoType == nsCSSPseudoElements::ePseudo_after) {
             nsIStyleRule* rule = PresContext()->TransitionManager()->
               GetAnimationRule(aElement, aPseudoType);
             if (rule) {
               ruleWalker.ForwardOnPossiblyCSSRule(rule);
               ruleWalker.CurrentNode()->SetIsAnimationRule();
             }
           }
           break;
         }
-        case nsStyleSet::eSVGAttrAnimationSheet: {
+        case SheetType::SVGAttrAnimation: {
           SVGAttrAnimationRuleProcessor* ruleProcessor =
             static_cast<SVGAttrAnimationRuleProcessor*>(
-              mRuleProcessors[eSVGAttrAnimationSheet].get());
+              mRuleProcessors[SheetType::SVGAttrAnimation].get());
           if (ruleProcessor &&
               aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
             ruleProcessor->ElementRulesMatching(aElement, &ruleWalker);
           }
           break;
         }
-        case nsStyleSet::eStyleAttrSheet: {
+        case SheetType::StyleAttr: {
           if (!level->mIsImportant) {
             // First time through, we handle the non-!important rule.
             nsHTMLCSSStyleSheet* ruleProcessor =
               static_cast<nsHTMLCSSStyleSheet*>(
-                mRuleProcessors[eStyleAttrSheet].get());
+                mRuleProcessors[SheetType::StyleAttr].get());
             if (ruleProcessor) {
               lastScopedRN = ruleWalker.CurrentNode();
               if (aPseudoType ==
                     nsCSSPseudoElements::ePseudo_NotPseudoElement) {
                 ruleProcessor->ElementRulesMatching(PresContext(),
                                                     aElement,
                                                     &ruleWalker);
               } else if (aPseudoType <
@@ -1763,29 +1770,29 @@ nsStyleSet::ResolveStyleForNonElement(ns
                     eNoFlags);
 }
 
 void
 nsStyleSet::WalkRestrictionRule(nsCSSPseudoElements::Type aPseudoType,
                                 nsRuleWalker* aRuleWalker)
 {
   // This needs to match GetPseudoRestriction in nsRuleNode.cpp.
-  aRuleWalker->SetLevel(eAgentSheet, false, false);
+  aRuleWalker->SetLevel(SheetType::Agent, false, false);
   if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLetter)
     aRuleWalker->Forward(mFirstLetterRule);
   else if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLine)
     aRuleWalker->Forward(mFirstLineRule);
   else if (aPseudoType == nsCSSPseudoElements::ePseudo_mozPlaceholder)
     aRuleWalker->Forward(mPlaceholderRule);
 }
 
 void
 nsStyleSet::WalkDisableTextZoomRule(Element* aElement, nsRuleWalker* aRuleWalker)
 {
-  aRuleWalker->SetLevel(eAgentSheet, false, false);
+  aRuleWalker->SetLevel(SheetType::Agent, false, false);
   if (aElement->IsSVGElement(nsGkAtoms::text))
     aRuleWalker->Forward(mDisableTextZoomStyleRule);
 }
 
 already_AddRefed<nsStyleContext>
 nsStyleSet::ResolvePseudoElementStyle(Element* aParentElement,
                                       nsCSSPseudoElements::Type aType,
                                       nsStyleContext* aParentContext,
@@ -2016,17 +2023,17 @@ nsStyleSet::ResolveXULTreePseudoStyle(El
 bool
 nsStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
 {
   NS_ENSURE_FALSE(mInShutdown, false);
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
   nsPresContext* presContext = PresContext();
   for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
-    if (gCSSSheetTypes[i] == eScopedDocSheet)
+    if (gCSSSheetTypes[i] == SheetType::ScopedDoc)
       continue;
     nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (ruleProc && !ruleProc->AppendFontFaceRules(presContext, aArray))
       return false;
   }
   return true;
 }
@@ -2034,17 +2041,17 @@ nsStyleSet::AppendFontFaceRules(nsTArray
 nsCSSKeyframesRule*
 nsStyleSet::KeyframesRuleForName(const nsString& aName)
 {
   NS_ENSURE_FALSE(mInShutdown, nullptr);
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
   nsPresContext* presContext = PresContext();
   for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
-    if (gCSSSheetTypes[i] == eScopedDocSheet)
+    if (gCSSSheetTypes[i] == SheetType::ScopedDoc)
       continue;
     nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (!ruleProc)
       continue;
     nsCSSKeyframesRule* result =
       ruleProc->KeyframesRuleForName(presContext, aName);
     if (result)
@@ -2056,17 +2063,17 @@ nsStyleSet::KeyframesRuleForName(const n
 nsCSSCounterStyleRule*
 nsStyleSet::CounterStyleRuleForName(const nsAString& aName)
 {
   NS_ENSURE_FALSE(mInShutdown, nullptr);
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
   nsPresContext* presContext = PresContext();
   for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
-    if (gCSSSheetTypes[i] == eScopedDocSheet)
+    if (gCSSSheetTypes[i] == SheetType::ScopedDoc)
       continue;
     nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (!ruleProc)
       continue;
     nsCSSCounterStyleRule *result =
       ruleProc->CounterStyleRuleForName(presContext, aName);
     if (result)
@@ -2132,17 +2139,17 @@ nsStyleSet::GetFontFeatureValuesLookup()
 bool
 nsStyleSet::AppendPageRules(nsTArray<nsCSSPageRule*>& aArray)
 {
   NS_ENSURE_FALSE(mInShutdown, false);
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
   nsPresContext* presContext = PresContext();
   for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
-    if (gCSSSheetTypes[i] == eScopedDocSheet)
+    if (gCSSSheetTypes[i] == SheetType::ScopedDoc)
       continue;
     nsCSSRuleProcessor* ruleProc = static_cast<nsCSSRuleProcessor*>
                                     (mRuleProcessors[gCSSSheetTypes[i]].get());
     if (ruleProc && !ruleProc->AppendPageRules(presContext, aArray))
       return false;
   }
   return true;
 }
@@ -2432,26 +2439,24 @@ nsStyleSet::HasAttributeDependentStyle(E
 bool
 nsStyleSet::MediumFeaturesChanged()
 {
   NS_ASSERTION(mBatching == 0, "rule processors out of date");
 
   // We can't use WalkRuleProcessors without a content node.
   nsPresContext* presContext = PresContext();
   bool stylesChanged = false;
-  for (uint32_t i = 0; i < ArrayLength(mRuleProcessors); ++i) {
-    nsIStyleRuleProcessor *processor = mRuleProcessors[i];
+  for (nsIStyleRuleProcessor* processor : mRuleProcessors) {
     if (!processor) {
       continue;
     }
     bool thisChanged = processor->MediumFeaturesChanged(presContext);
     stylesChanged = stylesChanged || thisChanged;
   }
-  for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); ++i) {
-    nsIStyleRuleProcessor *processor = mScopedDocSheetRuleProcessors[i];
+  for (nsIStyleRuleProcessor* processor : mScopedDocSheetRuleProcessors) {
     bool thisChanged = processor->MediumFeaturesChanged(presContext);
     stylesChanged = stylesChanged || thisChanged;
   }
 
   if (mBindingManager) {
     bool thisChanged = false;
     mBindingManager->MediumFeaturesChanged(presContext, &thisChanged);
     stylesChanged = stylesChanged || thisChanged;
@@ -2497,17 +2502,17 @@ nsStyleSet::InitialStyleRule()
 {
   if (!mInitialStyleRule) {
     mInitialStyleRule = new nsInitialStyleRule;
   }
   return mInitialStyleRule;
 }
 
 bool
-nsStyleSet::HasRuleProcessorUsedByMultipleStyleSets(sheetType aSheetType)
+nsStyleSet::HasRuleProcessorUsedByMultipleStyleSets(SheetType aSheetType)
 {
   MOZ_ASSERT(size_t(aSheetType) < ArrayLength(mRuleProcessors));
   if (!IsCSSSheetType(aSheetType) || !mRuleProcessors[aSheetType]) {
     return false;
   }
   nsCSSRuleProcessor* rp =
     static_cast<nsCSSRuleProcessor*>(mRuleProcessors[aSheetType].get());
   return rp->IsUsedByMultipleStyleSets();
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -9,17 +9,19 @@
  * potentially re-creating) style contexts
  */
 
 #ifndef nsStyleSet_h_
 #define nsStyleSet_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/CSSStyleSheet.h"
+#include "mozilla/EnumeratedArray.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/SheetType.h"
 
 #include "nsIStyleRuleProcessor.h"
 #include "nsBindingManager.h"
 #include "nsRuleNode.h"
 #include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsAutoPtr.h"
 #include "nsIStyleRule.h"
@@ -299,56 +301,38 @@ class nsStyleSet final
 
   // APIs for registering objects that can supply additional
   // rules during processing.
   void SetBindingManager(nsBindingManager* aBindingManager)
   {
     mBindingManager = aBindingManager;
   }
 
-  // The "origins" of the CSS cascade, from lowest precedence to
-  // highest (for non-!important rules).
-  enum sheetType {
-    eAgentSheet, // CSS
-    eUserSheet, // CSS
-    ePresHintSheet,
-    eSVGAttrAnimationSheet,
-    eDocSheet, // CSS
-    eScopedDocSheet,
-    eStyleAttrSheet,
-    eOverrideSheet, // CSS
-    eAnimationSheet,
-    eTransitionSheet,
-    eSheetTypeCount
-    // be sure to keep the number of bits in |mDirty| below and in
-    // NS_RULE_NODE_LEVEL_MASK updated when changing the number of sheet
-    // types
-  };
-
   // APIs to manipulate the style sheet lists.  The sheets in each
   // list are stored with the most significant sheet last.
-  nsresult AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
-  nsresult PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
-  nsresult RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
-  nsresult ReplaceSheets(sheetType aType,
+  nsresult AppendStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet);
+  nsresult PrependStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet);
+  nsresult RemoveStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet);
+  nsresult ReplaceSheets(mozilla::SheetType aType,
                          const nsCOMArray<nsIStyleSheet> &aNewSheets);
-  nsresult InsertStyleSheetBefore(sheetType aType, nsIStyleSheet *aNewSheet,
+  nsresult InsertStyleSheetBefore(mozilla::SheetType aType,
+                                  nsIStyleSheet *aNewSheet,
                                   nsIStyleSheet *aReferenceSheet);
 
-  nsresult DirtyRuleProcessors(sheetType aType);
+  nsresult DirtyRuleProcessors(mozilla::SheetType aType);
 
   // Enable/Disable entire author style level (Doc, ScopedDoc & PresHint levels)
   bool GetAuthorStyleDisabled();
   nsresult SetAuthorStyleDisabled(bool aStyleDisabled);
 
-  int32_t SheetCount(sheetType aType) const {
+  int32_t SheetCount(mozilla::SheetType aType) const {
     return mSheets[aType].Count();
   }
 
-  nsIStyleSheet* StyleSheetAt(sheetType aType, int32_t aIndex) const {
+  nsIStyleSheet* StyleSheetAt(mozilla::SheetType aType, int32_t aIndex) const {
     return mSheets[aType].ObjectAt(aIndex);
   }
 
   void AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const {
     if (mBindingManager) {
       mBindingManager->AppendAllSheets(aArray);
     }
   }
@@ -398,31 +382,31 @@ class nsStyleSet final
   // Called by CSSStyleSheet::EnsureUniqueInner to let us know it cloned
   // its inner.
   void SetNeedsRestyleAfterEnsureUniqueInner() {
     mNeedsRestyleAfterEnsureUniqueInner = true;
   }
 
   nsIStyleRule* InitialStyleRule();
 
-  bool HasRuleProcessorUsedByMultipleStyleSets(sheetType aSheetType);
+  bool HasRuleProcessorUsedByMultipleStyleSets(mozilla::SheetType aSheetType);
 
   // Tells the RestyleManager for the document using this style set
   // to drop any nsCSSSelector pointers it has.
   void ClearSelectors();
 
  private:
   nsStyleSet(const nsStyleSet& aCopy) = delete;
   nsStyleSet& operator=(const nsStyleSet& aCopy) = delete;
 
   // Run mark-and-sweep GC on mRuleTree and mOldRuleTrees, based on mRoots.
   void GCRuleTrees();
 
   // Update the rule processor list after a change to the style sheet list.
-  nsresult GatherRuleProcessors(sheetType aType);
+  nsresult GatherRuleProcessors(mozilla::SheetType aType);
 
   void AddImportantRules(nsRuleNode* aCurrLevelNode,
                          nsRuleNode* aLastPrevLevelNode,
                          nsRuleWalker* aRuleWalker);
 
   // Move aRuleWalker forward by the appropriate rule if we need to add
   // a rule due to property restrictions on pseudo-elements.
   void WalkRestrictionRule(nsCSSPseudoElements::Type aPseudoType,
@@ -480,21 +464,23 @@ class nsStyleSet final
 
   nsPresContext* PresContext() { return mRuleTree->PresContext(); }
 
   // The sheets in each array in mSheets are stored with the most significant
   // sheet last.
   // The arrays for ePresHintSheet, eStyleAttrSheet, eTransitionSheet,
   // eAnimationSheet and eSVGAttrAnimationSheet are always empty.
   // (FIXME:  We should reduce the storage needed for them.)
-  nsCOMArray<nsIStyleSheet> mSheets[eSheetTypeCount];
+  mozilla::EnumeratedArray<mozilla::SheetType, mozilla::SheetType::Count,
+                           nsCOMArray<nsIStyleSheet>> mSheets;
 
   // mRuleProcessors[eScopedDocSheet] is always null; rule processors
   // for scoped style sheets are stored in mScopedDocSheetRuleProcessors.
-  nsCOMPtr<nsIStyleRuleProcessor> mRuleProcessors[eSheetTypeCount];
+  mozilla::EnumeratedArray<mozilla::SheetType, mozilla::SheetType::Count,
+                           nsCOMPtr<nsIStyleRuleProcessor>> mRuleProcessors;
 
   // Rule processors for HTML5 scoped style sheets, one per scope.
   nsTArray<nsCOMPtr<nsIStyleRuleProcessor> > mScopedDocSheetRuleProcessors;
 
   RefPtr<nsBindingManager> mBindingManager;
 
   nsRuleNode* mRuleTree; // This is the root of our rule tree.  It is a
                          // lexicographic tree of matched rules that style
@@ -502,17 +488,17 @@ class nsStyleSet final
 
   uint16_t mBatching;
 
   unsigned mInShutdown : 1;
   unsigned mAuthorStyleDisabled: 1;
   unsigned mInReconstruct : 1;
   unsigned mInitFontFeatureValuesLookup : 1;
   unsigned mNeedsRestyleAfterEnsureUniqueInner : 1;
-  unsigned mDirty : 10;  // one dirty bit is used per sheet type
+  unsigned mDirty : int(mozilla::SheetType::Count);  // one bit per sheet type
 
   uint32_t mUnusedRuleNodeCount; // used to batch rule node GC
   nsTArray<nsStyleContext*> mRoots; // style contexts with no parent
 
   // Empty style rules to force things that restrict which properties
   // apply into different branches of the rule tree.
   RefPtr<nsEmptyStyleRule> mFirstLineRule, mFirstLetterRule, mPlaceholderRule;
 
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -9,16 +9,17 @@
  */
 
 #ifndef nsStyleStruct_h___
 #define nsStyleStruct_h___
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/CSSVariableValues.h"
+#include "mozilla/SheetType.h"
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsMargin.h"
 #include "nsFont.h"
 #include "nsStyleCoord.h"
 #include "nsStyleConsts.h"
 #include "nsChangeHint.h"
 #include "nsPresContext.h"
@@ -84,16 +85,20 @@ class imgIContainer;
 #define NS_RULE_NODE_USED_DIRECTLY          0x04000000
 #define NS_RULE_NODE_IS_IMPORTANT           0x08000000
 #define NS_RULE_NODE_LEVEL_MASK             0xf0000000
 #define NS_RULE_NODE_LEVEL_SHIFT            28
 
 // Additional bits for nsRuleNode's mNoneBits:
 #define NS_RULE_NODE_HAS_ANIMATION_DATA     0x80000000
 
+static_assert(int(mozilla::SheetType::Count) - 1 <=
+                (NS_RULE_NODE_LEVEL_MASK >> NS_RULE_NODE_LEVEL_SHIFT),
+              "NS_RULE_NODE_LEVEL_MASK cannot fit SheetType");
+
 // The lifetime of these objects is managed by the presshell's arena.
 
 struct nsStyleFont {
   nsStyleFont(const nsFont& aFont, nsPresContext *aPresContext);
   nsStyleFont(const nsStyleFont& aStyleFont);
   explicit nsStyleFont(nsPresContext *aPresContext);
   ~nsStyleFont(void) {
     MOZ_COUNT_DTOR(nsStyleFont);