Bug 1449522 - Cleanup some parent walks in StyleSheet code. r=nordzilla

Differential Revision: https://phabricator.services.mozilla.com/D71410
This commit is contained in:
Emilio Cobos Álvarez 2020-04-17 22:55:03 +00:00
Родитель 12bac77b70
Коммит c7992b8656
2 изменённых файлов: 35 добавлений и 31 удалений

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

@ -159,28 +159,26 @@ Document* StyleSheet::GetAssociatedDocument() const {
dom::DocumentOrShadowRoot* StyleSheet::GetAssociatedDocumentOrShadowRoot()
const {
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
if (sheet->mDocumentOrShadowRoot) {
return sheet->mDocumentOrShadowRoot;
}
if (sheet->IsConstructed()) {
return sheet->mConstructorDocument;
}
const StyleSheet& outer = OutermostSheet();
if (outer.mDocumentOrShadowRoot) {
return outer.mDocumentOrShadowRoot;
}
if (outer.IsConstructed()) {
return outer.mConstructorDocument;
}
return nullptr;
}
Document* StyleSheet::GetKeptAliveByDocument() const {
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
if (sheet->mDocumentOrShadowRoot) {
return sheet->mDocumentOrShadowRoot->AsNode().GetComposedDoc();
}
if (sheet->IsConstructed()) {
for (DocumentOrShadowRoot* adopter : sheet->mAdopters) {
MOZ_ASSERT(adopter->AsNode().OwnerDoc() == sheet->mConstructorDocument);
if (adopter->AsNode().IsInComposedDoc()) {
return sheet->mConstructorDocument.get();
}
const StyleSheet& outer = OutermostSheet();
if (outer.mDocumentOrShadowRoot) {
return outer.mDocumentOrShadowRoot->AsNode().GetComposedDoc();
}
if (outer.IsConstructed()) {
for (DocumentOrShadowRoot* adopter : outer.mAdopters) {
MOZ_ASSERT(adopter->AsNode().OwnerDoc() == outer.mConstructorDocument);
if (adopter->AsNode().IsInComposedDoc()) {
return outer.mConstructorDocument.get();
}
}
}
@ -306,15 +304,14 @@ void StyleSheet::ApplicableStateChanged(bool aApplicable) {
}
};
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
if (sheet->mDocumentOrShadowRoot) {
Notify(*sheet->mDocumentOrShadowRoot);
}
const StyleSheet& sheet = OutermostSheet();
if (sheet.mDocumentOrShadowRoot) {
Notify(*sheet.mDocumentOrShadowRoot);
}
for (DocumentOrShadowRoot* adopter : sheet->mAdopters) {
MOZ_ASSERT(adopter, "adopters should never be null");
Notify(*adopter);
}
for (DocumentOrShadowRoot* adopter : sheet.mAdopters) {
MOZ_ASSERT(adopter, "adopters should never be null");
Notify(*adopter);
}
}

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

@ -394,12 +394,7 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
// True if any of this sheet's ancestors were created through the
// Constructable StyleSheets API
bool SelfOrAncestorIsConstructed() const {
for (auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
if (sheet->IsConstructed()) {
return true;
}
}
return false;
return OutermostSheet().IsConstructed();
}
// Ture if the sheet's constructor document matches the given document
@ -473,6 +468,18 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
mState |= State::ModifiedRules | State::ModifiedRulesForDevtools;
}
const StyleSheet& OutermostSheet() const {
auto* current = this;
while (current->mParentSheet) {
MOZ_ASSERT(!current->mDocumentOrShadowRoot,
"Shouldn't be set on child sheets");
MOZ_ASSERT(!current->mConstructorDocument,
"Shouldn't be set on child sheets");
current = current->mParentSheet;
}
return *current;
}
StyleSheetInfo& Inner() {
MOZ_ASSERT(mInner);
return *mInner;