Bug 577974 - Part 2: Remove nsICSSGroupRule, r=bzbarsky
authorCraig Topper <craig.topper@gmail.com>
Sat, 07 Aug 2010 22:28:33 -0700
changeset 64677 f100d70f483a75430129d12a2b46b171687978a2
parent 64676 45d658bb4be18c836dc93fa6ff532731f3a55530
child 64678 8bd0c633031859162173a911b2b15a722a86e294
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs577974
milestone2.2a1pre
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 577974 - Part 2: Remove nsICSSGroupRule, r=bzbarsky
layout/style/GroupRule.h
layout/style/Makefile.in
layout/style/StyleRule.cpp
layout/style/StyleRule.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSRule.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRules.cpp
layout/style/nsCSSRules.h
layout/style/nsCSSStyleSheet.cpp
layout/style/nsCSSStyleSheet.h
layout/style/nsICSSGroupRule.h
layout/style/nsICSSRule.h
rename from layout/style/nsICSSGroupRule.h
rename to layout/style/GroupRule.h
--- a/layout/style/nsICSSGroupRule.h
+++ b/layout/style/GroupRule.h
@@ -35,52 +35,94 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * internal interface representing CSS style rules that contain other
  * rules, such as @media rules
  */
 
-#ifndef nsICSSGroupRule_h
-#define nsICSSGroupRule_h
+#ifndef mozilla_css_GroupRule_h__
+#define mozilla_css_GroupRule_h__
 
 #include "nsICSSRule.h"
+#include "nsCSSRule.h"
 #include "nsCOMArray.h"
+#include "nsAutoPtr.h"
 
 class nsPresContext;
 class nsMediaQueryResultCacheKey;
 
-#define NS_ICSS_GROUP_RULE_IID \
-{ 0xf1e3d96b, 0xe381, 0x4533, \
-  { 0xa6, 0x5e, 0xa5, 0x31, 0xba, 0xca, 0x93, 0x62 } }
+namespace mozilla {
+namespace css {
+
+class GroupRuleRuleList;
 
+// inherits from nsCSSRule so it can be shared between
+// nsCSSMediaRule and nsCSSDocumentRule
+class GroupRule : public nsCSSRule, public nsICSSRule
+{
+protected:
+  GroupRule();
+  GroupRule(const GroupRule& aCopy);
+  virtual ~GroupRule();
 
-class nsICSSGroupRule : public nsICSSRule {
+protected:
+  nsAutoRefCnt mRefCnt;
+  NS_DECL_OWNINGTHREAD
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_GROUP_RULE_IID)
+
+  // Implement part of nsISupports.
+  NS_IMETHOD_(nsrefcnt) AddRef();
+  NS_IMETHOD_(nsrefcnt) Release();
+
+  // implement part of nsIStyleRule and nsICSSRule
+  DECL_STYLE_RULE_INHERIT_NO_DOMRULE
 
-  NS_IMETHOD  AppendStyleRule(nsICSSRule* aRule) = 0;
+  // to help implement nsIStyleRule
+#ifdef DEBUG
+  virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
+#endif
 
-  NS_IMETHOD  StyleRuleCount(PRInt32& aCount) const = 0;
-  NS_IMETHOD  GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const = 0;
+public:
+  NS_IMETHOD  AppendStyleRule(nsICSSRule* aRule);
+
+  NS_IMETHOD  StyleRuleCount(PRInt32& aCount) const;
+  NS_IMETHOD  GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
 
   typedef nsCOMArray<nsICSSRule>::nsCOMArrayEnumFunc RuleEnumFunc;
-  NS_IMETHOD_(PRBool) EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const = 0;
+  NS_IMETHOD_(PRBool) EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
 
   /*
    * The next three methods should never be called unless you have first
    * called WillDirty() on the parent stylesheet.  After they are
    * called, DidDirty() needs to be called on the sheet.
    */
-  NS_IMETHOD  DeleteStyleRuleAt(PRUint32 aIndex) = 0;
+  NS_IMETHOD  DeleteStyleRuleAt(PRUint32 aIndex);
   NS_IMETHOD  InsertStyleRulesAt(PRUint32 aIndex,
-                                 nsCOMArray<nsICSSRule>& aRules) = 0;
-  NS_IMETHOD  ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew) = 0;
+                                 nsCOMArray<nsICSSRule>& aRules);
+  NS_IMETHOD  ReplaceStyleRule(nsICSSRule *aOld, nsICSSRule *aNew);
 
   NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext,
                                          nsMediaQueryResultCacheKey& aKey) = 0;
-   
+
+protected:
+  // to help implement nsIDOMCSSRule
+  nsresult AppendRulesToCssText(nsAString& aCssText);
+  // to implement methods on nsIDOMCSSRule
+  nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
+  nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
+
+  // to implement common methods on nsIDOMCSSMediaRule and
+  // nsIDOMCSSMozDocumentRule
+  nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
+  nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
+                      PRUint32* _retval);
+  nsresult DeleteRule(PRUint32 aIndex);
+
+  nsCOMArray<nsICSSRule> mRules;
+  nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSGroupRule, NS_ICSS_GROUP_RULE_IID)
+} // namespace css
+} // namespace mozilla
 
-#endif /* nsICSSGroupRule_h */
+#endif /* mozilla_css_GroupRule_h__ */
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -67,17 +67,16 @@ EXPORTS		= \
 		nsCSSPseudoElementList.h \
 		nsCSSPseudoElements.h \
 		nsCSSRuleProcessor.h \
 		nsCSSStyleSheet.h \
 		nsCSSValue.h \
 		nsDOMCSSAttrDeclaration.h \
 		nsDOMCSSDeclaration.h \
 		nsICSSDeclaration.h \
-		nsICSSGroupRule.h \
 		nsICSSLoaderObserver.h \
 		nsICSSPseudoComparator.h \
 		nsICSSRule.h \
 		nsICSSRuleList.h \
 		nsICSSStyleRuleDOMWrapper.h \
 		nsIStyleRule.h \
 		nsIStyleRuleProcessor.h \
 		nsIStyleSheet.h \
@@ -94,16 +93,17 @@ EXPORTS		= \
 		nsStyleStructInlines.h \
 		nsStyleStructList.h \
 		nsStyleTransformMatrix.h \
 		nsStyleUtil.h \
 		$(NULL)
 
 EXPORTS_mozilla/css = \
 		Declaration.h \
+		GroupRule.h \
 		ImportRule.h \
 		Loader.h \
 		NameSpaceRule.h \
 		StyleRule.h \
 		$(NULL)
 
 CPPSRCS		= \
 		nsCSSAnonBoxes.cpp \
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -40,17 +40,17 @@
 
 /*
  * representation of CSS style rules (selectors+declaration), CSS
  * selectors, and DOM objects for style rules, selectors, and
  * declarations
  */
 
 #include "mozilla/css/StyleRule.h"
-#include "nsICSSGroupRule.h"
+#include "mozilla/css/GroupRule.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSStyleSheet.h"
 #include "mozilla/css/Loader.h"
 #include "nsIURL.h"
 #include "nsIDocument.h"
 #include "nsIDeviceContext.h"
 #include "nsIAtom.h"
 #include "nsCRT.h"
@@ -1220,17 +1220,17 @@ DOMCSSStyleRule::GetParentStyleSheet(nsI
 
 NS_IMETHODIMP
 DOMCSSStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule)
 {
   if (!Rule()) {
     *aParentRule = nsnull;
     return NS_OK;
   }
-  nsICSSGroupRule* rule = Rule()->GetParentRule();
+  GroupRule* rule = Rule()->GetParentRule();
   if (!rule) {
     *aParentRule = nsnull;
     return NS_OK;
   }
   return rule->GetDOMRule(aParentRule);
 }
 
 NS_IMETHODIMP
@@ -1385,17 +1385,17 @@ StyleRule::GetStyleSheet() const
 
 /* virtual */ void
 StyleRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   nsCSSRule::SetStyleSheet(aSheet);
 }
 
 /* virtual */ void
-StyleRule::SetParentRule(nsICSSGroupRule* aRule)
+StyleRule::SetParentRule(GroupRule* aRule)
 {
   nsCSSRule::SetParentRule(aRule);
 }
 
 /* virtual */ PRInt32
 StyleRule::GetType() const
 {
   return nsICSSRule::STYLE_RULE;
--- a/layout/style/StyleRule.h
+++ b/layout/style/StyleRule.h
@@ -338,25 +338,25 @@ public:
    * nsRuleWalker::Forward on this rule during rule matching.
    */
   void RuleMatched();
 
   // hooks for DOM rule
   void GetCssText(nsAString& aCssText);
   void SetCssText(const nsAString& aCssText);
   nsCSSStyleSheet* GetParentStyleSheet() { return mSheet; }
-  nsICSSGroupRule* GetParentRule() { return mParentRule; }
+  GroupRule* GetParentRule() { return mParentRule; }
   void GetSelectorText(nsAString& aSelectorText);
   void SetSelectorText(const nsAString& aSelectorText);
 
   virtual PRInt32 GetType() const;
 
   virtual already_AddRefed<nsIStyleSheet> GetStyleSheet() const;
   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
-  virtual void SetParentRule(nsICSSGroupRule* aRule);
+  virtual void SetParentRule(GroupRule* aRule);
 
   virtual already_AddRefed<nsICSSRule> Clone() const;
 
   nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
 
   // The new mapping function.
   virtual void MapRuleInfoInto(nsRuleData* aRuleData);
 
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -318,35 +318,35 @@ protected:
   PRBool CheckEndProperty();
   nsSubstring* NextIdent();
   void SkipUntil(PRUnichar aStopSymbol);
   void SkipUntilOneOf(const PRUnichar* aStopSymbolChars);
   void SkipRuleSet(PRBool aInsideBraces);
   PRBool SkipAtRule(PRBool aInsideBlock);
   PRBool SkipDeclaration(PRBool aCheckForBraces);
 
-  PRBool PushGroup(nsICSSGroupRule* aRule);
-  void PopGroup(void);
+  PRBool PushGroup(css::GroupRule* aRule);
+  void PopGroup();
 
   PRBool ParseRuleSet(RuleAppendFunc aAppendFunc, void* aProcessData,
                       PRBool aInsideBraces = PR_FALSE);
   PRBool ParseAtRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   PRBool ParseCharsetRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   PRBool ParseImportRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   PRBool ParseURLOrString(nsString& aURL);
   PRBool GatherMedia(nsMediaList* aMedia,
                      PRBool aInAtRule);
   PRBool ParseMediaQuery(PRBool aInAtRule, nsMediaQuery **aQuery,
                          PRBool *aParsedSomething, PRBool *aHitStop);
   PRBool ParseMediaQueryExpression(nsMediaQuery* aQuery);
   void ProcessImport(const nsString& aURLSpec,
                      nsMediaList* aMedia,
                      RuleAppendFunc aAppendFunc,
                      void* aProcessData);
-  PRBool ParseGroupRule(nsICSSGroupRule* aRule, RuleAppendFunc aAppendFunc,
+  PRBool ParseGroupRule(css::GroupRule* aRule, RuleAppendFunc aAppendFunc,
                         void* aProcessData);
   PRBool ParseMediaRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   PRBool ParseMozDocumentRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   PRBool ParseNameSpaceRule(RuleAppendFunc aAppendFunc, void* aProcessData);
   void ProcessNameSpace(const nsString& aPrefix,
                         const nsString& aURLSpec, RuleAppendFunc aAppendFunc,
                         void* aProcessData);
 
@@ -651,17 +651,17 @@ protected:
   // when it encounters a prefix that is not mapped to a namespace.
   PRPackedBool  mFoundUnresolvablePrefix : 1;
 
 #ifdef DEBUG
   PRPackedBool mScannerInited : 1;
 #endif
 
   // Stack of rule groups; used for @media and such.
-  nsCOMArray<nsICSSGroupRule> mGroupStack;
+  nsTArray<nsRefPtr<css::GroupRule> > mGroupStack;
 
   // During the parsing of a property (which may be a shorthand), the data
   // are stored in |mTempData|.  (It is needed to ensure that parser
   // errors cause the data to be ignored, and to ensure that a
   // non-'!important' declaration does not override an '!important'
   // one.)
   nsCSSExpandedDataBlock mTempData;
 
@@ -1953,17 +1953,17 @@ CSSParserImpl::ProcessImport(const nsStr
 
   if (mChildLoader) {
     mChildLoader->LoadChildSheet(mSheet, url, aMedia, rule);
   }
 }
 
 // Parse the {} part of an @media or @-moz-document rule.
 PRBool
-CSSParserImpl::ParseGroupRule(nsICSSGroupRule* aRule,
+CSSParserImpl::ParseGroupRule(css::GroupRule* aRule,
                               RuleAppendFunc aAppendFunc,
                               void* aData)
 {
   // XXXbz this could use better error reporting throughout the method
   if (!ExpectSymbol('{', PR_TRUE)) {
     return PR_FALSE;
   }
 
@@ -2381,37 +2381,37 @@ CSSParserImpl::SkipRuleSet(PRBool aInsid
     } else if (eCSSToken_Function == tk->mType ||
                eCSSToken_Bad_URL == tk->mType) {
       SkipUntil(')');
     }
   } 
 }
 
 PRBool
-CSSParserImpl::PushGroup(nsICSSGroupRule* aRule)
-{
-  if (mGroupStack.AppendObject(aRule))
+CSSParserImpl::PushGroup(css::GroupRule* aRule)
+{
+  if (mGroupStack.AppendElement(aRule))
     return PR_TRUE;
 
   return PR_FALSE;
 }
 
 void
-CSSParserImpl::PopGroup(void)
-{
-  PRInt32 count = mGroupStack.Count();
+CSSParserImpl::PopGroup()
+{
+  PRUint32 count = mGroupStack.Length();
   if (0 < count) {
-    mGroupStack.RemoveObjectAt(count - 1);
+    mGroupStack.RemoveElementAt(count - 1);
   }
 }
 
 void
 CSSParserImpl::AppendRule(nsICSSRule* aRule)
 {
-  PRInt32 count = mGroupStack.Count();
+  PRUint32 count = mGroupStack.Length();
   if (0 < count) {
     mGroupStack[count - 1]->AppendStyleRule(aRule);
   }
   else {
     mSheet->AppendStyleRule(aRule);
   }
 }
 
--- a/layout/style/nsCSSRule.h
+++ b/layout/style/nsCSSRule.h
@@ -39,17 +39,36 @@
 
 #ifndef nsCSSRule_h___
 #define nsCSSRule_h___
 
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
 #include "nsCSSStyleSheet.h"
 
-class nsICSSGroupRule;
+class nsIStyleSheet;
+class nsCSSStyleSheet;
+struct nsRuleData;
+template<class T> struct already_AddRefed;
+
+namespace mozilla {
+namespace css {
+class GroupRule;
+}
+}
+
+#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
+virtual already_AddRefed<nsIStyleSheet> GetStyleSheet() const; \
+virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); \
+virtual void SetParentRule(mozilla::css::GroupRule* aRule); \
+virtual void MapRuleInfoInto(nsRuleData* aRuleData);
+
+#define DECL_STYLE_RULE_INHERIT  \
+DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
+virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
 
 class nsCSSRule {
 public:
   nsCSSRule(void)
     : mSheet(nsnull),
       mParentRule(nsnull)
   {
   }
@@ -72,22 +91,22 @@ public:
   {
     // We don't reference count this up reference. The style sheet
     // will tell us when it's going away or when we're detached from
     // it.
     mSheet = aSheet;
   }
 
   void
-  SetParentRule(nsICSSGroupRule* aRule)
+  SetParentRule(mozilla::css::GroupRule* aRule)
   {
     // We don't reference count this up reference. The group rule
     // will tell us when it's going away or when we're detached from
     // it.
     mParentRule = aRule;
   }
 
 protected:
-  nsCSSStyleSheet*    mSheet;
-  nsICSSGroupRule*    mParentRule;
+  nsCSSStyleSheet*         mSheet;
+  mozilla::css::GroupRule* mParentRule;
 };
 
 #endif /* nsCSSRule_h___ */
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -54,17 +54,17 @@
 
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "pldhash.h"
 #include "nsHashtable.h"
 #include "nsICSSPseudoComparator.h"
 #include "nsCSSRuleProcessor.h"
 #include "mozilla/css/StyleRule.h"
-#include "nsICSSGroupRule.h"
+#include "mozilla/css/GroupRule.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsIEventStateManager.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "nsDOMError.h"
 #include "nsRuleWalker.h"
@@ -2777,17 +2777,17 @@ CascadeRuleEnumFunc(nsICSSRule* aRule, v
       entry->data.mWeight = weight;
       // entry->data.mRules must be in forward order.
       entry->data.mRules.AppendElement(RuleSelectorPair(styleRule,
                                                         sel->mSelectors));
     }
   }
   else if (nsICSSRule::MEDIA_RULE == type ||
            nsICSSRule::DOCUMENT_RULE == type) {
-    nsICSSGroupRule* groupRule = (nsICSSGroupRule*)aRule;
+    css::GroupRule* groupRule = static_cast<css::GroupRule*>(aRule);
     if (groupRule->UseForPresentation(data->mPresContext, data->mCacheKey))
       if (!groupRule->EnumerateRulesForwards(CascadeRuleEnumFunc, aData))
         return PR_FALSE;
   }
   else if (nsICSSRule::FONT_FACE_RULE == type) {
     nsCSSFontFaceRule *fontFaceRule = static_cast<nsCSSFontFaceRule*>(aRule);
     nsFontFaceRuleContainer *ptr = data->mFontFaceRules.AppendElement();
     if (!ptr)
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -68,53 +68,53 @@
 #include "mozilla/css/Declaration.h"
 #include "nsPrintfCString.h"
 
 namespace css = mozilla::css;
 
 #define IMPL_STYLE_RULE_INHERIT(_class, super) \
 /* virtual */ already_AddRefed<nsIStyleSheet> _class::GetStyleSheet() const { return super::GetStyleSheet(); }  \
 /* virtual */ void _class::SetStyleSheet(nsCSSStyleSheet* aSheet) { super::SetStyleSheet(aSheet); }  \
-/* virtual */ void _class::SetParentRule(nsICSSGroupRule* aRule) { super::SetParentRule(aRule); }  \
+/* virtual */ void _class::SetParentRule(css::GroupRule* aRule) { super::SetParentRule(aRule); }  \
 nsIDOMCSSRule* _class::GetDOMRuleWeak(nsresult *aResult) { *aResult = NS_OK; return this; }  \
 /* virtual */ void _class::MapRuleInfoInto(nsRuleData* aRuleData) { }
 
 #define IMPL_STYLE_RULE_INHERIT2(_class, super) \
 /* virtual */ already_AddRefed<nsIStyleSheet> _class::GetStyleSheet() const { return super::GetStyleSheet(); }  \
-/* virtual */ void  _class::SetParentRule(nsICSSGroupRule* aRule) { super::SetParentRule(aRule); }  \
+/* virtual */ void  _class::SetParentRule(css::GroupRule* aRule) { super::SetParentRule(aRule); }  \
 /* virtual */ void _class::MapRuleInfoInto(nsRuleData* aRuleData) { }
 
 // -------------------------------
 // Style Rule List for group rules
 //
 
 namespace mozilla {
 namespace css {
 
 class NS_FINAL_CLASS GroupRuleRuleList : public nsICSSRuleList
 {
 public:
-  GroupRuleRuleList(nsICSSGroupRule *aGroupRule);
+  GroupRuleRuleList(GroupRule *aGroupRule);
 
   NS_DECL_ISUPPORTS
 
   NS_DECL_NSIDOMCSSRULELIST
 
   virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult);
 
   void DropReference() { mGroupRule = nsnull; }
 
 private:
   ~GroupRuleRuleList();
 
 private:
-  nsICSSGroupRule* mGroupRule;
+  GroupRule* mGroupRule;
 };
 
-GroupRuleRuleList::GroupRuleRuleList(nsICSSGroupRule *aGroupRule)
+GroupRuleRuleList::GroupRuleRuleList(GroupRule *aGroupRule)
 {
   // Not reference counted to avoid circular references.
   // The rule will tell us when its going away.
   mGroupRule = aGroupRule;
 }
 
 GroupRuleRuleList::~GroupRuleRuleList()
 {
@@ -571,169 +571,172 @@ NS_NewCSSImportRule(css::ImportRule** aI
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   it->SetURLSpec(aURLSpec);
   NS_ADDREF(*aInstancePtrResult = it);
   return NS_OK;
 }
 
-nsCSSGroupRule::nsCSSGroupRule()
-  : nsCSSRule()
-{
-}
-
 static PRBool
 CloneRuleInto(nsICSSRule* aRule, void* aArray)
 {
   nsCOMPtr<nsICSSRule> clone = aRule->Clone();
   static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(clone);
   return PR_TRUE;
 }
 
+namespace mozilla {
+namespace css {
+
+GroupRule::GroupRule()
+  : nsCSSRule()
+{
+}
+
 static PRBool
 SetParentRuleReference(nsICSSRule* aRule, void* aParentRule)
 {
-  nsCSSGroupRule* parentRule = static_cast<nsCSSGroupRule*>(aParentRule);
+  GroupRule* parentRule = static_cast<GroupRule*>(aParentRule);
   aRule->SetParentRule(parentRule);
   return PR_TRUE;
 }
 
-nsCSSGroupRule::nsCSSGroupRule(const nsCSSGroupRule& aCopy)
+GroupRule::GroupRule(const GroupRule& aCopy)
   : nsCSSRule(aCopy)
 {
-  const_cast<nsCSSGroupRule&>(aCopy).mRules.EnumerateForwards(CloneRuleInto, &mRules);
+  const_cast<GroupRule&>(aCopy).mRules.EnumerateForwards(CloneRuleInto, &mRules);
   mRules.EnumerateForwards(SetParentRuleReference, this);
 }
 
-nsCSSGroupRule::~nsCSSGroupRule()
+GroupRule::~GroupRule()
 {
   mRules.EnumerateForwards(SetParentRuleReference, nsnull);
   if (mRuleCollection) {
     mRuleCollection->DropReference();
   }
 }
 
-NS_IMPL_ADDREF(nsCSSGroupRule)
-NS_IMPL_RELEASE(nsCSSGroupRule)
+NS_IMPL_ADDREF(GroupRule)
+NS_IMPL_RELEASE(GroupRule)
 
-IMPL_STYLE_RULE_INHERIT2(nsCSSGroupRule, nsCSSRule)
+IMPL_STYLE_RULE_INHERIT2(GroupRule, nsCSSRule)
 
 static PRBool
 SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
 {
   nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
   aRule->SetStyleSheet(sheet);
   return PR_TRUE;
 }
 
 /* virtual */ void
-nsCSSGroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
+GroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
   nsCSSRule::SetStyleSheet(aSheet);
 }
 
 #ifdef DEBUG
 /* virtual */ void
-nsCSSGroupRule::List(FILE* out, PRInt32 aIndent) const
+GroupRule::List(FILE* out, PRInt32 aIndent) const
 {
   fputs(" {\n", out);
 
   for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
     mRules.ObjectAt(index)->List(out, aIndent + 1);
   }
   fputs("}\n", out);
 }
 #endif
 
 NS_IMETHODIMP
-nsCSSGroupRule::AppendStyleRule(nsICSSRule* aRule)
+GroupRule::AppendStyleRule(nsICSSRule* aRule)
 {
   mRules.AppendObject(aRule);
   aRule->SetStyleSheet(mSheet);
   aRule->SetParentRule(this);
   if (mSheet) {
     // XXXldb Shouldn't we be using |WillDirty| and |DidDirty| (and
     // shouldn't |SetModified| be removed?
     mSheet->SetModified(PR_TRUE);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsCSSGroupRule::StyleRuleCount(PRInt32& aCount) const
+GroupRule::StyleRuleCount(PRInt32& aCount) const
 {
   aCount = mRules.Count();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsCSSGroupRule::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
+GroupRule::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
 {
   if (aIndex < 0 || aIndex >= mRules.Count()) {
     aRule = nsnull;
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   NS_ADDREF(aRule = mRules.ObjectAt(aIndex));
   return NS_OK;
 }
 
 NS_IMETHODIMP_(PRBool)
-nsCSSGroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
+GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
 {
   return
-    const_cast<nsCSSGroupRule*>(this)->mRules.EnumerateForwards(aFunc, aData);
+    const_cast<GroupRule*>(this)->mRules.EnumerateForwards(aFunc, aData);
 }
 
 /*
  * The next two methods (DeleteStyleRuleAt and InsertStyleRulesAt)
  * should never be called unless you have first called WillDirty() on
  * the parents tylesheet.  After they are called, DidDirty() needs to
  * be called on the sheet
  */
 NS_IMETHODIMP
-nsCSSGroupRule::DeleteStyleRuleAt(PRUint32 aIndex)
+GroupRule::DeleteStyleRuleAt(PRUint32 aIndex)
 {
   nsICSSRule* rule = mRules.SafeObjectAt(aIndex);
   if (rule) {
     rule->SetStyleSheet(nsnull);
     rule->SetParentRule(nsnull);
   }
   return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
 }
 
 NS_IMETHODIMP
-nsCSSGroupRule::InsertStyleRulesAt(PRUint32 aIndex,
-                                   nsCOMArray<nsICSSRule>& aRules)
+GroupRule::InsertStyleRulesAt(PRUint32 aIndex,
+                              nsCOMArray<nsICSSRule>& aRules)
 {
   aRules.EnumerateForwards(SetStyleSheetReference, mSheet);
   aRules.EnumerateForwards(SetParentRuleReference, this);
   if (! mRules.InsertObjectsAt(aRules, aIndex)) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsCSSGroupRule::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
+GroupRule::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
 {
   PRInt32 index = mRules.IndexOf(aOld);
   NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
   mRules.ReplaceObjectAt(aNew, index);
   aNew->SetStyleSheet(mSheet);
   aNew->SetParentRule(this);
   aOld->SetStyleSheet(nsnull);
   aOld->SetParentRule(nsnull);
   return NS_OK;
 }
 
 nsresult
-nsCSSGroupRule::AppendRulesToCssText(nsAString& aCssText)
+GroupRule::AppendRulesToCssText(nsAString& aCssText)
 {
   aCssText.AppendLiteral(" {\n");
 
   // get all the rules
   for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
     nsICSSRule* rule = mRules.ObjectAt(index);
     nsCOMPtr<nsIDOMCSSRule> domRule;
     rule->GetDOMRule(getter_AddRefs(domRule));
@@ -747,81 +750,84 @@ nsCSSGroupRule::AppendRulesToCssText(nsA
   }
 
   aCssText.AppendLiteral("}");
   
   return NS_OK;
 }
 
 nsresult
-nsCSSGroupRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
+GroupRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
 {
   NS_IF_ADDREF(*aSheet = mSheet);
   return NS_OK;
 }
 
 nsresult
-nsCSSGroupRule::GetParentRule(nsIDOMCSSRule** aParentRule)
+GroupRule::GetParentRule(nsIDOMCSSRule** aParentRule)
 {
   if (mParentRule) {
     return mParentRule->GetDOMRule(aParentRule);
   }
   *aParentRule = nsnull;
   return NS_OK;
 }
 
 // nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods
 nsresult
-nsCSSGroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
+GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
 {
   if (!mRuleCollection) {
     mRuleCollection = new css::GroupRuleRuleList(this);
   }
 
   NS_ADDREF(*aRuleList = mRuleCollection);
   return NS_OK;
 }
 
 nsresult
-nsCSSGroupRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
+GroupRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
 {
   NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
   
   if (aIndex > PRUint32(mRules.Count()))
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
   NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
                "Too many style rules!");
 
   return mSheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval);
 }
 
 nsresult
-nsCSSGroupRule::DeleteRule(PRUint32 aIndex)
+GroupRule::DeleteRule(PRUint32 aIndex)
 {
   NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
 
   if (aIndex >= PRUint32(mRules.Count()))
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
   NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
                "Too many style rules!");
 
   return mSheet->DeleteRuleFromGroup(this, aIndex);
 }
 
+} // namespace css
+} // namespace mozilla
+
 // -------------------------------------------
 // nsICSSMediaRule
 //
 nsCSSMediaRule::nsCSSMediaRule()
 {
 }
 
 nsCSSMediaRule::nsCSSMediaRule(const nsCSSMediaRule& aCopy)
-  : nsCSSGroupRule(aCopy)
+  : GroupRule(aCopy)
 {
   if (aCopy.mMedia) {
     aCopy.mMedia->Clone(getter_AddRefs(mMedia));
     if (mMedia) {
       // XXXldb This doesn't really make sense.
       mMedia->SetStyleSheet(aCopy.mSheet);
     }
   }
@@ -829,42 +835,41 @@ nsCSSMediaRule::nsCSSMediaRule(const nsC
 
 nsCSSMediaRule::~nsCSSMediaRule()
 {
   if (mMedia) {
     mMedia->SetStyleSheet(nsnull);
   }
 }
 
-NS_IMPL_ADDREF_INHERITED(nsCSSMediaRule, nsCSSGroupRule)
-NS_IMPL_RELEASE_INHERITED(nsCSSMediaRule, nsCSSGroupRule)
+NS_IMPL_ADDREF_INHERITED(nsCSSMediaRule, GroupRule)
+NS_IMPL_RELEASE_INHERITED(nsCSSMediaRule, GroupRule)
 
 DOMCI_DATA(CSSMediaRule, nsCSSMediaRule)
 
 // QueryInterface implementation for nsCSSMediaRule
 NS_INTERFACE_MAP_BEGIN(nsCSSMediaRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSGroupRule)
   NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsCSSGroupRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
 NS_INTERFACE_MAP_END
 
 /* virtual */ void
 nsCSSMediaRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   if (mMedia) {
     // Set to null so it knows it's leaving one sheet and joining another.
     mMedia->SetStyleSheet(nsnull);
     mMedia->SetStyleSheet(aSheet);
   }
 
-  nsCSSGroupRule::SetStyleSheet(aSheet);
+  GroupRule::SetStyleSheet(aSheet);
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsCSSMediaRule::List(FILE* out, PRInt32 aIndent) const
 {
   for (PRInt32 indent = aIndent; --indent >= 0; ) fputs("  ", out);
 
@@ -873,17 +878,17 @@ nsCSSMediaRule::List(FILE* out, PRInt32 
   fputs("@media ", out);
 
   if (mMedia) {
     nsAutoString mediaText;
     mMedia->GetText(mediaText);
     fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
   }
 
-  nsCSSGroupRule::List(out, aIndent);
+  GroupRule::List(out, aIndent);
 }
 #endif
 
 /* virtual */ PRInt32
 nsCSSMediaRule::GetType() const
 {
   return nsICSSRule::MEDIA_RULE;
 }
@@ -918,103 +923,102 @@ nsCSSMediaRule::GetCssText(nsAString& aC
   aCssText.AssignLiteral("@media ");
   // get all the media
   if (mMedia) {
     nsAutoString mediaText;
     mMedia->GetText(mediaText);
     aCssText.Append(mediaText);
   }
 
-  return nsCSSGroupRule::AppendRulesToCssText(aCssText);
+  return GroupRule::AppendRulesToCssText(aCssText);
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::SetCssText(const nsAString& aCssText)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
 {
-  return nsCSSGroupRule::GetParentStyleSheet(aSheet);
+  return GroupRule::GetParentStyleSheet(aSheet);
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::GetParentRule(nsIDOMCSSRule** aParentRule)
 {
-  return nsCSSGroupRule::GetParentRule(aParentRule);
+  return GroupRule::GetParentRule(aParentRule);
 }
 
 // nsIDOMCSSMediaRule methods
 NS_IMETHODIMP
 nsCSSMediaRule::GetMedia(nsIDOMMediaList* *aMedia)
 {
   NS_ENSURE_ARG_POINTER(aMedia);
   NS_IF_ADDREF(*aMedia = mMedia);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
 {
-  return nsCSSGroupRule::GetCssRules(aRuleList);
+  return GroupRule::GetCssRules(aRuleList);
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
 {
-  return nsCSSGroupRule::InsertRule(aRule, aIndex, _retval);
+  return GroupRule::InsertRule(aRule, aIndex, _retval);
 }
 
 NS_IMETHODIMP
 nsCSSMediaRule::DeleteRule(PRUint32 aIndex)
 {
-  return nsCSSGroupRule::DeleteRule(aIndex);
+  return GroupRule::DeleteRule(aIndex);
 }
 
-// nsICSSGroupRule interface
+// GroupRule interface
 NS_IMETHODIMP_(PRBool)
 nsCSSMediaRule::UseForPresentation(nsPresContext* aPresContext,
                                    nsMediaQueryResultCacheKey& aKey)
 {
   if (mMedia) {
     return mMedia->Matches(aPresContext, aKey);
   }
   return PR_TRUE;
 }
 
 
 nsCSSDocumentRule::nsCSSDocumentRule(void)
 {
 }
 
 nsCSSDocumentRule::nsCSSDocumentRule(const nsCSSDocumentRule& aCopy)
-  : nsCSSGroupRule(aCopy)
+  : GroupRule(aCopy)
   , mURLs(new URL(*aCopy.mURLs))
 {
 }
 
 nsCSSDocumentRule::~nsCSSDocumentRule(void)
 {
 }
 
-NS_IMPL_ADDREF_INHERITED(nsCSSDocumentRule, nsCSSGroupRule)
-NS_IMPL_RELEASE_INHERITED(nsCSSDocumentRule, nsCSSGroupRule)
+NS_IMPL_ADDREF_INHERITED(nsCSSDocumentRule, GroupRule)
+NS_IMPL_RELEASE_INHERITED(nsCSSDocumentRule, GroupRule)
 
 DOMCI_DATA(CSSMozDocumentRule, nsCSSDocumentRule)
 
 // QueryInterface implementation for nsCSSDocumentRule
 NS_INTERFACE_MAP_BEGIN(nsCSSDocumentRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSGroupRule)
   NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsCSSGroupRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
 NS_INTERFACE_MAP_END
 
 #ifdef DEBUG
 /* virtual */ void
 nsCSSDocumentRule::List(FILE* out, PRInt32 aIndent) const
 {
   for (PRInt32 indent = aIndent; --indent >= 0; ) fputs("  ", out);
@@ -1036,17 +1040,17 @@ nsCSSDocumentRule::List(FILE* out, PRInt
     nsCAutoString escapedURL(url->url);
     escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
     str.Append(escapedURL);
     str.AppendLiteral("\"), ");
   }
   str.Cut(str.Length() - 2, 1); // remove last ,
   fputs(str.get(), out);
 
-  nsCSSGroupRule::List(out, aIndent);
+  GroupRule::List(out, aIndent);
 }
 #endif
 
 /* virtual */ PRInt32
 nsCSSDocumentRule::GetType() const
 {
   return nsICSSRule::DOCUMENT_RULE;
 }
@@ -1084,56 +1088,56 @@ nsCSSDocumentRule::GetCssText(nsAString&
         break;
     }
     nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(url->url),
                                         aCssText);
     aCssText.AppendLiteral("), ");
   }
   aCssText.Cut(aCssText.Length() - 2, 1); // remove last ,
 
-  return nsCSSGroupRule::AppendRulesToCssText(aCssText);
+  return GroupRule::AppendRulesToCssText(aCssText);
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::SetCssText(const nsAString& aCssText)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
 {
-  return nsCSSGroupRule::GetParentStyleSheet(aSheet);
+  return GroupRule::GetParentStyleSheet(aSheet);
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule)
 {
-  return nsCSSGroupRule::GetParentRule(aParentRule);
+  return GroupRule::GetParentRule(aParentRule);
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
 {
-  return nsCSSGroupRule::GetCssRules(aRuleList);
+  return GroupRule::GetCssRules(aRuleList);
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
 {
-  return nsCSSGroupRule::InsertRule(aRule, aIndex, _retval);
+  return GroupRule::InsertRule(aRule, aIndex, _retval);
 }
 
 NS_IMETHODIMP
 nsCSSDocumentRule::DeleteRule(PRUint32 aIndex)
 {
-  return nsCSSGroupRule::DeleteRule(aIndex);
+  return GroupRule::DeleteRule(aIndex);
 }
 
-// nsICSSGroupRule interface
+// GroupRule interface
 NS_IMETHODIMP_(PRBool)
 nsCSSDocumentRule::UseForPresentation(nsPresContext* aPresContext,
                                       nsMediaQueryResultCacheKey& aKey)
 {
   nsIURI *docURI = aPresContext->Document()->GetDocumentURI();
   nsCAutoString docURISpec;
   if (docURI)
     docURI->GetSpec(docURISpec);
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -39,141 +39,70 @@
  * ***** END LICENSE BLOCK ***** */
 
 /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
 
 #ifndef nsCSSRules_h_
 #define nsCSSRules_h_
 
 #include "nsCSSRule.h"
-#include "nsICSSGroupRule.h"
+#include "mozilla/css/GroupRule.h"
 #include "nsIDOMCSSMediaRule.h"
 #include "nsIDOMCSSMozDocumentRule.h"
 #include "nsIDOMCSSFontFaceRule.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsAutoPtr.h"
 #include "nsCSSProperty.h"
 #include "nsCSSValue.h"
 
 class nsMediaList;
-template<class T> struct already_AddRefed;
 
-namespace mozilla {
-namespace css {
-class GroupRuleRuleList;
-}
-}
-
-#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
-virtual already_AddRefed<nsIStyleSheet> GetStyleSheet() const; \
-virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); \
-virtual void SetParentRule(nsICSSGroupRule* aRule); \
-virtual void MapRuleInfoInto(nsRuleData* aRuleData);
-
-#define DECL_STYLE_RULE_INHERIT  \
-DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
-nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
-
-// inherits from nsCSSRule and also implements methods on nsICSSGroupRule
-// so they can be shared between nsCSSMediaRule and nsCSSDocumentRule
-class nsCSSGroupRule : public nsCSSRule, public nsICSSGroupRule
-{
-protected:
-  nsCSSGroupRule();
-  nsCSSGroupRule(const nsCSSGroupRule& aCopy);
-  virtual ~nsCSSGroupRule();
-
-  // Implement part of nsISupports.
-  NS_IMETHOD_(nsrefcnt) AddRef();
-  NS_IMETHOD_(nsrefcnt) Release();
-protected:
-  nsAutoRefCnt mRefCnt;
-  NS_DECL_OWNINGTHREAD
-public:
-
-  // implement part of nsIStyleRule and nsICSSRule
-  DECL_STYLE_RULE_INHERIT_NO_DOMRULE
-
-  // to help implement nsIStyleRule
-#ifdef DEBUG
-  virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
-#endif
-
-public:
-  // implement nsICSSGroupRule
-  NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
-  NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
-  NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
-  NS_IMETHOD_(PRBool) EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
-  NS_IMETHOD DeleteStyleRuleAt(PRUint32 aIndex);
-  NS_IMETHOD InsertStyleRulesAt(PRUint32 aIndex,
-                                nsCOMArray<nsICSSRule>& aRules);
-  NS_IMETHOD ReplaceStyleRule(nsICSSRule *aOld, nsICSSRule *aNew);
-
-protected:
-  // to help implement nsIDOMCSSRule
-  nsresult AppendRulesToCssText(nsAString& aCssText);
-  // to implement methods on nsIDOMCSSRule
-  nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
-  nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
-
-  // to implement common methods on nsIDOMCSSMediaRule and
-  // nsIDOMCSSMozDocumentRule
-  nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
-  nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
-                      PRUint32* _retval);
-  nsresult DeleteRule(PRUint32 aIndex);
-
-  nsCOMArray<nsICSSRule> mRules;
-  nsRefPtr<mozilla::css::GroupRuleRuleList> mRuleCollection; // lazily constructed
-};
-
-class NS_FINAL_CLASS nsCSSMediaRule : public nsCSSGroupRule,
+class NS_FINAL_CLASS nsCSSMediaRule : public mozilla::css::GroupRule,
                                       public nsIDOMCSSMediaRule
 {
 public:
   nsCSSMediaRule();
   nsCSSMediaRule(const nsCSSMediaRule& aCopy);
   virtual ~nsCSSMediaRule();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
   // nsICSSRule methods
-  virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); //override nsCSSGroupRule
+  virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); //override GroupRule
   virtual PRInt32 GetType() const;
   virtual already_AddRefed<nsICSSRule> Clone() const;
   nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
   {
     *aResult = NS_OK;
     return this;
   }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSMediaRule interface
   NS_DECL_NSIDOMCSSMEDIARULE
 
-  // rest of nsICSSGroupRule interface
+  // rest of GroupRule
   NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext,
                                          nsMediaQueryResultCacheKey& aKey);
 
   // @media rule methods
   nsresult SetMedia(nsMediaList* aMedia);
   
 protected:
   nsRefPtr<nsMediaList> mMedia;
 };
 
-class NS_FINAL_CLASS nsCSSDocumentRule : public nsCSSGroupRule,
+class NS_FINAL_CLASS nsCSSDocumentRule : public mozilla::css::GroupRule,
                                          public nsIDOMCSSMozDocumentRule
 {
 public:
   nsCSSDocumentRule(void);
   nsCSSDocumentRule(const nsCSSDocumentRule& aCopy);
   virtual ~nsCSSDocumentRule(void);
 
   NS_DECL_ISUPPORTS_INHERITED
@@ -193,17 +122,17 @@ public:
   }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSMozDocumentRule interface
   NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
 
-  // rest of nsICSSGroupRule interface
+  // rest of GroupRule
   NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext,
                                          nsMediaQueryResultCacheKey& aKey);
 
   enum Function {
     eURL,
     eURLPrefix,
     eDomain
   };
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -42,17 +42,17 @@
 /* representation of a CSS style sheet */
 
 #include "nsCSSStyleSheet.h"
 
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "nsCSSRuleProcessor.h"
 #include "mozilla/css/NameSpaceRule.h"
-#include "nsICSSGroupRule.h"
+#include "mozilla/css/GroupRule.h"
 #include "mozilla/css/ImportRule.h"
 #include "nsIMediaList.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsIDOMCSSStyleSheet.h"
@@ -1929,17 +1929,17 @@ nsCSSStyleSheet::DeleteRule(PRUint32 aIn
       }
     }
   }
 
   return result;
 }
 
 nsresult
-nsCSSStyleSheet::DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex)
+nsCSSStyleSheet::DeleteRuleFromGroup(css::GroupRule* aGroup, PRUint32 aIndex)
 {
   NS_ENSURE_ARG_POINTER(aGroup);
   NS_ASSERTION(mInner->mComplete, "No deleting from an incomplete sheet!");
   nsresult result;
   nsCOMPtr<nsICSSRule> rule;
   result = aGroup->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
   NS_ENSURE_SUCCESS(result, result);
   
@@ -1965,17 +1965,17 @@ nsCSSStyleSheet::DeleteRuleFromGroup(nsI
     mDocument->StyleRuleRemoved(this, rule);
   }
 
   return NS_OK;
 }
 
 nsresult
 nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
-                                     nsICSSGroupRule* aGroup,
+                                     css::GroupRule* aGroup,
                                      PRUint32 aIndex,
                                      PRUint32* _retval)
 {
   nsresult result;
   NS_ASSERTION(mInner->mComplete, "No inserting into an incomplete sheet!");
   // check that the group actually belongs to this sheet!
   nsCOMPtr<nsIStyleSheet> groupSheet = aGroup->GetStyleSheet();
   if (this != groupSheet) {
@@ -2038,17 +2038,17 @@ nsCSSStyleSheet::InsertRuleIntoGroup(con
     }
   }
 
   *_retval = aIndex;
   return NS_OK;
 }
 
 nsresult
-nsCSSStyleSheet::ReplaceRuleInGroup(nsICSSGroupRule* aGroup,
+nsCSSStyleSheet::ReplaceRuleInGroup(css::GroupRule* aGroup,
                                     nsICSSRule* aOld, nsICSSRule* aNew)
 {
   nsresult result;
   NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
 #ifdef DEBUG
   {
     nsCOMPtr<nsIStyleSheet> groupSheet = aGroup->GetStyleSheet();
     NS_ASSERTION(this == groupSheet, "group doesn't belong to this sheet");
--- a/layout/style/nsCSSStyleSheet.h
+++ b/layout/style/nsCSSStyleSheet.h
@@ -51,27 +51,27 @@
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsCOMArray.h"
 
 class nsICSSRule;
 class nsXMLNameSpaceMap;
 class nsCSSRuleProcessor;
 class nsMediaList;
-class nsICSSGroupRule;
 class nsIPrincipal;
 class nsIURI;
 class nsMediaList;
 class nsMediaQueryResultCacheKey;
 class nsCSSStyleSheet;
 class nsPresContext;
 template<class E, class A> class nsTArray;
 
 namespace mozilla {
 namespace css {
+class GroupRule;
 class ImportRule;
 }
 }
 
 // -------------------------------
 // CSS Style Sheet Inner Data Container
 //
 
@@ -167,19 +167,19 @@ public:
   // XXX do these belong here or are they generic?
   void PrependStyleRule(nsICSSRule* aRule);
   void AppendStyleRule(nsICSSRule* aRule);
   void ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
 
   PRInt32 StyleRuleCount() const;
   nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
 
-  nsresult DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
-  nsresult InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
-  nsresult ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
+  nsresult DeleteRuleFromGroup(mozilla::css::GroupRule* aGroup, PRUint32 aIndex);
+  nsresult InsertRuleIntoGroup(const nsAString& aRule, mozilla::css::GroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
+  nsresult ReplaceRuleInGroup(mozilla::css::GroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
 
   PRInt32 StyleSheetCount() const;
 
   /**
    * SetURIs must be called on all sheets before parsing into them.
    * SetURIs may only be called while the sheet is 1) incomplete and 2)
    * has no rules in it
    */
--- a/layout/style/nsICSSRule.h
+++ b/layout/style/nsICSSRule.h
@@ -39,25 +39,30 @@
 
 #ifndef nsICSSRule_h
 #define nsICSSRule_h
 
 #include "nsIStyleRule.h"
 #include "nsIDOMCSSRule.h"
 
 class nsCSSStyleSheet;
-class nsICSSGroupRule;
 class nsAString;
 template<class T> struct already_AddRefed;
 class nsIStyleSheet;
 
+namespace mozilla {
+namespace css {
+class GroupRule;
+}
+}
+
 // IID for the nsICSSRule interface
-#define NS_ICSS_RULE_IID \
-{ 0x1f560b20, 0xa829, 0x4b99, \
-  { 0x87, 0xbd, 0x8c, 0x87, 0x95, 0x2b, 0x3b, 0xb6 } }
+#define NS_ICSS_RULE_IID     \
+{ 0x471d733e, 0xc138, 0x4a50, \
+ { 0x9e, 0x1a, 0xd1, 0x3c, 0xbb, 0x65, 0xb5, 0x26 } }
 
 
 // inheriting from nsIStyleRule is only for style rules, not other rule types
 class nsICSSRule : public nsIStyleRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_RULE_IID)
   // The constants in this list must maintain the following invariants:
   //   If a rule of type N must appear before a rule of type M in stylesheets
@@ -75,17 +80,17 @@ public:
     PAGE_RULE,
     DOCUMENT_RULE
   };
 
   virtual PRInt32 GetType() const = 0;
 
   virtual already_AddRefed<nsIStyleSheet> GetStyleSheet() const = 0;
   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet) = 0;
-  virtual void SetParentRule(nsICSSGroupRule* aRule) = 0;
+  virtual void SetParentRule(mozilla::css::GroupRule* aRule) = 0;
 
   /**
    * Clones |this|. Never returns NULL.
    */
   virtual already_AddRefed<nsICSSRule> Clone() const = 0;
 
   // Note that this returns null for inline style rules since they aren't
   // supposed to have a DOM rule representation (and our code wouldn't work).