Bug 1452525: Deduplicate proto bindings, not bindings. r?xidorn
MozReview-Commit-ID: 2NWALzUhDjn
--- a/dom/xbl/nsBindingManager.cpp
+++ b/dom/xbl/nsBindingManager.cpp
@@ -662,49 +662,50 @@ nsBindingManager::GetBindingImplementati
}
*aResult = nullptr;
return NS_NOINTERFACE;
}
bool
-nsBindingManager::EnumerateBoundContentBindings(
- const BoundContentBindingCallback& aCallback) const
+nsBindingManager::EnumerateBoundContentProtoBindings(
+ const BoundContentProtoBindingCallback& aCallback) const
{
if (!mBoundContentSet) {
return true;
}
- nsTHashtable<nsPtrHashKey<nsXBLBinding>> bindings;
+ nsTHashtable<nsPtrHashKey<nsXBLPrototypeBinding>> bindings;
for (auto iter = mBoundContentSet->Iter(); !iter.Done(); iter.Next()) {
nsIContent* boundContent = iter.Get()->GetKey();
for (nsXBLBinding* binding = boundContent->GetXBLBinding();
binding;
binding = binding->GetBaseBinding()) {
+ nsXBLPrototypeBinding* proto = binding->PrototypeBinding();
// If we have already invoked the callback with a binding, we
// should have also invoked it for all its base bindings, so we
// don't need to continue this loop anymore.
- if (!bindings.EnsureInserted(binding)) {
+ if (!bindings.EnsureInserted(proto)) {
break;
}
- if (!aCallback(binding)) {
+ if (!aCallback(proto)) {
return false;
}
}
}
return true;
}
void
nsBindingManager::AppendAllSheets(nsTArray<StyleSheet*>& aArray)
{
- EnumerateBoundContentBindings([&aArray](nsXBLBinding* aBinding) {
- aBinding->PrototypeBinding()->AppendStyleSheetsTo(aArray);
+ EnumerateBoundContentProtoBindings([&aArray](nsXBLPrototypeBinding* aProto) {
+ aProto->AppendStyleSheetsTo(aArray);
return true;
});
}
static void
InsertAppendedContent(XBLChildrenElement* aPoint,
nsIContent* aFirstNewContent)
{
--- a/dom/xbl/nsBindingManager.h
+++ b/dom/xbl/nsBindingManager.h
@@ -154,19 +154,21 @@ public:
void DropDocumentReference();
nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
// Enumerate each bound content's bindings (including its base bindings)
// in mBoundContentSet. Return false from the callback to stop enumeration.
- using BoundContentBindingCallback = std::function<bool (nsXBLBinding*)>;
- bool EnumerateBoundContentBindings(
- const BoundContentBindingCallback& aCallback) const;
+ using BoundContentProtoBindingCallback =
+ std::function<bool (nsXBLPrototypeBinding*)>;
+
+ bool EnumerateBoundContentProtoBindings(
+ const BoundContentProtoBindingCallback&) const;
protected:
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
nsresult SetWrappedJS(nsIContent* aContent, nsIXPConnectWrappedJS* aResult);
// Called by ContentAppended and ContentInserted to handle a single child
// insertion. aChild must not be null. aContainer may be null.
// aAppend is true if this child is being appended, not inserted.
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -238,21 +238,19 @@ ServoStyleSet::InvalidateStyleForDocumen
// instead and run invalidation individually, passing mRawSet for the UA /
// User sheets.
AutoTArray<RawServoAuthorStylesBorrowed, 20> nonDocumentStyles;
EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
nonDocumentStyles.AppendElement(aShadowRoot.ServoStyles());
});
- // FIXME(emilio): When bug 1425759 is fixed we need to enumerate ShadowRoots
- // too.
- mDocument->BindingManager()->EnumerateBoundContentBindings(
- [&](nsXBLBinding* aBinding) {
- if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+ mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+ [&](nsXBLPrototypeBinding* aProto) {
+ if (auto* authorStyles = aProto->GetServoStyles()) {
nonDocumentStyles.AppendElement(authorStyles);
}
return true;
});
Servo_InvalidateStyleForDocStateChanges(
root, mRawSet.get(), &nonDocumentStyles, aStatesChanged.ServoValue());
}
@@ -274,19 +272,19 @@ ServoStyleSet::MediumFeaturesChanged(Med
{
AutoTArray<RawServoAuthorStylesBorrowedMut, 20> nonDocumentStyles;
EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
nonDocumentStyles.AppendElement(aShadowRoot.ServoStyles());
});
// FIXME(emilio): This is broken for XBL. See bug 1406875.
- mDocument->BindingManager()->EnumerateBoundContentBindings(
- [&](nsXBLBinding* aBinding) {
- if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+ mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+ [&](nsXBLPrototypeBinding* aProto) {
+ if (auto* authorStyles = aProto->GetServoStyles()) {
nonDocumentStyles.AppendElement(authorStyles);
}
return true;
});
bool mayAffectDefaultStyle =
bool(aReason & kMediaFeaturesAffectingDefaultStyle);
@@ -1277,22 +1275,22 @@ ServoStyleSet::EnsureUniqueInnerOnCSSShe
EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
queue.AppendElement(
MakePair(aShadowRoot.SheetAt(index), SheetOwner { &aShadowRoot }));
}
});
- mDocument->BindingManager()->EnumerateBoundContentBindings(
- [&](nsXBLBinding* aBinding) {
+ mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+ [&](nsXBLPrototypeBinding* aProto) {
AutoTArray<StyleSheet*, 3> sheets;
- aBinding->PrototypeBinding()->AppendStyleSheetsTo(sheets);
+ aProto->AppendStyleSheetsTo(sheets);
for (auto* sheet : sheets) {
- queue.AppendElement(MakePair(sheet, SheetOwner { aBinding->PrototypeBinding() }));
+ queue.AppendElement(MakePair(sheet, SheetOwner { aProto }));
}
return true;
});
bool anyNonDocStyleChanged = false;
while (!queue.IsEmpty()) {
uint32_t idx = queue.Length() - 1;
auto* sheet = queue[idx].first();
@@ -1483,19 +1481,19 @@ ServoStyleSet::UpdateStylist()
if (MOZ_UNLIKELY(mStylistState & StylistState::XBLStyleSheetsDirty)) {
MOZ_ASSERT(GetPresContext(), "How did they get dirty?");
EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
Servo_AuthorStyles_Flush(aShadowRoot.ServoStyles(), mRawSet.get());
});
- mDocument->BindingManager()->EnumerateBoundContentBindings(
- [&](nsXBLBinding* aBinding) {
- if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
+ mDocument->BindingManager()->EnumerateBoundContentProtoBindings(
+ [&](nsXBLPrototypeBinding* aProto) {
+ if (auto* authorStyles = aProto->GetServoStyles()) {
Servo_AuthorStyles_Flush(authorStyles, mRawSet.get());
}
return true;
});
}
mStylistState = StylistState::NotDirty;
}