зеркало из 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();
|
||||
|
||||
sheet->SetAssociatedDocumentOrShadowRoot(
|
||||
this, StyleSheet::OwnedByDocumentOrShadowRoot);
|
||||
sheet->SetAssociatedDocumentOrShadowRoot(this);
|
||||
MOZ_ASSERT(sheet->IsApplicable());
|
||||
|
||||
return AddAdditionalStyleSheet(aType, sheet);
|
||||
|
|
|
@ -73,8 +73,7 @@ StyleSheetList* DocumentOrShadowRoot::StyleSheets() {
|
|||
}
|
||||
|
||||
void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) {
|
||||
aSheet.SetAssociatedDocumentOrShadowRoot(
|
||||
this, StyleSheet::OwnedByDocumentOrShadowRoot);
|
||||
aSheet.SetAssociatedDocumentOrShadowRoot(this);
|
||||
mStyleSheets.InsertElementAt(aIndex, &aSheet);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ StyleSheet::StyleSheet(css::SheetParsingMode aParsingMode, CORSMode aCORSMode,
|
|||
mOwnerRule(nullptr),
|
||||
mParsingMode(aParsingMode),
|
||||
mState(static_cast<State>(0)),
|
||||
mAssociationMode(NotOwnedByDocumentOrShadowRoot),
|
||||
mInner(new StyleSheetInfo(aCORSMode, aIntegrity, aParsingMode)) {
|
||||
mInner->AddSheet(this);
|
||||
}
|
||||
|
@ -58,9 +57,6 @@ StyleSheet::StyleSheet(const StyleSheet& aCopy, StyleSheet* aParentSheetToUse,
|
|||
mOwnerRule(aOwnerRuleToUse),
|
||||
mParsingMode(aCopy.mParsingMode),
|
||||
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.
|
||||
mInner(aCopy.mInner) {
|
||||
MOZ_ASSERT(!aConstructorDocToUse || aCopy.IsConstructed());
|
||||
|
@ -176,8 +172,7 @@ dom::DocumentOrShadowRoot* StyleSheet::GetAssociatedDocumentOrShadowRoot()
|
|||
|
||||
Document* StyleSheet::GetKeptAliveByDocument() const {
|
||||
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
|
||||
if (sheet->mAssociationMode == OwnedByDocumentOrShadowRoot) {
|
||||
MOZ_ASSERT(sheet->mDocumentOrShadowRoot);
|
||||
if (sheet->mDocumentOrShadowRoot) {
|
||||
return sheet->mDocumentOrShadowRoot->AsNode().GetComposedDoc();
|
||||
}
|
||||
if (sheet->IsConstructed()) {
|
||||
|
@ -884,7 +879,7 @@ void StyleSheet::RemoveFromParent() {
|
|||
}
|
||||
|
||||
void StyleSheet::UnparentChildren() {
|
||||
MOZ_ASSERT(mAssociationMode == NotOwnedByDocumentOrShadowRoot,
|
||||
MOZ_ASSERT(!mDocumentOrShadowRoot,
|
||||
"How did we get to the destructor, exactly, if we're owned "
|
||||
"by a document?");
|
||||
// XXXbz this is a little bogus; see the comment where we
|
||||
|
@ -951,16 +946,12 @@ bool StyleSheet::AreRulesAvailable(nsIPrincipal& aSubjectPrincipal,
|
|||
}
|
||||
|
||||
void StyleSheet::SetAssociatedDocumentOrShadowRoot(
|
||||
DocumentOrShadowRoot* aDocOrShadowRoot, AssociationMode aAssociationMode) {
|
||||
DocumentOrShadowRoot* aDocOrShadowRoot) {
|
||||
MOZ_ASSERT(!IsConstructed());
|
||||
MOZ_ASSERT(aDocOrShadowRoot ||
|
||||
aAssociationMode == NotOwnedByDocumentOrShadowRoot);
|
||||
MOZ_ASSERT(!mParentSheet || !aDocOrShadowRoot,
|
||||
"Shouldn't be set on child sheets");
|
||||
|
||||
// not ref counted
|
||||
mDocumentOrShadowRoot = aDocOrShadowRoot;
|
||||
mAssociationMode = aAssociationMode;
|
||||
}
|
||||
|
||||
void StyleSheet::AppendStyleSheet(StyleSheet& aSheet) {
|
||||
|
|
|
@ -244,15 +244,10 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
|
|||
|
||||
void EnsureUniqueInner();
|
||||
|
||||
// style sheet owner info
|
||||
enum AssociationMode : uint8_t {
|
||||
// OwnedByDocumentOrShadowRoot means mDocumentOrShadowRoot owns us (possibly
|
||||
// via a chain of other stylesheets).
|
||||
OwnedByDocumentOrShadowRoot,
|
||||
// NotOwnedByDocument means we're owned by something that might have a
|
||||
// different lifetime than mDocument.
|
||||
NotOwnedByDocumentOrShadowRoot
|
||||
};
|
||||
// Returns the DocumentOrShadowRoot* that owns us, if any.
|
||||
//
|
||||
// TODO(emilio): Maybe rename to GetOwner*() or such? Might be
|
||||
// confusing with nsINode::OwnerDoc and such.
|
||||
dom::DocumentOrShadowRoot* GetAssociatedDocumentOrShadowRoot() const;
|
||||
|
||||
// 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.
|
||||
dom::Document* GetAssociatedDocument() const;
|
||||
|
||||
void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*,
|
||||
AssociationMode);
|
||||
void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*);
|
||||
void ClearAssociatedDocumentOrShadowRoot() {
|
||||
SetAssociatedDocumentOrShadowRoot(nullptr, NotOwnedByDocumentOrShadowRoot);
|
||||
SetAssociatedDocumentOrShadowRoot(nullptr);
|
||||
}
|
||||
|
||||
nsINode* GetOwnerNode() const { return mOwningNode; }
|
||||
|
@ -577,12 +571,6 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
|
|||
|
||||
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
|
||||
// StyleSheet clones.
|
||||
//
|
||||
|
|
Загрузка…
Ссылка в новой задаче