Bug 882573 patch 4: Make nsHTMLStyleSheet and nsHTMLCSSStyleSheet stop implementing nsIStyleSheet. r=heycam
authorL. David Baron <dbaron@dbaron.org>
Thu, 13 Jun 2013 22:34:37 -0700
changeset 146556 73a46cde2185d1221b19870c4291e858835b558d
parent 146555 54d0eecf55f29e221024251482702f96a531e67f
child 146557 8277fd16758cd48ee93171f5a72a6ba9997c8fbe
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs882573
milestone24.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 882573 patch 4: Make nsHTMLStyleSheet and nsHTMLCSSStyleSheet stop implementing nsIStyleSheet. r=heycam Note that this removes the Reset method and the mURL and mDocument members (and arguments to set them) from nsHTMLCSSStyleSheet. On the other hand, from nsHTMLStyleSheet it only removes mURL (and equivalent arguments), and nsHTMLStyleSheet keeps the SetOwningDocument method that was previously part of nsIStyleSheet (but no longer virtual).
content/base/src/nsDocument.cpp
layout/style/nsHTMLCSSStyleSheet.cpp
layout/style/nsHTMLCSSStyleSheet.h
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsHTMLStyleSheet.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1473,18 +1473,16 @@ nsDocument::~nsDocument()
   indx = mCatalogSheets.Count();
   while (--indx >= 0) {
     static_cast<nsCSSStyleSheet*>(mCatalogSheets[indx])->SetOwningNode(nullptr);
     mCatalogSheets[indx]->SetOwningDocument(nullptr);
   }
   if (mAttrStyleSheet) {
     mAttrStyleSheet->SetOwningDocument(nullptr);
   }
-  if (mStyleAttrStyleSheet)
-    mStyleAttrStyleSheet->SetOwningDocument(nullptr);
 
   if (mListenerManager) {
     mListenerManager->Disconnect();
     UnsetFlags(NODE_HAS_LISTENERMANAGER);
   }
 
   if (mScriptLoader) {
     mScriptLoader->DropDocumentReference();
@@ -2229,34 +2227,25 @@ nsDocument::ResetStylesheetsToURI(nsIURI
     mAdditionalSheets[i].Clear();
 
   // NOTE:  We don't release the catalog sheets.  It doesn't really matter
   // now, but it could in the future -- in which case not releasing them
   // is probably the right thing to do.
 
   // Now reset our inline style and attribute sheets.
   if (mAttrStyleSheet) {
-    mAttrStyleSheet->Reset(aURI);
+    mAttrStyleSheet->Reset();
+    mAttrStyleSheet->SetOwningDocument(this);
   } else {
-    mAttrStyleSheet = new nsHTMLStyleSheet(aURI, this);
-  }
-
-  // Don't use AddStyleSheet, since it'll put the sheet into style
-  // sets in the document level, which is not desirable here.
-  mAttrStyleSheet->SetOwningDocument(this);
-
-  if (mStyleAttrStyleSheet) {
-    mStyleAttrStyleSheet->Reset(aURI);
-  } else {
-    mStyleAttrStyleSheet = new nsHTMLCSSStyleSheet(aURI, this);
-  }
-
-  // The loop over style sets below will handle putting this sheet
-  // into style sets as needed.
-  mStyleAttrStyleSheet->SetOwningDocument(this);
+    mAttrStyleSheet = new nsHTMLStyleSheet(this);
+  }
+
+  if (!mStyleAttrStyleSheet) {
+    mStyleAttrStyleSheet = new nsHTMLCSSStyleSheet();
+  }
 
   // Now set up our style sets
   nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     FillStyleSet(shell->StyleSet());
   }
 }
 
--- a/layout/style/nsHTMLCSSStyleSheet.cpp
+++ b/layout/style/nsHTMLCSSStyleSheet.cpp
@@ -34,35 +34,29 @@ ClearAttrCache(const nsAString& aKey, Mi
   aValue->mValue.mCSSStyleRule->SetHTMLCSSStyleSheet(nullptr);
   aValue->mValue.mCached = 0;
 
   return PL_DHASH_REMOVE;
 }
 
 } // anonymous namespace
 
-nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet(nsIURI* aURL, nsIDocument* aDocument)
-  : mURL(aURL)
-  , mDocument(aDocument) // not refcounted!
+nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
 {
-  MOZ_ASSERT(aURL);
-  MOZ_ASSERT(aDocument);
   mCachedStyleAttrs.Init();
 }
 
 nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet()
 {
   // We may go away before all of our cached style attributes do,
   // so clean up any that are left.
   mCachedStyleAttrs.Enumerate(ClearAttrCache, nullptr);
 }
 
-NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
-                   nsIStyleSheet,
-                   nsIStyleRuleProcessor)
+NS_IMPL_ISUPPORTS1(nsHTMLCSSStyleSheet, nsIStyleRuleProcessor)
 
 /* virtual */ void
 nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
 {
   Element* element = aData->mElement;
 
   // just get the one and only style rule from the content's STYLE attribute
   css::StyleRule* rule = element->GetInlineStyleRule();
@@ -170,103 +164,8 @@ nsHTMLCSSStyleSheet::EvictStyleAttr(cons
   mCachedStyleAttrs.Remove(aSerialized);
 }
 
 MiscContainer*
 nsHTMLCSSStyleSheet::LookupStyleAttr(const nsAString& aSerialized)
 {
   return mCachedStyleAttrs.Get(aSerialized);
 }
-
-void
-nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
-{
-  mURL = aURL;
-}
-
-/* virtual */ nsIURI*
-nsHTMLCSSStyleSheet::GetSheetURI() const
-{
-  return mURL;
-}
-
-/* virtual */ nsIURI*
-nsHTMLCSSStyleSheet::GetBaseURI() const
-{
-  return mURL;
-}
-
-/* virtual */ void
-nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
-{
-  aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
-}
-
-/* virtual */ void
-nsHTMLCSSStyleSheet::GetType(nsString& aType) const
-{
-  aType.AssignLiteral("text/html");
-}
-
-/* virtual */ bool
-nsHTMLCSSStyleSheet::HasRules() const
-{
-  // Say we always have rules, since we don't know.
-  return true;
-}
-
-/* virtual */ bool
-nsHTMLCSSStyleSheet::IsApplicable() const
-{
-  return true;
-}
-
-/* virtual */ void
-nsHTMLCSSStyleSheet::SetEnabled(bool aEnabled)
-{ // these can't be disabled
-}
-
-/* virtual */ bool
-nsHTMLCSSStyleSheet::IsComplete() const
-{
-  return true;
-}
-
-/* virtual */ void
-nsHTMLCSSStyleSheet::SetComplete()
-{
-}
-
-// style sheet owner info
-/* virtual */ nsIStyleSheet*
-nsHTMLCSSStyleSheet::GetParentSheet() const
-{
-  return nullptr;
-}
-
-/* virtual */ nsIDocument*
-nsHTMLCSSStyleSheet::GetOwningDocument() const
-{
-  return mDocument;
-}
-
-/* virtual */ void
-nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
-{
-  mDocument = aDocument;
-}
-
-#ifdef DEBUG
-/* virtual */ void
-nsHTMLCSSStyleSheet::List(FILE* out, int32_t aIndent) const
-{
-  // Indent
-  for (int32_t index = aIndent; --index >= 0; ) fputs("  ", out);
-
-  fputs("HTML CSS Style Sheet: ", out);
-  nsAutoCString urlSpec;
-  mURL->GetSpec(urlSpec);
-  if (!urlSpec.IsEmpty()) {
-    fputs(urlSpec.get(), out);
-  }
-  fputs("\n", out);
-}
-#endif
--- a/layout/style/nsHTMLCSSStyleSheet.h
+++ b/layout/style/nsHTMLCSSStyleSheet.h
@@ -14,44 +14,24 @@
 
 #include "nsCOMPtr.h"
 #include "nsDataHashtable.h"
 #include "nsIStyleSheet.h"
 #include "nsIStyleRuleProcessor.h"
 
 struct MiscContainer;
 
-class nsHTMLCSSStyleSheet MOZ_FINAL : public nsIStyleSheet,
-                                      public nsIStyleRuleProcessor
+class nsHTMLCSSStyleSheet MOZ_FINAL : public nsIStyleRuleProcessor
 {
 public:
-  nsHTMLCSSStyleSheet(nsIURI* aURL, nsIDocument* aDocument);
+  nsHTMLCSSStyleSheet();
   ~nsHTMLCSSStyleSheet();
 
   NS_DECL_ISUPPORTS
 
-  void Reset(nsIURI* aURL);
-
-  // nsIStyleSheet
-  virtual nsIURI* GetSheetURI() const MOZ_OVERRIDE;
-  virtual nsIURI* GetBaseURI() const MOZ_OVERRIDE;
-  virtual void GetTitle(nsString& aTitle) const MOZ_OVERRIDE;
-  virtual void GetType(nsString& aType) const MOZ_OVERRIDE;
-  virtual bool HasRules() const MOZ_OVERRIDE;
-  virtual bool IsApplicable() const MOZ_OVERRIDE;
-  virtual void SetEnabled(bool aEnabled) MOZ_OVERRIDE;
-  virtual bool IsComplete() const MOZ_OVERRIDE;
-  virtual void SetComplete() MOZ_OVERRIDE;
-  virtual nsIStyleSheet* GetParentSheet() const MOZ_OVERRIDE;  // will be null
-  virtual nsIDocument* GetOwningDocument() const MOZ_OVERRIDE;
-  virtual void SetOwningDocument(nsIDocument* aDocument) MOZ_OVERRIDE;
-#ifdef DEBUG
-  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
-#endif
-
   // nsIStyleRuleProcessor
   virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
 #endif
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
@@ -68,20 +48,12 @@ public:
   void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue);
   MiscContainer* LookupStyleAttr(const nsAString& aSerialized);
 
 private: 
   nsHTMLCSSStyleSheet(const nsHTMLCSSStyleSheet& aCopy) MOZ_DELETE;
   nsHTMLCSSStyleSheet& operator=(const nsHTMLCSSStyleSheet& aCopy) MOZ_DELETE;
 
 protected:
-  nsCOMPtr<nsIURI> mURL;
-  nsIDocument*     mDocument;
   nsDataHashtable<nsStringHashKey, MiscContainer*> mCachedStyleAttrs;
 };
 
-inline nsISupports*
-ToSupports(nsHTMLCSSStyleSheet* aPointer)
-{
-  return static_cast<nsIStyleSheet*>(aPointer);
-}
-
 #endif /* !defined(nsHTMLCSSStyleSheet_h_) */
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -222,37 +222,35 @@ static PLDHashTableOps LangRuleTable_Ops
   PL_DHashMoveEntryStub,
   LangRuleTable_ClearEntry,
   PL_DHashFinalizeStub,
   LangRuleTable_InitEntry
 };
 
 // -----------------------------------------------------------
 
-nsHTMLStyleSheet::nsHTMLStyleSheet(nsIURI* aURL, nsIDocument* aDocument)
-  : mURL(aURL)
-  , mDocument(aDocument)
+nsHTMLStyleSheet::nsHTMLStyleSheet(nsIDocument* aDocument)
+  : mDocument(aDocument)
   , mTableQuirkColorRule(new TableQuirkColorRule())
   , mTableTHRule(new TableTHRule())
 {
-  MOZ_ASSERT(aURL);
   MOZ_ASSERT(aDocument);
   mMappedAttrTable.ops = nullptr;
   mLangRuleTable.ops = nullptr;
 }
 
 nsHTMLStyleSheet::~nsHTMLStyleSheet()
 {
   if (mLangRuleTable.ops)
     PL_DHashTableFinish(&mLangRuleTable);
   if (mMappedAttrTable.ops)
     PL_DHashTableFinish(&mMappedAttrTable);
 }
 
-NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
+NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet, nsIStyleRuleProcessor)
 
 /* virtual */ void
 nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
 {
   nsRuleWalker *ruleWalker = aData->mRuleWalker;
   if (aData->mElement->IsHTML() && !ruleWalker->AuthorStyleDisabled()) {
     nsIAtom* tag = aData->mElement->Tag();
 
@@ -397,92 +395,25 @@ nsHTMLStyleSheet::RulesMatching(AnonBoxR
 
 #ifdef MOZ_XUL
 /* virtual */ void
 nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
 {
 }
 #endif
 
-  // nsIStyleSheet api
-/* virtual */ nsIURI*
-nsHTMLStyleSheet::GetSheetURI() const
-{
-  return mURL;
-}
-
-/* virtual */ nsIURI*
-nsHTMLStyleSheet::GetBaseURI() const
-{
-  return mURL;
-}
-
-/* virtual */ void
-nsHTMLStyleSheet::GetTitle(nsString& aTitle) const
-{
-  aTitle.Truncate();
-}
-
-/* virtual */ void
-nsHTMLStyleSheet::GetType(nsString& aType) const
-{
-  aType.AssignLiteral("text/html");
-}
-
-/* virtual */ bool
-nsHTMLStyleSheet::HasRules() const
-{
-  return true; // We have rules at all reasonable times
-}
-
-/* virtual */ bool
-nsHTMLStyleSheet::IsApplicable() const
-{
-  return true;
-}
-
-/* virtual */ void
-nsHTMLStyleSheet::SetEnabled(bool aEnabled)
-{ // these can't be disabled
-}
-
-/* virtual */ bool
-nsHTMLStyleSheet::IsComplete() const
-{
-  return true;
-}
-
-/* virtual */ void
-nsHTMLStyleSheet::SetComplete()
-{
-}
-
-/* virtual */ nsIStyleSheet*
-nsHTMLStyleSheet::GetParentSheet() const
-{
-  return nullptr;
-}
-
-/* virtual */ nsIDocument*
-nsHTMLStyleSheet::GetOwningDocument() const
-{
-  return mDocument;
-}
-
-/* virtual */ void
+void
 nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument)
 {
   mDocument = aDocument; // not refcounted
 }
 
 void
-nsHTMLStyleSheet::Reset(nsIURI* aURL)
+nsHTMLStyleSheet::Reset()
 {
-  mURL = aURL;
-
   mLinkRule          = nullptr;
   mVisitedRule       = nullptr;
   mActiveRule        = nullptr;
 
   if (mLangRuleTable.ops) {
     PL_DHashTableFinish(&mLangRuleTable);
     mLangRuleTable.ops = nullptr;
   }
@@ -589,33 +520,16 @@ nsHTMLStyleSheet::LangRuleFor(const nsSt
     (PL_DHashTableOperate(&mLangRuleTable, &aLanguage, PL_DHASH_ADD));
   if (!entry) {
     NS_ASSERTION(false, "out of memory");
     return nullptr;
   }
   return entry->mRule;
 }
 
-#ifdef DEBUG
-/* virtual */ void
-nsHTMLStyleSheet::List(FILE* out, int32_t aIndent) const
-{
-  // Indent
-  for (int32_t index = aIndent; --index >= 0; ) fputs("  ", out);
-
-  fputs("HTML Style Sheet: ", out);
-  nsAutoCString urlSpec;
-  mURL->GetSpec(urlSpec);
-  if (!urlSpec.IsEmpty()) {
-    fputs(urlSpec.get(), out);
-  }
-  fputs("\n", out);
-}
-#endif
-
 static size_t
 SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
                                    nsMallocSizeOfFun aMallocSizeOf,
                                    void* aArg)
 {
   NS_PRECONDITION(aEntry, "The entry should not be null!");
 
   MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(aEntry);
--- a/layout/style/nsHTMLStyleSheet.h
+++ b/layout/style/nsHTMLStyleSheet.h
@@ -19,41 +19,25 @@
 #include "nsIStyleRuleProcessor.h"
 #include "nsIStyleSheet.h"
 #include "pldhash.h"
 #include "mozilla/Attributes.h"
 #include "nsString.h"
 
 class nsMappedAttributes;
 
-class nsHTMLStyleSheet MOZ_FINAL : public nsIStyleSheet,
-                                   public nsIStyleRuleProcessor
+class nsHTMLStyleSheet MOZ_FINAL : public nsIStyleRuleProcessor
 {
 public:
-  nsHTMLStyleSheet(nsIURI* aURL, nsIDocument* aDocument);
+  nsHTMLStyleSheet(nsIDocument* aDocument);
+
+  void SetOwningDocument(nsIDocument* aDocument);
 
   NS_DECL_ISUPPORTS
 
-  // nsIStyleSheet api
-  virtual nsIURI* GetSheetURI() const MOZ_OVERRIDE;
-  virtual nsIURI* GetBaseURI() const MOZ_OVERRIDE;
-  virtual void GetTitle(nsString& aTitle) const MOZ_OVERRIDE;
-  virtual void GetType(nsString& aType) const MOZ_OVERRIDE;
-  virtual bool HasRules() const MOZ_OVERRIDE;
-  virtual bool IsApplicable() const MOZ_OVERRIDE;
-  virtual void SetEnabled(bool aEnabled) MOZ_OVERRIDE;
-  virtual bool IsComplete() const MOZ_OVERRIDE;
-  virtual void SetComplete() MOZ_OVERRIDE;
-  virtual nsIStyleSheet* GetParentSheet() const MOZ_OVERRIDE;  // will be null
-  virtual nsIDocument* GetOwningDocument() const MOZ_OVERRIDE;
-  virtual void SetOwningDocument(nsIDocument* aDocumemt) MOZ_OVERRIDE;
-#ifdef DEBUG
-  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
-#endif
-
   // nsIStyleRuleProcessor API
   virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
 #endif
   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
@@ -62,17 +46,17 @@ public:
     HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
   virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
     const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
   virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
     const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
   size_t DOMSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
 
-  void Reset(nsIURI* aURL);
+  void Reset();
   nsresult SetLinkColor(nscolor aColor);
   nsresult SetActiveLinkColor(nscolor aColor);
   nsresult SetVisitedLinkColor(nscolor aColor);
 
   // Mapped Attribute management methods
   already_AddRefed<nsMappedAttributes>
     UniqueMappedAttributes(nsMappedAttributes* aMapped);
   void DropMappedAttributes(nsMappedAttributes* aMapped);
@@ -154,17 +138,16 @@ public: // for mLangRuleTable structures
   #ifdef DEBUG
     virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
   #endif
 
     nsString mLang;
   };
 
 private:
-  nsCOMPtr<nsIURI>        mURL;
   nsIDocument*            mDocument;
   nsRefPtr<HTMLColorRule> mLinkRule;
   nsRefPtr<HTMLColorRule> mVisitedRule;
   nsRefPtr<HTMLColorRule> mActiveRule;
   nsRefPtr<TableQuirkColorRule> mTableQuirkColorRule;
   nsRefPtr<TableTHRule>   mTableTHRule;
 
   PLDHashTable            mMappedAttrTable;