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.
This commit is contained in:
Cameron McCormack 2015-10-20 10:16:20 +11:00
parent e656367743
commit b14353f25e
28 changed files with 367 additions and 329 deletions

View File

@ -3196,7 +3196,7 @@ convertSheetType(uint32_t aSheetType)
default:
NS_ASSERTION(false, "wrong type");
// we must return something although this should never happen
return nsIDocument::SheetTypeCount;
return nsIDocument::AdditionalSheetTypeCount;
}
}

View File

@ -2413,7 +2413,7 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets()
}
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();
@ -2440,16 +2440,17 @@ nsDocument::ResetStylesheetsToURI(nsIURI* 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
@ -2483,14 +2484,14 @@ 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]);
@ -2502,13 +2503,13 @@ 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) {
@ -2528,16 +2529,16 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
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
@ -4141,7 +4142,7 @@ nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet)
// 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);
}
}
@ -4373,20 +4374,20 @@ nsDocument::NotifyStyleSheetApplicableStateChanged()
}
}
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;
}
}
@ -4460,7 +4461,7 @@ nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aS
BeginUpdate(UPDATE_STYLE);
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
nsStyleSet::sheetType type = ConvertAdditionalSheetType(aType);
SheetType type = ConvertAdditionalSheetType(aType);
shell->StyleSet()->AppendStyleSheet(type, aSheet);
}
@ -4488,7 +4489,7 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
MOZ_ASSERT(sheetRef->IsApplicable());
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
nsStyleSet::sheetType type = ConvertAdditionalSheetType(aType);
SheetType type = ConvertAdditionalSheetType(aType);
shell->StyleSet()->RemoveStyleSheet(type, sheetRef);
}
}

View File

@ -1516,7 +1516,7 @@ protected:
void RemoveDocStyleSheetsFromStyleSets();
void RemoveStyleSheetsFromStyleSets(nsCOMArray<nsIStyleSheet>& aSheets,
nsStyleSet::sheetType aType);
mozilla::SheetType aType);
void ResetStylesheetsToURI(nsIURI* aURI);
void FillStyleSet(nsStyleSet* aStyleSet);
@ -1571,7 +1571,7 @@ protected:
nsCOMArray<nsIStyleSheet> mStyleSheets;
nsCOMArray<nsIStyleSheet> mOnDemandBuiltInUASheets;
nsCOMArray<nsIStyleSheet> mAdditionalSheets[SheetTypeCount];
nsCOMArray<nsIStyleSheet> mAdditionalSheets[AdditionalSheetTypeCount];
// Array of observers
nsTObserverArray<nsIDocumentObserver*> mObservers;

View File

@ -944,7 +944,7 @@ public:
eAgentSheet,
eUserSheet,
eAuthorSheet,
SheetTypeCount
AdditionalSheetTypeCount
};
virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0;

View File

@ -143,7 +143,7 @@ void
nsXBLPrototypeResources::GatherRuleProcessor()
{
mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList,
nsStyleSet::eDocSheet,
SheetType::Doc,
nullptr,
mRuleProcessor);
}

View File

@ -2176,7 +2176,7 @@ 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;
}
@ -2184,7 +2184,7 @@ 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;
}
@ -2227,7 +2227,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
}
if (sheet)
styleSet->AppendStyleSheet(nsStyleSet::eUserSheet, sheet);
styleSet->AppendStyleSheet(SheetType::User, sheet);
// Append chrome sheets (scrollbars + forms).
bool shouldOverride = false;
@ -2263,7 +2263,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
cssLoader->LoadSheetSync(uri, getter_AddRefs(csssheet));
if (!csssheet) continue;
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, csssheet);
styleSet->PrependStyleSheet(SheetType::Agent, csssheet);
shouldOverride = true;
}
free(str);
@ -2274,7 +2274,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
if (!shouldOverride) {
sheet = nsLayoutStylesheetCache::ScrollbarsSheet();
if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
styleSet->PrependStyleSheet(SheetType::Agent, sheet);
}
}
@ -2290,12 +2290,12 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
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()) {
@ -2303,7 +2303,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
// up-front here.
sheet = nsLayoutStylesheetCache::XULSheet();
if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
styleSet->PrependStyleSheet(SheetType::Agent, sheet);
}
}
@ -2311,25 +2311,25 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
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);
}
}
@ -2338,16 +2338,16 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
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);
}
}

View File

@ -1381,11 +1381,11 @@ nsPresContext::CompatibilityModeChanged()
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");
}

View File

@ -1409,7 +1409,7 @@ PresShell::UpdatePreferenceStyles()
RemovePreferenceStyles();
mStyleSet->AppendStyleSheet(nsStyleSet::eUserSheet, newPrefSheet);
mStyleSet->AppendStyleSheet(SheetType::User, newPrefSheet);
mPrefStyleSheet = newPrefSheet;
mStyleSet->EndUpdate();
@ -1419,7 +1419,7 @@ void
PresShell::RemovePreferenceStyles()
{
if (mPrefStyleSheet) {
mStyleSet->RemoveStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
mStyleSet->RemoveStyleSheet(SheetType::User, mPrefStyleSheet);
mPrefStyleSheet = nullptr;
}
}
@ -1443,13 +1443,13 @@ PresShell::AddUserSheet(nsISupports* aSheet)
// 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();
@ -1467,7 +1467,7 @@ PresShell::AddAgentSheet(nsISupports* aSheet)
return;
}
mStyleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
mStyleSet->AppendStyleSheet(SheetType::Agent, sheet);
ReconstructStyleData();
}
@ -1483,16 +1483,16 @@ PresShell::AddAuthorSheet(nsISupports* aSheet)
// 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) {
@ -8665,10 +8665,10 @@ 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;
}
@ -8679,19 +8679,19 @@ PresShell::GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets)
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
@ -9437,17 +9437,17 @@ PresShell::Observe(nsISupports* aSubject,
}
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;
}
@ -9790,35 +9790,35 @@ 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);
clone->AppendStyleSheet(SheetType::User, ss);
}
n = aSet->SheetCount(nsStyleSet::eAgentSheet);
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;
}
@ -9947,9 +9947,9 @@ PresShell::ListStyleContexts(nsIFrame *aRootFrame, FILE *out, int32_t 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);
}
}
@ -10930,16 +10930,16 @@ 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");

View File

@ -564,7 +564,7 @@ protected:
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);

View File

@ -83,11 +83,11 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength,
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));
}

View File

@ -419,7 +419,7 @@ FontFaceSet::Add(FontFace& aFontFace, ErrorResult& aRv)
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;
@ -828,7 +828,7 @@ FontFaceSet::InsertNonRuleFontFace(FontFace* aFontFace,
// InsertRuleFontFace does?
RefPtr<gfxUserFontEntry> entry =
FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
nsStyleSet::eDocSheet);
SheetType::Doc);
if (!entry) {
return;
}
@ -840,7 +840,7 @@ FontFaceSet::InsertNonRuleFontFace(FontFace* aFontFace,
}
void
FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, uint8_t aSheetType,
FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
nsTArray<FontFaceRecord>& aOldRecords,
bool& aFontSetModified)
{
@ -951,13 +951,13 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace)
}
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;
@ -1094,8 +1094,8 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
// 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;

View File

@ -232,7 +232,7 @@ private:
// 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
@ -243,7 +243,7 @@ private:
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);
@ -264,7 +264,7 @@ private:
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);

36
layout/style/SheetType.h Normal file
View File

@ -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

View File

@ -88,6 +88,7 @@ EXPORTS.mozilla += [
'LayerAnimationInfo.h',
'RuleNodeCacheConditions.h',
'RuleProcessorCache.h',
'SheetType.h',
'StyleAnimationValue.h',
]

View File

@ -42,8 +42,8 @@ MoveValue(nsCSSValue* aSource, nsCSSValue* aDest)
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();
}

View File

@ -1014,7 +1014,7 @@ RuleCascadeData::AttributeListFor(nsIAtom* aAttribute)
//
nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
uint8_t aSheetType,
SheetType aSheetType,
Element* aScopeElement,
nsCSSRuleProcessor*
aPreviousCSSRuleProcessor,
@ -1035,7 +1035,7 @@ nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
, 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; ) {
@ -3551,7 +3551,7 @@ struct CascadeEnumData {
nsTArray<css::DocumentRule*>& aDocumentRules,
nsMediaQueryResultCacheKey& aKey,
nsDocumentRuleResultCacheKey& aDocumentKey,
uint8_t aSheetType,
SheetType aSheetType,
bool aMustGatherDocumentRules)
: mPresContext(aPresContext),
mFontFaceRules(aFontFaceRules),
@ -3589,7 +3589,7 @@ struct CascadeEnumData {
// 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;
};

View File

@ -15,14 +15,15 @@
#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;
@ -59,11 +60,11 @@ 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);
@ -262,7 +263,7 @@ private:
MozRefCountType mStyleSetRefCnt;
// type of stylesheet using this processor
uint8_t mSheetType; // == nsStyleSet::sheetType
mozilla::SheetType mSheetType;
const bool mIsShared;

View File

@ -9,12 +9,19 @@
#ifndef nsCSSRules_h_
#define nsCSSRules_h_
#include "Declaration.h"
#include "StyleRule.h"
#include "gfxFontFeatures.h"
#include "mozilla/Attributes.h"
#include "mozilla/Move.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.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"
@ -22,18 +29,11 @@
#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;
@ -287,7 +287,7 @@ protected:
// specific @font-face rules
struct nsFontFaceRuleContainer {
RefPtr<nsCSSFontFaceRule> mRule;
uint8_t mSheetType;
mozilla::SheetType mSheetType;
};
inline nsCSSFontFaceRule*

View File

@ -2538,7 +2538,7 @@ nsCSSValueGradient::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) con
nsCSSValueTokenStream::nsCSSValueTokenStream()
: mPropertyID(eCSSProperty_UNKNOWN)
, mShorthandPropertyID(eCSSProperty_UNKNOWN)
, mLevel(nsStyleSet::eSheetTypeCount)
, mLevel(SheetType::Count)
{
MOZ_COUNT_CTOR(nsCSSValueTokenStream);
}

View File

@ -10,6 +10,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/SheetType.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
@ -1542,7 +1543,7 @@ public:
// mozilla::CSSStyleSheet* mSheet;
uint32_t mLineNumber;
uint32_t mLineOffset;
uint16_t mLevel; // an nsStyleSet::sheetType
mozilla::SheetType mLevel;
private:
nsCSSValueTokenStream(const nsCSSValueTokenStream& aOther) = delete;

View File

@ -503,8 +503,8 @@ nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement,
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());
}
}

View File

@ -13,6 +13,7 @@
#include "mozilla/CSSVariableDeclarations.h"
#include "mozilla/RuleNodeCacheConditions.h"
#include "mozilla/SheetType.h"
#include "nsCSSProps.h"
#include "nsCSSValue.h"
#include "nsStyleStructFwd.h"
@ -28,7 +29,7 @@ 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;

View File

@ -1466,11 +1466,11 @@ nsRuleNode::DestroyInternal(nsRuleNode ***aDestroyQueueTail)
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),
@ -1505,9 +1505,9 @@ nsRuleNode::nsRuleNode(nsPresContext* aContext, nsRuleNode* aParent,
// 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");
}
@ -1522,7 +1522,7 @@ nsRuleNode::~nsRuleNode()
}
nsRuleNode*
nsRuleNode::Transition(nsIStyleRule* aRule, uint8_t aLevel,
nsRuleNode::Transition(nsIStyleRule* aRule, SheetType aLevel,
bool aIsImportantRule)
{
nsRuleNode* next = nullptr;
@ -2180,10 +2180,10 @@ nsRuleNode::ResolveVariableReferences(const nsStyleStructID aSID,
&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
@ -9692,8 +9692,8 @@ nsRuleNode::HasAuthorSpecifiedRules(nsStyleContext* aStyleContext,
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.
@ -9815,7 +9815,7 @@ nsRuleNode::ComputePropertiesOverridingAnimation(
// 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;
}

View File

@ -15,6 +15,7 @@
#include "mozilla/PodOperations.h"
#include "mozilla/RangedArray.h"
#include "mozilla/RuleNodeCacheConditions.h"
#include "mozilla/SheetType.h"
#include "nsPresContext.h"
#include "nsStyleStruct.h"
@ -418,10 +419,10 @@ private:
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)
{}
@ -800,7 +801,7 @@ protected:
private:
nsRuleNode(nsPresContext* aPresContext, nsRuleNode* aParent,
nsIStyleRule* aRule, uint8_t aLevel, bool aIsImportant);
nsIStyleRule* aRule, mozilla::SheetType aLevel, bool aIsImportant);
~nsRuleNode();
public:
@ -812,7 +813,7 @@ public:
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; }
@ -823,11 +824,11 @@ public:
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");

View File

@ -54,7 +54,7 @@ public:
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 "
@ -63,7 +63,7 @@ public:
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; }
@ -86,7 +86,7 @@ public:
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

View File

@ -13,6 +13,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/EnumeratedRange.h"
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/RuleProcessorCache.h"
@ -143,18 +144,18 @@ nsDisableTextZoomStyleRule::List(FILE* out, int32_t aIndent) const
}
#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;
}
@ -177,7 +178,7 @@ nsStyleSet::nsStyleSet()
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);
}
@ -185,12 +186,12 @@ nsStyleSet::~nsStyleSet()
// 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();
@ -202,17 +203,17 @@ 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
@ -220,7 +221,7 @@ nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
// 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++) {
@ -247,11 +248,11 @@ nsStyleSet::Init(nsPresContext *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
@ -387,7 +388,7 @@ SortStyleSheetsByScope(nsTArray<CSSStyleSheet*>& aSheets)
}
nsresult
nsStyleSet::GatherRuleProcessors(sheetType aType)
nsStyleSet::GatherRuleProcessors(SheetType aType)
{
NS_ENSURE_FALSE(mInShutdown, NS_ERROR_FAILURE);
@ -401,7 +402,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
}
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());
@ -411,7 +412,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
}
}
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 =
@ -422,9 +423,9 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
// 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.
@ -433,24 +434,24 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
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();
@ -459,9 +460,9 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
// 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
@ -469,7 +470,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
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();
@ -511,8 +512,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
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);
@ -521,8 +521,8 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
}
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];
@ -539,7 +539,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
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 */);
@ -555,8 +555,8 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
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];
@ -567,7 +567,7 @@ nsStyleSet::GatherRuleProcessors(sheetType aType)
cssSheets.AppendElement(cssSheet);
}
mRuleProcessors[aType] =
new nsCSSRuleProcessor(cssSheets, uint8_t(aType), nullptr,
new nsCSSRuleProcessor(cssSheets, aType, nullptr,
static_cast<nsCSSRuleProcessor*>(
oldRuleProcessor.get()));
} break;
@ -593,7 +593,7 @@ IsScopedStyleSheet(nsIStyleSheet* aSheet)
}
nsresult
nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
nsStyleSet::AppendStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsApplicable(),
@ -610,7 +610,7 @@ nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
}
nsresult
nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
nsStyleSet::PrependStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsApplicable(),
@ -627,7 +627,7 @@ nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
}
nsresult
nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
nsStyleSet::RemoveStyleSheet(SheetType aType, nsIStyleSheet *aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsComplete(),
@ -642,7 +642,7 @@ nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
}
nsresult
nsStyleSet::ReplaceSheets(sheetType aType,
nsStyleSet::ReplaceSheets(SheetType aType,
const nsCOMArray<nsIStyleSheet> &aNewSheets)
{
bool cssSheetType = IsCSSSheetType(aType);
@ -666,7 +666,7 @@ nsStyleSet::ReplaceSheets(sheetType aType,
}
nsresult
nsStyleSet::InsertStyleSheetBefore(sheetType aType, nsIStyleSheet *aNewSheet,
nsStyleSet::InsertStyleSheetBefore(SheetType aType, nsIStyleSheet *aNewSheet,
nsIStyleSheet *aReferenceSheet)
{
NS_PRECONDITION(aNewSheet && aReferenceSheet, "null arg");
@ -688,13 +688,19 @@ nsStyleSet::InsertStyleSheetBefore(sheetType aType, nsIStyleSheet *aNewSheet,
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;
}
@ -710,9 +716,9 @@ 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;
@ -727,9 +733,9 @@ nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
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);
@ -771,7 +777,8 @@ 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
@ -790,9 +797,9 @@ nsStyleSet::EndUpdate()
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);
}
}
@ -814,7 +821,7 @@ static inline bool
IsMoreSpecificThanAnimation(nsRuleNode *aRuleNode)
{
return !aRuleNode->IsRoot() &&
(aRuleNode->GetLevel() == nsStyleSet::eTransitionSheet ||
(aRuleNode->GetLevel() == SheetType::Transition ||
aRuleNode->IsImportantRule());
}
@ -826,7 +833,7 @@ GetAnimationRule(nsRuleNode *aRuleNode)
n = n->GetParent();
}
if (n->IsRoot() || n->GetLevel() != nsStyleSet::eAnimationSheet) {
if (n->IsRoot() || n->GetLevel() != SheetType::Animation) {
return nullptr;
}
@ -848,17 +855,17 @@ ReplaceAnimationRule(nsRuleNode *aOldRuleNode,
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();
}
@ -1113,30 +1120,30 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
// 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.
@ -1145,8 +1152,8 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
&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;
@ -1157,7 +1164,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
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();
@ -1169,25 +1176,25 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
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]) {
@ -1207,7 +1214,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#endif
if (haveImportantDocRules) {
aRuleWalker->SetLevel(eDocSheet, true, false);
aRuleWalker->SetLevel(SheetType::Doc, true, false);
AddImportantRules(lastDocRN, lastSVGAttrAnimationRN, aRuleWalker); // doc
}
#ifdef DEBUG
@ -1217,7 +1224,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#endif
if (haveImportantStyleAttrRules) {
aRuleWalker->SetLevel(eStyleAttrSheet, true, false);
aRuleWalker->SetLevel(SheetType::StyleAttr, true, false);
AddImportantRules(lastStyleAttrRN, lastScopedRN, aRuleWalker); // style attr
}
#ifdef DEBUG
@ -1227,7 +1234,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#endif
if (haveImportantOverrideRules) {
aRuleWalker->SetLevel(eOverrideSheet, true, false);
aRuleWalker->SetLevel(SheetType::Override, true, false);
AddImportantRules(lastOvrRN, lastStyleAttrRN, aRuleWalker); // override
}
#ifdef DEBUG
@ -1241,7 +1248,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#endif
if (haveImportantUserRules) {
aRuleWalker->SetLevel(eUserSheet, true, false);
aRuleWalker->SetLevel(SheetType::User, true, false);
AddImportantRules(lastUserRN, lastAgentRN, aRuleWalker); //user
}
#ifdef DEBUG
@ -1251,7 +1258,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#endif
if (haveImportantUARules) {
aRuleWalker->SetLevel(eAgentSheet, true, false);
aRuleWalker->SetLevel(SheetType::Agent, true, false);
AddImportantRules(lastAgentRN, lastRestrictionRN, aRuleWalker); //agent
}
#ifdef DEBUG
@ -1267,8 +1274,8 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
#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
@ -1284,18 +1291,18 @@ nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
{
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) {
@ -1307,19 +1314,19 @@ nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
}
}
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
@ -1393,7 +1400,7 @@ nsStyleSet::ResolveStyleForRules(nsStyleContext* aParentContext,
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));
}
@ -1417,7 +1424,7 @@ nsStyleSet::ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
// 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));
}
@ -1452,37 +1459,37 @@ nsStyleSet::ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
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*
@ -1547,7 +1554,7 @@ nsStyleSet::RuleNodeWithReplacement(Element* aElement,
if (doReplace) {
switch (level->mLevel) {
case nsStyleSet::eAnimationSheet: {
case SheetType::Animation: {
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
aPseudoType == nsCSSPseudoElements::ePseudo_before ||
aPseudoType == nsCSSPseudoElements::ePseudo_after) {
@ -1560,7 +1567,7 @@ nsStyleSet::RuleNodeWithReplacement(Element* aElement,
}
break;
}
case nsStyleSet::eTransitionSheet: {
case SheetType::Transition: {
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
aPseudoType == nsCSSPseudoElements::ePseudo_before ||
aPseudoType == nsCSSPseudoElements::ePseudo_after) {
@ -1573,22 +1580,22 @@ nsStyleSet::RuleNodeWithReplacement(Element* aElement,
}
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 ==
@ -1768,7 +1775,7 @@ 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)
@ -1780,7 +1787,7 @@ nsStyleSet::WalkRestrictionRule(nsCSSPseudoElements::Type aPseudoType,
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);
}
@ -2021,7 +2028,7 @@ nsStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
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());
@ -2039,7 +2046,7 @@ nsStyleSet::KeyframesRuleForName(const nsString& aName)
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());
@ -2061,7 +2068,7 @@ nsStyleSet::CounterStyleRuleForName(const nsAString& aName)
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());
@ -2137,7 +2144,7 @@ nsStyleSet::AppendPageRules(nsTArray<nsCSSPageRule*>& aArray)
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());
@ -2437,16 +2444,14 @@ nsStyleSet::MediumFeaturesChanged()
// 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;
}
@ -2502,7 +2507,7 @@ nsStyleSet::InitialStyleRule()
}
bool
nsStyleSet::HasRuleProcessorUsedByMultipleStyleSets(sheetType aSheetType)
nsStyleSet::HasRuleProcessorUsedByMultipleStyleSets(SheetType aSheetType)
{
MOZ_ASSERT(size_t(aSheetType) < ArrayLength(mRuleProcessors));
if (!IsCSSSheetType(aSheetType) || !mRuleProcessors[aSheetType]) {

View File

@ -14,7 +14,9 @@
#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"
@ -304,46 +306,28 @@ class nsStyleSet final
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);
}
@ -403,7 +387,7 @@ class nsStyleSet final
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.
@ -417,7 +401,7 @@ class nsStyleSet final
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,
@ -485,11 +469,13 @@ class nsStyleSet final
// 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;
@ -507,7 +493,7 @@ class nsStyleSet final
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

View File

@ -14,6 +14,7 @@
#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"
@ -89,6 +90,10 @@ class imgIContainer;
// 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 {