Bug 576831 part 4. Remove nsICSSStyleRule and use mozilla::css::StyleRule instead. r=bzbarsky
authorCraig Topper <craig.topper@gmail.com>
Thu, 10 Mar 2011 21:48:57 -0500
changeset 63693 cbb08a3bd9752b3f07bff6123c92513a179c64bc
parent 63692 055167d450a91e1c766ab511d87777ffa0b57985
child 63694 bf3db16c8149983763e62f9327cccf6707d4129d
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs576831
milestone2.0b13pre
Bug 576831 part 4. Remove nsICSSStyleRule and use mozilla::css::StyleRule instead. r=bzbarsky
content/base/public/nsIContent.h
content/base/src/nsAttrValue.cpp
content/base/src/nsAttrValue.h
content/base/src/nsGenericDOMDataNode.cpp
content/base/src/nsGenericDOMDataNode.h
content/base/src/nsGenericElement.cpp
content/base/src/nsGenericElement.h
content/base/src/nsStyledElement.cpp
content/base/src/nsStyledElement.h
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/document/src/nsHTMLFragmentContentSink.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGElement.h
content/xul/content/src/nsXULElement.cpp
content/xul/content/src/nsXULElement.h
layout/base/nsPresShell.cpp
layout/inspector/src/inDOMUtils.cpp
layout/mathml/nsMathMLFrame.cpp
layout/style/Makefile.in
layout/style/StyleRule.cpp
layout/style/StyleRule.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSParser.h
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSStyleRule.cpp
layout/style/nsDOMCSSAttrDeclaration.cpp
layout/style/nsHTMLCSSStyleSheet.cpp
layout/style/nsICSSStyleRule.h
layout/style/nsICSSStyleRuleDOMWrapper.h
layout/style/nsStyleAnimation.cpp
layout/style/nsStyleSet.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -45,39 +45,44 @@
 #include "nsIDocument.h" // for IsInHTMLDocument
 
 // Forward declarations
 class nsIAtom;
 class nsIDOMEvent;
 class nsIContent;
 class nsIEventListenerManager;
 class nsIURI;
-class nsICSSStyleRule;
 class nsRuleWalker;
 class nsAttrValue;
 class nsAttrName;
 class nsTextFragment;
 class nsIDocShell;
 class nsIFrame;
 #ifdef MOZ_SMIL
 class nsISMILAttr;
 class nsIDOMCSSStyleDeclaration;
 #endif // MOZ_SMIL
 
+namespace mozilla {
+namespace css {
+class StyleRule;
+}
+}
+
 enum nsLinkState {
   eLinkState_Unknown    = 0,
   eLinkState_Unvisited  = 1,
   eLinkState_Visited    = 2,
   eLinkState_NotLink    = 3
 };
 
 // IID for the nsIContent interface
 #define NS_ICONTENT_IID       \
-{ 0x71afb9e6, 0xe8a7, 0x475d, \
-  { 0x89, 0xc4, 0xe4, 0x62, 0x21, 0xeb, 0xe1, 0xa4 } }
+{ 0x557a7d96, 0xb9cd, 0x4be2, \
+  { 0xa3, 0xe7, 0x5f, 0x43, 0x6d, 0xfd, 0xd9, 0x4f } }
 
 /**
  * A node of content in a document's content model. This interface
  * is supported by all content objects.
  */
 class nsIContent : public nsINode {
 public:
 #ifdef MOZILLA_INTERNAL_API
@@ -818,23 +823,23 @@ public:
    * Walk aRuleWalker over the content style rules (presentational
    * hint rules) for this content node.
    */
   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0;
 
   /**
    * Get the inline style rule, if any, for this content node
    */
-  virtual nsICSSStyleRule* GetInlineStyleRule() = 0;
+  virtual mozilla::css::StyleRule* GetInlineStyleRule() = 0;
 
   /**
    * Set the inline style rule for this node.  This will send an
    * appropriate AttributeChanged notification if aNotify is true.
    */
-  NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify) = 0;
+  NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, PRBool aNotify) = 0;
 
   /**
    * Is the attribute named stored in the mapped attributes?
    *
    * // XXXbz we use this method in HasAttributeDependentStyle, so svg
    *    returns true here even though it stores nothing in the mapped
    *    attributes.
    */
@@ -911,24 +916,24 @@ public:
     */
   virtual nsresult GetSMILOverrideStyle(nsIDOMCSSStyleDeclaration** aStyle) = 0;
 
   /**
    * Get the SMIL override style rule for this content node.  If the rule
    * hasn't been created (or if this nsIContent object doesn't support SMIL
    * override style), this method simply returns null.
    */
-  virtual nsICSSStyleRule* GetSMILOverrideStyleRule() = 0;
+  virtual mozilla::css::StyleRule* GetSMILOverrideStyleRule() = 0;
 
   /**
    * Set the SMIL override style rule for this node.  If aNotify is true, this
    * method will notify the document's pres context, so that the style changes
    * will be noticed.
    */
-  virtual nsresult SetSMILOverrideStyleRule(nsICSSStyleRule* aStyleRule,
+  virtual nsresult SetSMILOverrideStyleRule(mozilla::css::StyleRule* aStyleRule,
                                             PRBool aNotify) = 0;
 #endif // MOZ_SMIL
 
   nsresult LookupNamespaceURI(const nsAString& aNamespacePrefix,
                               nsAString& aNamespaceURI) const;
 
   nsIAtom* LookupPrefix(const nsAString& aNamespaceURI);
 
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -39,17 +39,17 @@
 /*
  * A struct that represents the value (type and actual data) of an
  * attribute.
  */
 
 #include "nsAttrValue.h"
 #include "nsIAtom.h"
 #include "nsUnicharUtils.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "mozilla/css/Declaration.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocument.h"
 #include "nsTPtrArray.h"
 #include "nsContentUtils.h"
 #include "nsReadableUtils.h"
 #include "prprf.h"
 #ifdef MOZ_SVG
@@ -75,17 +75,17 @@ nsAttrValue::nsAttrValue(const nsAttrVal
 }
 
 nsAttrValue::nsAttrValue(const nsAString& aValue)
     : mBits(0)
 {
   SetTo(aValue);
 }
 
-nsAttrValue::nsAttrValue(nsICSSStyleRule* aValue, const nsAString* aSerialized)
+nsAttrValue::nsAttrValue(css::StyleRule* aValue, const nsAString* aSerialized)
     : mBits(0)
 {
   SetTo(aValue, aSerialized);
 }
 
 #ifdef MOZ_SVG
 nsAttrValue::nsAttrValue(nsISVGValue* aValue)
     : mBits(0)
@@ -308,17 +308,17 @@ nsAttrValue::SetTo(const nsAString& aVal
 void
 nsAttrValue::SetTo(PRInt16 aInt)
 {
   ResetIfSet();
   SetIntValueAndType(aInt, eInteger, nsnull);
 }
 
 void
-nsAttrValue::SetTo(nsICSSStyleRule* aValue, const nsAString* aSerialized)
+nsAttrValue::SetTo(css::StyleRule* aValue, const nsAString* aSerialized)
 {
   if (EnsureEmptyMiscContainer()) {
     MiscContainer* cont = GetMiscContainer();
     NS_ADDREF(cont->mCSSStyleRule = aValue);
     cont->mType = eCSSStyleRule;
     SetMiscAtomOrString(aSerialized);
   }
 }
--- a/content/base/src/nsAttrValue.h
+++ b/content/base/src/nsAttrValue.h
@@ -50,23 +50,28 @@
 #include "nsColor.h"
 #include "nsCaseTreatment.h"
 #include "nsMargin.h"
 #include "nsCOMPtr.h"
 
 typedef PRUptrdiff PtrBits;
 class nsAString;
 class nsIAtom;
-class nsICSSStyleRule;
 class nsISVGValue;
 class nsIDocument;
 template<class E, class A> class nsTArray;
 template<class E, class A> class nsTPtrArray;
 struct nsTArrayDefaultAllocator;
 
+namespace mozilla {
+namespace css {
+class StyleRule;
+}
+}
+
 #define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12
 
 #define NS_ATTRVALUE_BASETYPE_MASK (PtrBits(3))
 #define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK)
 
 #define NS_ATTRVALUE_INTEGERTYPE_BITS 4
 #define NS_ATTRVALUE_INTEGERTYPE_MASK (PtrBits((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1))
 #define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS)
@@ -94,17 +99,17 @@ public:
 
 class nsAttrValue {
 public:
   typedef nsTArray< nsCOMPtr<nsIAtom> > AtomArray;
 
   nsAttrValue();
   nsAttrValue(const nsAttrValue& aOther);
   explicit nsAttrValue(const nsAString& aValue);
-  nsAttrValue(nsICSSStyleRule* aValue, const nsAString* aSerialized);
+  nsAttrValue(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
 #ifdef MOZ_SVG
   explicit nsAttrValue(nsISVGValue* aValue);
 #endif
   explicit nsAttrValue(const nsIntMargin& aValue);
   ~nsAttrValue();
 
   static nsresult Init();
   static void Shutdown();
@@ -131,17 +136,17 @@ public:
 
   ValueType Type() const;
 
   void Reset();
 
   void SetTo(const nsAttrValue& aOther);
   void SetTo(const nsAString& aValue);
   void SetTo(PRInt16 aInt);
-  void SetTo(nsICSSStyleRule* aValue, const nsAString* aSerialized);
+  void SetTo(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
 #ifdef MOZ_SVG
   void SetTo(nsISVGValue* aValue);
 #endif
   void SetTo(const nsIntMargin& aValue);
 
   void SwapValueWith(nsAttrValue& aOther);
 
   void ToString(nsAString& aResult) const;
@@ -151,17 +156,17 @@ public:
   inline PRBool IsEmptyString() const;
   const nsCheapString GetStringValue() const;
   inline nsIAtom* GetAtomValue() const;
   inline PRInt32 GetIntegerValue() const;
   PRBool GetColorValue(nscolor& aColor) const;
   inline PRInt16 GetEnumValue() const;
   inline float GetPercentValue() const;
   inline AtomArray* GetAtomArrayValue() const;
-  inline nsICSSStyleRule* GetCSSStyleRuleValue() const;
+  inline mozilla::css::StyleRule* GetCSSStyleRuleValue() const;
 #ifdef MOZ_SVG
   inline nsISVGValue* GetSVGValue() const;
 #endif
   inline float GetFloatValue() const;
   PRBool GetIntMarginValue(nsIntMargin& aMargin) const;
 
   /**
    * Returns the string corresponding to the stored enum value.
@@ -331,17 +336,17 @@ private:
     // Note eStringBase and eAtomBase is used also to handle the type of
     // mStringBits.
     PtrBits mStringBits;
     union {
       PRInt32 mInteger;
       nscolor mColor;
       PRUint32 mEnumValue;
       PRInt32 mPercent;
-      nsICSSStyleRule* mCSSStyleRule;
+      mozilla::css::StyleRule* mCSSStyleRule;
       AtomArray* mAtomArray;
 #ifdef MOZ_SVG
       nsISVGValue* mSVGValue;
 #endif
       float mFloatValue;
       nsIntMargin* mIntMargin;
     };
   };
@@ -432,17 +437,17 @@ nsAttrValue::GetPercentValue() const
 
 inline nsAttrValue::AtomArray*
 nsAttrValue::GetAtomArrayValue() const
 {
   NS_PRECONDITION(Type() == eAtomArray, "wrong type");
   return GetMiscContainer()->mAtomArray;
 }
 
-inline nsICSSStyleRule*
+inline mozilla::css::StyleRule*
 nsAttrValue::GetCSSStyleRuleValue() const
 {
   NS_PRECONDITION(Type() == eCSSStyleRule, "wrong type");
   return GetMiscContainer()->mCSSStyleRule;
 }
 
 #ifdef MOZ_SVG
 inline nsISVGValue*
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -62,16 +62,18 @@
 #include "nsNodeUtils.h"
 #include "nsBindingManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozAutoDocUpdate.h"
 
 #include "pldhash.h"
 #include "prprf.h"
 
+namespace css = mozilla::css;
+
 nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsIContent(aNodeInfo)
 {
 }
 
 nsGenericDOMDataNode::~nsGenericDOMDataNode()
 {
   NS_PRECONDITION(!IsInDoc(),
@@ -1115,39 +1117,39 @@ nsGenericDOMDataNode::WalkContentStyleRu
 #ifdef MOZ_SMIL
 nsresult
 nsGenericDOMDataNode::GetSMILOverrideStyle(nsIDOMCSSStyleDeclaration** aStyle)
 {
   *aStyle = nsnull;
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-nsICSSStyleRule*
+css::StyleRule*
 nsGenericDOMDataNode::GetSMILOverrideStyleRule()
 {
   return nsnull;
 }
 
 nsresult
-nsGenericDOMDataNode::SetSMILOverrideStyleRule(nsICSSStyleRule* aStyleRule,
+nsGenericDOMDataNode::SetSMILOverrideStyleRule(css::StyleRule* aStyleRule,
                                                PRBool aNotify)
 {
   NS_NOTREACHED("How come we're setting SMILOverrideStyle on a non-element?");
   return NS_ERROR_UNEXPECTED;
 }
 #endif // MOZ_SMIL
 
-nsICSSStyleRule*
+css::StyleRule*
 nsGenericDOMDataNode::GetInlineStyleRule()
 {
   return nsnull;
 }
 
 NS_IMETHODIMP
-nsGenericDOMDataNode::SetInlineStyleRule(nsICSSStyleRule* aStyleRule,
+nsGenericDOMDataNode::SetInlineStyleRule(css::StyleRule* aStyleRule,
                                          PRBool aNotify)
 {
   NS_NOTREACHED("How come we're setting inline style on a non-element?");
   return NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP_(PRBool)
 nsGenericDOMDataNode::IsAttributeMapped(const nsIAtom* aAttribute) const
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -230,35 +230,35 @@ public:
   virtual void SaveSubtreeState();
 
 #ifdef MOZ_SMIL
   virtual nsISMILAttr* GetAnimatedAttr(PRInt32 /*aNamespaceID*/, nsIAtom* /*aName*/)
   {
     return nsnull;
   }
   virtual nsresult GetSMILOverrideStyle(nsIDOMCSSStyleDeclaration** aStyle);
-  virtual nsICSSStyleRule* GetSMILOverrideStyleRule();
-  virtual nsresult SetSMILOverrideStyleRule(nsICSSStyleRule* aStyleRule,
+  virtual mozilla::css::StyleRule* GetSMILOverrideStyleRule();
+  virtual nsresult SetSMILOverrideStyleRule(mozilla::css::StyleRule* aStyleRule,
                                             PRBool aNotify);
 #endif // MOZ_SMIL
 
 #ifdef DEBUG
   virtual void List(FILE* out, PRInt32 aIndent) const;
   virtual void DumpContent(FILE* out, PRInt32 aIndent, PRBool aDumpAll) const;
 #endif
 
   virtual nsIContent *GetBindingParent() const;
   virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
   virtual PRBool IsLink(nsIURI** aURI) const;
 
   virtual nsIAtom* DoGetID() const;
   virtual const nsAttrValue* DoGetClasses() const;
   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
-  virtual nsICSSStyleRule* GetInlineStyleRule();
-  NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
+  virtual mozilla::css::StyleRule* GetInlineStyleRule();
+  NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, PRBool aNotify);
   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
   virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
                                               PRInt32 aModType) const;
   virtual nsIAtom *GetClassAttributeName() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
   {
     *aResult = CloneDataNode(aNodeInfo, PR_TRUE);
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -128,17 +128,17 @@
 #include "nsEventDispatcher.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsIControllers.h"
 #include "nsLayoutUtils.h"
 #include "nsIView.h"
 #include "nsIViewManager.h"
 #include "nsIScrollableFrame.h"
 #include "nsXBLInsertionPoint.h"
-#include "nsICSSStyleRule.h" /* For nsCSSSelectorList */
+#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
 #include "nsCSSRuleProcessor.h"
 #include "nsRuleProcessorData.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif /* MOZ_XUL */
 
 #include "nsCycleCollectionParticipant.h"
@@ -150,16 +150,17 @@
 #include "nsTPtrArray.h"
 #include "prprf.h"
 
 #ifdef MOZ_SVG
 #include "nsSVGFeatures.h"
 #endif /* MOZ_SVG */
 
 using namespace mozilla::dom;
+namespace css = mozilla::css;
 
 NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
 
 PRInt32 nsIContent::sTabFocusModel = eTabFocus_any;
 PRBool nsIContent::sTabFocusModelAppliesToXUL = PR_FALSE;
 PRUint32 nsMutationGuard::sMutationCount = 0;
 
 nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
@@ -3363,25 +3364,25 @@ nsGenericElement::GetSMILOverrideStyle(n
     NS_ENSURE_TRUE(slots->mSMILOverrideStyle, NS_ERROR_OUT_OF_MEMORY);
   }
 
   // Why bother with QI?
   NS_ADDREF(*aStyle = slots->mSMILOverrideStyle);
   return NS_OK;
 }
 
-nsICSSStyleRule*
+css::StyleRule*
 nsGenericElement::GetSMILOverrideStyleRule()
 {
   nsGenericElement::nsDOMSlots *slots = GetExistingDOMSlots();
   return slots ? slots->mSMILOverrideStyleRule.get() : nsnull;
 }
 
 nsresult
-nsGenericElement::SetSMILOverrideStyleRule(nsICSSStyleRule* aStyleRule,
+nsGenericElement::SetSMILOverrideStyleRule(css::StyleRule* aStyleRule,
                                            PRBool aNotify)
 {
   nsGenericElement::nsDOMSlots *slots = DOMSlots();
 
   slots->mSMILOverrideStyleRule = aStyleRule;
 
   if (aNotify) {
     nsIDocument* doc = GetCurrentDoc();
@@ -3395,24 +3396,24 @@ nsGenericElement::SetSMILOverrideStyleRu
       }
     }
   }
 
   return NS_OK;
 }
 #endif // MOZ_SMIL
 
-nsICSSStyleRule*
+css::StyleRule*
 nsGenericElement::GetInlineStyleRule()
 {
   return nsnull;
 }
 
 NS_IMETHODIMP
-nsGenericElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule,
+nsGenericElement::SetInlineStyleRule(css::StyleRule* aStyleRule,
                                      PRBool aNotify)
 {
   NS_NOTYETIMPLEMENTED("nsGenericElement::SetInlineStyleRule");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP_(PRBool)
 nsGenericElement::IsAttributeMapped(const nsIAtom* aAttribute) const
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -451,35 +451,35 @@ public:
   virtual void SaveSubtreeState();
 
 #ifdef MOZ_SMIL
   virtual nsISMILAttr* GetAnimatedAttr(PRInt32 /*aNamespaceID*/, nsIAtom* /*aName*/)
   {
     return nsnull;
   }
   virtual nsresult GetSMILOverrideStyle(nsIDOMCSSStyleDeclaration** aStyle);
-  virtual nsICSSStyleRule* GetSMILOverrideStyleRule();
-  virtual nsresult SetSMILOverrideStyleRule(nsICSSStyleRule* aStyleRule,
+  virtual mozilla::css::StyleRule* GetSMILOverrideStyleRule();
+  virtual nsresult SetSMILOverrideStyleRule(mozilla::css::StyleRule* aStyleRule,
                                             PRBool aNotify);
 #endif // MOZ_SMIL
 
 #ifdef DEBUG
   virtual void List(FILE* out, PRInt32 aIndent) const
   {
     List(out, aIndent, EmptyCString());
   }
   virtual void DumpContent(FILE* out, PRInt32 aIndent, PRBool aDumpAll) const;
   void List(FILE* out, PRInt32 aIndent, const nsCString& aPrefix) const;
   void ListAttributes(FILE* out) const;
 #endif
 
   virtual const nsAttrValue* DoGetClasses() const;
   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
-  virtual nsICSSStyleRule* GetInlineStyleRule();
-  NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
+  virtual mozilla::css::StyleRule* GetInlineStyleRule();
+  NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, PRBool aNotify);
   NS_IMETHOD_(PRBool)
     IsAttributeMapped(const nsIAtom* aAttribute) const;
   virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
                                               PRInt32 aModType) const;
   /*
    * Attribute Mapping Helpers
    */
   struct MappedAttributeEntry {
@@ -956,17 +956,17 @@ public:
      * SMIL Overridde style rules (for SMIL animation of CSS properties)
      * @see nsIContent::GetSMILOverrideStyle
      */
     nsCOMPtr<nsICSSDeclaration> mSMILOverrideStyle;
 
     /**
      * Holds any SMIL override style rules for this element.
      */
-    nsCOMPtr<nsICSSStyleRule> mSMILOverrideStyleRule;
+    nsRefPtr<mozilla::css::StyleRule> mSMILOverrideStyleRule;
 
     /**
      * An object implementing nsIDOMNamedNodeMap for this content (attributes)
      * @see nsGenericElement::GetAttributes
      */
     nsRefPtr<nsDOMAttributeMap> mAttributeMap;
 
     union {
--- a/content/base/src/nsStyledElement.cpp
+++ b/content/base/src/nsStyledElement.cpp
@@ -42,26 +42,28 @@
 #include "nsGkAtoms.h"
 #include "nsAttrValue.h"
 #include "nsGenericElement.h"
 #include "nsMutationEvent.h"
 #include "nsDOMCSSDeclaration.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIDocument.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsCSSParser.h"
 #include "mozilla/css/Loader.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsXULElement.h"
 
 #ifdef MOZ_SVG
 #include "nsIDOMSVGStylable.h"
 #endif
 
+namespace css = mozilla::css;
+
 //----------------------------------------------------------------------
 // nsIContent methods
 
 nsIAtom*
 nsStyledElement::GetClassAttributeName() const
 {
   return nsGkAtoms::_class;
 }
@@ -152,17 +154,17 @@ nsStyledElement::AfterSetAttr(PRInt32 aN
     UnsetFlags(NODE_HAS_ID);
   }
 
   return nsGenericElement::AfterSetAttr(aNamespaceID, aAttribute, aValue,
                                         aNotify);
 }
 
 NS_IMETHODIMP
-nsStyledElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify)
+nsStyledElement::SetInlineStyleRule(css::StyleRule* aStyleRule, PRBool aNotify)
 {
   SetFlags(NODE_MAY_HAVE_STYLE);
   PRBool modification = PR_FALSE;
   nsAutoString oldValueStr;
 
   PRBool hasListeners = aNotify &&
     nsContentUtils::HasMutationListeners(this,
                                          NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
@@ -190,17 +192,17 @@ nsStyledElement::SetInlineStyleRule(nsIC
     static_cast<PRUint8>(nsIDOMMutationEvent::MODIFICATION) :
     static_cast<PRUint8>(nsIDOMMutationEvent::ADDITION);
 
   return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nsnull,
                           oldValueStr, attrValue, modType, hasListeners,
                           aNotify, nsnull);
 }
 
-nsICSSStyleRule*
+css::StyleRule*
 nsStyledElement::GetInlineStyleRule()
 {
   if (!HasFlag(NODE_MAY_HAVE_STYLE)) {
     return nsnull;
   }
   const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(nsGkAtoms::style);
 
   if (attrVal && attrVal->Type() == nsAttrValue::eCSSStyleRule) {
@@ -315,22 +317,22 @@ nsStyledElement::ParseStyleAttribute(con
       doc->GetHeaderData(nsGkAtoms::headerContentStyleType, styleType);
       if (!styleType.IsEmpty()) {
         static const char textCssStr[] = "text/css";
         isCSS = (styleType.EqualsIgnoreCase(textCssStr, sizeof(textCssStr) - 1));
       }
     }
 
     if (isCSS) {
-      mozilla::css::Loader* cssLoader = doc->CSSLoader();
+      css::Loader* cssLoader = doc->CSSLoader();
       nsCSSParser cssParser(cssLoader);
       if (cssParser) {
         nsCOMPtr<nsIURI> baseURI = GetBaseURI();
 
-        nsCOMPtr<nsICSSStyleRule> rule;
+        nsRefPtr<css::StyleRule> rule;
         cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(),
                                       baseURI,
                                       NodePrincipal(),
                                       getter_AddRefs(rule));
         if (rule) {
           aResult.SetTo(rule, &aValue);
           return;
         }
--- a/content/base/src/nsStyledElement.h
+++ b/content/base/src/nsStyledElement.h
@@ -44,17 +44,21 @@
  */
 
 #ifndef __NS_STYLEDELEMENT_H_
 #define __NS_STYLEDELEMENT_H_
 
 #include "nsString.h"
 #include "nsGenericElement.h"
 
-class nsICSSStyleRule;
+namespace mozilla {
+namespace css {
+class StyleRule;
+}
+}
 
 typedef nsGenericElement nsStyledElementBase;
 
 class nsStyledElement : public nsStyledElementBase
 {
 
 protected:
 
@@ -65,18 +69,18 @@ protected:
 public:
 
   // nsIContent interface methods
   virtual nsIAtom* GetClassAttributeName() const;
   virtual nsIAtom* GetIDAttributeName() const;
   virtual nsIAtom* DoGetID() const;
   virtual const nsAttrValue* DoGetClasses() const;
 
-  virtual nsICSSStyleRule* GetInlineStyleRule();
-  NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
+  virtual mozilla::css::StyleRule* GetInlineStyleRule();
+  NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, PRBool aNotify);
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               PRBool aCompileEventHandlers);
   virtual void UnbindFromTree(PRBool aDeep, PRBool aNullParent);
 
   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
                              PRBool aNotify);
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -69,17 +69,17 @@
 #include "nsIVariant.h"
 
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFrame.h"
 #include "nsDOMError.h"
 #include "nsIScriptError.h"
 
 #include "nsCSSParser.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "mozilla/css/Declaration.h"
 #include "nsComputedDOMStyle.h"
 #include "nsStyleSet.h"
 
 #include "nsPrintfCString.h"
 
 #include "nsReadableUtils.h"
 
@@ -2170,19 +2170,19 @@ nsCanvasRenderingContext2D::Rect(float x
  * @param aFont The CSS font string
  * @param aNode The canvas element
  * @param aResult Pointer in which to place the new style rule.
  * @remark Assumes all pointer arguments are non-null.
  */
 static nsresult
 CreateFontStyleRule(const nsAString& aFont,
                     nsINode* aNode,
-                    nsICSSStyleRule** aResult)
+                    css::StyleRule** aResult)
 {
-    nsCOMPtr<nsICSSStyleRule> rule;
+    nsRefPtr<css::StyleRule> rule;
     PRBool changed;
 
     nsIPrincipal* principal = aNode->NodePrincipal();
     nsIDocument* document = aNode->GetOwnerDoc();
 
     nsIURI* docURL = document->GetDocumentURI();
     nsIURI* baseURL = document->GetDocBaseURI();
 
@@ -2236,17 +2236,17 @@ nsCanvasRenderingContext2D::SetFont(cons
 
     nsIPresShell* presShell = GetPresShell();
     if (!presShell)
       return NS_ERROR_FAILURE;
     nsIDocument* document = presShell->GetDocument();
 
     nsCOMArray<nsIStyleRule> rules;
 
-    nsCOMPtr<nsICSSStyleRule> rule;
+    nsRefPtr<css::StyleRule> rule;
     rv = CreateFontStyleRule(font, document, getter_AddRefs(rule));
     if (NS_FAILED(rv))
         return rv;
 
     css::Declaration *declaration = rule->GetDeclaration();
     // The easiest way to see whether we got a syntax error or whether
     // we got 'inherit' or 'initial' is to look at font-size-adjust,
     // which the shorthand resets to either 'none' or
@@ -2273,17 +2273,17 @@ nsCanvasRenderingContext2D::SetFont(cons
     if (content && content->IsInDoc()) {
         // inherit from the canvas element
         parentContext = nsComputedDOMStyle::GetStyleContextForElement(
                 content->AsElement(),
                 nsnull,
                 presShell);
     } else {
         // otherwise inherit from default (10px sans-serif)
-        nsCOMPtr<nsICSSStyleRule> parentRule;
+        nsRefPtr<css::StyleRule> parentRule;
         rv = CreateFontStyleRule(NS_LITERAL_STRING("10px sans-serif"),
                                  document,
                                  getter_AddRefs(parentRule));
         if (NS_FAILED(rv))
             return rv;
         nsCOMArray<nsIStyleRule> parentRules;
         parentRules.AppendObject(parentRule);
         parentContext = styleSet->ResolveStyleForRules(nsnull, parentRules);
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -36,17 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nscore.h"
 #include "nsGenericHTMLElement.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIContentViewer.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsCSSStruct.h"
 #include "nsIDocument.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIDOMHTMLBodyElement.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMAttr.h"
 #include "nsIDOMDocumentFragment.h"
 #include "nsIDOMNSHTMLDocument.h"
@@ -315,17 +315,17 @@ nsGenericHTMLElement::CopyInnerTo(nsGene
     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();
-      nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(ruleClone);
+      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
@@ -65,17 +65,17 @@
 #include "nsNetUtil.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsContentSink.h"
 #include "nsTHashtable.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsCSSParser.h"
 #include "nsCSSProperty.h"
 #include "mozilla/css/Declaration.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsUnicharInputStream.h"
 #include "nsCSSStyleSheet.h"
 #include "nsICSSRuleList.h"
 #include "nsIDOMCSSRule.h"
 
 using namespace mozilla::dom;
 namespace css = mozilla::css;
 
@@ -810,17 +810,17 @@ public:
 protected:
   nsresult NameFromType(const nsHTMLTag aTag,
                         nsIAtom **aResult);
 
   nsresult NameFromNode(const nsIParserNode& aNode,
                         nsIAtom **aResult);
 
   // The return value will be true if we have sanitized the rule
-  PRBool SanitizeStyleRule(nsICSSStyleRule *aRule, nsAutoString &aRuleText);
+  PRBool SanitizeStyleRule(css::StyleRule *aRule, nsAutoString &aRuleText);
 
   PRPackedBool mSkip; // used when we descend into <style> or <script>
   PRPackedBool mProcessStyle; // used when style is explicitly white-listed
   PRPackedBool mInStyle; // whether we're inside a style element
   PRPackedBool mProcessComments; // used when comments are allowed
 
   nsCOMPtr<nsIPrincipal> mNullPrincipal;
 
@@ -1045,17 +1045,17 @@ nsHTMLParanoidFragmentSink::AddAttribute
     if (mProcessStyle && keyAtom == nsGkAtoms::style) {
       if (!baseURI) {
         baseURI = aContent->GetBaseURI();
       }
 
       // Pass the CSS Loader object to the parser, to allow parser error reports
       // to include the outer window ID.
       nsCSSParser parser(mTargetDocument->CSSLoader());
-      nsCOMPtr<nsICSSStyleRule> rule;
+      nsRefPtr<css::StyleRule> rule;
       rv = parser.ParseStyleAttribute(aNode.GetValueAt(i),
                                       mTargetDocument->GetDocumentURI(),
                                       baseURI,
                                       mTargetDocument->NodePrincipal(),
                                       getter_AddRefs(rule));
       if (NS_SUCCEEDED(rv)) {
         nsAutoString cleanValue;
         PRBool didSanitize = SanitizeStyleRule(rule, cleanValue);
@@ -1208,17 +1208,17 @@ nsHTMLParanoidFragmentSink::CloseContain
                       sanitizedStyleText.Append(cssText);
                     }
                   }
                   break;
                 }
                 case nsICSSRule::STYLE_RULE: {
                   // For style rules, we will just look for and remove the
                   // -moz-binding properties.
-                  nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(rule);
+                  nsRefPtr<css::StyleRule> styleRule = do_QueryObject(rule);
                   NS_ASSERTION(styleRule, "Must be a style rule");
                   nsAutoString decl;
                   didSanitize = SanitizeStyleRule(styleRule, decl) || didSanitize;
                   rv = styleRule->GetCssText(decl);
                   // Only add the rule when sanitized.
                   if (NS_SUCCEEDED(rv)) {
                     sanitizedStyleText.Append(decl);
                   }
@@ -1234,17 +1234,17 @@ nsHTMLParanoidFragmentSink::CloseContain
       }
     }
   }
 
   return nsHTMLFragmentContentSink::CloseContainer(aTag);
 }
 
 PRBool
-nsHTMLParanoidFragmentSink::SanitizeStyleRule(nsICSSStyleRule *aRule, nsAutoString &aRuleText)
+nsHTMLParanoidFragmentSink::SanitizeStyleRule(css::StyleRule *aRule, nsAutoString &aRuleText)
 {
   PRBool didSanitize = PR_FALSE;
   aRuleText.Truncate();
   css::Declaration *style = aRule->GetDeclaration();
   if (style) {
     didSanitize = style->HasProperty(eCSSProperty_binding);
     style->RemoveProperty(eCSSProperty_binding);
     style->ToString(aRuleText);
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -51,17 +51,17 @@
 #include "nsStyleConsts.h"
 #include "nsDOMError.h"
 #include "nsIPresShell.h"
 #include "nsIDOMViewCSS.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsIServiceManager.h"
 #include "nsIXBLService.h"
 #include "nsGkAtoms.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsRuleWalker.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSProps.h"
 #include "nsCSSParser.h"
 #include "nsGenericHTMLElement.h"
 #include "nsNodeInfoManager.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIEventListenerManager.h"
@@ -865,17 +865,17 @@ nsSVGElement::WalkContentStyleRules(nsRu
       // Any style changes right now could trigger CSS Transitions. We don't
       // want that to happen from SMIL-animated value of mapped attrs, so
       // ignore animated value for now, and request an animation restyle to
       // get our animated value noticed.
       shell->RestyleForAnimation(this, eRestyle_Self);
     } else {
       // Ok, this is an animation restyle -- go ahead and update/walk the
       // animated content style rule.
-      nsICSSStyleRule* animContentStyleRule = GetAnimatedContentStyleRule();
+      css::StyleRule* animContentStyleRule = GetAnimatedContentStyleRule();
       if (!animContentStyleRule) {
         UpdateAnimatedContentStyleRule();
         animContentStyleRule = GetAnimatedContentStyleRule();
       }
       if (animContentStyleRule) {
         animContentStyleRule->RuleMatched();
         aRuleWalker->Forward(animContentStyleRule);
       }
@@ -1178,19 +1178,19 @@ public:
                    nsIPrincipal* aNodePrincipal);
   ~MappedAttrParser();
 
   // Parses a mapped attribute value.
   void ParseMappedAttrValue(nsIAtom* aMappedAttrName,
                             nsAString& aMappedAttrValue);
 
   // If we've parsed any values for mapped attributes, this method returns
-  // a new already_AddRefed nsICSSStyleRule that incorporates the parsed
+  // a new already_AddRefed css::StyleRule that incorporates the parsed
   // values. Otherwise, this method returns null.
-  already_AddRefed<nsICSSStyleRule> CreateStyleRule();
+  already_AddRefed<css::StyleRule> CreateStyleRule();
 
 private:
   // MEMBER DATA
   // -----------
   nsCSSParser       mParser;
 
   // Arguments for nsCSSParser::ParseProperty
   nsIURI*           mDocURI;
@@ -1241,24 +1241,24 @@ MappedAttrParser::ParseMappedAttrValue(n
   // Get the nsCSSProperty ID for our mapped attribute.
   nsCSSProperty propertyID =
     nsCSSProps::LookupProperty(nsDependentAtomString(aMappedAttrName));
   PRBool changed; // outparam for ParseProperty. (ignored)
   mParser.ParseProperty(propertyID, aMappedAttrValue, mDocURI, mBaseURI,
                         mNodePrincipal, mDecl, &changed, PR_FALSE);
 }
 
-already_AddRefed<nsICSSStyleRule>
+already_AddRefed<css::StyleRule>
 MappedAttrParser::CreateStyleRule()
 {
   if (!mDecl) {
     return nsnull; // No mapped attributes were parsed
   }
 
-  nsCOMPtr<nsICSSStyleRule> rule = NS_NewCSSStyleRule(nsnull, mDecl);
+  nsRefPtr<css::StyleRule> rule = NS_NewCSSStyleRule(nsnull, mDecl);
   mDecl = nsnull; // We no longer own the declaration -- drop our pointer to it
   return rule.forget();
 }
 
 } // anonymous namespace
 
 //----------------------------------------------------------------------
 // Implementation Helpers:
@@ -1328,17 +1328,17 @@ static void
 ReleaseStyleRule(void*    aObject,       /* unused */
                  nsIAtom* aPropertyName,
                  void*    aPropertyValue,
                  void*    aData          /* unused */)
 {
   NS_ABORT_IF_FALSE(aPropertyName == SMIL_MAPPED_ATTR_STYLERULE_ATOM,
                     "unexpected property name, for "
                     "animated content style rule");
-  nsICSSStyleRule* styleRule = static_cast<nsICSSStyleRule*>(aPropertyValue);
+  css::StyleRule* styleRule = static_cast<css::StyleRule*>(aPropertyValue);
   NS_ABORT_IF_FALSE(styleRule, "unexpected null style rule");
   styleRule->Release();
 }
 
 void
 nsSVGElement::UpdateAnimatedContentStyleRule()
 {
   NS_ABORT_IF_FALSE(!GetAnimatedContentStyleRule(),
@@ -1350,40 +1350,40 @@ nsSVGElement::UpdateAnimatedContentStyle
     return;
   }
 
   MappedAttrParser mappedAttrParser(doc->CSSLoader(), doc->GetDocumentURI(),
                                     GetBaseURI(), NodePrincipal());
   doc->PropertyTable(SMIL_MAPPED_ATTR_ANIMVAL)->
     Enumerate(this, ParseMappedAttrAnimValueCallback, &mappedAttrParser);
  
-  nsRefPtr<nsICSSStyleRule>
+  nsRefPtr<css::StyleRule>
     animContentStyleRule(mappedAttrParser.CreateStyleRule());
 
   if (animContentStyleRule) {
 #ifdef DEBUG
     nsresult rv =
 #endif
       SetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
                   SMIL_MAPPED_ATTR_STYLERULE_ATOM,
                   animContentStyleRule.get(),
                   ReleaseStyleRule);
     animContentStyleRule.forget();
     NS_ABORT_IF_FALSE(rv == NS_OK,
                       "SetProperty failed (or overwrote something)");
   }
 }
 
-nsICSSStyleRule*
+css::StyleRule*
 nsSVGElement::GetAnimatedContentStyleRule()
 {
   return
-    static_cast<nsICSSStyleRule*>(GetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
-                                              SMIL_MAPPED_ATTR_STYLERULE_ATOM,
-                                              nsnull));
+    static_cast<css::StyleRule*>(GetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
+                                             SMIL_MAPPED_ATTR_STYLERULE_ATOM,
+                                             nsnull));
 }
 #endif // MOZ_SMIL
 
 nsISVGValue*
 nsSVGElement::GetMappedAttribute(PRInt32 aNamespaceID, nsIAtom* aName)
 {
   const nsAttrValue* attrVal = mMappedAttributes.GetAttr(aName, aNamespaceID);
   if (!attrVal)
--- a/content/svg/content/src/nsSVGElement.h
+++ b/content/svg/content/src/nsSVGElement.h
@@ -47,17 +47,16 @@
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMSVGElement.h"
 #include "nsGenericElement.h"
 #include "nsStyledElement.h"
 #include "nsISVGValue.h"
 #include "nsISVGValueObserver.h"
 #include "nsWeakReference.h"
-#include "nsICSSStyleRule.h"
 
 #ifdef MOZ_SMIL
 #include "nsISMILAttr.h"
 #include "nsSMILAnimationController.h"
 #endif
 
 class nsSVGSVGElement;
 class nsSVGLength2;
@@ -249,17 +248,17 @@ protected:
                                               const nsAString& aValue);
 
   // Hooks for subclasses
   virtual PRBool IsEventName(nsIAtom* aName);
 
   void UpdateContentStyleRule();
 #ifdef MOZ_SMIL
   void UpdateAnimatedContentStyleRule();
-  nsICSSStyleRule* GetAnimatedContentStyleRule();
+  mozilla::css::StyleRule* GetAnimatedContentStyleRule();
 #endif // MOZ_SMIL
 
   nsISVGValue* GetMappedAttribute(PRInt32 aNamespaceID, nsIAtom* aName);
   nsresult AddMappedSVGValue(nsIAtom* aName, nsISupports* aValue,
                              PRInt32 aNamespaceID = kNameSpaceID_None);
   
   static nsIAtom* GetEventNameForAttr(nsIAtom* aAttr);
 
@@ -492,17 +491,17 @@ private:
     {}
     const nsAttrName* name;
     PRUint8 modType;
   };
   ObservableModificationData
     GetModificationDataForObservable(nsISVGValue* aObservable,
                                      nsISVGValue::modificationType aModType);
 
-  nsCOMPtr<nsICSSStyleRule> mContentStyleRule;
+  nsRefPtr<mozilla::css::StyleRule> mContentStyleRule;
   nsAttrAndChildArray mMappedAttributes;
 
   PRPackedBool mSuppressNotification;
 };
 
 /**
  * A macro to implement the NS_NewSVGXXXElement() functions.
  */
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -95,17 +95,17 @@
 #include "nsIRDFCompositeDataSource.h"
 #include "nsIRDFNode.h"
 #include "nsIRDFService.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptRuntime.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptGlobalObjectOwner.h"
 #include "nsIServiceManager.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsIStyleSheet.h"
 #include "nsIURL.h"
 #include "nsIViewManager.h"
 #include "nsIWidget.h"
 #include "nsIXULDocument.h"
 #include "nsIXULTemplateBuilder.h"
 #include "nsIXBLService.h"
 #include "nsLayoutCID.h"
@@ -148,16 +148,18 @@
 #include "nsNodeInfoManager.h"
 #include "nsXBLBinding.h"
 #include "nsEventDispatcher.h"
 #include "mozAutoDocUpdate.h"
 #include "nsIDOMXULCommandEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsCCUncollectableMarker.h"
 
+namespace css = mozilla::css;
+
 // Global object maintenance
 nsIXBLService * nsXULElement::gXBLService = nsnull;
 
 /**
  * A tearoff class for nsXULElement to implement nsIScriptEventHandlerOwner.
  */
 class nsScriptEventHandlerOwnerTearoff : public nsIScriptEventHandlerOwner
 {
@@ -1799,17 +1801,17 @@ nsXULElement::DoGetClasses() const
 }
 
 NS_IMETHODIMP
 nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
 {
     return NS_OK;
 }
 
-nsICSSStyleRule*
+css::StyleRule*
 nsXULElement::GetInlineStyleRule()
 {
     if (!HasFlag(NODE_MAY_HAVE_STYLE)) {
         return nsnull;
     }
     // Fetch the cached style rule from the attributes.
     const nsAttrValue* attrVal = FindLocalOrProtoAttr(kNameSpaceID_None, nsGkAtoms::style);
 
@@ -1964,17 +1966,17 @@ nsXULElement::EnsureLocalStyle()
         if (protoattr && protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
             nsCOMPtr<nsICSSRule> ruleClone =
                 protoattr->mValue.GetCSSStyleRuleValue()->Clone();
 
             nsString stringValue;
             protoattr->mValue.ToString(stringValue);
 
             nsAttrValue value;
-            nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(ruleClone);
+            nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
             value.SetTo(styleRule, &stringValue);
 
             nsresult rv =
                 mAttrsAndChildren.SetAndTakeAttr(nsGkAtoms::style, value);
             NS_ENSURE_SUCCESS(rv, rv);
         }
     }
 
@@ -2342,17 +2344,17 @@ nsresult nsXULElement::MakeHeavyweight()
         // Style rules need to be cloned.
         if (protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
             nsCOMPtr<nsICSSRule> ruleClone =
                 protoattr->mValue.GetCSSStyleRuleValue()->Clone();
 
             nsString stringValue;
             protoattr->mValue.ToString(stringValue);
 
-            nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(ruleClone);
+            nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
             attrValue.SetTo(styleRule, &stringValue);
         }
         else {
             attrValue.SetTo(protoattr->mValue);
         }
 
         // XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName
         if (protoattr->mName.IsAtom()) {
@@ -2873,17 +2875,17 @@ nsXULPrototypeElement::SetAttrAt(PRUint3
         // Compute the element's class list
         mAttributes[aPos].mValue.ParseAtomArray(aValue);
 
         return NS_OK;
     }
     else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
         mHasStyleAttribute = PR_TRUE;
         // Parse the element's 'style' attribute
-        nsCOMPtr<nsICSSStyleRule> rule;
+        nsRefPtr<css::StyleRule> rule;
 
         nsCSSParser parser;
         NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
 
         // XXX Get correct Base URI (need GetBaseURI on *prototype* element)
         parser.ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
                                    // This is basically duplicating what
                                    // nsINode::NodePrincipal() does
--- a/content/xul/content/src/nsXULElement.h
+++ b/content/xul/content/src/nsXULElement.h
@@ -75,24 +75,29 @@
 #include "nsAutoPtr.h"
 #include "nsStyledElement.h"
 #include "nsDOMScriptObjectHolder.h"
 #include "nsIFrameLoader.h"
 
 class nsIDocument;
 class nsString;
 class nsIDocShell;
-class nsICSSStyleRule;
 
 class nsIObjectInputStream;
 class nsIObjectOutputStream;
 class nsIScriptGlobalObjectOwner;
 class nsXULPrototypeNode;
 typedef nsTArray<nsRefPtr<nsXULPrototypeNode> > nsPrototypeArray;
 
+namespace mozilla {
+namespace css {
+class StyleRule;
+}
+}
+
 static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
 
 ////////////////////////////////////////////////////////////////////////
 
 #ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
 #define XUL_PROTOTYPE_ATTRIBUTE_METER(counter) (nsXULPrototypeAttribute::counter++)
 #else
 #define XUL_PROTOTYPE_ATTRIBUTE_METER(counter) ((void) 0)
@@ -535,17 +540,17 @@ public:
 
     virtual nsIContent *GetBindingParent() const;
     virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
     virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull, PRBool aWithMouse = PR_FALSE);
     virtual nsIAtom* DoGetID() const;
     virtual const nsAttrValue* DoGetClasses() const;
 
     NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
-    virtual nsICSSStyleRule* GetInlineStyleRule();
+    virtual mozilla::css::StyleRule* GetInlineStyleRule();
     virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
                                                 PRInt32 aModType) const;
     NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
     // XUL element methods
     /**
      * The template-generated flag is used to indicate that a
      * template-generated element has already had its children generated.
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -2271,17 +2271,17 @@ nsresult PresShell::CreatePreferenceStyl
   if (NS_FAILED(result)) {
     mPrefStyleSheet = nsnull;
   }
 
   return result;
 }
 
 // XXX We want these after the @namespace rule.  Does order matter
-// for these rules, or can we call nsICSSStyleRule::StyleRuleCount()
+// for these rules, or can we call StyleRule::StyleRuleCount()
 // and just "append"?
 static PRUint32 sInsertPrefSheetRulesAt = 1;
 
 nsresult
 PresShell::SetPrefNoScriptRule()
 {
   NS_TIME_FUNCTION_MIN(1.0);
 
--- a/layout/inspector/src/inDOMUtils.cpp
+++ b/layout/inspector/src/inDOMUtils.cpp
@@ -43,17 +43,17 @@
 #include "nsString.h"
 #include "nsIDOMElement.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMCharacterData.h"
 #include "nsRuleNode.h"
 #include "nsIStyleRule.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsICSSStyleRuleDOMWrapper.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsIDOMElement.h"
 #include "nsIMutableArray.h"
 #include "nsBindingManager.h"
 #include "nsComputedDOMStyle.h"
@@ -165,20 +165,20 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
     // if the document they're in doesn't have a presshell.  Bail out.
     return NS_OK;
   }
 
   nsCOMPtr<nsISupportsArray> rules;
   NS_NewISupportsArray(getter_AddRefs(rules));
   if (!rules) return NS_ERROR_OUT_OF_MEMORY;
 
-  nsCOMPtr<nsICSSStyleRule> cssRule;
+  nsRefPtr<mozilla::css::StyleRule> cssRule;
   nsCOMPtr<nsIDOMCSSRule> domRule;
   for ( ; !ruleNode->IsRoot(); ruleNode = ruleNode->GetParent()) {
-    cssRule = do_QueryInterface(ruleNode->GetRule());
+    cssRule = do_QueryObject(ruleNode->GetRule());
     if (cssRule) {
       cssRule->GetDOMRule(getter_AddRefs(domRule));
       if (domRule)
         rules->InsertElementAt(domRule, 0);
     }
   }
 
   *_retval = rules;
@@ -190,17 +190,17 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
 NS_IMETHODIMP
 inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, PRUint32 *_retval)
 {
   *_retval = 0;
 
   NS_ENSURE_ARG_POINTER(aRule);
 
   nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule);
-  nsCOMPtr<nsICSSStyleRule> cssrule;
+  nsRefPtr<mozilla::css::StyleRule> cssrule;
   nsresult rv = rule->GetCSSStyleRule(getter_AddRefs(cssrule));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(cssrule != nsnull, NS_ERROR_FAILURE);
   *_retval = cssrule->GetLineNumber();
   return NS_OK;
 }
 
 NS_IMETHODIMP 
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -42,17 +42,16 @@
 #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 "nsICSSStyleRule.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"
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -75,17 +75,16 @@ EXPORTS		= \
 		nsICSSDeclaration.h \
 		nsICSSGroupRule.h \
 		nsICSSImportRule.h \
 		nsICSSLoaderObserver.h \
 		nsICSSNameSpaceRule.h \
 		nsICSSPseudoComparator.h \
 		nsICSSRule.h \
 		nsICSSRuleList.h \
-		nsICSSStyleRule.h \
 		nsICSSStyleRuleDOMWrapper.h \
 		nsIStyleRule.h \
 		nsIStyleRuleProcessor.h \
 		nsIStyleSheet.h \
 		nsLayoutStylesheetCache.h \
 		nsRuleData.h \
 		nsRuleNode.h \
 		nsRuleProcessorData.h \
@@ -99,33 +98,33 @@ EXPORTS		= \
 		nsStyleStructList.h \
 		nsStyleTransformMatrix.h \
 		nsStyleUtil.h \
 		$(NULL)
 
 EXPORTS_mozilla/css = \
 		Declaration.h \
 		Loader.h \
+		StyleRule.h \
 		$(NULL)
 
 CPPSRCS		= \
 		nsCSSAnonBoxes.cpp \
 		nsCSSDataBlock.cpp \
 		Declaration.cpp \
 		nsCSSKeywords.cpp \
 		Loader.cpp \
 		nsCSSParser.cpp \
 		nsCSSProps.cpp \
 		nsCSSPseudoClasses.cpp \
 		nsCSSPseudoElements.cpp \
 		nsCSSRuleProcessor.cpp \
 		nsCSSRules.cpp \
 		nsCSSScanner.cpp \
 		nsCSSStruct.cpp \
-		nsCSSStyleRule.cpp \
 		nsCSSStyleSheet.cpp \
 		nsCSSValue.cpp \
 		nsComputedDOMStyle.cpp \
 		nsDOMCSSAttrDeclaration.cpp \
 		nsDOMCSSDeclaration.cpp \
 		nsDOMCSSRGBColor.cpp \
 		nsDOMCSSRect.cpp \
 		nsDOMCSSValueList.cpp \
@@ -140,16 +139,17 @@ CPPSRCS		= \
 		nsStyleAnimation.cpp \
 		nsStyleContext.cpp \
 		nsStyleCoord.cpp \
 		nsStyleSet.cpp \
 		nsStyleStruct.cpp \
 		nsStyleTransformMatrix.cpp \
 		nsStyleUtil.cpp \
 		nsTransitionManager.cpp \
+		StyleRule.cpp \
 		$(NULL)
 
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../base \
rename from layout/style/nsCSSStyleRule.cpp
rename to layout/style/StyleRule.cpp
--- a/layout/style/nsCSSStyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -39,19 +39,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * representation of CSS style rules (selectors+declaration), CSS
  * selectors, and DOM objects for style rules, selectors, and
  * declarations
  */
 
-#include "nsCOMPtr.h"
-#include "nsCSSRule.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsICSSGroupRule.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"
@@ -962,27 +960,27 @@ namespace mozilla {
 namespace css {
 class DOMCSSStyleRule;
 }
 }
 
 class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
 {
 public:
-  DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
+  DOMCSSDeclarationImpl(css::StyleRule *aRule);
   virtual ~DOMCSSDeclarationImpl(void);
 
   NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
   void DropReference(void);
   virtual css::Declaration* GetCSSDeclaration(PRBool aAllocate);
   virtual nsresult SetCSSDeclaration(css::Declaration* aDecl);
   virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
                                             nsIURI** aBaseURI,
                                             nsIPrincipal** aSheetPrincipal,
-                                            mozilla::css::Loader** aCSSLoader);
+                                            css::Loader** aCSSLoader);
   virtual nsIDocument* DocToUpdate();
 
   // Override |AddRef| and |Release| for being a member of
   // |DOMCSSStyleRule|.
   NS_IMETHOD_(nsrefcnt) AddRef(void);
   NS_IMETHOD_(nsrefcnt) Release(void);
 
   virtual nsINode *GetParentObject()
@@ -990,59 +988,59 @@ public:
     return nsnull;
   }
 
   friend class css::DOMCSSStyleRule;
 
 protected:
   // This reference is not reference-counted. The rule object tells us
   // when it's about to go away.
-  nsICSSStyleRule *mRule;
+  css::StyleRule *mRule;
 
   inline css::DOMCSSStyleRule* DomRule();
 
 private:
   // NOT TO BE IMPLEMENTED
   // This object cannot be allocated on its own.  It must be a member of
   // DOMCSSStyleRule.
   void* operator new(size_t size) CPP_THROW_NEW;
 };
 
 namespace mozilla {
 namespace css {
 
 class DOMCSSStyleRule : public nsICSSStyleRuleDOMWrapper
 {
 public:
-  DOMCSSStyleRule(nsICSSStyleRule *aRule);
+  DOMCSSStyleRule(StyleRule *aRule);
   virtual ~DOMCSSStyleRule();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMCSSRULE
   NS_DECL_NSIDOMCSSSTYLERULE
 
   // nsICSSStyleRuleDOMWrapper
-  NS_IMETHOD GetCSSStyleRule(nsICSSStyleRule **aResult);
+  NS_IMETHOD GetCSSStyleRule(StyleRule **aResult);
 
   DOMCSSDeclarationImpl* DOMDeclaration() { return &mDOMDeclaration; }
 
   friend class ::DOMCSSDeclarationImpl;
 
 protected:
   DOMCSSDeclarationImpl mDOMDeclaration;
 
-  nsICSSStyleRule* Rule() {
+  StyleRule* Rule() {
     return mDOMDeclaration.mRule;
   }
 };
 
 } // namespace css
 } // namespace mozilla
 
-DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
+DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *aRule)
   : mRule(aRule)
 {
   MOZ_COUNT_CTOR(DOMCSSDeclarationImpl);
 }
 
 DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl(void)
 {
   NS_ASSERTION(!mRule, "DropReference not called.");
@@ -1080,17 +1078,17 @@ DOMCSSDeclarationImpl::GetCSSDeclaration
  * This is a utility function.  It will only fail if it can't get a
  * parser.  This means it can return NS_OK without aURI or aCSSLoader
  * being initialized.
  */
 nsresult
 DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
                                                 nsIURI** aBaseURI,
                                                 nsIPrincipal** aSheetPrincipal,
-                                                mozilla::css::Loader** aCSSLoader)
+                                                css::Loader** aCSSLoader)
 {
   // null out the out params since some of them may not get initialized below
   *aSheetURI = nsnull;
   *aBaseURI = nsnull;
   *aSheetPrincipal = nsnull;
   *aCSSLoader = nsnull;
 
   nsCOMPtr<nsIStyleSheet> sheet;
@@ -1143,17 +1141,17 @@ DOMCSSDeclarationImpl::SetCSSDeclaration
   nsCOMPtr<nsIDocument> owningDoc;
   nsCOMPtr<nsIStyleSheet> sheet = mRule->GetStyleSheet();
   if (sheet) {
     owningDoc = sheet->GetOwningDocument();
   }
 
   mozAutoDocUpdate updateBatch(owningDoc, UPDATE_STYLE, PR_TRUE);
 
-  nsCOMPtr<nsICSSStyleRule> oldRule = mRule;
+  nsRefPtr<css::StyleRule> oldRule = mRule;
   mRule = oldRule->DeclarationChanged(aDecl, PR_TRUE).get();
   if (!mRule)
     return NS_ERROR_OUT_OF_MEMORY;
   nsrefcnt cnt = mRule->Release();
   if (cnt == 0) {
     NS_NOTREACHED("container didn't take ownership");
     mRule = nsnull;
     return NS_ERROR_UNEXPECTED;
@@ -1172,17 +1170,17 @@ DOMCSSDeclarationImpl::DocToUpdate()
 }
 
 // needs to be outside the namespace
 DOMCI_DATA(CSSStyleRule, css::DOMCSSStyleRule)
 
 namespace mozilla {
 namespace css {
 
-DOMCSSStyleRule::DOMCSSStyleRule(nsICSSStyleRule* aRule)
+DOMCSSStyleRule::DOMCSSStyleRule(StyleRule* aRule)
   : mDOMDeclaration(aRule)
 {
 }
 
 DOMCSSStyleRule::~DOMCSSStyleRule()
 {
 }
 
@@ -1276,101 +1274,31 @@ NS_IMETHODIMP
 DOMCSSStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
 {
   *aStyle = &mDOMDeclaration;
   NS_ADDREF(*aStyle);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-DOMCSSStyleRule::GetCSSStyleRule(nsICSSStyleRule **aResult)
+DOMCSSStyleRule::GetCSSStyleRule(StyleRule **aResult)
 {
   *aResult = Rule();
   NS_IF_ADDREF(*aResult);
   return NS_OK;
 }
 
 } // namespace css
 } // namespace mozilla
 
 // -- StyleRule ------------------------------------
 
 namespace mozilla {
 namespace css {
 
-class NS_FINAL_CLASS StyleRule : public nsCSSRule,
-                                 public nsICSSStyleRule
-{
-public:
-  StyleRule(nsCSSSelectorList* aSelector,
-            Declaration *aDeclaration);
-private:
-  // for |Clone|
-  StyleRule(const StyleRule& aCopy);
-  // for |DeclarationChanged|
-  StyleRule(StyleRule& aCopy,
-            Declaration *aDeclaration);
-public:
-
-  NS_DECL_ISUPPORTS
-
-  virtual nsCSSSelectorList* Selector(void);
-
-  virtual PRUint32 GetLineNumber(void) const;
-  virtual void SetLineNumber(PRUint32 aLineNumber);
-
-  virtual Declaration* GetDeclaration(void) const;
-
-  virtual nsIStyleRule* GetImportantRule(void);
-  virtual void RuleMatched();
-
-  virtual already_AddRefed<nsIStyleSheet> GetStyleSheet() const;
-  virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
-
-  virtual void SetParentRule(nsICSSGroupRule* aRule);
-
-  virtual nsresult GetCssText(nsAString& aCssText);
-  virtual nsresult SetCssText(const nsAString& aCssText);
-  virtual nsresult GetParentStyleSheet(nsCSSStyleSheet** aSheet);
-  virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule);
-  virtual nsresult GetSelectorText(nsAString& aSelectorText);
-  virtual nsresult SetSelectorText(const nsAString& aSelectorText);
-
-  virtual PRInt32 GetType() const;
-  virtual already_AddRefed<nsICSSRule> Clone() const;
-
-  nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
-
-  virtual already_AddRefed<nsICSSStyleRule>
-  DeclarationChanged(Declaration* aDecl, PRBool aHandleContainer);
-
-  // The new mapping function.
-  virtual void MapRuleInfoInto(nsRuleData* aRuleData);
-
-#ifdef DEBUG
-  virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
-#endif
-
-private:
-  // These are not supported and are not implemented!
-  StyleRule& operator=(const StyleRule& aCopy);
-
-private:
-  ~StyleRule();
-
-protected:
-  nsCSSSelectorList*      mSelector; // null for style attribute
-  Declaration*            mDeclaration;
-  ImportantRule*          mImportantRule; // initialized by RuleMatched
-  DOMCSSStyleRule*        mDOMRule;
-  // Keep the same type so that MSVC packs them.
-  PRUint32                mLineNumber : 31;
-  PRUint32                mWasMatched : 1;
-};
-
 StyleRule::StyleRule(nsCSSSelectorList* aSelector,
                      Declaration* aDeclaration)
   : nsCSSRule(),
     mSelector(aSelector),
     mDeclaration(aDeclaration),
     mImportantRule(nsnull),
     mDOMRule(nsnull),
     mLineNumber(0),
@@ -1427,20 +1355,25 @@ StyleRule::~StyleRule()
   if (mDOMRule) {
     mDOMRule->DOMDeclaration()->DropReference();
     NS_RELEASE(mDOMRule);
   }
 }
 
 // QueryInterface implementation for StyleRule
 NS_INTERFACE_MAP_BEGIN(StyleRule)
-  NS_INTERFACE_MAP_ENTRY(nsICSSStyleRule)
+  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, nsICSSStyleRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(StyleRule)
 NS_IMPL_RELEASE(StyleRule)
 
 nsCSSSelectorList* StyleRule::Selector()
 {
   return mSelector;
@@ -1527,17 +1460,17 @@ StyleRule::GetDOMRuleWeak(nsresult *aRes
       *aResult = NS_ERROR_OUT_OF_MEMORY;
       return nsnull;
     }
     NS_ADDREF(mDOMRule);
   }
   return mDOMRule;
 }
 
-/* virtual */ already_AddRefed<nsICSSStyleRule>
+/* virtual */ already_AddRefed<StyleRule>
 StyleRule::DeclarationChanged(Declaration* aDecl,
                               PRBool aHandleContainer)
 {
   StyleRule* clone = new StyleRule(*this, aDecl);
   if (!clone) {
     return nsnull;
   }
 
@@ -1554,17 +1487,17 @@ StyleRule::DeclarationChanged(Declaratio
 
   return clone;
 }
 
 /* virtual */ void
 StyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
   NS_ABORT_IF_FALSE(mWasMatched,
-                    "somebody forgot to call nsICSSStyleRule::RuleMatched");
+                    "somebody forgot to call css::StyleRule::RuleMatched");
   mDeclaration->MapNormalRuleInfoInto(aRuleData);
 }
 
 #ifdef DEBUG
 /* virtual */ void
 StyleRule::List(FILE* out, PRInt32 aIndent) const
 {
   // Indent
@@ -1646,17 +1579,17 @@ StyleRule::SetSelectorText(const nsAStri
   // XXX then need to re-compute the cascade
   // XXX and dirty sheet
   return NS_OK;
 }
 
 } // namespace css
 } // namespace mozilla
 
-already_AddRefed<nsICSSStyleRule>
+already_AddRefed<css::StyleRule>
 NS_NewCSSStyleRule(nsCSSSelectorList* aSelector,
                    css::Declaration* aDeclaration)
 {
   NS_PRECONDITION(aDeclaration, "must have a declaration");
   css::StyleRule *it = new css::StyleRule(aSelector, aDeclaration);
   NS_ADDREF(it);
   return it;
 }
rename from layout/style/nsICSSStyleRule.h
rename to layout/style/StyleRule.h
--- a/layout/style/nsICSSStyleRule.h
+++ b/layout/style/StyleRule.h
@@ -37,36 +37,32 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * representation of CSS style rules (selectors+declaration) and CSS
  * selectors
  */
 
-#ifndef nsICSSStyleRule_h___
-#define nsICSSStyleRule_h___
+#ifndef mozilla_css_StyleRule_h__
+#define mozilla_css_StyleRule_h__
 
 //#include <stdio.h>
 #include "nsICSSRule.h"
+#include "nsCSSRule.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
-#include "nsCSSValue.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSPseudoClasses.h"
+#include "nsAutoPtr.h"
 
 class nsIAtom;
 class nsCSSStyleSheet;
 struct nsCSSSelectorList;
-
-namespace mozilla {
-namespace css {
-class Declaration;
-}
-}
+class nsCSSCompressedDataBlock;
 
 struct nsAtomList {
 public:
   nsAtomList(nsIAtom* aAtom);
   nsAtomList(const nsString& aAtomValue);
   ~nsAtomList(void);
 
   /** Do a deep clone.  Should be used only on the first in the linked list. */
@@ -287,60 +283,116 @@ struct nsCSSSelectorList {
 private: 
   nsCSSSelectorList* Clone(PRBool aDeep) const;
 
   // These are not supported and are not implemented! 
   nsCSSSelectorList(const nsCSSSelectorList& aCopy);
   nsCSSSelectorList& operator=(const nsCSSSelectorList& aCopy); 
 };
 
-// 97eb9881-55fb-462c-be1a-b6309d42f8d0
-#define NS_ICSS_STYLE_RULE_IID \
-{ 0x97eb9881, 0x55fb, 0x462c, \
-  { 0xbe, 0x1a, 0xb6, 0x30, 0x9d, 0x42, 0xf8, 0xd0 } }
+// 464bab7a-2fce-4f30-ab44-b7a5f3aae57d
+#define NS_CSS_STYLE_RULE_IMPL_CID \
+{ 0x464bab7a, 0x2fce, 0x4f30, \
+  { 0xab, 0x44, 0xb7, 0xa5, 0xf3, 0xaa, 0xe5, 0x7d } }
+
+namespace mozilla {
+namespace css {
+
+class Declaration;
+class ImportantRule;
+class DOMCSSStyleRule;
 
-class nsICSSStyleRule : public nsICSSRule {
+class NS_FINAL_CLASS StyleRule : public nsCSSRule,
+                                 public nsICSSRule {
+ public:
+  StyleRule(nsCSSSelectorList* aSelector,
+            Declaration *aDeclaration);
+private:
+  // for |Clone|
+  StyleRule(const StyleRule& aCopy);
+  // for |DeclarationChanged|
+  StyleRule(StyleRule& aCopy,
+            Declaration *aDeclaration);
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_IID)
+  NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID)
+
+  NS_DECL_ISUPPORTS
 
   // null for style attribute
-  virtual nsCSSSelectorList* Selector(void) = 0;
+  virtual nsCSSSelectorList* Selector();
 
-  virtual PRUint32 GetLineNumber(void) const = 0;
-  virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
+  virtual PRUint32 GetLineNumber() const;
+  virtual void SetLineNumber(PRUint32 aLineNumber);
 
-  virtual mozilla::css::Declaration* GetDeclaration(void) const = 0;
+  virtual Declaration* GetDeclaration() const;
 
   /**
    * Return a new |nsIStyleRule| instance that replaces the current
    * one, with |aDecl| replacing the previous declaration. Due to the
    * |nsIStyleRule| contract of immutability, this must be called if
    * the declaration is modified.
    *
    * |DeclarationChanged| handles replacing the object in the container
    * sheet or group rule if |aHandleContainer| is true.
    */
-  virtual already_AddRefed<nsICSSStyleRule>
-  DeclarationChanged(mozilla::css::Declaration* aDecl,
-                     PRBool aHandleContainer) = 0;
+  virtual already_AddRefed<StyleRule>
+  DeclarationChanged(Declaration* aDecl, PRBool aHandleContainer);
+
+  virtual nsIStyleRule* GetImportantRule();
 
   /**
    * The rule processor must call this method before calling
    * nsRuleWalker::Forward on this rule during rule matching.
    */
-  virtual void RuleMatched() = 0;
+  virtual void RuleMatched();
 
   // hooks for DOM rule
-  virtual nsresult GetCssText(nsAString& aCssText) = 0;
-  virtual nsresult SetCssText(const nsAString& aCssText) = 0;
-  virtual nsresult GetParentStyleSheet(nsCSSStyleSheet** aSheet) = 0;
-  virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule) = 0;
-  virtual nsresult GetSelectorText(nsAString& aSelectorText) = 0;
-  virtual nsresult SetSelectorText(const nsAString& aSelectorText) = 0;
+  virtual nsresult GetCssText(nsAString& aCssText);
+  virtual nsresult SetCssText(const nsAString& aCssText);
+  virtual nsresult GetParentStyleSheet(nsCSSStyleSheet** aSheet);
+  virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule);
+  virtual nsresult GetSelectorText(nsAString& aSelectorText);
+  virtual nsresult 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 already_AddRefed<nsICSSRule> 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;
+#endif
+
+private:
+  // This is not supported and not implemented!
+  StyleRule& operator=(const StyleRule& aCopy);
+
+private:
+  ~StyleRule();
+
+private:
+  nsCSSSelectorList*      mSelector; // null for style attribute
+  Declaration*            mDeclaration;
+  ImportantRule*          mImportantRule; // initialized by RuleMatched
+  DOMCSSStyleRule*        mDOMRule;
+  // Keep the same type so that MSVC packs them.
+  PRUint32                mLineNumber : 31;
+  PRUint32                mWasMatched : 1;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleRule, NS_ICSS_STYLE_RULE_IID)
+} // namespace css
+} // namespace mozilla
 
-already_AddRefed<nsICSSStyleRule>
+NS_DEFINE_STATIC_IID_ACCESSOR(mozilla::css::StyleRule, NS_CSS_STYLE_RULE_IMPL_CID)
+
+already_AddRefed<mozilla::css::StyleRule>
 NS_NewCSSStyleRule(nsCSSSelectorList* aSelector,
                    mozilla::css::Declaration* aDeclaration);
 
-#endif /* nsICSSStyleRule_h___ */
+#endif /* mozilla_css_StyleRule_h__ */
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -46,17 +46,17 @@
 
 /* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
 
 #include "nsCSSParser.h"
 #include "nsCSSProps.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSScanner.h"
 #include "mozilla/css/Loader.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsICSSImportRule.h"
 #include "nsCSSRules.h"
 #include "nsICSSNameSpaceRule.h"
 #include "nsIUnicharInputStream.h"
 #include "nsCSSStyleSheet.h"
 #include "mozilla/css/Declaration.h"
 #include "nsStyleConsts.h"
 #include "nsIURL.h"
@@ -209,17 +209,17 @@ public:
                  nsIPrincipal*          aSheetPrincipal,
                  PRUint32               aLineNumber,
                  PRBool                 aAllowUnsafeRules);
 
   nsresult ParseStyleAttribute(const nsAString&  aAttributeValue,
                                nsIURI*           aDocURL,
                                nsIURI*           aBaseURL,
                                nsIPrincipal*     aNodePrincipal,
-                               nsICSSStyleRule** aResult);
+                               css::StyleRule**  aResult);
 
   nsresult ParseDeclarations(const nsAString&  aBuffer,
                              nsIURI*           aSheetURL,
                              nsIURI*           aBaseURL,
                              nsIPrincipal*     aSheetPrincipal,
                              css::Declaration* aDeclaration,
                              PRBool*           aChanged);
 
@@ -957,20 +957,20 @@ NonMozillaVendorIdentifier(const nsAStri
   return (ident.First() == PRUnichar('-') &&
           !StringBeginsWith(ident, NS_LITERAL_STRING("-moz-"))) ||
          ident.First() == PRUnichar('_');
 
 }
 
 nsresult
 CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
-                                   nsIURI*                  aDocURI,
-                                   nsIURI*                  aBaseURI,
-                                   nsIPrincipal*            aNodePrincipal,
-                                   nsICSSStyleRule**        aResult)
+                                   nsIURI*          aDocURI,
+                                   nsIURI*          aBaseURI,
+                                   nsIPrincipal*    aNodePrincipal,
+                                   css::StyleRule** aResult)
 {
   NS_PRECONDITION(aNodePrincipal, "Must have principal here!");
   AssertInitialState();
 
   NS_ASSERTION(nsnull != aBaseURI, "need base URI");
 
   // XXX line number?
   InitScanner(aAttributeValue, aDocURI, 0, aBaseURI, aNodePrincipal);
@@ -2455,17 +2455,17 @@ CSSParserImpl::ParseRuleSet(RuleAppendFu
   slist->Dump();
   fputs("{\n", stdout);
   declaration->List();
   fputs("}\n", stdout);
 #endif
 
   // Translate the selector list and declaration block into style data
 
-  nsCOMPtr<nsICSSStyleRule> rule = NS_NewCSSStyleRule(slist, declaration);
+  nsRefPtr<css::StyleRule> rule = NS_NewCSSStyleRule(slist, declaration);
   rule->SetLineNumber(linenum);
   (*aAppendFunc)(rule, aData);
 
   return PR_TRUE;
 }
 
 PRBool
 CSSParserImpl::ParseSelectorList(nsCSSSelectorList*& aListHead,
@@ -8499,17 +8499,17 @@ nsCSSParser::Parse(nsIUnicharInputStream
           aAllowUnsafeRules);
 }
 
 nsresult
 nsCSSParser::ParseStyleAttribute(const nsAString&  aAttributeValue,
                                  nsIURI*           aDocURI,
                                  nsIURI*           aBaseURI,
                                  nsIPrincipal*     aNodePrincipal,
-                                 nsICSSStyleRule** aResult)
+                                 css::StyleRule**  aResult)
 {
   return static_cast<CSSParserImpl*>(mImpl)->
     ParseStyleAttribute(aAttributeValue, aDocURI, aBaseURI,
                         aNodePrincipal, aResult);
 }
 
 nsresult
 nsCSSParser::ParseDeclarations(const nsAString&  aBuffer,
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -41,28 +41,28 @@
 #define nsCSSParser_h___
 
 #include "nsAString.h"
 #include "nsCSSProperty.h"
 #include "nsColor.h"
 #include "nsCOMArray.h"
 
 class nsICSSRule;
-class nsICSSStyleRule;
 class nsCSSStyleSheet;
 class nsIPrincipal;
 class nsIURI;
 class nsIUnicharInputStream;
 struct nsCSSSelectorList;
 class nsMediaList;
 
 namespace mozilla {
 namespace css {
 class Declaration;
 class Loader;
+class StyleRule;
 }
 }
 
 // Interface to the css parser.
 
 class NS_STACK_CLASS nsCSSParser {
 public:
   nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
@@ -123,17 +123,17 @@ public:
 
   // Parse HTML style attribute or its equivalent in other markup
   // languages.  aBaseURL is the base url to use for relative links in
   // the declaration.
   nsresult ParseStyleAttribute(const nsAString&  aAttributeValue,
                                nsIURI*           aDocURL,
                                nsIURI*           aBaseURL,
                                nsIPrincipal*     aNodePrincipal,
-                               nsICSSStyleRule** aResult);
+                               mozilla::css::StyleRule** aResult);
 
   // Parse the body of a declaration block.  Very similar to
   // ParseStyleAttribute, but used under different circumstances.
   // The contents of aDeclaration will be erased and replaced with the
   // results of parsing; aChanged will be set true if the aDeclaration
   // argument was modified.
   nsresult ParseDeclarations(const nsAString&  aBuffer,
                              nsIURI*           aSheetURL,
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -53,17 +53,17 @@
 #include "plarena.h"
 
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "pldhash.h"
 #include "nsHashtable.h"
 #include "nsICSSPseudoComparator.h"
 #include "nsCSSRuleProcessor.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsICSSGroupRule.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsIEventStateManager.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "nsDOMError.h"
@@ -90,16 +90,17 @@
 #include "nsIObserverService.h"
 #include "nsIPrivateBrowsingService.h"
 #include "nsNetCID.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/Element.h"
 #include "nsGenericElement.h"
 
 using namespace mozilla::dom;
+namespace css = mozilla::css;
 
 #define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled"
 
 static PRBool gSupportVisitedPseudo = PR_TRUE;
 
 static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
 static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
 
@@ -107,20 +108,20 @@ static nsTArray< nsCOMPtr<nsIAtom> >* sS
 PRUint8 nsCSSRuleProcessor::sWinThemeId = nsILookAndFeel::eWindowsTheme_Generic;
 #endif
 
 /**
  * A struct representing a given CSS rule and a particular selector
  * from that rule's selector list.
  */
 struct RuleSelectorPair {
-  RuleSelectorPair(nsICSSStyleRule* aRule, nsCSSSelector* aSelector)
+  RuleSelectorPair(css::StyleRule* aRule, nsCSSSelector* aSelector)
     : mRule(aRule), mSelector(aSelector) {}
 
-  nsICSSStyleRule*  mRule;
+  css::StyleRule*   mRule;
   nsCSSSelector*    mSelector; // which of |mRule|'s selectors
 };
 
 /**
  * A struct representing a particular rule in an ordered list of rules
  * (the ordering depending on the weight of mSelector and the order of
  * our rules to start with).
  */
@@ -585,17 +586,17 @@ void RuleHash::AppendRule(const RuleSele
 #define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
   (var_) += (list_).Length()
 #else
 #define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
   PR_BEGIN_MACRO PR_END_MACRO
 #endif
 
 static inline
-void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector,
+void ContentEnumFunc(css::StyleRule* aRule, nsCSSSelector* aSelector,
                      RuleProcessorData* data);
 
 void RuleHash::EnumerateAllRules(PRInt32 aNameSpace, nsIAtom* aTag,
                                  nsIAtom* aID, const nsAttrValue* aClassList,
                                  RuleProcessorData* aData)
 {
   PRInt32 classCount = aClassList ? aClassList->GetAtomCount() : 0;
 
@@ -2342,36 +2343,28 @@ static PRBool SelectorMatchesTree(RulePr
       }
     }
     prevdata = data;
   }
   return PR_TRUE; // all the selectors matched.
 }
 
 static inline
-void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector,
+void ContentEnumFunc(css::StyleRule* aRule, nsCSSSelector* aSelector,
                      RuleProcessorData* data)
 {
   TreeMatchContext treeContext(PR_TRUE, data->mRuleWalker->VisitedHandling());
   NodeMatchContext nodeContext(nsEventStates(), data->IsLink());
   if (nodeContext.mIsRelevantLink) {
     treeContext.mHaveRelevantLink = PR_TRUE;
   }
   if (SelectorMatches(*data, aSelector, nodeContext, treeContext)) {
     nsCSSSelector *next = aSelector->mNext;
     if (!next || SelectorMatchesTree(*data, next, treeContext,
                                      !nodeContext.mIsRelevantLink)) {
-      // for performance, require that every implementation of
-      // nsICSSStyleRule return the same pointer for nsIStyleRule (why
-      // would anything multiply inherit nsIStyleRule anyway?)
-#ifdef DEBUG
-      nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(aRule);
-      NS_ASSERTION(static_cast<nsIStyleRule*>(aRule) == iRule.get(),
-                   "Please fix QI so this performance optimization is valid");
-#endif
       aRule->RuleMatched();
       data->mRuleWalker->Forward(static_cast<nsIStyleRule*>(aRule));
       // nsStyleSet will deal with the !important rule
     }
   }
 
   if (treeContext.mHaveRelevantLink) {
     data->mRuleWalker->SetHaveRelevantLink();
@@ -2417,24 +2410,16 @@ nsCSSRuleProcessor::RulesMatching(AnonBo
   if (cascade && cascade->mAnonBoxRules.entryCount) {
     RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>
       (PL_DHashTableOperate(&cascade->mAnonBoxRules, aData->mPseudoTag,
                             PL_DHASH_LOOKUP));
     if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
       nsTArray<RuleValue>& rules = entry->mRules;
       for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
            value != end; ++value) {
-        // for performance, require that every implementation of
-        // nsICSSStyleRule return the same pointer for nsIStyleRule (why
-        // would anything multiply inherit nsIStyleRule anyway?)
-#ifdef DEBUG
-        nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(value->mRule);
-        NS_ASSERTION(static_cast<nsIStyleRule*>(value->mRule) == iRule.get(),
-                     "Please fix QI so this performance optimization is valid");
-#endif
         value->mRule->RuleMatched();
         aData->mRuleWalker->Forward(static_cast<nsIStyleRule*>(value->mRule));
       }
     }
   }
 }
 
 #ifdef MOZ_XUL
@@ -2976,17 +2961,17 @@ struct CascadeEnumData {
  */
 static PRBool
 CascadeRuleEnumFunc(nsICSSRule* aRule, void* aData)
 {
   CascadeEnumData* data = (CascadeEnumData*)aData;
   PRInt32 type = aRule->GetType();
 
   if (nsICSSRule::STYLE_RULE == type) {
-    nsICSSStyleRule* styleRule = (nsICSSStyleRule*)aRule;
+    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)
--- a/layout/style/nsDOMCSSAttrDeclaration.cpp
+++ b/layout/style/nsDOMCSSAttrDeclaration.cpp
@@ -37,18 +37,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 /* DOM object for element.style */
 
 #include "nsDOMCSSAttrDeclaration.h"
 
 #include "mozilla/css/Declaration.h"
 #include "mozilla/css/Loader.h"
+#include "mozilla/css/StyleRule.h"
 #include "mozilla/dom/Element.h"
-#include "nsICSSStyleRule.h"
 #include "nsIDocument.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
 #include "nsNodeUtils.h"
 
 namespace css = mozilla::css;
 namespace dom = mozilla::dom;
@@ -82,24 +82,24 @@ NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDe
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSAttributeDeclaration)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSAttributeDeclaration)
 
 nsresult
 nsDOMCSSAttributeDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
 {
   NS_ASSERTION(mElement, "Must have Element to set the declaration!");
-  nsICSSStyleRule* oldRule =
+  css::StyleRule* oldRule =
 #ifdef MOZ_SMIL
     mIsSMILOverride ? mElement->GetSMILOverrideStyleRule() :
 #endif // MOZ_SMIL
     mElement->GetInlineStyleRule();
   NS_ASSERTION(oldRule, "Element must have rule");
 
-  nsCOMPtr<nsICSSStyleRule> newRule =
+  nsRefPtr<css::StyleRule> newRule =
     oldRule->DeclarationChanged(aDecl, PR_FALSE);
   if (!newRule) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return
 #ifdef MOZ_SMIL
     mIsSMILOverride ? mElement->SetSMILOverrideStyleRule(newRule, PR_TRUE) :
@@ -129,17 +129,17 @@ nsDOMCSSAttributeDeclaration::DocToUpdat
 }
 
 css::Declaration*
 nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate)
 {
   if (!mElement)
     return nsnull;
 
-  nsICSSStyleRule* cssRule;
+  css::StyleRule* cssRule;
 #ifdef MOZ_SMIL
   if (mIsSMILOverride)
     cssRule = mElement->GetSMILOverrideStyleRule();
   else
 #endif // MOZ_SMIL
     cssRule = mElement->GetInlineStyleRule();
 
   if (cssRule) {
@@ -147,17 +147,17 @@ nsDOMCSSAttributeDeclaration::GetCSSDecl
   }
   if (!aAllocate) {
     return nsnull;
   }
 
   // cannot fail
   css::Declaration *decl = new css::Declaration();
   decl->InitializeEmpty();
-  nsCOMPtr<nsICSSStyleRule> newRule = NS_NewCSSStyleRule(nsnull, decl);
+  nsRefPtr<css::StyleRule> newRule = NS_NewCSSStyleRule(nsnull, decl);
 
   // this *can* fail (inside SetAttrAndNotify, at least).
   nsresult rv;
 #ifdef MOZ_SMIL
   if (mIsSMILOverride)
     rv = mElement->SetSMILOverrideStyleRule(newRule, PR_FALSE);
   else
 #endif // MOZ_SMIL
--- a/layout/style/nsHTMLCSSStyleSheet.cpp
+++ b/layout/style/nsHTMLCSSStyleSheet.cpp
@@ -42,44 +42,45 @@
 
 #include "nsHTMLCSSStyleSheet.h"
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "nsIURL.h"
 #include "nsCSSPseudoElements.h"
 #include "nsIStyleRule.h"
 #include "nsIFrame.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsIStyleRuleProcessor.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
 #include "nsCOMPtr.h"
 #include "nsRuleWalker.h"
 #include "nsRuleData.h"
 #include "nsRuleProcessorData.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla::dom;
+namespace css = mozilla::css;
 
 nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
   : mDocument(nsnull)
 {
 }
 
 NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
                    nsIStyleSheet,
                    nsIStyleRuleProcessor)
 
 /* virtual */ void
 nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
 {
   Element* element = aData->mElement;
 
   // just get the one and only style rule from the content's STYLE attribute
-  nsICSSStyleRule* rule = element->GetInlineStyleRule();
+  css::StyleRule* rule = element->GetInlineStyleRule();
   if (rule) {
     rule->RuleMatched();
     aData->mRuleWalker->Forward(rule);
   }
 
 #ifdef MOZ_SMIL
   rule = element->GetSMILOverrideStyleRule();
   if (rule) {
--- a/layout/style/nsICSSStyleRuleDOMWrapper.h
+++ b/layout/style/nsICSSStyleRuleDOMWrapper.h
@@ -41,23 +41,24 @@
  */
 
 #ifndef nsICSSStyleRuleDOMWrapper_h_
 #define nsICSSStyleRuleDOMWrapper_h_
 
 #include "nsIDOMCSSStyleRule.h"
 
 // IID for the nsICSSStyleRuleDOMWrapper interface
-// {476a4290-1194-4099-8f2d-a1ccc9bdd676}
+// {cee1bbb6-0a32-4cf3-8d42-ba3938e9ecaa}
 #define NS_ICSS_STYLE_RULE_DOM_WRAPPER_IID \
-{0x476a4290, 0x1194, 0x4099, {0x8f, 0x2d, 0xa1, 0xcc, 0xc9, 0xbd, 0xd6, 0x76}}
+{0xcee1bbb6, 0x0a32, 0x4cf3, {0x8d, 0x42, 0xba, 0x39, 0x38, 0xe9, 0xec, 0xaa}}
+
 
 class nsICSSStyleRuleDOMWrapper : public nsIDOMCSSStyleRule {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_DOM_WRAPPER_IID)
 
-  NS_IMETHOD GetCSSStyleRule(nsICSSStyleRule** aResult) = 0;
+  NS_IMETHOD GetCSSStyleRule(mozilla::css::StyleRule** aResult) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleRuleDOMWrapper,
                               NS_ICSS_STYLE_RULE_DOM_WRAPPER_IID)
 
 #endif /* !defined(nsICSSStyleRuleDOMWrapper_h_) */
--- a/layout/style/nsStyleAnimation.cpp
+++ b/layout/style/nsStyleAnimation.cpp
@@ -37,17 +37,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* Utilities for animation of computed style values */
 
 #include "nsStyleAnimation.h"
 #include "nsCOMArray.h"
 #include "nsIStyleRule.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsString.h"
 #include "nsStyleContext.h"
 #include "nsStyleSet.h"
 #include "nsComputedDOMStyle.h"
 #include "nsCSSParser.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSStruct.h"
 #include "prlog.h"
@@ -1773,17 +1773,17 @@ nsStyleAnimation::AddWeighted(nsCSSPrope
       return PR_TRUE;
     }
   }
 
   NS_ABORT_IF_FALSE(false, "Can't interpolate using the given common unit");
   return PR_FALSE;
 }
 
-already_AddRefed<nsICSSStyleRule>
+already_AddRefed<css::StyleRule>
 BuildStyleRule(nsCSSProperty aProperty,
                nsIContent* aTargetElement,
                const nsAString& aSpecifiedValue,
                PRBool aUseSVGMode)
 {
   // Set up an empty CSS Declaration
   nsAutoPtr<css::Declaration> declaration(new css::Declaration());
   declaration->InitializeEmpty();
@@ -1865,18 +1865,18 @@ StyleWithDeclarationAdded(nsCSSProperty 
                     "if we're going to look up its style context");
 
   // Look up style context for our target element
   nsRefPtr<nsStyleContext> styleContext = LookupStyleContext(aTargetElement);
   if (!styleContext) {
     return nsnull;
   }
 
-  // Parse specified value into a temporary nsICSSStyleRule
-  nsCOMPtr<nsICSSStyleRule> styleRule =
+  // Parse specified value into a temporary StyleRule
+  nsRefPtr<css::StyleRule> styleRule =
     BuildStyleRule(aProperty, aTargetElement, aSpecifiedValue, aUseSVGMode);
   if (!styleRule) {
     return nsnull;
   }
 
   styleRule->RuleMatched();
 
   // Create a temporary nsStyleContext for the style rule
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -45,17 +45,17 @@
  */
 
 #include "nsStyleSet.h"
 #include "nsNetUtil.h"
 #include "nsCSSStyleSheet.h"
 #include "nsIDocument.h"
 #include "nsRuleWalker.h"
 #include "nsStyleContext.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsIContent.h"
 #include "nsIFrame.h"
 #include "nsContentUtils.h"
 #include "nsRuleProcessorData.h"
 #include "nsTransitionManager.h"
@@ -559,17 +559,17 @@ nsStyleSet::AssertNoCSSRules(nsRuleNode*
                              nsRuleNode* aLastPrevLevelNode)
 {
   if (!aCurrLevelNode)
     return;
 
   for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
        node = node->GetParent()) {
     nsIStyleRule *rule = node->GetRule();
-    nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
+    nsRefPtr<mozilla::css::StyleRule> cssRule(do_QueryObject(rule));
     NS_ASSERTION(!cssRule || !cssRule->Selector(), "Unexpected CSS rule");
   }
 }
 #endif
 
 // Enumerate the rules in a way that cares about the order of the rules.
 void
 nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, 
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -69,17 +69,17 @@
 #include "nsIDOMElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMDocumentEvent.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
-#include "nsICSSStyleRule.h"
+#include "mozilla/css/StyleRule.h"
 #include "nsCSSRendering.h"
 #include "nsIFontMetrics.h"
 #include "nsIDeviceContext.h"
 #include "nsIXULTemplateBuilder.h"
 #include "nsXPIDLString.h"
 #include "nsHTMLContainerFrame.h"
 #include "nsIView.h"
 #include "nsIViewManager.h"