Bug 1221436 patch 1 - Have a pointer back from the css::Declaration for style attributes to the nsHTMLCSSStyleSheet. r=heycam
authorL. David Baron <dbaron@dbaron.org>
Mon, 09 Nov 2015 15:57:16 +0800
changeset 271736 2894f200ed038736e06851432e01fbb1e3311bce
parent 271735 27066ece22a9f79db7415eca2b1f66a7fa5c67c3
child 271737 84c5d7320a5ccc49dff580d78486d29443e25259
push id29650
push usercbook@mozilla.com
push dateMon, 09 Nov 2015 13:56:12 +0000
treeherdermozilla-central@e1ef2be156de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1221436
milestone45.0a1
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
Bug 1221436 patch 1 - Have a pointer back from the css::Declaration for style attributes to the nsHTMLCSSStyleSheet. r=heycam This is needed for patch 2, since we need a replacement for the mechanism to get from rules to the style attribute sheet (nsHTMLCSSStyleSheet) that works instead for declarations rather than rules. This pointer will be merged with the owning rule pointer in patch 4, but we can't do that until after patch 2.
dom/base/nsAttrValue.cpp
layout/style/Declaration.cpp
layout/style/Declaration.h
layout/style/nsHTMLCSSStyleSheet.cpp
--- a/dom/base/nsAttrValue.cpp
+++ b/dom/base/nsAttrValue.cpp
@@ -1691,16 +1691,17 @@ nsAttrValue::ParseStyleAttribute(const n
   nsCSSParser cssParser(cssLoader);
 
   RefPtr<css::StyleRule> rule;
   cssParser.ParseStyleAttribute(aString, docURI, baseURI,
                                 aElement->NodePrincipal(),
                                 getter_AddRefs(rule));
   if (rule) {
     rule->SetHTMLCSSStyleSheet(sheet);
+    rule->GetDeclaration()->SetHTMLCSSStyleSheet(sheet);
     SetTo(rule, &aString);
     if (cachingAllowed) {
       MiscContainer* cont = GetMiscContainer();
       cont->Cache();
     }
 
     return true;
   }
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -41,16 +41,17 @@ ImportantStyleData::List(FILE* out, int3
 
   str.AppendLiteral("! important rule\n");
   fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 Declaration::Declaration()
   : mOwningRule(nullptr)
+  , mHTMLCSSStyleSheet(nullptr)
   , mImmutable(false)
 {
 }
 
 Declaration::Declaration(const Declaration& aCopy)
   : mOrder(aCopy.mOrder),
     mVariableOrder(aCopy.mVariableOrder),
     mData(aCopy.mData ? aCopy.mData->Clone() : nullptr),
@@ -58,16 +59,17 @@ Declaration::Declaration(const Declarati
                      aCopy.mImportantData->Clone() : nullptr),
     mVariables(aCopy.mVariables ?
         new CSSVariableDeclarations(*aCopy.mVariables) :
         nullptr),
     mImportantVariables(aCopy.mImportantVariables ?
         new CSSVariableDeclarations(*aCopy.mImportantVariables) :
         nullptr),
     mOwningRule(nullptr),
+    mHTMLCSSStyleSheet(nullptr),
     mImmutable(false)
 {
 }
 
 Declaration::~Declaration()
 {
 }
 
--- a/layout/style/Declaration.h
+++ b/layout/style/Declaration.h
@@ -28,16 +28,18 @@
 #include "nsTArray.h"
 #include <stdio.h>
 
 // feec07b8-3fe6-491e-90d5-cc93f853e048
 #define NS_CSS_DECLARATION_IMPL_CID \
 { 0xfeec07b8, 0x3fe6, 0x491e, \
   { 0x90, 0xd5, 0xcc, 0x93, 0xf8, 0x53, 0xe0, 0x48 } }
 
+class nsHTMLCSSStyleSheet;
+
 namespace mozilla {
 namespace css {
 
 class Rule;
 class Declaration;
 
 /**
  * ImportantStyleData is the implementation of nsIStyleRule (a source of
@@ -316,16 +318,24 @@ public:
   void SetOwningRule(Rule* aRule) {
     MOZ_ASSERT(!mOwningRule || !aRule,
                "should never overwrite one rule with another");
     mOwningRule = aRule;
   }
 
   Rule* GetOwningRule() { return mOwningRule; }
 
+  void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aHTMLCSSStyleSheet) {
+    MOZ_ASSERT(!mHTMLCSSStyleSheet || !aHTMLCSSStyleSheet,
+               "should never overwrite one sheet with another");
+    mHTMLCSSStyleSheet = aHTMLCSSStyleSheet;
+  }
+
+  nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() { return mHTMLCSSStyleSheet; }
+
   ImportantStyleData* GetImportantStyleData() {
     if (HasImportantData()) {
       return &mImportantStyleData;
     }
     return nullptr;
   }
 
 private:
@@ -401,16 +411,20 @@ private:
   nsAutoPtr<CSSVariableDeclarations> mVariables;
 
   // may be null
   nsAutoPtr<CSSVariableDeclarations> mImportantVariables;
 
   // The style rule that owns this declaration.  May be null.
   Rule* mOwningRule;
 
+  // The nsHTMLCSSStyleSheet that is responsible for this declaration.
+  // Only non-null for style attributes.
+  nsHTMLCSSStyleSheet* mHTMLCSSStyleSheet;
+
   friend class ImportantStyleData;
   ImportantStyleData mImportantStyleData;
 
   // set when declaration put in the rule tree;
   // also by ToString (hence the 'mutable').
   mutable bool mImmutable;
 };
 
--- a/layout/style/nsHTMLCSSStyleSheet.cpp
+++ b/layout/style/nsHTMLCSSStyleSheet.cpp
@@ -26,17 +26,22 @@ namespace {
 
 PLDHashOperator
 ClearAttrCache(const nsAString& aKey, MiscContainer*& aValue, void*)
 {
   // Ideally we'd just call MiscContainer::Evict, but we can't do that since
   // we're iterating the hashtable.
   MOZ_ASSERT(aValue->mType == nsAttrValue::eCSSStyleRule);
 
-  aValue->mValue.mCSSStyleRule->SetHTMLCSSStyleSheet(nullptr);
+  css::StyleRule* styleRule = aValue->mValue.mCSSStyleRule;
+  styleRule->SetHTMLCSSStyleSheet(nullptr);
+  css::Declaration* declaration = styleRule->GetDeclaration();
+  if (declaration) {
+    declaration->SetHTMLCSSStyleSheet(nullptr);
+  }
   aValue->mValue.mCached = 0;
 
   return PL_DHASH_REMOVE;
 }
 
 } // namespace
 
 nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()