Issue #2488 - Part 6: Define and declare CSSStyleSheet cast functions directly in StyleSheet

This renames AsGecko calls to AsConcrete and removes the header containing leftover Stylo macros.
This commit is contained in:
FranklinDM 2024-03-29 16:30:12 +08:00 • committed by roytam1
commit f0116f51db
18 changed files with 109 additions and 134 deletions

View file

@ -2306,7 +2306,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
}
if (sheet)
styleSet->AppendStyleSheet(SheetType::User, sheet->AsGecko());
styleSet->AppendStyleSheet(SheetType::User, sheet->AsConcrete());
// Append chrome sheets (scrollbars + forms).
bool shouldOverride = false;
@ -2342,7 +2342,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
cssLoader->LoadSheetSync(uri, &chromeSheet);
if (!chromeSheet) continue;
styleSet->PrependStyleSheet(SheetType::Agent, chromeSheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, chromeSheet->AsConcrete());
shouldOverride = true;
}
free(str);
@ -2353,7 +2353,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
if (!shouldOverride) {
sheet = cache->ScrollbarsSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
}
@ -2369,12 +2369,12 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
sheet = cache->NumberControlSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
sheet = cache->FormsSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
if (aDocument->LoadsFullXULStyleSheetUpFront()) {
@ -2382,7 +2382,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
// up-front here.
sheet = cache->XULSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
}
@ -2390,25 +2390,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(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
sheet = cache->CounterStylesSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
sheet = cache->NoScriptSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
}
if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) {
sheet = cache->NoFramesSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
}
@ -2417,26 +2417,26 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
sheet = cache->HTMLSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
styleSet->PrependStyleSheet(SheetType::Agent,
cache->UASheet()->AsGecko());
cache->UASheet()->AsConcrete());
} else {
// SVG documents may have scrollbars and need the scrollbar styling.
sheet = cache->MinimalXULSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
}
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
if (sheetService) {
for (StyleSheet* sheet : *sheetService->AgentStyleSheets()) {
styleSet->AppendStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->AppendStyleSheet(SheetType::Agent, sheet->AsConcrete());
}
for (StyleSheet* sheet : Reversed(*sheetService->UserStyleSheets())) {
styleSet->PrependStyleSheet(SheetType::User, sheet->AsGecko());
styleSet->PrependStyleSheet(SheetType::User, sheet->AsConcrete());
}
}

View file

@ -1146,11 +1146,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(SheetType::Agent, sheet->AsGecko());
styleSet->AppendStyleSheet(SheetType::Agent, sheet->AsConcrete());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "failed to insert quirk.css");
} else {
DebugOnly<nsresult> rv =
styleSet->RemoveStyleSheet(SheetType::Agent, sheet->AsGecko());
styleSet->RemoveStyleSheet(SheetType::Agent, sheet->AsConcrete());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "failed to remove quirk.css");
}

View file

@ -1397,7 +1397,7 @@ PresShell::UpdatePreferenceStyles()
RemovePreferenceStyles();
mStyleSet->AppendStyleSheet(SheetType::User, newPrefSheet->AsGecko());
mStyleSet->AppendStyleSheet(SheetType::User, newPrefSheet->AsConcrete());
mPrefStyleSheet = newPrefSheet;
mStyleSet->EndUpdate();
@ -1407,7 +1407,7 @@ void
PresShell::RemovePreferenceStyles()
{
if (mPrefStyleSheet) {
mStyleSet->RemoveStyleSheet(SheetType::User, mPrefStyleSheet->AsGecko());
mStyleSet->RemoveStyleSheet(SheetType::User, mPrefStyleSheet->AsConcrete());
mPrefStyleSheet = nullptr;
}
}
@ -1430,13 +1430,13 @@ PresShell::AddUserSheet(nsISupports* aSheet)
// Iterate forwards when removing so the searches for RemoveStyleSheet are as
// short as possible.
for (StyleSheet* sheet : userSheets) {
mStyleSet->RemoveStyleSheet(SheetType::User, sheet->AsGecko());
mStyleSet->RemoveStyleSheet(SheetType::User, sheet->AsConcrete());
}
// 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 (StyleSheet* sheet : Reversed(userSheets)) {
mStyleSet->PrependStyleSheet(SheetType::User, sheet->AsGecko());
mStyleSet->PrependStyleSheet(SheetType::User, sheet->AsConcrete());
}
mStyleSet->EndUpdate();
@ -1454,7 +1454,7 @@ PresShell::AddAgentSheet(nsISupports* aSheet)
return;
}
mStyleSet->AppendStyleSheet(SheetType::Agent, sheet->AsGecko());
mStyleSet->AppendStyleSheet(SheetType::Agent, sheet->AsConcrete());
RestyleForCSSRuleChanges();
}
@ -1471,9 +1471,9 @@ PresShell::AddAuthorSheet(nsISupports* aSheet)
StyleSheet* firstAuthorSheet =
mDocument->GetFirstAdditionalAuthorSheet();
if (firstAuthorSheet) {
mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet->AsGecko(), firstAuthorSheet->AsGecko());
mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet->AsConcrete(), firstAuthorSheet->AsConcrete());
} else {
mStyleSet->AppendStyleSheet(SheetType::Doc, sheet->AsGecko());
mStyleSet->AppendStyleSheet(SheetType::Doc, sheet->AsConcrete());
}
RestyleForCSSRuleChanges();
@ -1487,7 +1487,7 @@ PresShell::RemoveSheet(SheetType aType, nsISupports* aSheet)
return;
}
mStyleSet->RemoveStyleSheet(aType, sheet->AsGecko());
mStyleSet->RemoveStyleSheet(aType, sheet->AsConcrete());
RestyleForCSSRuleChanges();
}
@ -4471,7 +4471,7 @@ PresShell::RecordStyleSheetChange(StyleSheet* aStyleSheet)
if (mStylesHaveChanged)
return;
Element* scopeElement = aStyleSheet->AsGecko()->GetScopeElement();
Element* scopeElement = aStyleSheet->AsConcrete()->GetScopeElement();
if (scopeElement) {
mChangedScopeStyleRoots.AppendElement(scopeElement);
return;
@ -8771,7 +8771,7 @@ PresShell::SetAgentStyleSheets(const nsTArray<RefPtr<StyleSheet>>& aSheets)
{
nsTArray<RefPtr<CSSStyleSheet>> newSheets(aSheets.Length());
for (auto& sheet : aSheets) {
newSheets.AppendElement(sheet->AsGecko());
newSheets.AppendElement(sheet->AsConcrete());
}
return mStyleSet->ReplaceSheets(SheetType::Agent, newSheets);
}
@ -8779,13 +8779,13 @@ PresShell::SetAgentStyleSheets(const nsTArray<RefPtr<StyleSheet>>& aSheets)
nsresult
PresShell::AddOverrideStyleSheet(StyleSheet* aSheet)
{
return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet->AsGecko());
return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet->AsConcrete());
}
nsresult
PresShell::RemoveOverrideStyleSheet(StyleSheet* aSheet)
{
return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet->AsGecko());
return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet->AsConcrete());
}
static void

View file

@ -177,7 +177,7 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
// mSheets[aSheetType]
StyleSheet* sheet = mSheets[aSheetType].LastElement();
CSSStyleSheet* cssSheet = sheet->AsGecko();
CSSStyleSheet* cssSheet = sheet->AsConcrete();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
}
@ -283,7 +283,7 @@ nsStyleSheetService::PreloadSheet(nsIURI *aSheetURI, uint32_t aSheetType,
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<CSSStyleSheet> cssSheet = sheet->AsGecko();
RefPtr<CSSStyleSheet> cssSheet = sheet->AsConcrete();
cssSheet.forget(aSheet);
return NS_OK;
@ -317,7 +317,7 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType)
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
if (serv) {
CSSStyleSheet* cssSheet = sheet->AsGecko();
CSSStyleSheet* cssSheet = sheet->AsConcrete();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
}