Bug 1629989 - Unify RemoveStyleSheet() Function r=emilio

- Remove function `Document::RemoveStyleSheet()`
- Remove function `ShadowRoot::RemoveSheet()`
- Remove function `DocumentOrShadowRoot::RemoveSheet()`, which was used by the former two functions.
- Add function `DocumentOrShadowRoot::RemoveStyleSheet()`, now uesed in all cases.

Differential Revision: https://phabricator.services.mozilla.com/D70927

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Erik Nordin 2020-04-15 17:20:11 +00:00
Родитель cf753296a8
Коммит 468350e56a
7 изменённых файлов: 12 добавлений и 39 удалений

Просмотреть файл

@ -6580,21 +6580,6 @@ void Document::RemoveStyleSheetFromStyleSets(StyleSheet& aSheet) {
}
}
void Document::RemoveStyleSheet(StyleSheet& aSheet) {
RefPtr<StyleSheet> sheet = DocumentOrShadowRoot::RemoveSheet(aSheet);
if (!sheet) {
NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found");
return;
}
if (!mIsGoingAway && sheet->IsApplicable()) {
RemoveStyleSheetFromStyleSets(*sheet);
}
sheet->ClearAssociatedDocumentOrShadowRoot();
}
void Document::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) {
DocumentOrShadowRoot::InsertSheetAt(aIndex, aSheet);

Просмотреть файл

@ -1715,11 +1715,6 @@ class Document : public nsINode,
InsertSheetAt(SheetCount(), *aSheet);
}
/**
* Remove a stylesheet from the document
*/
void RemoveStyleSheet(StyleSheet&);
/**
* Notify the document that the applicable state of the sheet changed
* and that observers should be notified and style sets updated

Просмотреть файл

@ -78,16 +78,20 @@ void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) {
mStyleSheets.InsertElementAt(aIndex, &aSheet);
}
already_AddRefed<StyleSheet> DocumentOrShadowRoot::RemoveSheet(
StyleSheet& aSheet) {
void DocumentOrShadowRoot::RemoveStyleSheet(StyleSheet& aSheet) {
auto index = mStyleSheets.IndexOf(&aSheet);
if (index == mStyleSheets.NoIndex) {
return nullptr;
// We should only hit this case if we are unlinking
// in which case mStyleSheets should be cleared.
MOZ_ASSERT(mKind != Kind::Document ||
AsNode().AsDocument()->InUnlinkOrDeletion());
MOZ_ASSERT(mStyleSheets.IsEmpty());
return;
}
RefPtr<StyleSheet> sheet = std::move(mStyleSheets[index]);
mStyleSheets.RemoveElementAt(index);
RemoveSheetFromStylesIfApplicable(*sheet);
sheet->ClearAssociatedDocumentOrShadowRoot();
return sheet.forget();
}
void DocumentOrShadowRoot::RemoveSheetFromStylesIfApplicable(

Просмотреть файл

@ -88,6 +88,8 @@ class DocumentOrShadowRoot {
void GetAdoptedStyleSheets(nsTArray<RefPtr<StyleSheet>>&) const;
void RemoveStyleSheet(StyleSheet&);
Element* GetElementById(const nsAString& aElementId);
/**
@ -251,8 +253,6 @@ class DocumentOrShadowRoot {
*/
void CloneAdoptedSheetsFrom(const DocumentOrShadowRoot&);
// Returns the reference to the sheet, if found in mStyleSheets.
already_AddRefed<StyleSheet> RemoveSheet(StyleSheet& aSheet);
void InsertSheetAt(size_t aIndex, StyleSheet& aSheet);
void AddSizeOfExcludingThis(nsWindowSizes&) const;

Просмотреть файл

@ -477,16 +477,6 @@ void ShadowRoot::RemoveSheetFromStyles(StyleSheet& aSheet) {
ApplicableRulesChanged();
}
void ShadowRoot::RemoveSheet(StyleSheet& aSheet) {
RefPtr<StyleSheet> sheet = DocumentOrShadowRoot::RemoveSheet(aSheet);
MOZ_ASSERT(sheet || mStyleSheets.IsEmpty(),
"sheet should always be found, except after unlink, where we "
"should've cleared all stylesheets");
if (sheet && sheet->IsApplicable()) {
RemoveSheetFromStyles(*sheet);
}
}
void ShadowRoot::AddToIdTable(Element* aElement, nsAtom* aId) {
IdentifierMapEntry* entry = mIdentifierMap.PutEntry(aId);
if (entry) {

Просмотреть файл

@ -74,7 +74,6 @@ class ShadowRoot final : public DocumentFragment,
ShadowRootMode Mode() const { return mMode; }
bool IsClosed() const { return mMode == ShadowRootMode::Closed; }
void RemoveSheet(StyleSheet&);
void RemoveSheetFromStyles(StyleSheet&);
void RuleAdded(StyleSheet&, css::Rule&);
void RuleRemoved(StyleSheet&, css::Rule&);

Просмотреть файл

@ -260,7 +260,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
// disabled, since otherwise a sheet with a stale linking element pointer
// will be hanging around -- not good!
if (aOldShadowRoot) {
aOldShadowRoot->RemoveSheet(*mStyleSheet);
aOldShadowRoot->RemoveStyleSheet(*mStyleSheet);
} else {
aOldDocument->RemoveStyleSheet(*mStyleSheet);
}
@ -297,7 +297,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument,
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
// Could be null only during unlink.
if (MOZ_LIKELY(containingShadow)) {
containingShadow->RemoveSheet(*mStyleSheet);
containingShadow->RemoveStyleSheet(*mStyleSheet);
}
} else {
doc->RemoveStyleSheet(*mStyleSheet);