Append style sheets from binding manager when ensuring unique inner on all sheets. (Bug 578810) r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Fri, 16 Jul 2010 22:36:34 -0700
changeset 47849 53a5c3bb6c5c1f7f765982d8c8826b3a6ac81bc7
parent 47848 46af914448aefb49b77f6bba7786b6ba3eea0e2c
child 47850 9fc8bbdd1ace93e34a338c12ced981de684c10a8
push id14446
push userdbaron@mozilla.com
push dateSat, 17 Jul 2010 05:37:31 +0000
treeherderautoland@53a5c3bb6c5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs578810
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Append style sheets from binding manager when ensuring unique inner on all sheets. (Bug 578810) r=bzbarsky
content/xbl/src/nsBindingManager.cpp
content/xbl/src/nsBindingManager.h
layout/style/nsStyleSet.cpp
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -1397,16 +1397,43 @@ nsBindingManager::MediumFeaturesChanged(
   if (!set.IsInitialized())
     return NS_OK;
 
   MediumFeaturesChangedData data = { aPresContext, aRulesChanged };
   set.EnumerateEntries(EnumMediumFeaturesChanged, &data);
   return NS_OK;
 }
 
+static PLDHashOperator
+EnumAppendAllSheets(nsISupports *aKey, nsXBLBinding *aBinding, void* aClosure)
+{
+  nsTArray<nsCSSStyleSheet*>* array =
+    static_cast<nsTArray<nsCSSStyleSheet*>*>(aClosure);
+  for (nsXBLBinding *binding = aBinding; binding;
+       binding = binding->GetBaseBinding()) {
+    nsXBLPrototypeResources::sheet_array_type* sheets =
+      binding->PrototypeBinding()->GetStyleSheets();
+    if (sheets) {
+      // Copy from nsTArray<nsRefPtr<nsCSSStyleSheet> > to
+      // nsTArray<nsCSSStyleSheet*>.
+      array->AppendElements(*sheets);
+    }
+  }
+  return PL_DHASH_NEXT;
+}
+
+void
+nsBindingManager::AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray)
+{
+  if (!mBindingTable.IsInitialized())
+    return;
+
+  mBindingTable.EnumerateRead(EnumAppendAllSheets, &aArray);
+}
+
 nsIContent*
 nsBindingManager::GetNestedInsertionPoint(nsIContent* aParent,
                                           const nsIContent* aChild)
 {
   // Check to see if the content is anonymous.
   if (aChild->GetBindingParent() == aParent)
     return nsnull; // It is anonymous. Don't use the insertion point, since that's only
                    // for the explicit kids.
--- a/content/xbl/src/nsBindingManager.h
+++ b/content/xbl/src/nsBindingManager.h
@@ -221,16 +221,18 @@ public:
   /**
    * Do any processing that needs to happen as a result of a change in
    * the characteristics of the medium, and return whether this rule
    * processor's rules have changed (e.g., because of media queries).
    */
   nsresult MediumFeaturesChanged(nsPresContext* aPresContext,
                                  PRBool* aRulesChanged);
 
+  void AppendAllSheets(nsTArray<nsCSSStyleSheet*>& aArray);
+
   NS_HIDDEN_(void) Traverse(nsIContent *aContent,
                             nsCycleCollectionTraversalCallback &cb);
 
   NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
 
   // Notify the binding manager when an outermost update begins and
   // ends.  The end method can execute script.
   void BeginOutermostUpdate();
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -1331,16 +1331,20 @@ nsStyleSet::EnsureUniqueInnerOnCSSSheets
     for (PRUint32 j = 0, j_end = sheets.Count(); j < j_end; ++j) {
       nsCSSStyleSheet *sheet = static_cast<nsCSSStyleSheet*>(sheets[j]);
       if (!queue.AppendElement(sheet)) {
         return nsCSSStyleSheet::eUniqueInner_CloneFailed;
       }
     }
   }
 
+  if (mBindingManager) {
+    mBindingManager->AppendAllSheets(queue);
+  }
+
   nsCSSStyleSheet::EnsureUniqueInnerResult res =
     nsCSSStyleSheet::eUniqueInner_AlreadyUnique;
   while (!queue.IsEmpty()) {
     PRUint32 idx = queue.Length() - 1;
     nsCSSStyleSheet *sheet = queue[idx];
     queue.RemoveElementAt(idx);
 
     nsCSSStyleSheet::EnsureUniqueInnerResult sheetRes =