зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1449522 - Clean up stylesheet association modes. r=nordzilla
Should also have no behavior change. After the previous patch we don't have sheets associated with a document but not owned by it, so take advantage of that. Differential Revision: https://phabricator.services.mozilla.com/D71264
This commit is contained in:
Родитель
31821e1fc4
Коммит
5f95854d9b
|
@ -6692,8 +6692,7 @@ nsresult Document::LoadAdditionalStyleSheet(additionalSheetType aType,
|
||||||
|
|
||||||
RefPtr<StyleSheet> sheet = result.unwrap();
|
RefPtr<StyleSheet> sheet = result.unwrap();
|
||||||
|
|
||||||
sheet->SetAssociatedDocumentOrShadowRoot(
|
sheet->SetAssociatedDocumentOrShadowRoot(this);
|
||||||
this, StyleSheet::OwnedByDocumentOrShadowRoot);
|
|
||||||
MOZ_ASSERT(sheet->IsApplicable());
|
MOZ_ASSERT(sheet->IsApplicable());
|
||||||
|
|
||||||
return AddAdditionalStyleSheet(aType, sheet);
|
return AddAdditionalStyleSheet(aType, sheet);
|
||||||
|
|
|
@ -73,8 +73,7 @@ StyleSheetList* DocumentOrShadowRoot::StyleSheets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) {
|
void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) {
|
||||||
aSheet.SetAssociatedDocumentOrShadowRoot(
|
aSheet.SetAssociatedDocumentOrShadowRoot(this);
|
||||||
this, StyleSheet::OwnedByDocumentOrShadowRoot);
|
|
||||||
mStyleSheets.InsertElementAt(aIndex, &aSheet);
|
mStyleSheets.InsertElementAt(aIndex, &aSheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ StyleSheet::StyleSheet(css::SheetParsingMode aParsingMode, CORSMode aCORSMode,
|
||||||
mOwnerRule(nullptr),
|
mOwnerRule(nullptr),
|
||||||
mParsingMode(aParsingMode),
|
mParsingMode(aParsingMode),
|
||||||
mState(static_cast<State>(0)),
|
mState(static_cast<State>(0)),
|
||||||
mAssociationMode(NotOwnedByDocumentOrShadowRoot),
|
|
||||||
mInner(new StyleSheetInfo(aCORSMode, aIntegrity, aParsingMode)) {
|
mInner(new StyleSheetInfo(aCORSMode, aIntegrity, aParsingMode)) {
|
||||||
mInner->AddSheet(this);
|
mInner->AddSheet(this);
|
||||||
}
|
}
|
||||||
|
@ -58,9 +57,6 @@ StyleSheet::StyleSheet(const StyleSheet& aCopy, StyleSheet* aParentSheetToUse,
|
||||||
mOwnerRule(aOwnerRuleToUse),
|
mOwnerRule(aOwnerRuleToUse),
|
||||||
mParsingMode(aCopy.mParsingMode),
|
mParsingMode(aCopy.mParsingMode),
|
||||||
mState(aCopy.mState),
|
mState(aCopy.mState),
|
||||||
// We only use this constructor during cloning. It's the cloner's
|
|
||||||
// responsibility to notify us if we end up being owned by a document.
|
|
||||||
mAssociationMode(NotOwnedByDocumentOrShadowRoot),
|
|
||||||
// Shallow copy, but concrete subclasses will fix up.
|
// Shallow copy, but concrete subclasses will fix up.
|
||||||
mInner(aCopy.mInner) {
|
mInner(aCopy.mInner) {
|
||||||
MOZ_ASSERT(!aConstructorDocToUse || aCopy.IsConstructed());
|
MOZ_ASSERT(!aConstructorDocToUse || aCopy.IsConstructed());
|
||||||
|
@ -176,8 +172,7 @@ dom::DocumentOrShadowRoot* StyleSheet::GetAssociatedDocumentOrShadowRoot()
|
||||||
|
|
||||||
Document* StyleSheet::GetKeptAliveByDocument() const {
|
Document* StyleSheet::GetKeptAliveByDocument() const {
|
||||||
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
|
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
|
||||||
if (sheet->mAssociationMode == OwnedByDocumentOrShadowRoot) {
|
if (sheet->mDocumentOrShadowRoot) {
|
||||||
MOZ_ASSERT(sheet->mDocumentOrShadowRoot);
|
|
||||||
return sheet->mDocumentOrShadowRoot->AsNode().GetComposedDoc();
|
return sheet->mDocumentOrShadowRoot->AsNode().GetComposedDoc();
|
||||||
}
|
}
|
||||||
if (sheet->IsConstructed()) {
|
if (sheet->IsConstructed()) {
|
||||||
|
@ -884,7 +879,7 @@ void StyleSheet::RemoveFromParent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleSheet::UnparentChildren() {
|
void StyleSheet::UnparentChildren() {
|
||||||
MOZ_ASSERT(mAssociationMode == NotOwnedByDocumentOrShadowRoot,
|
MOZ_ASSERT(!mDocumentOrShadowRoot,
|
||||||
"How did we get to the destructor, exactly, if we're owned "
|
"How did we get to the destructor, exactly, if we're owned "
|
||||||
"by a document?");
|
"by a document?");
|
||||||
// XXXbz this is a little bogus; see the comment where we
|
// XXXbz this is a little bogus; see the comment where we
|
||||||
|
@ -951,16 +946,12 @@ bool StyleSheet::AreRulesAvailable(nsIPrincipal& aSubjectPrincipal,
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleSheet::SetAssociatedDocumentOrShadowRoot(
|
void StyleSheet::SetAssociatedDocumentOrShadowRoot(
|
||||||
DocumentOrShadowRoot* aDocOrShadowRoot, AssociationMode aAssociationMode) {
|
DocumentOrShadowRoot* aDocOrShadowRoot) {
|
||||||
MOZ_ASSERT(!IsConstructed());
|
MOZ_ASSERT(!IsConstructed());
|
||||||
MOZ_ASSERT(aDocOrShadowRoot ||
|
|
||||||
aAssociationMode == NotOwnedByDocumentOrShadowRoot);
|
|
||||||
MOZ_ASSERT(!mParentSheet || !aDocOrShadowRoot,
|
MOZ_ASSERT(!mParentSheet || !aDocOrShadowRoot,
|
||||||
"Shouldn't be set on child sheets");
|
"Shouldn't be set on child sheets");
|
||||||
|
|
||||||
// not ref counted
|
// not ref counted
|
||||||
mDocumentOrShadowRoot = aDocOrShadowRoot;
|
mDocumentOrShadowRoot = aDocOrShadowRoot;
|
||||||
mAssociationMode = aAssociationMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleSheet::AppendStyleSheet(StyleSheet& aSheet) {
|
void StyleSheet::AppendStyleSheet(StyleSheet& aSheet) {
|
||||||
|
|
|
@ -244,15 +244,10 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
|
||||||
|
|
||||||
void EnsureUniqueInner();
|
void EnsureUniqueInner();
|
||||||
|
|
||||||
// style sheet owner info
|
// Returns the DocumentOrShadowRoot* that owns us, if any.
|
||||||
enum AssociationMode : uint8_t {
|
//
|
||||||
// OwnedByDocumentOrShadowRoot means mDocumentOrShadowRoot owns us (possibly
|
// TODO(emilio): Maybe rename to GetOwner*() or such? Might be
|
||||||
// via a chain of other stylesheets).
|
// confusing with nsINode::OwnerDoc and such.
|
||||||
OwnedByDocumentOrShadowRoot,
|
|
||||||
// NotOwnedByDocument means we're owned by something that might have a
|
|
||||||
// different lifetime than mDocument.
|
|
||||||
NotOwnedByDocumentOrShadowRoot
|
|
||||||
};
|
|
||||||
dom::DocumentOrShadowRoot* GetAssociatedDocumentOrShadowRoot() const;
|
dom::DocumentOrShadowRoot* GetAssociatedDocumentOrShadowRoot() const;
|
||||||
|
|
||||||
// Whether this stylesheet is kept alive by the associated or constructor
|
// Whether this stylesheet is kept alive by the associated or constructor
|
||||||
|
@ -267,10 +262,9 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
|
||||||
// Non-null iff GetAssociatedDocumentOrShadowRoot is non-null.
|
// Non-null iff GetAssociatedDocumentOrShadowRoot is non-null.
|
||||||
dom::Document* GetAssociatedDocument() const;
|
dom::Document* GetAssociatedDocument() const;
|
||||||
|
|
||||||
void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*,
|
void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*);
|
||||||
AssociationMode);
|
|
||||||
void ClearAssociatedDocumentOrShadowRoot() {
|
void ClearAssociatedDocumentOrShadowRoot() {
|
||||||
SetAssociatedDocumentOrShadowRoot(nullptr, NotOwnedByDocumentOrShadowRoot);
|
SetAssociatedDocumentOrShadowRoot(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsINode* GetOwnerNode() const { return mOwningNode; }
|
nsINode* GetOwnerNode() const { return mOwningNode; }
|
||||||
|
@ -577,12 +571,6 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
|
||||||
|
|
||||||
State mState;
|
State mState;
|
||||||
|
|
||||||
// mAssociationMode determines whether mDocumentOrShadowRoot directly owns us
|
|
||||||
// (in the sense that if it's known-live then we're known-live).
|
|
||||||
//
|
|
||||||
// Always NotOwnedByDocumentOrShadowRoot when mDocumentOrShadowRoot is null.
|
|
||||||
AssociationMode mAssociationMode;
|
|
||||||
|
|
||||||
// Core information we get from parsed sheets, which are shared amongst
|
// Core information we get from parsed sheets, which are shared amongst
|
||||||
// StyleSheet clones.
|
// StyleSheet clones.
|
||||||
//
|
//
|
||||||
|
|
Загрузка…
Ссылка в новой задаче