Bug 1418216 - Move IsCSSSheetType out of nsStyleSet. r=TYLin
MozReview-Commit-ID: 6OV5WHX4INb
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -738,17 +738,17 @@ ServoStyleSet::ResolveXULTreePseudoStyle
// manage the set of style sheets in the style set
nsresult
ServoStyleSet::AppendStyleSheet(SheetType aType,
ServoStyleSheet* aSheet)
{
MOZ_ASSERT(aSheet);
MOZ_ASSERT(aSheet->IsApplicable());
- MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+ MOZ_ASSERT(IsCSSSheetType(aType));
MOZ_ASSERT(aSheet->RawContents(), "Raw sheet should be in place before insertion.");
RemoveSheetOfType(aType, aSheet);
AppendSheetOfType(aType, aSheet);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
// Servo will remove aSheet from its original position as part of the call
@@ -761,17 +761,17 @@ ServoStyleSet::AppendStyleSheet(SheetTyp
}
nsresult
ServoStyleSet::PrependStyleSheet(SheetType aType,
ServoStyleSheet* aSheet)
{
MOZ_ASSERT(aSheet);
MOZ_ASSERT(aSheet->IsApplicable());
- MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+ MOZ_ASSERT(IsCSSSheetType(aType));
MOZ_ASSERT(aSheet->RawContents(),
"Raw sheet should be in place before insertion.");
RemoveSheetOfType(aType, aSheet);
PrependSheetOfType(aType, aSheet);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
@@ -784,17 +784,17 @@ ServoStyleSet::PrependStyleSheet(SheetTy
return NS_OK;
}
nsresult
ServoStyleSet::RemoveStyleSheet(SheetType aType,
ServoStyleSheet* aSheet)
{
MOZ_ASSERT(aSheet);
- MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+ MOZ_ASSERT(IsCSSSheetType(aType));
RemoveSheetOfType(aType, aSheet);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet);
SetStylistStyleSheetsDirty();
}
@@ -858,24 +858,24 @@ ServoStyleSet::InsertStyleSheetBefore(Sh
}
return NS_OK;
}
int32_t
ServoStyleSet::SheetCount(SheetType aType) const
{
- MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+ MOZ_ASSERT(IsCSSSheetType(aType));
return mSheets[aType].Length();
}
ServoStyleSheet*
ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const
{
- MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+ MOZ_ASSERT(IsCSSSheetType(aType));
return mSheets[aType][aIndex];
}
void
ServoStyleSet::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
{
if (mBindingManager) {
mBindingManager->AppendAllSheets(aArray);
--- a/layout/style/SheetType.h
+++ b/layout/style/SheetType.h
@@ -18,21 +18,38 @@ namespace mozilla {
//
// 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,
Doc, // CSS
- ScopedDoc,
+ ScopedDoc, // CSS
StyleAttr,
Override, // CSS
Animation,
Transition,
Count,
Unknown = 0xff
};
+// Returns whether aSheetType represents a level of the cascade that uses
+// a StyleSheet object.
+inline bool
+IsCSSSheetType(SheetType aSheetType)
+{
+ switch (aSheetType) {
+ case SheetType::Agent:
+ case SheetType::User:
+ case SheetType::Doc:
+ case SheetType::ScopedDoc:
+ case SheetType::Override:
+ return true;
+ default:
+ return false;
+ }
+}
+
} // namespace mozilla
#endif // mozilla_SheetType_h
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -194,27 +194,16 @@ static const SheetType gCSSSheetTypes[]
// From lowest to highest in cascading order.
SheetType::Agent,
SheetType::User,
SheetType::Doc,
SheetType::ScopedDoc,
SheetType::Override
};
-/* static */ bool
-nsStyleSet::IsCSSSheetType(SheetType aSheetType)
-{
- for (SheetType type : gCSSSheetTypes) {
- if (type == aSheetType) {
- return true;
- }
- }
- return false;
-}
-
nsStyleSet::nsStyleSet()
: mRuleTree(nullptr),
mBatching(0),
mStylesHaveChanged(0),
mInShutdown(false),
mInGC(false),
mAuthorStyleDisabled(false),
mInReconstruct(false),
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -491,21 +491,16 @@ class nsStyleSet final
nsIStyleRule* InitialStyleRule();
bool HasRuleProcessorUsedByMultipleStyleSets(mozilla::SheetType aSheetType);
// Tells the RestyleManager for the document using this style set
// to drop any nsCSSSelector pointers it has.
void ClearSelectors();
- // Returns whether aSheetType represents a level of the cascade that uses
- // CSSStyleSheets. See gCSSSheetTypes in nsStyleSet.cpp for the list
- // of CSS sheet types.
- static bool IsCSSSheetType(mozilla::SheetType aSheetType);
-
void SetUsesViewportUnits(bool aValue) {
mUsesViewportUnits = aValue;
}
private:
nsStyleSet(const nsStyleSet& aCopy) = delete;
nsStyleSet& operator=(const nsStyleSet& aCopy) = delete;