Bug 648925 - Part 1: Change uses of nsICSSRule to css::Rule. r=bzbarsky
authorCraig Topper <craig.topper@gmail.com>
Thu, 07 Apr 2011 18:23:46 -0700
changeset 69440 6140c532052523d208530f597c499dca136aac62
parent 69439 fde4fa1ec72639e71b9e1ee6c2bb9a5d9eb03ad6
child 69441 750d39ddb81f1a0b0385e253705dbe1049fbbb4b
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs648925
milestone6.0a1
Bug 648925 - Part 1: Change uses of nsICSSRule to css::Rule. r=bzbarsky
content/html/content/src/nsGenericHTMLElement.cpp
content/html/document/src/nsHTMLFragmentContentSink.cpp
content/xul/content/src/nsXULElement.cpp
dom/base/nsDOMClassInfo.cpp
layout/mathml/nsMathMLFrame.cpp
layout/style/GroupRule.h
layout/style/ImportRule.h
layout/style/Makefile.in
layout/style/NameSpaceRule.h
layout/style/Rule.h
layout/style/StyleRule.cpp
layout/style/StyleRule.h
layout/style/nsAnimationManager.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSParser.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRules.cpp
layout/style/nsCSSRules.h
layout/style/nsCSSStyleSheet.cpp
layout/style/nsCSSStyleSheet.h
layout/style/nsDOMCSSDeclaration.cpp
layout/style/nsDOMCSSDeclaration.h
layout/style/nsFontFaceLoader.cpp
layout/style/nsICSSRule.h
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -310,18 +310,18 @@ nsGenericHTMLElement::CopyInnerTo(nsGene
   PRInt32 i, count = GetAttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
     const nsAttrValue *value = mAttrsAndChildren.AttrAt(i);
     if (name->Equals(nsGkAtoms::style, kNameSpaceID_None) &&
         value->Type() == nsAttrValue::eCSSStyleRule) {
       // We can't just set this as a string, because that will fail
       // to reparse the string into style data until the node is
-      // inserted into the document.  Clone the nsICSSRule instead.
-      nsCOMPtr<nsICSSRule> ruleClone = value->GetCSSStyleRuleValue()->Clone();
+      // inserted into the document.  Clone the Rule instead.
+      nsRefPtr<mozilla::css::Rule> ruleClone = value->GetCSSStyleRuleValue()->Clone();
       nsRefPtr<mozilla::css::StyleRule> styleRule = do_QueryObject(ruleClone);
       NS_ENSURE_TRUE(styleRule, NS_ERROR_UNEXPECTED);
 
       rv = aDst->SetInlineStyleRule(styleRule, PR_FALSE);
       NS_ENSURE_SUCCESS(rv, rv);
 
       continue;
     }
--- a/content/html/document/src/nsHTMLFragmentContentSink.cpp
+++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp
@@ -1175,40 +1175,40 @@ nsHTMLParanoidFragmentSink::CloseContain
             NS_ABORT_IF_FALSE(!sheet->IsModified(),
                               "should not get marked modified during parsing");
             sheet->SetComplete();
           }
           if (NS_SUCCEEDED(rv)) {
             // Loop through all the rules found in the CSS text
             PRInt32 ruleCount = sheet->StyleRuleCount();
             for (PRInt32 i = 0; i < ruleCount; ++i) {
-              nsRefPtr<nsICSSRule> rule;
+              nsRefPtr<css::Rule> rule;
               rv = sheet->GetStyleRuleAt(i, *getter_AddRefs(rule));
               if (NS_FAILED(rv))
                 continue;
               NS_ASSERTION(rule, "We should have a rule by now");
               switch (rule->GetType()) {
                 default:
                   didSanitize = PR_TRUE;
                   // Ignore these rule types.
                   break;
-                case nsICSSRule::NAMESPACE_RULE:
-                case nsICSSRule::FONT_FACE_RULE: {
+                case css::Rule::NAMESPACE_RULE:
+                case css::Rule::FONT_FACE_RULE: {
                   // Append @namespace and @font-face rules verbatim.
                   nsAutoString cssText;
                   nsCOMPtr<nsIDOMCSSRule> styleRule = do_QueryInterface(rule);
                   if (styleRule) {
                     rv = styleRule->GetCssText(cssText);
                     if (NS_SUCCEEDED(rv)) {
                       sanitizedStyleText.Append(cssText);
                     }
                   }
                   break;
                 }
-                case nsICSSRule::STYLE_RULE: {
+                case css::Rule::STYLE_RULE: {
                   // For style rules, we will just look for and remove the
                   // -moz-binding properties.
                   nsRefPtr<css::StyleRule> styleRule = do_QueryObject(rule);
                   NS_ASSERTION(styleRule, "Must be a style rule");
                   nsAutoString decl;
                   didSanitize = SanitizeStyleRule(styleRule, decl) || didSanitize;
                   styleRule->GetCssText(decl);
                   sanitizedStyleText.Append(decl);
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -1955,17 +1955,17 @@ nsXULElement::EnsureLocalStyle()
 {
     // Clone the prototype rule, if we don't have a local one.
     if (mPrototype &&
         !mAttrsAndChildren.GetAttr(nsGkAtoms::style, kNameSpaceID_None)) {
 
         nsXULPrototypeAttribute *protoattr =
                   FindPrototypeAttribute(kNameSpaceID_None, nsGkAtoms::style);
         if (protoattr && protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
-            nsCOMPtr<nsICSSRule> ruleClone =
+            nsRefPtr<css::Rule> ruleClone =
                 protoattr->mValue.GetCSSStyleRuleValue()->Clone();
 
             nsString stringValue;
             protoattr->mValue.ToString(stringValue);
 
             nsAttrValue value;
             nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
             value.SetTo(styleRule, &stringValue);
@@ -2334,17 +2334,17 @@ nsresult nsXULElement::MakeHeavyweight()
                                       protoattr->mName.NamespaceID())) {
             continue;
         }
 
         nsAttrValue attrValue;
         
         // Style rules need to be cloned.
         if (protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
-            nsCOMPtr<nsICSSRule> ruleClone =
+            nsRefPtr<css::Rule> ruleClone =
                 protoattr->mValue.GetCSSStyleRuleValue()->Clone();
 
             nsString stringValue;
             protoattr->mValue.ToString(stringValue);
 
             nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
             attrValue.SetTo(styleRule, &stringValue);
         }
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -174,17 +174,16 @@
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMNSEventTarget.h"
 
 // CSS related includes
 #include "nsIDOMStyleSheet.h"
 #include "nsIDOMStyleSheetList.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsIDOMCSSRule.h"
-#include "nsICSSRule.h"
 #include "nsICSSRuleList.h"
 #include "nsIDOMRect.h"
 #include "nsIDOMRGBColor.h"
 #include "nsIDOMNSRGBAColor.h"
 #include "nsDOMCSSAttrDeclaration.h"
 
 // XBL related includes.
 #include "nsIXBLService.h"
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -37,31 +37,19 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsINameSpaceManager.h"
 #include "nsMathMLFrame.h"
 #include "nsMathMLChar.h"
 #include "nsCSSPseudoElements.h"
 
 // used to map attributes into CSS rules
-#include "nsIDocument.h"
 #include "nsStyleSet.h"
-#include "nsIStyleSheet.h"
-#include "nsIDOMCSSStyleSheet.h"
-#include "nsICSSRule.h"
-#include "nsStyleChangeList.h"
-#include "nsFrameManager.h"
-#include "nsNetUtil.h"
-#include "nsIURI.h"
-#include "nsContentCID.h"
 #include "nsAutoPtr.h"
-#include "nsStyleSet.h"
-#include "nsStyleUtil.h"
 #include "nsDisplayList.h"
-#include "nsAttrName.h"
 #include "nsRenderingContext.h"
 
 eMathMLFrameType
 nsMathMLFrame::GetMathMLFrameType()
 {
   // see if it is an embellished operator (mapped to 'Op' in TeX)
   if (mEmbellishData.coreFrame)
     return GetMathMLFrameTypeFor(mEmbellishData.coreFrame);
--- a/layout/style/GroupRule.h
+++ b/layout/style/GroupRule.h
@@ -38,17 +38,17 @@
 /*
  * internal interface representing CSS style rules that contain other
  * rules, such as @media rules
  */
 
 #ifndef mozilla_css_GroupRule_h__
 #define mozilla_css_GroupRule_h__
 
-#include "Rule.h"
+#include "mozilla/css/Rule.h"
 #include "nsCOMArray.h"
 #include "nsAutoPtr.h"
 
 class nsPresContext;
 class nsMediaQueryResultCacheKey;
 
 namespace mozilla {
 namespace css {
@@ -60,43 +60,43 @@ class GroupRuleRuleList;
 class GroupRule : public Rule
 {
 protected:
   GroupRule();
   GroupRule(const GroupRule& aCopy);
   virtual ~GroupRule();
 public:
 
-  // implement part of nsIStyleRule and nsICSSRule
+  // implement part of nsIStyleRule and Rule
   DECL_STYLE_RULE_INHERIT_NO_DOMRULE
   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
 
   // to help implement nsIStyleRule
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
 public:
-  void AppendStyleRule(nsICSSRule* aRule);
+  void AppendStyleRule(Rule* aRule);
 
   PRInt32 StyleRuleCount() const { return mRules.Count(); }
-  nsICSSRule* GetStyleRuleAt(PRInt32 aIndex) const;
+  Rule* GetStyleRuleAt(PRInt32 aIndex) const;
 
-  typedef nsCOMArray<nsICSSRule>::nsCOMArrayEnumFunc RuleEnumFunc;
+  typedef nsCOMArray<Rule>::nsCOMArrayEnumFunc RuleEnumFunc;
   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.
    */
   nsresult DeleteStyleRuleAt(PRUint32 aIndex);
   nsresult InsertStyleRulesAt(PRUint32 aIndex,
-                              nsCOMArray<nsICSSRule>& aRules);
-  nsresult ReplaceStyleRule(nsICSSRule *aOld, nsICSSRule *aNew);
+                              nsCOMArray<Rule>& aRules);
+  nsresult ReplaceStyleRule(Rule *aOld, Rule *aNew);
 
   virtual PRBool UseForPresentation(nsPresContext* aPresContext,
                                     nsMediaQueryResultCacheKey& aKey) = 0;
 
 protected:
   // to help implement nsIDOMCSSRule
   nsresult AppendRulesToCssText(nsAString& aCssText);
   // to implement methods on nsIDOMCSSRule
@@ -104,16 +104,16 @@ protected:
 
   // to implement common methods on nsIDOMCSSMediaRule and
   // nsIDOMCSSMozDocumentRule
   nsIDOMCSSRuleList* GetCssRules();
   nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
                       PRUint32* _retval);
   nsresult DeleteRule(PRUint32 aIndex);
 
-  nsCOMArray<nsICSSRule> mRules;
+  nsCOMArray<Rule> mRules;
   nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
 };
 
 } // namespace css
 } // namespace mozilla
 
 #endif /* mozilla_css_GroupRule_h__ */
--- a/layout/style/ImportRule.h
+++ b/layout/style/ImportRule.h
@@ -35,17 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* class for CSS @import rules */
 
 #ifndef mozilla_css_ImportRule_h__
 #define mozilla_css_ImportRule_h__
 
-#include "Rule.h"
+#include "mozilla/css/Rule.h"
 #include "nsIDOMCSSImportRule.h"
 #include "nsCSSRules.h"
 
 class nsMediaList;
 class nsString;
 
 namespace mozilla {
 namespace css {
@@ -68,19 +68,19 @@ public:
   using Rule::GetStyleSheet; // unhide since nsIDOMCSSImportRule has its own GetStyleSheet
 #endif
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
 
   void SetSheet(nsCSSStyleSheet*);
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSImportRule interface
   NS_DECL_NSIDOMCSSIMPORTRULE
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -70,17 +70,16 @@ EXPORTS		= \
 		nsCSSStyleSheet.h \
 		nsCSSValue.h \
 		nsDOMCSSAttrDeclaration.h \
 		nsDOMCSSDeclaration.h \
 		nsDOMMediaQueryList.h \
 		nsICSSDeclaration.h \
 		nsICSSLoaderObserver.h \
 		nsICSSPseudoComparator.h \
-		nsICSSRule.h \
 		nsICSSRuleList.h \
 		nsICSSStyleRuleDOMWrapper.h \
 		nsIStyleRule.h \
 		nsIStyleRuleProcessor.h \
 		nsIStyleSheet.h \
 		nsLayoutStylesheetCache.h \
 		nsRuleData.h \
 		nsRuleNode.h \
@@ -98,16 +97,17 @@ EXPORTS		= \
 		$(NULL)
 
 EXPORTS_mozilla/css = \
 		Declaration.h \
 		GroupRule.h \
 		ImportRule.h \
 		Loader.h \
 		NameSpaceRule.h \
+		Rule.h \
 		StyleRule.h \
 		$(NULL)
 
 CPPSRCS		= \
 		AnimationCommon.cpp \
 		nsCSSAnonBoxes.cpp \
 		nsCSSDataBlock.cpp \
 		Declaration.cpp \
--- a/layout/style/NameSpaceRule.h
+++ b/layout/style/NameSpaceRule.h
@@ -35,22 +35,22 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* class for CSS @namespace rules */
 
 #ifndef mozilla_css_NameSpaceRule_h__
 #define mozilla_css_NameSpaceRule_h__
 
-#include "Rule.h"
+#include "mozilla/css/Rule.h"
 #include "nsIDOMCSSRule.h"
 
 class nsIAtom;
 
-// IID for the nsCSSNameSpaceRule class {f0b0dbe1-5031-4a21-b06a-dc141ef2af98}
+// IID for the NameSpaceRule class {f0b0dbe1-5031-4a21-b06a-dc141ef2af98}
 #define NS_CSS_NAMESPACE_RULE_IMPL_CID     \
 {0xf0b0dbe1, 0x5031, 0x4a21, {0xb0, 0x6a, 0xdc, 0x14, 0x1e, 0xf2, 0xaf, 0x98}}
 
 
 namespace mozilla {
 namespace css {
 
 class NS_FINAL_CLASS NameSpaceRule : public Rule,
@@ -69,19 +69,19 @@ public:
 
   DECL_STYLE_RULE_INHERIT
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
 
   nsIAtom* GetPrefix() const { return mPrefix; }
 
   void GetURLSpec(nsString& aURLSpec) const { aURLSpec = mURLSpec; }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
--- a/layout/style/Rule.h
+++ b/layout/style/Rule.h
@@ -35,17 +35,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* base class for all rule types in a CSS style sheet */
 
 #ifndef mozilla_css_Rule_h___
 #define mozilla_css_Rule_h___
 
-#include "nsICSSRule.h"
+#include "nsIStyleRule.h"
+#include "nsIDOMCSSRule.h"
 
 class nsIStyleSheet;
 class nsCSSStyleSheet;
 struct nsRuleData;
 template<class T> struct already_AddRefed;
 
 namespace mozilla {
 namespace css {
@@ -53,17 +54,17 @@ class GroupRule;
 
 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
 virtual void MapRuleInfoInto(nsRuleData* aRuleData);
 
 #define DECL_STYLE_RULE_INHERIT  \
 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
 virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
 
-class Rule : public nsICSSRule {
+class Rule : public nsIStyleRule {
 protected:
   Rule()
     : mSheet(nsnull),
       mParentRule(nsnull)
   {
   }
 
   Rule(const Rule& aCopy)
@@ -78,20 +79,57 @@ public:
   // for implementing nsISupports
   NS_IMETHOD_(nsrefcnt) AddRef();
   NS_IMETHOD_(nsrefcnt) Release();
 protected:
   nsAutoRefCnt mRefCnt;
   NS_DECL_OWNINGTHREAD
 public:
 
+  // 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
+  //   then N < M
+  // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
+  // rules can come between two rules of type IMPORT_RULE.
+  enum {
+    UNKNOWN_RULE = 0,
+    CHARSET_RULE,
+    IMPORT_RULE,
+    NAMESPACE_RULE,
+    STYLE_RULE,
+    MEDIA_RULE,
+    FONT_FACE_RULE,
+    PAGE_RULE,
+#ifdef MOZ_CSS_ANIMATIONS
+    KEYFRAME_RULE,
+    KEYFRAMES_RULE,
+#endif
+    DOCUMENT_RULE
+  };
+
+  virtual PRInt32 GetType() const = 0;
+
   virtual nsIStyleSheet* GetStyleSheet() const;
   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
+  virtual void SetParentRule(GroupRule* aRule);
 
-  virtual void SetParentRule(GroupRule* aRule);
+  /**
+   * Clones |this|. Never returns NULL.
+   */
+  virtual already_AddRefed<Rule> 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).
+  nsresult GetDOMRule(nsIDOMCSSRule** aDOMRule)
+  {
+    nsresult rv;
+    NS_IF_ADDREF(*aDOMRule = GetDOMRuleWeak(&rv));
+    return rv;
+  }
+  virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult) = 0;
 
 protected:
   nsCSSStyleSheet*  mSheet;
   GroupRule*        mParentRule;
 };
 
 } // namespace css
 } // namespace mozilla
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -1301,19 +1301,18 @@ StyleRule::~StyleRule()
 // QueryInterface implementation for StyleRule
 NS_INTERFACE_MAP_BEGIN(StyleRule)
   if (aIID.Equals(NS_GET_IID(mozilla::css::StyleRule))) {
     *aInstancePtr = this;
     NS_ADDREF_THIS();
     return NS_OK;
   }
   else
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF_INHERITED(StyleRule, Rule)
 NS_IMPL_RELEASE_INHERITED(StyleRule, Rule)
 
 nsIStyleRule* StyleRule::GetImportantRule()
 {
   return mImportantRule;
@@ -1331,23 +1330,23 @@ StyleRule::RuleMatched()
       NS_ADDREF(mImportantRule = new ImportantRule(mDeclaration));
     }
   }
 }
 
 /* virtual */ PRInt32
 StyleRule::GetType() const
 {
-  return nsICSSRule::STYLE_RULE;
+  return Rule::STYLE_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 StyleRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new StyleRule(*this);
+  nsRefPtr<Rule> clone = new StyleRule(*this);
   return clone.forget();
 }
 
 nsIDOMCSSRule*
 StyleRule::GetDOMRuleWeak(nsresult *aResult)
 {
   *aResult = NS_OK;
   if (!mSheet) {
--- a/layout/style/StyleRule.h
+++ b/layout/style/StyleRule.h
@@ -41,17 +41,17 @@
  * representation of CSS style rules (selectors+declaration) and CSS
  * selectors
  */
 
 #ifndef mozilla_css_StyleRule_h__
 #define mozilla_css_StyleRule_h__
 
 //#include <stdio.h>
-#include "Rule.h"
+#include "mozilla/css/Rule.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSPseudoClasses.h"
 #include "nsAutoPtr.h"
 
 class nsIAtom;
 class nsCSSStyleSheet;
@@ -343,17 +343,17 @@ public:
   void SetCssText(const nsAString& aCssText);
   nsCSSStyleSheet* GetParentStyleSheet() { return mSheet; }
   GroupRule* GetParentRule() { return mParentRule; }
   void GetSelectorText(nsAString& aSelectorText);
   void SetSelectorText(const nsAString& aSelectorText);
 
   virtual PRInt32 GetType() const;
 
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
 
   nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
 
   // The new mapping function.
   virtual void MapRuleInfoInto(nsRuleData* aRuleData);
 
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -665,19 +665,19 @@ nsAnimationManager::BuildAnimations(nsSt
 
     // Build the set of unique keyframes in the @keyframes rule.  Per
     // css3-animations, later keyframes with the same key replace
     // earlier ones (no cascading).
     nsDataHashtable<PercentageHashKey, nsCSSKeyframeRule*> keyframes;
     keyframes.Init(16); // FIXME: make infallible!
     for (PRUint32 ruleIdx = 0, ruleEnd = rule->StyleRuleCount();
          ruleIdx != ruleEnd; ++ruleIdx) {
-      nsICSSRule* cssRule = rule->GetStyleRuleAt(ruleIdx);
+      css::Rule* cssRule = rule->GetStyleRuleAt(ruleIdx);
       NS_ABORT_IF_FALSE(cssRule, "must have rule");
-      NS_ABORT_IF_FALSE(cssRule->GetType() == nsICSSRule::KEYFRAME_RULE,
+      NS_ABORT_IF_FALSE(cssRule->GetType() == css::Rule::KEYFRAME_RULE,
                         "must be keyframe rule");
       nsCSSKeyframeRule *kfRule = static_cast<nsCSSKeyframeRule*>(cssRule);
 
       const nsTArray<float> &keys = kfRule->GetKeys();
       for (PRUint32 keyIdx = 0, keyEnd = keys.Length();
            keyIdx != keyEnd; ++keyIdx) {
         float key = keys[keyIdx];
         // FIXME (spec):  The spec doesn't say what to do with
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -173,19 +173,19 @@ nsCSSProps::kParserVariantTable[eCSSProp
 #undef CSS_PROP
 };
 
 //----------------------------------------------------------------------
 
 namespace {
 
 // Rule processing function
-typedef void (* RuleAppendFunc) (nsICSSRule* aRule, void* aData);
-static void AppendRuleToArray(nsICSSRule* aRule, void* aArray);
-static void AppendRuleToSheet(nsICSSRule* aRule, void* aParser);
+typedef void (* RuleAppendFunc) (css::Rule* aRule, void* aData);
+static void AppendRuleToArray(css::Rule* aRule, void* aArray);
+static void AppendRuleToSheet(css::Rule* aRule, void* aParser);
 
 // Your basic top-down recursive descent style parser
 // The exposed methods and members of this class are precisely those
 // needed by nsCSSParser, far below.
 class CSSParserImpl {
 public:
   CSSParserImpl();
   ~CSSParserImpl();
@@ -222,17 +222,17 @@ public:
                              nsIPrincipal*     aSheetPrincipal,
                              css::Declaration* aDeclaration,
                              PRBool*           aChanged);
 
   nsresult ParseRule(const nsAString&        aRule,
                      nsIURI*                 aSheetURL,
                      nsIURI*                 aBaseURL,
                      nsIPrincipal*           aSheetPrincipal,
-                     nsCOMArray<nsICSSRule>& aResult);
+                     nsCOMArray<css::Rule>&  aResult);
 
   nsresult ParseProperty(const nsCSSProperty aPropID,
                          const nsAString& aPropValue,
                          nsIURI* aSheetURL,
                          nsIURI* aBaseURL,
                          nsIPrincipal* aSheetPrincipal,
                          css::Declaration* aDeclaration,
                          PRBool* aChanged,
@@ -265,18 +265,18 @@ public:
                                    PRUint32 aLineNumber, // for error reporting
                                    nsTArray<float>& aSelectorList);
 #endif
 
 protected:
   class nsAutoParseCompoundProperty;
   friend class nsAutoParseCompoundProperty;
 
-  void AppendRule(nsICSSRule* aRule);
-  friend void AppendRuleToSheet(nsICSSRule*, void*); // calls AppendRule
+  void AppendRule(css::Rule* aRule);
+  friend void AppendRuleToSheet(css::Rule*, void*); // calls AppendRule
 
   /**
    * This helper class automatically calls SetParsingCompoundProperty in its
    * constructor and takes care of resetting it to false in its destructor.
    */
   class nsAutoParseCompoundProperty {
     public:
       nsAutoParseCompoundProperty(CSSParserImpl* aParser) : mParser(aParser)
@@ -698,22 +698,22 @@ protected:
   // All data from successfully parsed properties are placed into |mData|.
   nsCSSExpandedDataBlock mData;
 
 public:
   // Used from nsCSSParser constructors and destructors
   CSSParserImpl* mNextFree;
 };
 
-static void AppendRuleToArray(nsICSSRule* aRule, void* aArray)
-{
-  static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(aRule);
-}
-
-static void AppendRuleToSheet(nsICSSRule* aRule, void* aParser)
+static void AppendRuleToArray(css::Rule* aRule, void* aArray)
+{
+  static_cast<nsCOMArray<css::Rule>*>(aArray)->AppendObject(aRule);
+}
+
+static void AppendRuleToSheet(css::Rule* aRule, void* aParser)
 {
   CSSParserImpl* parser = (CSSParserImpl*) aParser;
   parser->AppendRule(aRule);
 }
 
 #ifdef CSS_REPORT_PARSE_ERRORS
 
 #define REPORT_UNEXPECTED(msg_) \
@@ -916,25 +916,25 @@ CSSParserImpl::Parse(nsIUnicharInputStre
                equal,
                "Sheet principal does not match passed principal");
 #endif
 
   InitScanner(aInput, aSheetURI, aLineNumber, aBaseURI, aSheetPrincipal);
 
   PRInt32 ruleCount = mSheet->StyleRuleCount();
   if (0 < ruleCount) {
-    nsICSSRule* lastRule = nsnull;
+    css::Rule* lastRule = nsnull;
     mSheet->GetStyleRuleAt(ruleCount - 1, lastRule);
     if (lastRule) {
       switch (lastRule->GetType()) {
-        case nsICSSRule::CHARSET_RULE:
-        case nsICSSRule::IMPORT_RULE:
+        case css::Rule::CHARSET_RULE:
+        case css::Rule::IMPORT_RULE:
           mSection = eCSSSection_Import;
           break;
-        case nsICSSRule::NAMESPACE_RULE:
+        case css::Rule::NAMESPACE_RULE:
           mSection = eCSSSection_NameSpace;
           break;
         default:
           mSection = eCSSSection_General;
           break;
       }
       NS_RELEASE(lastRule);
     }
@@ -1071,17 +1071,17 @@ CSSParserImpl::ParseDeclarations(const n
   return rv;
 }
 
 nsresult
 CSSParserImpl::ParseRule(const nsAString&        aRule,
                          nsIURI*                 aSheetURI,
                          nsIURI*                 aBaseURI,
                          nsIPrincipal*           aSheetPrincipal,
-                         nsCOMArray<nsICSSRule>& aResult)
+                         nsCOMArray<css::Rule>&  aResult)
 {
   NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
   AssertInitialState();
 
   NS_ASSERTION(nsnull != aBaseURI, "need base URI");
 
   InitScanner(aRule, aSheetURI, 0, aBaseURI, aSheetPrincipal);
 
@@ -1641,17 +1641,17 @@ CSSParserImpl::ParseCharsetRule(RuleAppe
   }
 
   nsAutoString charset = mToken.mIdent;
 
   if (!ExpectSymbol(';', PR_TRUE)) {
     return PR_FALSE;
   }
 
-  nsCOMPtr<nsICSSRule> rule = new css::CharsetRule(charset);
+  nsRefPtr<css::CharsetRule> rule = new css::CharsetRule(charset);
   (*aAppendFunc)(rule, aData);
 
   return PR_TRUE;
 }
 
 PRBool
 CSSParserImpl::ParseURLOrString(nsString& aURL)
 {
@@ -2577,17 +2577,17 @@ CSSParserImpl::PopGroup()
 {
   PRUint32 count = mGroupStack.Length();
   if (0 < count) {
     mGroupStack.RemoveElementAt(count - 1);
   }
 }
 
 void
-CSSParserImpl::AppendRule(nsICSSRule* aRule)
+CSSParserImpl::AppendRule(css::Rule* aRule)
 {
   PRUint32 count = mGroupStack.Length();
   if (0 < count) {
     mGroupStack[count - 1]->AppendStyleRule(aRule);
   }
   else {
     mSheet->AppendStyleRule(aRule);
   }
@@ -8799,17 +8799,17 @@ nsCSSParser::ParseDeclarations(const nsA
                       aDeclaration, aChanged);
 }
 
 nsresult
 nsCSSParser::ParseRule(const nsAString&        aRule,
                        nsIURI*                 aSheetURI,
                        nsIURI*                 aBaseURI,
                        nsIPrincipal*           aSheetPrincipal,
-                       nsCOMArray<nsICSSRule>& aResult)
+                       nsCOMArray<css::Rule>&  aResult)
 {
   return static_cast<CSSParserImpl*>(mImpl)->
     ParseRule(aRule, aSheetURI, aBaseURI, aSheetPrincipal, aResult);
 }
 
 nsresult
 nsCSSParser::ParseProperty(const nsCSSProperty aPropID,
                            const nsAString&    aPropValue,
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -41,29 +41,29 @@
 #define nsCSSParser_h___
 
 #include "nsAString.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 
-class nsICSSRule;
 class nsCSSStyleSheet;
 class nsIPrincipal;
 class nsIURI;
 class nsIUnicharInputStream;
 struct nsCSSSelectorList;
 class nsMediaList;
 #ifdef MOZ_CSS_ANIMATIONS
 class nsCSSKeyframeRule;
 #endif
 
 namespace mozilla {
 namespace css {
+class Rule;
 class Declaration;
 class Loader;
 class StyleRule;
 }
 }
 
 // Interface to the css parser.
 
@@ -140,17 +140,17 @@ public:
                              nsIPrincipal*     aSheetPrincipal,
                              mozilla::css::Declaration* aDeclaration,
                              PRBool*           aChanged);
 
   nsresult ParseRule(const nsAString&        aRule,
                      nsIURI*                 aSheetURL,
                      nsIURI*                 aBaseURL,
                      nsIPrincipal*           aSheetPrincipal,
-                     nsCOMArray<nsICSSRule>& aResult);
+                     nsCOMArray<mozilla::css::Rule>& aResult);
 
   nsresult ParseProperty(const nsCSSProperty aPropID,
                          const nsAString&    aPropValue,
                          nsIURI*             aSheetURL,
                          nsIURI*             aBaseURL,
                          nsIPrincipal*       aSheetPrincipal,
                          mozilla::css::Declaration* aDeclaration,
                          PRBool*             aChanged,
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -2817,55 +2817,55 @@ struct CascadeEnumData {
  * grouping rules) in order to:
  *  (1) add any style rules, in order, into data->mRulesByWeight (for
  *      the primary CSS cascade), where they are separated by weight
  *      but kept in order per-weight, and
  *  (2) add any @font-face rules, in order, into data->mFontFaceRules.
  *  (3) add any @keyframes rules, in order, into data->mKeyframesRules.
  */
 static PRBool
-CascadeRuleEnumFunc(nsICSSRule* aRule, void* aData)
+CascadeRuleEnumFunc(css::Rule* aRule, void* aData)
 {
   CascadeEnumData* data = (CascadeEnumData*)aData;
   PRInt32 type = aRule->GetType();
 
-  if (nsICSSRule::STYLE_RULE == type) {
+  if (css::Rule::STYLE_RULE == type) {
     css::StyleRule* styleRule = static_cast<css::StyleRule*>(aRule);
 
     for (nsCSSSelectorList *sel = styleRule->Selector();
          sel; sel = sel->mNext) {
       PRInt32 weight = sel->mWeight;
       RuleByWeightEntry *entry = static_cast<RuleByWeightEntry*>(
         PL_DHashTableOperate(&data->mRulesByWeight, NS_INT32_TO_PTR(weight),
                              PL_DHASH_ADD));
       if (!entry)
         return PR_FALSE;
       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) {
+  else if (css::Rule::MEDIA_RULE == type ||
+           css::Rule::DOCUMENT_RULE == type) {
     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) {
+  else if (css::Rule::FONT_FACE_RULE == type) {
     nsCSSFontFaceRule *fontFaceRule = static_cast<nsCSSFontFaceRule*>(aRule);
     nsFontFaceRuleContainer *ptr = data->mFontFaceRules.AppendElement();
     if (!ptr)
       return PR_FALSE;
     ptr->mRule = fontFaceRule;
     ptr->mSheetType = data->mSheetType;
   }
 #ifdef MOZ_CSS_ANIMATIONS
-  else if (nsICSSRule::KEYFRAMES_RULE == type) {
+  else if (css::Rule::KEYFRAMES_RULE == type) {
     nsCSSKeyframesRule *keyframesRule =
       static_cast<nsCSSKeyframesRule*>(aRule);
     if (!data->mKeyframesRules.AppendElement(keyframesRule)) {
       return PR_FALSE;
     }
   }
 #endif
 
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -177,17 +177,17 @@ GroupRuleRuleList::GetLength(PRUint32* a
 }
 
 nsIDOMCSSRule*
 GroupRuleRuleList::GetItemAt(PRUint32 aIndex, nsresult* aResult)
 {
   *aResult = NS_OK;
 
   if (mGroupRule) {
-    nsCOMPtr<nsICSSRule> rule = mGroupRule->GetStyleRuleAt(aIndex);
+    nsRefPtr<Rule> rule = mGroupRule->GetStyleRuleAt(aIndex);
     if (rule) {
       return rule->GetDOMRuleWeak(aResult);
     }
   }
 
   return nsnull;
 }
 
@@ -233,21 +233,20 @@ CharsetRule::CharsetRule(const CharsetRu
 {
 }
 
 NS_IMPL_ADDREF_INHERITED(CharsetRule, css::Rule)
 NS_IMPL_RELEASE_INHERITED(CharsetRule, css::Rule)
 
 // QueryInterface implementation for CharsetRule
 NS_INTERFACE_MAP_BEGIN(CharsetRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCharsetRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCharsetRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(CharsetRule, css::Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 CharsetRule::List(FILE* out, PRInt32 aIndent) const
@@ -259,23 +258,23 @@ CharsetRule::List(FILE* out, PRInt32 aIn
   fputs(NS_LossyConvertUTF16toASCII(mEncoding).get(), out);
   fputs("\"\n", out);
 }
 #endif
 
 /* virtual */ PRInt32
 CharsetRule::GetType() const
 {
-  return nsICSSRule::CHARSET_RULE;
+  return Rule::CHARSET_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 CharsetRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new CharsetRule(*this);
+  nsRefPtr<Rule> clone = new CharsetRule(*this);
   return clone.forget();
 }
 
 NS_IMETHODIMP
 CharsetRule::GetEncoding(nsAString& aEncoding)
 {
   aEncoding = mEncoding;
   return NS_OK;
@@ -367,21 +366,20 @@ ImportRule::~ImportRule()
   }
 }
 
 NS_IMPL_ADDREF_INHERITED(ImportRule, Rule)
 NS_IMPL_RELEASE_INHERITED(ImportRule, Rule)
 
 // QueryInterface implementation for ImportRule
 NS_INTERFACE_MAP_BEGIN(ImportRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(ImportRule, Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 ImportRule::List(FILE* out, PRInt32 aIndent) const
@@ -398,23 +396,23 @@ ImportRule::List(FILE* out, PRInt32 aInd
   fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
   fputs("\n", out);
 }
 #endif
 
 /* virtual */ PRInt32
 ImportRule::GetType() const
 {
-  return nsICSSRule::IMPORT_RULE;
+  return Rule::IMPORT_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 ImportRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new ImportRule(*this);
+  nsRefPtr<Rule> clone = new ImportRule(*this);
   return clone.forget();
 }
 
 void
 ImportRule::SetSheet(nsCSSStyleSheet* aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
 
@@ -507,33 +505,33 @@ ImportRule::GetStyleSheet(nsIDOMCSSStyle
 
 } // namespace css
 } // namespace mozilla
 
 // must be outside the namespace
 DOMCI_DATA(CSSImportRule, css::ImportRule)
 
 static PRBool
-CloneRuleInto(nsICSSRule* aRule, void* aArray)
+CloneRuleInto(css::Rule* aRule, void* aArray)
 {
-  nsCOMPtr<nsICSSRule> clone = aRule->Clone();
-  static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(clone);
+  nsRefPtr<css::Rule> clone = aRule->Clone();
+  static_cast<nsCOMArray<css::Rule>*>(aArray)->AppendObject(clone);
   return PR_TRUE;
 }
 
 namespace mozilla {
 namespace css {
 
 GroupRule::GroupRule()
   : Rule()
 {
 }
 
 static PRBool
-SetParentRuleReference(nsICSSRule* aRule, void* aParentRule)
+SetParentRuleReference(Rule* aRule, void* aParentRule)
 {
   GroupRule* parentRule = static_cast<GroupRule*>(aParentRule);
   aRule->SetParentRule(parentRule);
   return PR_TRUE;
 }
 
 GroupRule::GroupRule(const GroupRule& aCopy)
   : Rule(aCopy)
@@ -549,17 +547,17 @@ GroupRule::~GroupRule()
   if (mRuleCollection) {
     mRuleCollection->DropReference();
   }
 }
 
 IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(GroupRule, Rule)
 
 static PRBool
-SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
+SetStyleSheetReference(Rule* aRule, void* aSheet)
 {
   nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
   aRule->SetStyleSheet(sheet);
   return PR_TRUE;
 }
 
 /* virtual */ void
 GroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
@@ -577,27 +575,27 @@ GroupRule::List(FILE* out, PRInt32 aInde
   for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
     mRules.ObjectAt(index)->List(out, aIndent + 1);
   }
   fputs("}\n", out);
 }
 #endif
 
 void
-GroupRule::AppendStyleRule(nsICSSRule* aRule)
+GroupRule::AppendStyleRule(Rule* aRule)
 {
   mRules.AppendObject(aRule);
   aRule->SetStyleSheet(mSheet);
   aRule->SetParentRule(this);
   if (mSheet) {
     mSheet->SetModifiedByChildRule();
   }
 }
 
-nsICSSRule*
+Rule*
 GroupRule::GetStyleRuleAt(PRInt32 aIndex) const
 {
   return mRules.SafeObjectAt(aIndex);
 }
 
 PRBool
 GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
 {
@@ -609,38 +607,38 @@ GroupRule::EnumerateRulesForwards(RuleEn
  * 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
  */
 nsresult
 GroupRule::DeleteStyleRuleAt(PRUint32 aIndex)
 {
-  nsICSSRule* rule = mRules.SafeObjectAt(aIndex);
+  Rule* rule = mRules.SafeObjectAt(aIndex);
   if (rule) {
     rule->SetStyleSheet(nsnull);
     rule->SetParentRule(nsnull);
   }
   return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
 }
 
 nsresult
 GroupRule::InsertStyleRulesAt(PRUint32 aIndex,
-                              nsCOMArray<nsICSSRule>& aRules)
+                              nsCOMArray<Rule>& aRules)
 {
   aRules.EnumerateForwards(SetStyleSheetReference, mSheet);
   aRules.EnumerateForwards(SetParentRuleReference, this);
   if (! mRules.InsertObjectsAt(aRules, aIndex)) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 nsresult
-GroupRule::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
+GroupRule::ReplaceStyleRule(Rule* aOld, Rule* 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);
@@ -649,17 +647,17 @@ GroupRule::ReplaceStyleRule(nsICSSRule* 
 
 nsresult
 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);
+    Rule* rule = mRules.ObjectAt(index);
     nsCOMPtr<nsIDOMCSSRule> domRule;
     rule->GetDOMRule(getter_AddRefs(domRule));
     if (domRule) {
       nsAutoString cssText;
       domRule->GetCssText(cssText);
       aCssText.Append(NS_LITERAL_STRING("  ") +
                       cssText +
                       NS_LITERAL_STRING("\n"));
@@ -747,21 +745,20 @@ MediaRule::~MediaRule()
   }
 }
 
 NS_IMPL_ADDREF_INHERITED(MediaRule, Rule)
 NS_IMPL_RELEASE_INHERITED(MediaRule, Rule)
 
 // QueryInterface implementation for MediaRule
 NS_INTERFACE_MAP_BEGIN(MediaRule)
-  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, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
 NS_INTERFACE_MAP_END
 
 /* virtual */ void
 MediaRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
 {
   if (mMedia) {
     // Set to null so it knows it's leaving one sheet and joining another.
@@ -790,23 +787,23 @@ MediaRule::List(FILE* out, PRInt32 aInde
 
   GroupRule::List(out, aIndent);
 }
 #endif
 
 /* virtual */ PRInt32
 MediaRule::GetType() const
 {
-  return nsICSSRule::MEDIA_RULE;
+  return Rule::MEDIA_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 MediaRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new MediaRule(*this);
+  nsRefPtr<Rule> clone = new MediaRule(*this);
   return clone.forget();
 }
 
 nsresult
 MediaRule::SetMedia(nsMediaList* aMedia)
 {
   mMedia = aMedia;
   if (aMedia)
@@ -917,21 +914,20 @@ DocumentRule::~DocumentRule()
 {
 }
 
 NS_IMPL_ADDREF_INHERITED(DocumentRule, Rule)
 NS_IMPL_RELEASE_INHERITED(DocumentRule, Rule)
 
 // QueryInterface implementation for DocumentRule
 NS_INTERFACE_MAP_BEGIN(DocumentRule)
-  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, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
 NS_INTERFACE_MAP_END
 
 #ifdef DEBUG
 /* virtual */ void
 DocumentRule::List(FILE* out, PRInt32 aIndent) const
 {
   for (PRInt32 indent = aIndent; --indent >= 0; ) fputs("  ", out);
@@ -962,23 +958,23 @@ DocumentRule::List(FILE* out, PRInt32 aI
 
   GroupRule::List(out, aIndent);
 }
 #endif
 
 /* virtual */ PRInt32
 DocumentRule::GetType() const
 {
-  return nsICSSRule::DOCUMENT_RULE;
+  return Rule::DOCUMENT_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 DocumentRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new DocumentRule(*this);
+  nsRefPtr<Rule> clone = new DocumentRule(*this);
   return clone.forget();
 }
 
 // nsIDOMCSSRule methods
 NS_IMETHODIMP
 DocumentRule::GetType(PRUint16* aType)
 {
   // XXX What should really happen here?
@@ -1142,20 +1138,19 @@ NS_IMPL_RELEASE_INHERITED(NameSpaceRule,
 // QueryInterface implementation for NameSpaceRule
 NS_INTERFACE_MAP_BEGIN(NameSpaceRule)
   if (aIID.Equals(NS_GET_IID(css::NameSpaceRule))) {
     *aInstancePtr = this;
     NS_ADDREF_THIS();
     return NS_OK;
   }
   else
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 NameSpaceRule::List(FILE* out, PRInt32 aIndent) const
@@ -1176,23 +1171,23 @@ NameSpaceRule::List(FILE* out, PRInt32 a
   fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
   fputs(")\n", out);
 }
 #endif
 
 /* virtual */ PRInt32
 NameSpaceRule::GetType() const
 {
-  return nsICSSRule::NAMESPACE_RULE;
+  return Rule::NAMESPACE_RULE;
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<Rule>
 NameSpaceRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new NameSpaceRule(*this);
+  nsRefPtr<Rule> clone = new NameSpaceRule(*this);
   return clone.forget();
 }
 
 NS_IMETHODIMP
 NameSpaceRule::GetType(PRUint16* aType)
 {
   // XXX What should really happen here?
   *aType = nsIDOMCSSRule::UNKNOWN_RULE;
@@ -1569,35 +1564,34 @@ nsCSSFontFaceStyleDecl::GetParentRule(ns
   return ContainingRule()->GetDOMRule(aParentRule);
 }
 
 
 // -------------------------------------------
 // nsCSSFontFaceRule
 // 
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<css::Rule>
 nsCSSFontFaceRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new nsCSSFontFaceRule(*this);
+  nsRefPtr<css::Rule> clone = new nsCSSFontFaceRule(*this);
   return clone.forget();
 }
 
 NS_IMPL_ADDREF_INHERITED(nsCSSFontFaceRule, css::Rule)
 NS_IMPL_RELEASE_INHERITED(nsCSSFontFaceRule, css::Rule)
 
 DOMCI_DATA(CSSFontFaceRule, nsCSSFontFaceRule)
 
 // QueryInterface implementation for nsCSSFontFaceRule
 NS_INTERFACE_MAP_BEGIN(nsCSSFontFaceRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule)
 
 #ifdef DEBUG
 void
 nsCSSFontFaceRule::List(FILE* out, PRInt32 aIndent) const
@@ -1627,17 +1621,17 @@ nsCSSFontFaceRule::List(FILE* out, PRInt
     }
   fprintf(out, "%s}\n", baseInd.get());
 }
 #endif
 
 /* virtual */ PRInt32
 nsCSSFontFaceRule::GetType() const
 {
-  return nsICSSRule::FONT_FACE_RULE;
+  return css::Rule::FONT_FACE_RULE;
 }
 
 NS_IMETHODIMP
 nsCSSFontFaceRule::GetType(PRUint16* aType)
 {
   *aType = nsIDOMCSSRule::FONT_FACE_RULE;
   return NS_OK;
 }
@@ -1778,35 +1772,34 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(con
 
 nsCSSKeyframeRule::~nsCSSKeyframeRule()
 {
   if (mDOMDeclaration) {
     mDOMDeclaration->DropReference();
   }
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<css::Rule>
 nsCSSKeyframeRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new nsCSSKeyframeRule(*this);
+  nsRefPtr<css::Rule> clone = new nsCSSKeyframeRule(*this);
   return clone.forget();
 }
 
 NS_IMPL_ADDREF(nsCSSKeyframeRule)
 NS_IMPL_RELEASE(nsCSSKeyframeRule)
 
 DOMCI_DATA(MozCSSKeyframeRule, nsCSSKeyframeRule)
 
 // QueryInterface implementation for nsCSSKeyframeRule
 NS_INTERFACE_MAP_BEGIN(nsCSSKeyframeRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframeRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule)
 
 /* virtual */ void
 nsCSSKeyframeRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
@@ -1828,17 +1821,17 @@ nsCSSKeyframeRule::List(FILE* out, PRInt
 {
   // FIXME: WRITE ME
 }
 #endif
 
 /* virtual */ PRInt32
 nsCSSKeyframeRule::GetType() const
 {
-  return nsICSSRule::KEYFRAME_RULE;
+  return css::Rule::KEYFRAME_RULE;
 }
 
 NS_IMETHODIMP
 nsCSSKeyframeRule::GetType(PRUint16* aType)
 {
   *aType = nsIDOMCSSRule::MOZ_KEYFRAME_RULE;
   return NS_OK;
 }
@@ -1948,50 +1941,49 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(c
     mName(aCopy.mName)
 {
 }
 
 nsCSSKeyframesRule::~nsCSSKeyframesRule()
 {
 }
 
-/* virtual */ already_AddRefed<nsICSSRule>
+/* virtual */ already_AddRefed<css::Rule>
 nsCSSKeyframesRule::Clone() const
 {
-  nsCOMPtr<nsICSSRule> clone = new nsCSSKeyframesRule(*this);
+  nsRefPtr<css::Rule> clone = new nsCSSKeyframesRule(*this);
   return clone.forget();
 }
 
 NS_IMPL_ADDREF_INHERITED(nsCSSKeyframesRule, mozilla::css::GroupRule)
 NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, mozilla::css::GroupRule)
 
 DOMCI_DATA(MozCSSKeyframesRule, nsCSSKeyframesRule)
 
 // QueryInterface implementation for nsCSSKeyframesRule
 NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframesRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframesRule)
 NS_INTERFACE_MAP_END
 
 #ifdef DEBUG
 void
 nsCSSKeyframesRule::List(FILE* out, PRInt32 aIndent) const
 {
   // FIXME: WRITE ME
 }
 #endif
 
 /* virtual */ PRInt32
 nsCSSKeyframesRule::GetType() const
 {
-  return nsICSSRule::KEYFRAMES_RULE;
+  return css::Rule::KEYFRAMES_RULE;
 }
 
 NS_IMETHODIMP
 nsCSSKeyframesRule::GetType(PRUint16* aType)
 {
   *aType = nsIDOMCSSRule::MOZ_KEYFRAMES_RULE;
   return NS_OK;
 }
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -38,17 +38,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
 
 #ifndef nsCSSRules_h_
 #define nsCSSRules_h_
 
-#include "Rule.h"
 #include "mozilla/css/GroupRule.h"
 #include "nsIDOMCSSMediaRule.h"
 #include "nsIDOMCSSMozDocumentRule.h"
 #include "nsIDOMCSSFontFaceRule.h"
 #ifdef MOZ_CSS_ANIMATIONS
 #include "nsIDOMMozCSSKeyframeRule.h"
 #include "nsIDOMMozCSSKeyframesRule.h"
 #endif
@@ -85,20 +84,20 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); //override GroupRule
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
   virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
   {
     *aResult = NS_OK;
     return this;
   }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
@@ -129,19 +128,19 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
   virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
   {
     *aResult = NS_OK;
     return this;
   }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
@@ -229,21 +228,21 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   DECL_STYLE_RULE_INHERIT
 
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<mozilla::css::Rule> Clone() const;
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSFontFaceRule interface
   NS_DECL_NSIDOMCSSFONTFACERULE
 
   void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue);
@@ -293,19 +292,19 @@ public:
 
   DECL_STYLE_RULE_INHERIT
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<Rule> Clone() const;
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMCSSCharsetRule methods
   NS_IMETHOD GetEncoding(nsAString& aEncoding);
   NS_IMETHOD SetEncoding(const nsAString& aEncoding);
 
@@ -356,31 +355,31 @@ class NS_FINAL_CLASS nsCSSKeyframeRule :
 public:
   // WARNING: Steals the contents of aKeys *and* aDeclaration
   nsCSSKeyframeRule(nsTArray<float> aKeys,
                     nsAutoPtr<mozilla::css::Declaration> aDeclaration)
     : mDeclaration(aDeclaration)
   {
     mKeys.SwapElements(aKeys);
   }
-
+private:
   nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy);
   ~nsCSSKeyframeRule();
-
+public:
   NS_DECL_ISUPPORTS
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   DECL_STYLE_RULE_INHERIT
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<mozilla::css::Rule> Clone() const;
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
 
   // nsIDOMMozCSSKeyframeRule interface
   NS_DECL_NSIDOMMOZCSSKEYFRAMERULE
 
   const nsTArray<float>& GetKeys() const     { return mKeys; }
@@ -398,29 +397,30 @@ private:
 class NS_FINAL_CLASS nsCSSKeyframesRule : public mozilla::css::GroupRule,
                                           public nsIDOMMozCSSKeyframesRule
 {
 public:
   nsCSSKeyframesRule(const nsSubstring& aName)
     : mName(aName)
   {
   }
+private:
   nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy);
   ~nsCSSKeyframesRule();
-
+public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIStyleRule methods
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
-  // nsICSSRule methods
+  // Rule methods
   virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
+  virtual already_AddRefed<mozilla::css::Rule> Clone() const;
   virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
   {
     *aResult = NS_OK;
     return this;
   }
 
   // nsIDOMCSSRule interface
   NS_DECL_NSIDOMCSSRULE
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -143,17 +143,17 @@ nsIDOMCSSRule*
 CSSRuleListImpl::GetItemAt(PRUint32 aIndex, nsresult* aResult)
 {
   nsresult result = NS_OK;
 
   if (mStyleSheet) {
     // ensure rules have correct parent
     if (mStyleSheet->EnsureUniqueInner() !=
           nsCSSStyleSheet::eUniqueInner_CloneFailed) {
-      nsCOMPtr<nsICSSRule> rule;
+      nsRefPtr<css::Rule> rule;
 
       result = mStyleSheet->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
       if (rule) {
         return rule->GetDOMRuleWeak(aResult);
       }
       if (result == NS_ERROR_ILLEGAL_VALUE) {
         result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
       }
@@ -800,29 +800,29 @@ nsCSSStyleSheetInner::nsCSSStyleSheetInn
 #endif
 {
   MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
   mSheets.AppendElement(aPrimarySheet);
 
   mPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
 }
 
-static PRBool SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
+static PRBool SetStyleSheetReference(css::Rule* aRule, void* aSheet)
 {
   if (aRule) {
     aRule->SetStyleSheet(static_cast<nsCSSStyleSheet*>(aSheet));
   }
   return PR_TRUE;
 }
 
 static PRBool
-CloneRuleInto(nsICSSRule* aRule, void* aArray)
+CloneRuleInto(css::Rule* aRule, void* aArray)
 {
-  nsCOMPtr<nsICSSRule> clone = aRule->Clone();
-  static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(clone);
+  nsRefPtr<css::Rule> clone = aRule->Clone();
+  static_cast<nsCOMArray<css::Rule>*>(aArray)->AppendObject(clone);
   return PR_TRUE;
 }
 
 struct ChildSheetListBuilder {
   nsRefPtr<nsCSSStyleSheet>* sheetSlot;
   nsCSSStyleSheet* parent;
 
   void SetParentLinks(nsCSSStyleSheet* aSheet) {
@@ -836,25 +836,25 @@ struct ChildSheetListBuilder {
     for (nsCSSStyleSheet *child = aFirstChild; child; child = child->mNext) {
       child->mParent = aPrimarySheet;
       child->SetOwningDocument(aPrimarySheet->mDocument);
     }
   }
 };
   
 PRBool
-nsCSSStyleSheet::RebuildChildList(nsICSSRule* aRule, void* aBuilder)
+nsCSSStyleSheet::RebuildChildList(css::Rule* aRule, void* aBuilder)
 {
   PRInt32 type = aRule->GetType();
-  if (type < nsICSSRule::IMPORT_RULE) {
+  if (type < css::Rule::IMPORT_RULE) {
     // Keep going till we get to the import rules.
     return PR_TRUE;
   }
 
-  if (type != nsICSSRule::IMPORT_RULE) {
+  if (type != css::Rule::IMPORT_RULE) {
     // We're past all the import rules; stop the enumeration.
     return PR_FALSE;
   }
 
   ChildSheetListBuilder* builder =
     static_cast<ChildSheetListBuilder*>(aBuilder);
 
   // XXXbz We really need to decomtaminate all this stuff.  Is there a reason
@@ -937,40 +937,40 @@ nsCSSStyleSheetInner::RemoveSheet(nsCSSS
     ChildSheetListBuilder::ReparentChildList(mSheets[0], mFirstChild);
   }
   else {
     mSheets.RemoveElement(aSheet);
   }
 }
 
 static void
-AddNamespaceRuleToMap(nsICSSRule* aRule, nsXMLNameSpaceMap* aMap)
+AddNamespaceRuleToMap(css::Rule* aRule, nsXMLNameSpaceMap* aMap)
 {
-  NS_ASSERTION(aRule->GetType() == nsICSSRule::NAMESPACE_RULE, "Bogus rule type");
+  NS_ASSERTION(aRule->GetType() == css::Rule::NAMESPACE_RULE, "Bogus rule type");
 
   nsRefPtr<css::NameSpaceRule> nameSpaceRule = do_QueryObject(aRule);
 
   nsAutoString  urlSpec;
   nameSpaceRule->GetURLSpec(urlSpec);
 
   aMap->AddPrefix(nameSpaceRule->GetPrefix(), urlSpec);
 }
 
 static PRBool
-CreateNameSpace(nsICSSRule* aRule, void* aNameSpacePtr)
+CreateNameSpace(css::Rule* aRule, void* aNameSpacePtr)
 {
   PRInt32 type = aRule->GetType();
-  if (nsICSSRule::NAMESPACE_RULE == type) {
+  if (css::Rule::NAMESPACE_RULE == type) {
     AddNamespaceRuleToMap(aRule,
                           static_cast<nsXMLNameSpaceMap*>(aNameSpacePtr));
     return PR_TRUE;
   }
   // stop if not namespace, import or charset because namespace can't follow
   // anything else
-  return (nsICSSRule::CHARSET_RULE == type || nsICSSRule::IMPORT_RULE == type);
+  return (css::Rule::CHARSET_RULE == type || css::Rule::IMPORT_RULE == type);
 }
 
 void 
 nsCSSStyleSheetInner::RebuildNameSpaces()
 {
   // Just nuke our existing namespace map, if any
   if (NS_SUCCEEDED(CreateNamespaceMap())) {
     mOrderedRules.EnumerateForwards(CreateNameSpace, mNameSpaceMap);
@@ -1324,83 +1324,83 @@ nsCSSStyleSheet::InsertStyleSheetAt(nsCS
     // it's going away.
     aSheet->mParent = this;
     aSheet->mDocument = mDocument;
     DidDirty();
   }
 }
 
 void
-nsCSSStyleSheet::PrependStyleRule(nsICSSRule* aRule)
+nsCSSStyleSheet::PrependStyleRule(css::Rule* aRule)
 {
   NS_PRECONDITION(nsnull != aRule, "null arg");
 
   if (NS_SUCCEEDED(WillDirty())) {
     mInner->mOrderedRules.InsertObjectAt(aRule, 0);
     aRule->SetStyleSheet(this);
     DidDirty();
 
-    if (nsICSSRule::NAMESPACE_RULE == aRule->GetType()) {
+    if (css::Rule::NAMESPACE_RULE == aRule->GetType()) {
       // no api to prepend a namespace (ugh), release old ones and re-create them all
       mInner->RebuildNameSpaces();
     }
   }
 }
 
 void
-nsCSSStyleSheet::AppendStyleRule(nsICSSRule* aRule)
+nsCSSStyleSheet::AppendStyleRule(css::Rule* aRule)
 {
   NS_PRECONDITION(nsnull != aRule, "null arg");
 
   if (NS_SUCCEEDED(WillDirty())) {
     mInner->mOrderedRules.AppendObject(aRule);
     aRule->SetStyleSheet(this);
     DidDirty();
 
-    if (nsICSSRule::NAMESPACE_RULE == aRule->GetType()) {
+    if (css::Rule::NAMESPACE_RULE == aRule->GetType()) {
 #ifdef DEBUG
       nsresult rv =
 #endif
         RegisterNamespaceRule(aRule);
       NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
                        "RegisterNamespaceRule returned error");
     }
   }
 }
 
 void
-nsCSSStyleSheet::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
+nsCSSStyleSheet::ReplaceStyleRule(css::Rule* aOld, css::Rule* aNew)
 {
   NS_PRECONDITION(mInner->mOrderedRules.Count() != 0, "can't have old rule");
   NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
 
   if (NS_SUCCEEDED(WillDirty())) {
     PRInt32 index = mInner->mOrderedRules.IndexOf(aOld);
     if (NS_UNLIKELY(index == -1)) {
       NS_NOTREACHED("Couldn't find old rule");
       return;
     }
     mInner->mOrderedRules.ReplaceObjectAt(aNew, index);
 
     aNew->SetStyleSheet(this);
     aOld->SetStyleSheet(nsnull);
     DidDirty();
-    NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != aNew->GetType(), "not yet implemented");
-    NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != aOld->GetType(), "not yet implemented");
+    NS_ASSERTION(css::Rule::NAMESPACE_RULE != aNew->GetType(), "not yet implemented");
+    NS_ASSERTION(css::Rule::NAMESPACE_RULE != aOld->GetType(), "not yet implemented");
   }
 }
 
 PRInt32
 nsCSSStyleSheet::StyleRuleCount() const
 {
   return mInner->mOrderedRules.Count();
 }
 
 nsresult
-nsCSSStyleSheet::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
+nsCSSStyleSheet::GetStyleRuleAt(PRInt32 aIndex, css::Rule*& aRule) const
 {
   // Important: If this function is ever made scriptable, we must add
   // a security check here. See GetCssRules below for an example.
   aRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
   if (aRule) {
     NS_ADDREF(aRule);
     return NS_OK;
   }
@@ -1472,17 +1472,17 @@ nsCSSStyleSheet::Clone(nsCSSStyleSheet* 
                                                aCloneDocument,
                                                aCloneOwningNode);
   NS_IF_ADDREF(clone);
   return clone;
 }
 
 #ifdef DEBUG
 static void
-ListRules(const nsCOMArray<nsICSSRule>& aRules, FILE* aOut, PRInt32 aIndent)
+ListRules(const nsCOMArray<css::Rule>& aRules, FILE* aOut, PRInt32 aIndent)
 {
   for (PRInt32 index = aRules.Count() - 1; index >= 0; --index) {
     aRules.ObjectAt(index)->List(aOut, aIndent);
   }
 }
 
 struct ListEnumData {
   ListEnumData(FILE* aOut, PRInt32 aIndent)
@@ -1592,17 +1592,17 @@ nsCSSStyleSheet::SubjectSubsumesInnerPri
   if (!nsContentUtils::IsCallerTrustedForWrite()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   return NS_OK;
 }
 
 nsresult
-nsCSSStyleSheet::RegisterNamespaceRule(nsICSSRule* aRule)
+nsCSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule)
 {
   if (!mInner->mNameSpaceMap) {
     nsresult rv = mInner->CreateNamespaceMap();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   AddNamespaceRuleToMap(aRule, mInner->mNameSpaceMap);
   return NS_OK;
@@ -1780,102 +1780,102 @@ nsCSSStyleSheet::InsertRuleInternal(cons
     loader = mDocument->CSSLoader();
     NS_ASSERTION(loader, "Document with no CSS loader!");
   }
 
   nsCSSParser css(loader, this);
 
   mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
 
-  nsCOMArray<nsICSSRule> rules;
+  nsCOMArray<css::Rule> rules;
   result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
                          mInner->mPrincipal, rules);
   if (NS_FAILED(result))
     return result;
 
   PRInt32 rulecount = rules.Count();
   if (rulecount == 0) {
     // Since we know aRule was not an empty string, just throw
     return NS_ERROR_DOM_SYNTAX_ERR;
   }
   
   // Hierarchy checking.  Just check the first and last rule in the list.
   
   // check that we're not inserting before a charset rule
-  nsICSSRule* nextRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
+  css::Rule* nextRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
   if (nextRule) {
     PRInt32 nextType = nextRule->GetType();
-    if (nextType == nsICSSRule::CHARSET_RULE) {
+    if (nextType == css::Rule::CHARSET_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
 
     // check last rule in list
-    nsICSSRule* lastRule = rules.ObjectAt(rulecount - 1);
+    css::Rule* lastRule = rules.ObjectAt(rulecount - 1);
     PRInt32 lastType = lastRule->GetType();
 
-    if (nextType == nsICSSRule::IMPORT_RULE &&
-        lastType != nsICSSRule::CHARSET_RULE &&
-        lastType != nsICSSRule::IMPORT_RULE) {
+    if (nextType == css::Rule::IMPORT_RULE &&
+        lastType != css::Rule::CHARSET_RULE &&
+        lastType != css::Rule::IMPORT_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
     
-    if (nextType == nsICSSRule::NAMESPACE_RULE &&
-        lastType != nsICSSRule::CHARSET_RULE &&
-        lastType != nsICSSRule::IMPORT_RULE &&
-        lastType != nsICSSRule::NAMESPACE_RULE) {
+    if (nextType == css::Rule::NAMESPACE_RULE &&
+        lastType != css::Rule::CHARSET_RULE &&
+        lastType != css::Rule::IMPORT_RULE &&
+        lastType != css::Rule::NAMESPACE_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     } 
   }
   
   // check first rule in list
-  nsICSSRule* firstRule = rules.ObjectAt(0);
+  css::Rule* firstRule = rules.ObjectAt(0);
   PRInt32 firstType = firstRule->GetType();
   if (aIndex != 0) {
-    if (firstType == nsICSSRule::CHARSET_RULE) { // no inserting charset at nonzero position
+    if (firstType == css::Rule::CHARSET_RULE) { // no inserting charset at nonzero position
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
   
-    nsICSSRule* prevRule = mInner->mOrderedRules.SafeObjectAt(aIndex - 1);
+    css::Rule* prevRule = mInner->mOrderedRules.SafeObjectAt(aIndex - 1);
     PRInt32 prevType = prevRule->GetType();
 
-    if (firstType == nsICSSRule::IMPORT_RULE &&
-        prevType != nsICSSRule::CHARSET_RULE &&
-        prevType != nsICSSRule::IMPORT_RULE) {
+    if (firstType == css::Rule::IMPORT_RULE &&
+        prevType != css::Rule::CHARSET_RULE &&
+        prevType != css::Rule::IMPORT_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
 
-    if (firstType == nsICSSRule::NAMESPACE_RULE &&
-        prevType != nsICSSRule::CHARSET_RULE &&
-        prevType != nsICSSRule::IMPORT_RULE &&
-        prevType != nsICSSRule::NAMESPACE_RULE) {
+    if (firstType == css::Rule::NAMESPACE_RULE &&
+        prevType != css::Rule::CHARSET_RULE &&
+        prevType != css::Rule::IMPORT_RULE &&
+        prevType != css::Rule::NAMESPACE_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
   }
   
   PRBool insertResult = mInner->mOrderedRules.InsertObjectsAt(rules, aIndex);
   NS_ENSURE_TRUE(insertResult, NS_ERROR_OUT_OF_MEMORY);
   DidDirty();
 
   for (PRInt32 counter = 0; counter < rulecount; counter++) {
-    nsICSSRule* cssRule = rules.ObjectAt(counter);
+    css::Rule* cssRule = rules.ObjectAt(counter);
     cssRule->SetStyleSheet(this);
 
     PRInt32 type = cssRule->GetType();
-    if (type == nsICSSRule::NAMESPACE_RULE) {
+    if (type == css::Rule::NAMESPACE_RULE) {
       // XXXbz does this screw up when inserting a namespace rule before
       // another namespace rule that binds the same prefix to a different
       // namespace?
       result = RegisterNamespaceRule(cssRule);
       NS_ENSURE_SUCCESS(result, result);
     }
 
     // We don't notify immediately for @import rules, but rather when
     // the sheet the rule is importing is loaded
     PRBool notify = PR_TRUE;
-    if (type == nsICSSRule::IMPORT_RULE) {
+    if (type == css::Rule::IMPORT_RULE) {
       nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(cssRule));
       NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!");
       nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
       importRule->GetStyleSheet(getter_AddRefs(childSheet));
       if (!childSheet) {
         notify = PR_FALSE;
       }
     }
@@ -1910,17 +1910,17 @@ nsCSSStyleSheet::DeleteRule(PRUint32 aIn
   if (NS_SUCCEEDED(result)) {
     if (aIndex >= PRUint32(mInner->mOrderedRules.Count()))
       return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
     NS_ASSERTION(PRUint32(mInner->mOrderedRules.Count()) <= PR_INT32_MAX,
                  "Too many style rules!");
 
     // Hold a strong ref to the rule so it doesn't die when we RemoveObjectAt
-    nsCOMPtr<nsICSSRule> rule = mInner->mOrderedRules.ObjectAt(aIndex);
+    nsRefPtr<css::Rule> rule = mInner->mOrderedRules.ObjectAt(aIndex);
     if (rule) {
       mInner->mOrderedRules.RemoveObjectAt(aIndex);
       rule->SetStyleSheet(nsnull);
       DidDirty();
 
       if (mDocument) {
         mDocument->StyleRuleRemoved(this, rule);
       }
@@ -1931,17 +1931,17 @@ nsCSSStyleSheet::DeleteRule(PRUint32 aIn
 }
 
 nsresult
 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 = aGroup->GetStyleRuleAt(aIndex);
+  nsRefPtr<css::Rule> rule = aGroup->GetStyleRuleAt(aIndex);
   NS_ENSURE_TRUE(rule, NS_ERROR_ILLEGAL_VALUE);
 
   // check that the rule actually belongs to this sheet!
   if (this != rule->GetStyleSheet()) {
     return NS_ERROR_INVALID_ARG;
   }
 
   mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
@@ -1992,33 +1992,33 @@ nsCSSStyleSheet::InsertRuleIntoGroup(con
   nsCSSParser css(loader, this);
 
   // parse and grab the rule
   mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
 
   result = WillDirty();
   NS_ENSURE_SUCCESS(result, result);
 
-  nsCOMArray<nsICSSRule> rules;
+  nsCOMArray<css::Rule> rules;
   result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
                          mInner->mPrincipal, rules);
   NS_ENSURE_SUCCESS(result, result);
 
   PRInt32 rulecount = rules.Count();
   if (rulecount == 0) {
     // Since we know aRule was not an empty string, just throw
     return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   PRInt32 counter;
-  nsICSSRule* rule;
+  css::Rule* rule;
   for (counter = 0; counter < rulecount; counter++) {
     // Only rulesets are allowed in a group as of CSS2
     rule = rules.ObjectAt(counter);
-    if (rule->GetType() != nsICSSRule::STYLE_RULE) {
+    if (rule->GetType() != css::Rule::STYLE_RULE) {
       return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
     }
   }
   
   result = aGroup->InsertStyleRulesAt(aIndex, rules);
   NS_ENSURE_SUCCESS(result, result);
   DidDirty();
   for (counter = 0; counter < rulecount; counter++) {
@@ -2030,17 +2030,17 @@ nsCSSStyleSheet::InsertRuleIntoGroup(con
   }
 
   *_retval = aIndex;
   return NS_OK;
 }
 
 nsresult
 nsCSSStyleSheet::ReplaceRuleInGroup(css::GroupRule* aGroup,
-                                    nsICSSRule* aOld, nsICSSRule* aNew)
+                                    css::Rule* aOld, css::Rule* aNew)
 {
   nsresult result;
   NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
   NS_ASSERTION(this == aGroup->GetStyleSheet(), "group doesn't belong to this sheet");
   result = WillDirty();
   NS_ENSURE_SUCCESS(result, result);
 
   result = aGroup->ReplaceStyleRule(aOld, aNew);
--- a/layout/style/nsCSSStyleSheet.h
+++ b/layout/style/nsCSSStyleSheet.h
@@ -47,30 +47,30 @@
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsIStyleSheet.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsCOMArray.h"
 
-class nsICSSRule;
 class nsXMLNameSpaceMap;
 class nsCSSRuleProcessor;
 class nsMediaList;
 class nsIPrincipal;
 class nsIURI;
 class nsMediaList;
 class nsMediaQueryResultCacheKey;
 class nsCSSStyleSheet;
 class nsPresContext;
 template<class E, class A> class nsTArray;
 
 namespace mozilla {
 namespace css {
+class Rule;
 class GroupRule;
 class ImportRule;
 }
 }
 
 // -------------------------------
 // CSS Style Sheet Inner Data Container
 //
@@ -95,17 +95,17 @@ private:
   // Create a new namespace map
   nsresult CreateNamespaceMap();
 
   nsAutoTArray<nsCSSStyleSheet*, 8> mSheets;
   nsCOMPtr<nsIURI>       mSheetURI; // for error reports, etc.
   nsCOMPtr<nsIURI>       mOriginalSheetURI;  // for GetHref.  Can be null.
   nsCOMPtr<nsIURI>       mBaseURI; // for resolving relative URIs
   nsCOMPtr<nsIPrincipal> mPrincipal;
-  nsCOMArray<nsICSSRule> mOrderedRules;
+  nsCOMArray<mozilla::css::Rule> mOrderedRules;
   nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
   // Linked list of child sheets.  This is al fundamentally broken, because
   // each of the child sheets has a unique parent... We can only hope (and
   // currently this is the case) that any time page JS can get ts hands on a
   // child sheet that means we've already ensured unique inners throughout its
   // parent chain and things are good.
   nsRefPtr<nsCSSStyleSheet> mFirstChild;
   PRBool                 mComplete;
@@ -160,26 +160,26 @@ public:
 #ifdef DEBUG
   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
 
   void AppendStyleSheet(nsCSSStyleSheet* aSheet);
   void InsertStyleSheetAt(nsCSSStyleSheet* aSheet, PRInt32 aIndex);
 
   // XXX do these belong here or are they generic?
-  void PrependStyleRule(nsICSSRule* aRule);
-  void AppendStyleRule(nsICSSRule* aRule);
-  void ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
+  void PrependStyleRule(mozilla::css::Rule* aRule);
+  void AppendStyleRule(mozilla::css::Rule* aRule);
+  void ReplaceStyleRule(mozilla::css::Rule* aOld, mozilla::css::Rule* aNew);
 
   PRInt32 StyleRuleCount() const;
-  nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
+  nsresult GetStyleRuleAt(PRInt32 aIndex, mozilla::css::Rule*& aRule) const;
 
   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);
+  nsresult ReplaceRuleInGroup(mozilla::css::GroupRule* aGroup, mozilla::css::Rule* aOld, mozilla::css::Rule* 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
    */
@@ -255,17 +255,17 @@ public:
   // nsIDOMStyleSheet interface
   NS_DECL_NSIDOMSTYLESHEET
 
   // nsIDOMCSSStyleSheet interface
   NS_DECL_NSIDOMCSSSTYLESHEET
 
   // Function used as a callback to rebuild our inner's child sheet
   // list after we clone a unique inner for ourselves.
-  static PRBool RebuildChildList(nsICSSRule* aRule, void* aBuilder);
+  static PRBool RebuildChildList(mozilla::css::Rule* aRule, void* aBuilder);
 
 private:
   nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
                   nsCSSStyleSheet* aParentToUse,
                   mozilla::css::ImportRule* aOwnerRuleToUse,
                   nsIDocument* aDocumentToUse,
                   nsIDOMNode* aOwningNodeToUse);
 
@@ -282,17 +282,17 @@ protected:
   void     DidDirty();
 
   // Return success if the subject principal subsumes the principal of our
   // inner, error otherwise.  This will also succeed if the subject has
   // UniversalBrowserWrite.
   nsresult SubjectSubsumesInnerPrincipal() const;
 
   // Add the namespace mapping from this @namespace rule to our namespace map
-  nsresult RegisterNamespaceRule(nsICSSRule* aRule);
+  nsresult RegisterNamespaceRule(mozilla::css::Rule* aRule);
 
 protected:
   nsString              mTitle;
   nsRefPtr<nsMediaList> mMedia;
   nsRefPtr<nsCSSStyleSheet> mNext;
   nsCSSStyleSheet*      mParent;    // weak ref
   mozilla::css::ImportRule* mOwnerRule; // weak ref
 
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -39,17 +39,17 @@
 /* base class for DOM objects for element.style and cssStyleRule.style */
 
 #include "nsDOMCSSDeclaration.h"
 #include "nsIDOMCSSRule.h"
 #include "nsCSSParser.h"
 #include "mozilla/css/Loader.h"
 #include "nsCSSStyleSheet.h"
 #include "nsIStyleRule.h"
-#include "nsICSSRule.h"
+#include "mozilla/css/Rule.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSProps.h"
 #include "nsCOMPtr.h"
 #include "nsIURL.h"
 #include "nsReadableUtils.h"
 #include "nsIPrincipal.h"
 
 #include "nsContentUtils.h"
@@ -260,17 +260,17 @@ nsDOMCSSDeclaration::RemoveProperty(cons
 
   nsresult rv = GetPropertyValue(propID, aReturn);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return RemoveProperty(propID);
 }
 
 /* static */ void
-nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(nsICSSRule* aRule,
+nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule,
                                                      CSSParsingEnvironment& aCSSParseEnv)
 {
   nsIStyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nsnull;
   nsRefPtr<nsCSSStyleSheet> cssSheet(do_QueryObject(sheet));
   if (!cssSheet) {
     aCSSParseEnv.mPrincipal = nsnull;
     return;
   }
--- a/layout/style/nsDOMCSSDeclaration.h
+++ b/layout/style/nsDOMCSSDeclaration.h
@@ -43,22 +43,22 @@
 #include "nsICSSDeclaration.h"
 #include "nsIDOMCSS2Properties.h"
 #include "nsCOMPtr.h"
 
 class nsCSSParser;
 class nsIURI;
 class nsIPrincipal;
 class nsIDocument;
-class nsICSSRule;
 
 namespace mozilla {
 namespace css {
 class Declaration;
 class Loader;
+class Rule;
 }
 }
 
 class nsDOMCSSDeclaration : public nsICSSDeclaration,
                             public nsIDOMCSS2Properties
 {
 public:
   // Only implement QueryInterface; subclasses have the responsibility
@@ -115,18 +115,18 @@ protected:
   };
   
   // On failure, mPrincipal should be set to null in aCSSParseEnv.
   // If mPrincipal is null, the other members may not be set to
   // anything meaningful.
   virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0;
 
   // An implementation for GetCSSParsingEnvironment for callers wrapping
-  // an nsICSSRule.
-  static void GetCSSParsingEnvironmentForRule(nsICSSRule* aRule,
+  // an css::Rule.
+  static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
                                               CSSParsingEnvironment& aCSSParseEnv);
 
   nsresult ParsePropertyValue(const nsCSSProperty aPropID,
                               const nsAString& aPropValue,
                               PRBool aIsImportant);
 
   // Prop-id based version of RemoveProperty.  Note that this does not
   // return the old value; it just does a straight removal.
--- a/layout/style/nsFontFaceLoader.cpp
+++ b/layout/style/nsFontFaceLoader.cpp
@@ -473,17 +473,17 @@ nsUserFontSet::UpdateRules(const nsTArra
   return modified;
 }
 
 void
 nsUserFontSet::InsertRule(nsCSSFontFaceRule *aRule, PRUint8 aSheetType,
                           nsTArray<FontFaceRuleRecord>& aOldRules,
                           PRBool& aFontSetModified)
 {
-  NS_ABORT_IF_FALSE(aRule->GetType() == nsICSSRule::FONT_FACE_RULE,
+  NS_ABORT_IF_FALSE(aRule->GetType() == mozilla::css::Rule::FONT_FACE_RULE,
                     "InsertRule passed a non-fontface CSS rule");
 
   // set up family name
   nsAutoString fontfamily;
   nsCSSValue val;
   PRUint32 unit;
 
   aRule->GetDesc(eCSSFontDesc_Family, val);
deleted file mode 100644
--- a/layout/style/nsICSSRule.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* internal interface for all rule types in a CSS style sheet */
-
-#ifndef nsICSSRule_h
-#define nsICSSRule_h
-
-#include "nsIStyleRule.h"
-#include "nsIDOMCSSRule.h"
-
-class nsCSSStyleSheet;
-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     \
-{ 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
-  //   then N < M
-  // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
-  // rules can come between two rules of type IMPORT_RULE.
-  enum {
-    UNKNOWN_RULE = 0,
-    CHARSET_RULE,
-    IMPORT_RULE,
-    NAMESPACE_RULE,
-    STYLE_RULE,
-    MEDIA_RULE,
-    FONT_FACE_RULE,
-    PAGE_RULE,
-#ifdef MOZ_CSS_ANIMATIONS
-    KEYFRAME_RULE,
-    KEYFRAMES_RULE,
-#endif
-    DOCUMENT_RULE
-  };
-
-  virtual PRInt32 GetType() const = 0;
-
-  virtual nsIStyleSheet* GetStyleSheet() const = 0;
-  virtual void SetStyleSheet(nsCSSStyleSheet* aSheet) = 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).
-  nsresult GetDOMRule(nsIDOMCSSRule** aDOMRule)
-  {
-    nsresult rv;
-    NS_IF_ADDREF(*aDOMRule = GetDOMRuleWeak(&rv));
-    return rv;
-  }
-  virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSRule, NS_ICSS_RULE_IID)
-
-#endif /* nsICSSRule_h */