Bug 562688 part 13. Eliminate eELEMENT usage in layout/style, except the rule processor. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 30 Apr 2010 09:12:06 -0400
changeset 41643 1b7b064ee77a12a37b49fe3d598080696ce3c595
parent 41642 6ac70189d1b83a70f303a4aa9b3ab27bca9bf87d
child 41644 27aa022a527d272d181870e96db12fd0d4725905
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs562688
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 562688 part 13. Eliminate eELEMENT usage in layout/style, except the rule processor. r=dbaron
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/smil/nsSMILCSSValueType.cpp
content/svg/content/src/nsSVGLength.cpp
layout/base/nsLayoutUtils.h
layout/inspector/src/inDOMUtils.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsDOMCSSAttrDeclaration.cpp
layout/style/nsStyleAnimation.cpp
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
layout/svg/base/src/nsSVGUtils.cpp
layout/svg/base/src/nsSVGUtils.h
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -2016,18 +2016,18 @@ nsCanvasRenderingContext2D::SetFont(cons
     nsStyleSet* styleSet = presShell->StyleSet();
 
     // have to get a parent style context for inherit-like relative
     // values (2em, bolder, etc.)
     nsRefPtr<nsStyleContext> parentContext;
 
     if (content && content->IsInDoc()) {
         // inherit from the canvas element
-        parentContext = nsComputedDOMStyle::GetStyleContextForContent(
-                content,
+        parentContext = nsComputedDOMStyle::GetStyleContextForElement(
+                content->AsElement(),
                 nsnull,
                 presShell);
     } else {
         // otherwise inherit from default (10px sans-serif)
         nsCOMPtr<nsICSSStyleRule> parentRule;
         rv = CreateFontStyleRule(NS_LITERAL_STRING("10px sans-serif"),
                                  document,
                                  getter_AddRefs(parentRule));
@@ -2367,17 +2367,17 @@ nsCanvasRenderingContext2D::DrawOrMeasur
     TextReplaceWhitespaceCharacters(textToDraw);
 
     // for now, default to ltr if not in doc
     PRBool isRTL = PR_FALSE;
 
     if (content && content->IsInDoc()) {
         // try to find the closest context
         nsRefPtr<nsStyleContext> canvasStyle =
-            nsComputedDOMStyle::GetStyleContextForContent(content,
+            nsComputedDOMStyle::GetStyleContextForElement(content->AsElement(),
                                                           nsnull,
                                                           presShell);
         if (!canvasStyle)
             return NS_ERROR_FAILURE;
         isRTL = canvasStyle->GetStyleVisibility()->mDirection ==
             NS_STYLE_DIRECTION_RTL;
     } else {
       isRTL = GET_BIDI_OPTION_DIRECTION(document->GetBidiOptions()) == IBMBIDI_TEXTDIRECTION_RTL;
--- a/content/smil/nsSMILCSSValueType.cpp
+++ b/content/smil/nsSMILCSSValueType.cpp
@@ -374,16 +374,17 @@ ValueFromStringHelper(nsCSSProperty aPro
 // static
 void
 nsSMILCSSValueType::ValueFromString(nsCSSProperty aPropID,
                                     nsIContent* aTargetElement,
                                     const nsAString& aString,
                                     PRBool aUseSVGMode,
                                     nsSMILValue& aValue)
 {
+  // XXXbz aTargetElement should be an Element
   NS_ABORT_IF_FALSE(aValue.IsNull(), "Outparam should be null-typed");
   nsPresContext* presContext = GetPresContextForElement(aTargetElement);
   if (!presContext) {
     NS_WARNING("Not parsing animation value; unable to get PresContext");
     return;
   }
 
   nsStyleAnimation::Value parsedValue;
--- a/content/svg/content/src/nsSVGLength.cpp
+++ b/content/svg/content/src/nsSVGLength.cpp
@@ -504,23 +504,23 @@ float nsSVGLength::AxisLength()
   }
 
   return d;
 }
 
 float nsSVGLength::EmLength()
 {
   nsCOMPtr<nsIContent> element = do_QueryReferent(mElement);
-  return nsSVGUtils::GetFontSize(element);
+  return nsSVGUtils::GetFontSize(element->AsElement());
 }
 
 float nsSVGLength::ExLength()
 {
   nsCOMPtr<nsIContent> element = do_QueryReferent(mElement);
-  return nsSVGUtils::GetFontXHeight(element);
+  return nsSVGUtils::GetFontXHeight(element->AsElement());
 }
 
 PRBool nsSVGLength::IsValidUnitType(PRUint16 unit)
 {
   if (unit > SVG_LENGTHTYPE_UNKNOWN && unit <= SVG_LENGTHTYPE_PC)
     return PR_TRUE;
 
   return PR_FALSE;
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -343,17 +343,18 @@ public:
                                nsCSSPseudoElements::Type aPseudoElement,
                                nsPresContext* aPresContext)
   {
     NS_PRECONDITION(aPresContext, "Must have a prescontext");
 
     nsRefPtr<nsStyleContext> pseudoContext;
     if (aContent) {
       pseudoContext = aPresContext->StyleSet()->
-        ProbePseudoElementStyle(aContent, aPseudoElement, aStyleContext);
+        ProbePseudoElementStyle(aContent->AsElement(), aPseudoElement,
+                                aStyleContext);
     }
     return pseudoContext != nsnull;
   }
 
   /**
    * If this frame is a placeholder for a float, then return the float,
    * otherwise return nsnull.  aPlaceholder must be a placeholder frame.
    */
--- a/layout/inspector/src/inDOMUtils.cpp
+++ b/layout/inspector/src/inDOMUtils.cpp
@@ -268,26 +268,31 @@ inDOMUtils::GetContentState(nsIDOMElemen
 /* static */ nsresult
 inDOMUtils::GetRuleNodeForContent(nsIContent* aContent,
                                   nsStyleContext** aStyleContext,
                                   nsRuleNode** aRuleNode)
 {
   *aRuleNode = nsnull;
   *aStyleContext = nsnull;
 
+  if (!aContent->IsElement()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
   nsIDocument* doc = aContent->GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
 
   nsIPresShell *presShell = doc->GetPrimaryShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
 
   nsPresContext *presContext = presShell->GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_UNEXPECTED);
 
   PRBool safe = presContext->EnsureSafeToHandOutCSSRules();
   NS_ENSURE_TRUE(safe, NS_ERROR_OUT_OF_MEMORY);
 
   nsRefPtr<nsStyleContext> sContext =
-    nsComputedDOMStyle::GetStyleContextForContent(aContent, nsnull, presShell);
+    nsComputedDOMStyle::GetStyleContextForElement(aContent->AsElement(),
+						  nsnull, presShell);
   *aRuleNode = sContext->GetRuleNode();
   sContext.forget(aStyleContext);
   return NS_OK;
 }
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -75,16 +75,19 @@
 #include "imgIRequest.h"
 #include "nsLayoutUtils.h"
 #include "nsFrameManager.h"
 #include "prlog.h"
 #include "nsCSSKeywords.h"
 #include "nsStyleCoord.h"
 #include "nsDisplayList.h"
 #include "nsDOMCSSDeclaration.h"
+#include "Element.h"
+
+using namespace mozilla::dom;
 
 #if defined(DEBUG_bzbarsky) || defined(DEBUG_caillon)
 #define DEBUG_ComputedDOMStyle
 #endif
 
 /*
  * This is the implementation of the readonly CSSStyleDeclaration that is
  * returned by the getComputedStyle() function.
@@ -319,52 +322,49 @@ nsComputedDOMStyle::GetPropertyValue(con
     rv = val->GetCssText(aReturn);
   }
 
   return rv;
 }
 
 /* static */
 already_AddRefed<nsStyleContext>
-nsComputedDOMStyle::GetStyleContextForContent(nsIContent* aContent,
+nsComputedDOMStyle::GetStyleContextForElement(Element* aElement,
                                               nsIAtom* aPseudo,
                                               nsIPresShell* aPresShell)
 {
-  NS_ASSERTION(aContent->IsNodeOfType(nsINode::eELEMENT),
-               "aContent must be an element");
-
   // If there's no pres shell, get it from the content
   if (!aPresShell) {
-    aPresShell = GetPresShellForContent(aContent);
+    aPresShell = GetPresShellForContent(aElement);
     if (!aPresShell)
       return nsnull;
   }
 
   aPresShell->FlushPendingNotifications(Flush_Style);
 
-  return GetStyleContextForContentNoFlush(aContent, aPseudo, aPresShell);
+  return GetStyleContextForElementNoFlush(aElement, aPseudo, aPresShell);
 }
 
 /* static */
 already_AddRefed<nsStyleContext>
-nsComputedDOMStyle::GetStyleContextForContentNoFlush(nsIContent* aContent,
+nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement,
                                                      nsIAtom* aPseudo,
                                                      nsIPresShell* aPresShell)
 {
-  NS_ABORT_IF_FALSE(aContent, "NULL content node");
+  NS_ABORT_IF_FALSE(aElement, "NULL element");
 
   // If there's no pres shell, get it from the content
   if (!aPresShell) {
-    aPresShell = GetPresShellForContent(aContent);
+    aPresShell = GetPresShellForContent(aElement);
     if (!aPresShell)
       return nsnull;
   }
 
   if (!aPseudo) {
-    nsIFrame* frame = aContent->GetPrimaryFrame();
+    nsIFrame* frame = aElement->GetPrimaryFrame();
     if (frame) {
       nsStyleContext* result =
         nsLayoutUtils::GetStyleFrame(frame)->GetStyleContext();
       // Don't use the style context if it was influenced by
       // pseudo-elements, since then it's not the primary style
       // for this element.
       if (!result->HasPseudoElementData()) {
         // this function returns an addrefed style context
@@ -372,36 +372,37 @@ nsComputedDOMStyle::GetStyleContextForCo
         return result;
       }
     }
   }
 
   // No frame has been created or we have a pseudo, so resolve the
   // style ourselves
   nsRefPtr<nsStyleContext> parentContext;
-  nsIContent* parent = aPseudo ? aContent : aContent->GetParent();
+  nsIContent* parent = aPseudo ? aElement : aElement->GetParent();
   // Don't resolve parent context for document fragments.
-  if (parent && parent->IsNodeOfType(nsINode::eELEMENT))
-    parentContext = GetStyleContextForContentNoFlush(parent, nsnull, aPresShell);
+  if (parent && parent->IsElement())
+    parentContext = GetStyleContextForElementNoFlush(parent->AsElement(),
+                                                     nsnull, aPresShell);
 
   nsPresContext *presContext = aPresShell->GetPresContext();
   if (!presContext)
     return nsnull;
 
   nsStyleSet *styleSet = aPresShell->StyleSet();
 
   if (aPseudo) {
     nsCSSPseudoElements::Type type = nsCSSPseudoElements::GetPseudoType(aPseudo);
     if (type >= nsCSSPseudoElements::ePseudo_PseudoElementCount) {
       return nsnull;
     }
-    return styleSet->ResolvePseudoElementStyle(aContent, type, parentContext);
+    return styleSet->ResolvePseudoElementStyle(aElement, type, parentContext);
   }
 
-  return styleSet->ResolveStyleFor(aContent, parentContext);
+  return styleSet->ResolveStyleFor(aElement, parentContext);
 }
 
 /* static */
 nsIPresShell*
 nsComputedDOMStyle::GetPresShellForContent(nsIContent* aContent)
 {
   nsIDocument* currentDoc = aContent->GetCurrentDoc();
   if (!currentDoc)
@@ -490,17 +491,17 @@ nsComputedDOMStyle::GetPropertyCSSValue(
       NS_ASSERTION(nsCSSPseudoElements::PseudoElementContainsElements(
                      topWithPseudoElementData->GetPseudo()),
                    "we should be in a pseudo-element that is expected to "
                    "contain elements");
     }
 #endif
     // Need to resolve a style context
     mStyleContextHolder =
-      nsComputedDOMStyle::GetStyleContextForContent(mContent,
+      nsComputedDOMStyle::GetStyleContextForElement(mContent->AsElement(),
                                                     mPseudo,
                                                     mPresShell);
     NS_ENSURE_TRUE(mStyleContextHolder, NS_ERROR_OUT_OF_MEMORY);
     NS_ASSERTION(mPseudo || !mStyleContextHolder->HasPseudoElementData(),
                  "should not have pseudo-element data");
   }
 
   // mExposeVisitedStyle is set to true only by testing APIs that
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -78,21 +78,22 @@ public:
   static void Shutdown();
 
   virtual nsINode *GetParentObject()
   {
     return mContent;
   }
 
   static already_AddRefed<nsStyleContext>
-  GetStyleContextForContent(nsIContent* aContent, nsIAtom* aPseudo,
+  GetStyleContextForElement(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
                             nsIPresShell* aPresShell);
 
   static already_AddRefed<nsStyleContext>
-  GetStyleContextForContentNoFlush(nsIContent* aContent, nsIAtom* aPseudo,
+  GetStyleContextForElementNoFlush(mozilla::dom::Element* aElement,
+                                   nsIAtom* aPseudo,
                                    nsIPresShell* aPresShell);
 
   static nsIPresShell*
   GetPresShellForContent(nsIContent* aContent);
 
   // Helper for nsDOMWindowUtils::GetVisitedDependentComputedStyle
   void SetExposeVisitedStyle(PRBool aExpose) {
     NS_ASSERTION(aExpose != mExposeVisitedStyle, "should always be changing");
--- a/layout/style/nsDOMCSSAttrDeclaration.cpp
+++ b/layout/style/nsDOMCSSAttrDeclaration.cpp
@@ -58,17 +58,17 @@ nsDOMCSSAttributeDeclaration::nsDOMCSSAt
                                                            )
   : mContent(aContent)
 #ifdef MOZ_SMIL
   , mIsSMILOverride(aIsSMILOverride)
 #endif // MOZ_SMIL
 {
   MOZ_COUNT_CTOR(nsDOMCSSAttributeDeclaration);
 
-  NS_ASSERTION(aContent && aContent->IsNodeOfType(nsINode::eELEMENT),
+  NS_ASSERTION(aContent && aContent->IsElement(),
                "Inline style for non-element content?");
 }
 
 nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
 {
   MOZ_COUNT_DTOR(nsDOMCSSAttributeDeclaration);
 }
 
--- a/layout/style/nsStyleAnimation.cpp
+++ b/layout/style/nsStyleAnimation.cpp
@@ -976,17 +976,18 @@ inline
 already_AddRefed<nsStyleContext>
 LookupStyleContext(nsIContent* aElement)
 {
   nsIDocument* doc = aElement->GetCurrentDoc();
   nsIPresShell* shell = doc->GetPrimaryShell();
   if (!shell) {
     return nsnull;
   }
-  return nsComputedDOMStyle::GetStyleContextForContent(aElement, nsnull, shell);
+  return nsComputedDOMStyle::GetStyleContextForElement(aElement->AsElement(),
+                                                       nsnull, shell);
 }
 
 
 /**
  * Helper function: StyleWithDeclarationAdded
  * Creates a nsStyleRule with the specified property set to the specified
  * value, and returns a nsStyleContext for this rule, as a sibling of the
  * given element's nsStyleContext.
@@ -1039,16 +1040,17 @@ StyleWithDeclarationAdded(nsCSSProperty 
 
 PRBool
 nsStyleAnimation::ComputeValue(nsCSSProperty aProperty,
                                nsIContent* aTargetElement,
                                const nsAString& aSpecifiedValue,
                                PRBool aUseSVGMode,
                                Value& aComputedValue)
 {
+  // XXXbz aTargetElement should be an Element
   NS_ABORT_IF_FALSE(aTargetElement, "null target element");
   NS_ABORT_IF_FALSE(aTargetElement->GetCurrentDoc(),
                     "we should only be able to actively animate nodes that "
                     "are in a document");
 
   nsRefPtr<nsStyleContext> tmpStyleContext =
     StyleWithDeclarationAdded(aProperty, aTargetElement,
                               aSpecifiedValue, aUseSVGMode);
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -55,16 +55,19 @@
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsIContent.h"
 #include "nsIFrame.h"
 #include "nsContentUtils.h"
 #include "nsRuleProcessorData.h"
 #include "nsTransitionManager.h"
 #include "nsIEventStateManager.h"
+#include "Element.h"
+
+using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS1(nsEmptyStyleRule, nsIStyleRule)
 
 NS_IMETHODIMP
 nsEmptyStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
   return NS_OK;
 }
@@ -788,34 +791,33 @@ PRBool nsStyleSet::BuildDefaultStyleData
 #undef STYLE_STRUCT_INHERITED
 #undef STYLE_STRUCT_RESET
 #undef SSARG_PRESCONTEXT
 
   return PR_TRUE;
 }
 
 already_AddRefed<nsStyleContext>
-nsStyleSet::ResolveStyleFor(nsIContent* aContent,
+nsStyleSet::ResolveStyleFor(Element* aElement,
                             nsStyleContext* aParentContext)
 {
   NS_ENSURE_FALSE(mInShutdown, nsnull);
-  NS_ASSERTION(aContent && aContent->IsNodeOfType(nsINode::eELEMENT),
-               "aContent must be element");
+  NS_ASSERTION(aElement, "aElement must not be null");
 
   nsRuleWalker ruleWalker(mRuleTree);
-  ElementRuleProcessorData data(PresContext(), aContent, &ruleWalker);
-  FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aContent,
+  ElementRuleProcessorData data(PresContext(), aElement, &ruleWalker);
+  FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
             &ruleWalker);
 
   nsRuleNode *ruleNode = ruleWalker.CurrentNode();
   nsRuleNode *visitedRuleNode = nsnull;
 
   if (ruleWalker.HaveRelevantLink()) {
     ruleWalker.ResetForVisitedMatching();
-    FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aContent,
+    FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
               &ruleWalker);
     visitedRuleNode = ruleWalker.CurrentNode();
   }
 
   return GetContext(aParentContext, ruleNode, visitedRuleNode,
                     data.IsLink(),
                     (data.ContentState() & NS_EVENT_STATE_VISITED) != 0,
                     nsnull, nsCSSPseudoElements::ePseudo_NotPseudoElement);
@@ -891,86 +893,82 @@ nsStyleSet::WalkRestrictionRule(nsCSSPse
   aRuleWalker->SetLevel(eAgentSheet, PR_FALSE, PR_FALSE);
   if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLetter)
     aRuleWalker->Forward(mFirstLetterRule);
   else if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLine)
     aRuleWalker->Forward(mFirstLineRule);
 }
 
 already_AddRefed<nsStyleContext>
-nsStyleSet::ResolvePseudoElementStyle(nsIContent* aParentContent,
+nsStyleSet::ResolvePseudoElementStyle(Element* aParentElement,
                                       nsCSSPseudoElements::Type aType,
                                       nsStyleContext* aParentContext)
 {
   NS_ENSURE_FALSE(mInShutdown, nsnull);
 
   NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
                "must have pseudo element type");
-  NS_ASSERTION(aParentContent &&
-               aParentContent->IsNodeOfType(nsINode::eELEMENT),
-               "aParentContent must be element");
+  NS_ASSERTION(aParentElement, "Must have parent element");
 
   nsRuleWalker ruleWalker(mRuleTree);
-  PseudoElementRuleProcessorData data(PresContext(), aParentContent,
+  PseudoElementRuleProcessorData data(PresContext(), aParentElement,
                                       &ruleWalker, aType);
   WalkRestrictionRule(aType, &ruleWalker);
   FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
-            aParentContent, &ruleWalker);
+            aParentElement, &ruleWalker);
 
   nsRuleNode *ruleNode = ruleWalker.CurrentNode();
   nsRuleNode *visitedRuleNode = nsnull;
 
   if (ruleWalker.HaveRelevantLink()) {
     ruleWalker.ResetForVisitedMatching();
     FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
-              aParentContent, &ruleWalker);
+              aParentElement, &ruleWalker);
     visitedRuleNode = ruleWalker.CurrentNode();
   }
 
   return GetContext(aParentContext, ruleNode, visitedRuleNode,
                     // For pseudos, |data.IsLink()| being true means that
                     // our parent node is a link.
                     PR_FALSE, PR_FALSE,
                     nsCSSPseudoElements::GetPseudoAtom(aType), aType);
 }
 
 already_AddRefed<nsStyleContext>
-nsStyleSet::ProbePseudoElementStyle(nsIContent* aParentContent,
+nsStyleSet::ProbePseudoElementStyle(Element* aParentElement,
                                     nsCSSPseudoElements::Type aType,
                                     nsStyleContext* aParentContext)
 {
   NS_ENSURE_FALSE(mInShutdown, nsnull);
 
   NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
                "must have pseudo element type");
-  NS_ASSERTION(aParentContent &&
-               aParentContent->IsNodeOfType(nsINode::eELEMENT),
-               "aParentContent must be element");
+  NS_ASSERTION(aParentElement, "aParentElement must not be null");
 
   nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
   nsRuleWalker ruleWalker(mRuleTree);
-  PseudoElementRuleProcessorData data(PresContext(), aParentContent,
+  PseudoElementRuleProcessorData data(PresContext(), aParentElement,
                                       &ruleWalker, aType);
   WalkRestrictionRule(aType, &ruleWalker);
   // not the root if there was a restriction rule
   nsRuleNode *adjustedRoot = ruleWalker.CurrentNode();
   FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
-            aParentContent, &ruleWalker);
+            aParentElement, &ruleWalker);
 
   nsRuleNode *ruleNode = ruleWalker.CurrentNode();
   if (ruleNode == adjustedRoot) {
     return nsnull;
   }
 
   nsRuleNode *visitedRuleNode = nsnull;
 
   if (ruleWalker.HaveRelevantLink()) {
     ruleWalker.ResetForVisitedMatching();
     FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
-              aParentContent, &ruleWalker);
+              aParentElement, &ruleWalker);
     visitedRuleNode = ruleWalker.CurrentNode();
   }
 
   nsRefPtr<nsStyleContext> result =
     GetContext(aParentContext, ruleNode, visitedRuleNode,
                // For pseudos, |data.IsLink()| being true means that
                // our parent node is a link.
                PR_FALSE, PR_FALSE,
@@ -1016,42 +1014,40 @@ nsStyleSet::ResolveAnonymousBoxStyle(nsI
 
   return GetContext(aParentContext, ruleWalker.CurrentNode(), nsnull,
                     PR_FALSE, PR_FALSE,
                     aPseudoTag, nsCSSPseudoElements::ePseudo_AnonBox);
 }
 
 #ifdef MOZ_XUL
 already_AddRefed<nsStyleContext>
-nsStyleSet::ResolveXULTreePseudoStyle(nsIContent* aParentContent,
+nsStyleSet::ResolveXULTreePseudoStyle(Element* aParentElement,
                                       nsIAtom* aPseudoTag,
                                       nsStyleContext* aParentContext,
                                       nsICSSPseudoComparator* aComparator)
 {
   NS_ENSURE_FALSE(mInShutdown, nsnull);
 
   NS_ASSERTION(aPseudoTag, "must have pseudo tag");
-  NS_ASSERTION(aParentContent->IsNodeOfType(nsINode::eELEMENT),
-               "content (if non-null) must be element");
   NS_ASSERTION(nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag),
                "Unexpected pseudo");
 
   nsRuleWalker ruleWalker(mRuleTree);
-  XULTreeRuleProcessorData data(PresContext(), aParentContent, &ruleWalker,
+  XULTreeRuleProcessorData data(PresContext(), aParentElement, &ruleWalker,
                                 aPseudoTag, aComparator);
-  FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data, aParentContent,
+  FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data, aParentElement,
             &ruleWalker);
 
   nsRuleNode *ruleNode = ruleWalker.CurrentNode();
   nsRuleNode *visitedRuleNode = nsnull;
 
   if (ruleWalker.HaveRelevantLink()) {
     ruleWalker.ResetForVisitedMatching();
     FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data,
-              aParentContent, &ruleWalker);
+              aParentElement, &ruleWalker);
     visitedRuleNode = ruleWalker.CurrentNode();
   }
 
   return GetContext(aParentContext, ruleNode, visitedRuleNode,
                     // For pseudos, |data.IsLink()| being true means that
                     // our parent node is a link.
                     PR_FALSE, PR_FALSE,
                     aPseudoTag, nsCSSPseudoElements::ePseudo_XULTree);
@@ -1204,20 +1200,20 @@ static PRBool SheetHasDocumentStateStyle
 }
 
 // Test if style is dependent on a document state.
 PRBool
 nsStyleSet::HasDocumentStateDependentStyle(nsPresContext* aPresContext,
                                            nsIContent*    aContent,
                                            PRInt32        aStateMask)
 {
-  if (!aContent || !aContent->IsNodeOfType(nsINode::eELEMENT))
+  if (!aContent || !aContent->IsElement())
     return PR_FALSE;
 
-  StatefulData data(aPresContext, aContent, aStateMask);
+  StatefulData data(aPresContext, aContent->AsElement(), aStateMask);
   WalkRuleProcessors(SheetHasDocumentStateStyle, &data, PR_TRUE);
   return data.mHint != 0;
 }
 
 static PRBool SheetHasStatefulStyle(nsIStyleRuleProcessor* aProcessor,
                                     void *aData)
 {
   StatefulData* data = (StatefulData*)aData;
@@ -1229,18 +1225,18 @@ static PRBool SheetHasStatefulStyle(nsIS
 // Test if style is dependent on content state
 nsRestyleHint
 nsStyleSet::HasStateDependentStyle(nsPresContext* aPresContext,
                                    nsIContent*     aContent,
                                    PRInt32         aStateMask)
 {
   nsRestyleHint result = nsRestyleHint(0);
 
-  if (aContent->IsNodeOfType(nsINode::eELEMENT)) {
-    StatefulData data(aPresContext, aContent, aStateMask);
+  if (aContent->IsElement()) {
+    StatefulData data(aPresContext, aContent->AsElement(), aStateMask);
     WalkRuleProcessors(SheetHasStatefulStyle, &data, PR_FALSE);
     result = data.mHint;
   }
 
   return result;
 }
 
 struct AttributeData : public AttributeRuleProcessorData {
@@ -1268,19 +1264,19 @@ nsRestyleHint
 nsStyleSet::HasAttributeDependentStyle(nsPresContext* aPresContext,
                                        nsIContent*    aContent,
                                        nsIAtom*       aAttribute,
                                        PRInt32        aModType,
                                        PRBool         aAttrHasChanged)
 {
   nsRestyleHint result = nsRestyleHint(0);
 
-  if (aContent->IsNodeOfType(nsINode::eELEMENT)) {
-    AttributeData data(aPresContext, aContent, aAttribute, aModType,
-                       aAttrHasChanged);
+  if (aContent->IsElement()) {
+    AttributeData data(aPresContext, aContent->AsElement(), aAttribute,
+                       aModType, aAttrHasChanged);
     WalkRuleProcessors(SheetHasAttributeStyle, &data, PR_FALSE);
     result = data.mHint;
   }
 
   return result;
 }
 
 PRBool
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -92,17 +92,18 @@ class nsStyleSet
 
   nsRuleNode* GetRuleTree() { return mRuleTree; }
 
   // enable / disable the Quirk style sheet
   void EnableQuirkStyleSheet(PRBool aEnable);
 
   // get a style context for a non-pseudo frame.
   already_AddRefed<nsStyleContext>
-  ResolveStyleFor(nsIContent* aContent, nsStyleContext* aParentContext);
+  ResolveStyleFor(mozilla::dom::Element* aElement,
+                  nsStyleContext* aParentContext);
 
   // Get a style context (with the given parent) for the
   // sequence of style rules in the |aRules| array.
   already_AddRefed<nsStyleContext>
   ResolveStyleForRules(nsStyleContext* aParentContext,
                        const nsCOMArray<nsIStyleRule> &aRules);
 
   // Get a style context that represents aBaseContext, but as though
@@ -117,43 +118,43 @@ class nsStyleSet
   // for everything after the first letter.
   //
   // Perhaps this should go away and we shouldn't even create style
   // contexts for such content nodes.  However, not doing any rule
   // matching for them is a first step.
   already_AddRefed<nsStyleContext>
   ResolveStyleForNonElement(nsStyleContext* aParentContext);
 
-  // Get a style context for a pseudo-element.  aParentContent must be
+  // Get a style context for a pseudo-element.  aParentElement must be
   // non-null.  aPseudoID is the nsCSSPseudoElements::Type for the
   // pseudo-element.
   already_AddRefed<nsStyleContext>
-  ResolvePseudoElementStyle(nsIContent* aParentContent,
+  ResolvePseudoElementStyle(mozilla::dom::Element* aParentElement,
                             nsCSSPseudoElements::Type aType,
                             nsStyleContext* aParentContext);
 
   // This functions just like ResolvePseudoElementStyle except that it will
   // return nsnull if there are no explicit style rules for that
   // pseudo element.
   already_AddRefed<nsStyleContext>
-  ProbePseudoElementStyle(nsIContent* aParentContent,
+  ProbePseudoElementStyle(mozilla::dom::Element* aParentElement,
                           nsCSSPseudoElements::Type aType,
                           nsStyleContext* aParentContext);
   
   // Get a style context for an anonymous box.  aPseudoTag is the
   // pseudo-tag to use and must be non-null.
   already_AddRefed<nsStyleContext>
   ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag, nsStyleContext* aParentContext);
 
 #ifdef MOZ_XUL
   // Get a style context for a XUL tree pseudo.  aPseudoTag is the
   // pseudo-tag to use and must be non-null.  aParentContent must be
   // non-null.  aComparator must be non-null.
   already_AddRefed<nsStyleContext>
-  ResolveXULTreePseudoStyle(nsIContent* aParentContent,
+  ResolveXULTreePseudoStyle(mozilla::dom::Element* aParentElement,
                             nsIAtom* aPseudoTag,
                             nsStyleContext* aParentContext,
                             nsICSSPseudoComparator* aComparator);
 #endif
 
   // Append all the currently-active font face rules to aArray.  Return
   // true for success and false for failure.
   PRBool AppendFontFaceRules(nsPresContext* aPresContext,
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -84,16 +84,19 @@
 #include "nsSVGEffects.h"
 #include "nsMathUtils.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGFilterPaintCallback.h"
 #include "nsSVGGeometryFrame.h"
 #include "nsComputedDOMStyle.h"
 #include "nsSVGPathGeometryFrame.h"
 #include "prdtoa.h"
+#include "Element.h"
+
+using namespace mozilla::dom;
 
 gfxASurface *nsSVGUtils::mThebesComputationalSurface = nsnull;
 
 // c = n / 255
 // (c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055) * 255 + 0.5
 static const PRUint8 glinearRGBTosRGBMap[256] = {
   0,  13,  22,  28,  34,  38,  42,  46,
  50,  53,  56,  59,  61,  64,  66,  69,
@@ -251,24 +254,24 @@ nsSVGUtils::GetParentElement(nsIContent 
     }
   }
 
   // otherewise use the explicit one, whether it's null or not...
   return aContent->GetParent();
 }
 
 float
-nsSVGUtils::GetFontSize(nsIContent *aContent)
+nsSVGUtils::GetFontSize(Element *aElement)
 {
-  if (!aContent)
+  if (!aElement)
     return 1.0f;
 
   nsRefPtr<nsStyleContext> styleContext = 
-    nsComputedDOMStyle::GetStyleContextForContentNoFlush(aContent, nsnull,
-                                                         nsnull);
+    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
+                                                         nsnull, nsnull);
   if (!styleContext) {
     NS_WARNING("Couldn't get style context for content in GetFontStyle");
     return 1.0f;
   }
 
   return GetFontSize(styleContext);
 }
 
@@ -288,24 +291,24 @@ nsSVGUtils::GetFontSize(nsStyleContext *
   NS_ABORT_IF_FALSE(presContext, "NULL pres context in GetFontSize");
 
   nscoord fontSize = aStyleContext->GetStyleFont()->mSize;
   return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) / 
          presContext->TextZoom();
 }
 
 float
-nsSVGUtils::GetFontXHeight(nsIContent *aContent)
+nsSVGUtils::GetFontXHeight(Element *aElement)
 {
-  if (!aContent)
+  if (!aElement)
     return 1.0f;
 
   nsRefPtr<nsStyleContext> styleContext = 
-    nsComputedDOMStyle::GetStyleContextForContentNoFlush(aContent, nsnull,
-                                                         nsnull);
+    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
+                                                         nsnull, nsnull);
   if (!styleContext) {
     NS_WARNING("Couldn't get style context for content in GetFontStyle");
     return 1.0f;
   }
 
   return GetFontXHeight(styleContext);
 }
   
--- a/layout/svg/base/src/nsSVGUtils.h
+++ b/layout/svg/base/src/nsSVGUtils.h
@@ -75,16 +75,22 @@ class gfxImageSurface;
 struct gfxSize;
 struct gfxIntSize;
 struct nsStyleFont;
 class nsSVGEnum;
 class nsISVGChildFrame;
 class nsSVGGeometryFrame;
 class nsSVGDisplayContainerFrame;
 
+namespace mozilla {
+namespace dom {
+class Element;
+} // namespace dom
+} // namespace mozilla
+
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
 // SVG Frame state bits
 #define NS_STATE_IS_OUTER_SVG         0x00100000
 
 #define NS_STATE_SVG_DIRTY            0x00200000
@@ -204,23 +210,23 @@ public:
   /*
    * Get the parent element of an nsIContent
    */
   static nsIContent *GetParentElement(nsIContent *aContent);
 
   /*
    * Get a font-size (em) of an nsIContent
    */
-  static float GetFontSize(nsIContent *aContent);
+  static float GetFontSize(mozilla::dom::Element *aElement);
   static float GetFontSize(nsIFrame *aFrame);
   static float GetFontSize(nsStyleContext *aStyleContext);
   /*
    * Get an x-height of of an nsIContent
    */
-  static float GetFontXHeight(nsIContent *aContent);
+  static float GetFontXHeight(mozilla::dom::Element *aElement);
   static float GetFontXHeight(nsIFrame *aFrame);
   static float GetFontXHeight(nsStyleContext *aStyleContext);
 
   /*
    * Converts image data from premultipled to unpremultiplied alpha
    */
   static void UnPremultiplyImageDataAlpha(PRUint8 *data, 
                                           PRInt32 stride,