Bug 708846 - Clean up the SVG namespace checks to use nsIContent::IsSVG() instead; r=longsonr
authorBrian O'Keefe <bokeefe@alum.wpi.edu>
Thu, 15 Dec 2011 14:47:03 +0000
changeset 84637 5df2a353f393712d994dd419cd076098e4f96f4a
parent 84636 e8659eb419fbff376015ef5c4ab83c7dccbaabc5
child 84638 b9a619e265d5d0df36493c80f6029f12910a154c
push id114
push userffxbld
push dateFri, 09 Mar 2012 01:01:18 +0000
treeherdermozilla-release@c081ebf13261 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs708846
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 708846 - Clean up the SVG namespace checks to use nsIContent::IsSVG() instead; r=longsonr
accessible/src/base/nsAccessibilityService.cpp
content/base/public/nsIContent.h
content/base/src/nsXMLContentSerializer.cpp
content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGMpathElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGSVGElement.h
content/xml/document/src/nsXMLContentSink.cpp
content/xml/document/src/nsXMLFragmentContentSink.cpp
image/src/SVGDocumentWrapper.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/svg/base/src/nsSVGImageFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -1194,23 +1194,21 @@ nsAccessibilityService::GetOrCreateAcces
   if (!newAcc) {
     // Elements may implement nsIAccessibleProvider via XBL. This allows them to
     // say what kind of accessible to create.
     newAcc = CreateAccessibleByType(content, aWeakShell);
   }
 
   if (!newAcc) {
     // Create generic accessibles for SVG and MathML nodes.
-    if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
-        content->Tag() == nsGkAtoms::svg) {
+    if (content->IsSVG(nsGkAtoms::svg)) {
       newAcc = new nsEnumRoleAccessible(content, aWeakShell,
                                         nsIAccessibleRole::ROLE_DIAGRAM);
     }
-    else if (content->GetNameSpaceID() == kNameSpaceID_MathML &&
-             content->Tag() == nsGkAtoms::math) {
+    else if (content->IsMathML(nsGkAtoms::math)) {
       newAcc = new nsEnumRoleAccessible(content, aWeakShell,
                                         nsIAccessibleRole::ROLE_EQUATION);
     }
   }
 
   if (!newAcc) {
     newAcc = CreateAccessibleForDeckChild(weakFrame.GetFrame(), content,
                                           aWeakShell);
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -73,18 +73,18 @@ enum nsLinkState {
   eLinkState_Unknown    = 0,
   eLinkState_Unvisited  = 1,
   eLinkState_Visited    = 2,
   eLinkState_NotLink    = 3
 };
 
 // IID for the nsIContent interface
 #define NS_ICONTENT_IID \
-{ 0xed40a3e5, 0xd7ed, 0x473e, \
- { 0x85, 0xe3, 0x82, 0xc3, 0xf0, 0x41, 0xdb, 0x52 } }
+{ 0xdc68f070, 0x226d, 0x11e1, \
+ { 0xbf, 0xc2, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
 
 /**
  * A node of content in a document's content model. This interface
  * is supported by all content objects.
  */
 class nsIContent : public nsINode {
 public:
   typedef mozilla::widget::IMEState IMEState;
@@ -322,24 +322,32 @@ public:
   inline bool IsHTML(nsIAtom* aTag) const {
     return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
   }
 
   inline bool IsSVG() const {
     return IsInNamespace(kNameSpaceID_SVG);
   }
 
+  inline bool IsSVG(nsIAtom* aTag) const {
+    return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
+  }
+
   inline bool IsXUL() const {
     return IsInNamespace(kNameSpaceID_XUL);
   }
 
   inline bool IsMathML() const {
     return IsInNamespace(kNameSpaceID_MathML);
   }
 
+  inline bool IsMathML(nsIAtom* aTag) const {
+    return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
+  }
+
   /**
    * Returns an atom holding the name of the attribute of type ID on
    * this content node (if applicable).  Returns null for non-element
    * content nodes.
    */
   virtual nsIAtom *GetIDAttributeName() const = 0;
 
   /**
--- a/content/base/src/nsXMLContentSerializer.cpp
+++ b/content/base/src/nsXMLContentSerializer.cpp
@@ -791,23 +791,22 @@ nsXMLContentSerializer::ScanNamespaceDec
   return skipAttr;
 }
 
 
 bool
 nsXMLContentSerializer::IsJavaScript(nsIContent * aContent, nsIAtom* aAttrNameAtom,
                                      PRInt32 aAttrNamespaceID, const nsAString& aValueString)
 {
-  PRInt32 namespaceID = aContent->GetNameSpaceID();
   bool isHtml = aContent->IsHTML();
+  bool isXul = aContent->IsXUL();
+  bool isSvg = aContent->IsSVG();
 
   if (aAttrNamespaceID == kNameSpaceID_None &&
-      (isHtml ||
-       namespaceID == kNameSpaceID_XUL ||
-       namespaceID == kNameSpaceID_SVG) &&
+      (isHtml || isXul || isSvg) &&
       (aAttrNameAtom == nsGkAtoms::href ||
        aAttrNameAtom == nsGkAtoms::src)) {
 
     static const char kJavaScript[] = "javascript";
     PRInt32 pos = aValueString.FindChar(':');
     if (pos < (PRInt32)(sizeof kJavaScript - 1))
         return false;
     nsAutoString scheme(Substring(aValueString, 0, pos));
@@ -817,20 +816,20 @@ nsXMLContentSerializer::IsJavaScript(nsI
       return true;
     else
       return false;
   }
 
   if (isHtml) {
     return nsContentUtils::IsEventAttributeName(aAttrNameAtom, EventNameType_HTML);
   }
-  else if (namespaceID == kNameSpaceID_XUL) {
+  else if (isXul) {
     return nsContentUtils::IsEventAttributeName(aAttrNameAtom, EventNameType_XUL);
   }
-  else if (namespaceID == kNameSpaceID_SVG) {
+  else if (isSvg) {
     return nsContentUtils::IsEventAttributeName(aAttrNameAtom,
                                                 EventNameType_SVGGraphic | EventNameType_SVGSVG);
   }
   return false;
 }
 
 
 void 
--- a/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
+++ b/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
@@ -155,18 +155,17 @@ SVGMotionSMILAnimationFunction::GetCalcM
  */
 
 static nsSVGMpathElement*
 GetFirstMpathChild(nsIContent* aElem)
 {
   for (nsIContent* child = aElem->GetFirstChild();
        child;
        child = child->GetNextSibling()) {
-    if (child->Tag() == nsGkAtoms::mpath &&
-        child->GetNameSpaceID() == kNameSpaceID_SVG) {
+    if (child->IsSVG(nsGkAtoms::mpath)) {
       return static_cast<nsSVGMpathElement*>(child);
     }
   }
 
   return nsnull;
 }
 
 void
@@ -174,17 +173,17 @@ SVGMotionSMILAnimationFunction::
   RebuildPathAndVerticesFromBasicAttrs(const nsIContent* aContextElem)
 {
   NS_ABORT_IF_FALSE(!HasAttr(nsGkAtoms::path),
                     "Should be using |path| attr if we have it");
   NS_ABORT_IF_FALSE(!mPath, "regenerating when we aleady have path");
   NS_ABORT_IF_FALSE(mPathVertices.IsEmpty(),
                     "regenerating when we already have vertices");
 
-  if (aContextElem->GetNameSpaceID() != kNameSpaceID_SVG) {
+  if (!aContextElem->IsSVG()) {
     NS_ERROR("Uh oh, SVG animateMotion element targeting a non-SVG node");
     return;
   }
 
   SVGMotionSMILPathUtils::PathGenerator
     pathGenerator(static_cast<const nsSVGElement*>(aContextElem));
 
   bool success = false;
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -1225,17 +1225,17 @@ nsIAtom* nsSVGElement::GetEventNameForAt
   return aAttr;
 }
 
 nsSVGSVGElement *
 nsSVGElement::GetCtx() const
 {
   nsIContent* ancestor = GetFlattenedTreeParent();
 
-  while (ancestor && ancestor->GetNameSpaceID() == kNameSpaceID_SVG) {
+  while (ancestor && ancestor->IsSVG()) {
     nsIAtom* tag = ancestor->Tag();
     if (tag == nsGkAtoms::foreignObject) {
       return nsnull;
     }
     if (tag == nsGkAtoms::svg) {
       return static_cast<nsSVGSVGElement*>(ancestor);
     }
     ancestor = ancestor->GetFlattenedTreeParent();
--- a/content/svg/content/src/nsSVGMpathElement.cpp
+++ b/content/svg/content/src/nsSVGMpathElement.cpp
@@ -223,19 +223,17 @@ nsSVGMpathElement::GetReferencedPath()
   if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) {
     NS_ABORT_IF_FALSE(!mHrefTarget.get(),
                       "We shouldn't have an xlink:href target "
                       "if we don't have an xlink:href attribute");
     return nsnull;
   }
 
   nsIContent* genericTarget = mHrefTarget.get();
-  if (genericTarget &&
-      genericTarget->GetNameSpaceID() == kNameSpaceID_SVG &&
-      genericTarget->Tag() == nsGkAtoms::path) {
+  if (genericTarget && genericTarget->IsSVG(nsGkAtoms::path)) {
     return static_cast<nsSVGPathElement*>(genericTarget);
   }
   return nsnull;
 }
 
 //----------------------------------------------------------------------
 // Protected helper methods
 
@@ -284,19 +282,17 @@ nsSVGMpathElement::UnlinkHrefTarget(bool
   if (aNotifyParent) {
     NotifyParentOfMpathChange(GetParent());
   }
 }
 
 void
 nsSVGMpathElement::NotifyParentOfMpathChange(nsIContent* aParent)
 {
-  if (aParent &&
-      aParent->GetNameSpaceID() == kNameSpaceID_SVG &&
-      aParent->Tag() == nsGkAtoms::animateMotion) {
+  if (aParent && aParent->IsSVG(nsGkAtoms::animateMotion)) {
 
     nsSVGAnimateMotionElement* animateMotionParent =
       static_cast<nsSVGAnimateMotionElement*>(aParent);
 
     animateMotionParent->MpathChanged();
     AnimationNeedsResample();
   }
 }
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -1081,17 +1081,17 @@ nsSVGSVGElement::UnbindFromTree(bool aDe
 // implementation helpers
 
 bool
 nsSVGSVGElement::WillBeOutermostSVG(nsIContent* aParent,
                                     nsIContent* aBindingParent) const
 {
   nsIContent* parent = aBindingParent ? aBindingParent : aParent;
 
-  while (parent && parent->GetNameSpaceID() == kNameSpaceID_SVG) {
+  while (parent && parent->IsSVG()) {
     nsIAtom* tag = parent->Tag();
     if (tag == nsGkAtoms::foreignObject) {
       // SVG in a foreignObject must have its own <svg> (nsSVGOuterSVGFrame).
       return false;
     }
     if (tag == nsGkAtoms::svg) {
       return false;
     }
--- a/content/svg/content/src/nsSVGSVGElement.h
+++ b/content/svg/content/src/nsSVGSVGElement.h
@@ -244,17 +244,17 @@ protected:
   }
 
   /**
    * Returns true if this is an SVG <svg> element that is the child of
    * another non-foreignObject SVG element.
    */
   bool IsInner() const {
     const nsIContent *parent = GetFlattenedTreeParent();
-    return parent && parent->GetNameSpaceID() == kNameSpaceID_SVG &&
+    return parent && parent->IsSVG() &&
            parent->Tag() != nsGkAtoms::foreignObject;
   }
 
   /* 
    * While binding to the tree we need to determine if we will be the outermost
    * <svg> element _before_ the children are bound (as they want to know what
    * timed document root to register with) and therefore _before_ our parent is
    * set (both actions are performed by nsGenericElement::BindToTree) so we
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -1162,18 +1162,17 @@ nsXMLContentSink::HandleEndElement(const
   if (mNotifyLevel >= stackLen) {
     if (numFlushed < content->GetChildCount()) {
     	  NotifyAppend(content, numFlushed);
     }
     mNotifyLevel = stackLen - 1;
   }
   DidAddContent();
 
-  if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
-      content->Tag() == nsGkAtoms::svg) {
+  if (content->IsSVG(nsGkAtoms::svg)) {
     FlushTags();
     nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(content);
     if (NS_FAILED(NS_DispatchToMainThread(event))) {
       NS_WARNING("failed to dispatch svg load dispatcher");
     }
   }
 
   return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
--- a/content/xml/document/src/nsXMLFragmentContentSink.cpp
+++ b/content/xml/document/src/nsXMLFragmentContentSink.cpp
@@ -267,18 +267,17 @@ nsXMLFragmentContentSink::CreateElement(
   return rv;
 }
 
 nsresult
 nsXMLFragmentContentSink::CloseElement(nsIContent* aContent)
 {
   // don't do fancy stuff in nsXMLContentSink
   if (mPreventScriptExecution && aContent->Tag() == nsGkAtoms::script &&
-      (aContent->GetNameSpaceID() == kNameSpaceID_XHTML ||
-       aContent->GetNameSpaceID() == kNameSpaceID_SVG)) {
+      (aContent->IsHTML() || aContent->IsSVG())) {
     nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aContent);
     NS_ASSERTION(sele, "script did QI correctly!");
     sele->PreventExecution();
   }
   return NS_OK;
 }
 
 void
--- a/image/src/SVGDocumentWrapper.cpp
+++ b/image/src/SVGDocumentWrapper.cpp
@@ -452,19 +452,17 @@ SVGDocumentWrapper::GetRootSVGElem()
   if (!mViewer)
     return nsnull; // Can happen during destruction
 
   nsIDocument* doc = mViewer->GetDocument();
   if (!doc)
     return nsnull; // Can happen during destruction
 
   Element* rootElem = mViewer->GetDocument()->GetRootElement();
-  if (!rootElem ||
-      rootElem->GetNameSpaceID() != kNameSpaceID_SVG ||
-      rootElem->Tag() != nsGkAtoms::svg) {
+  if (!rootElem || !rootElem->IsSVG(nsGkAtoms::svg)) {
     return nsnull;
   }
 
   return static_cast<nsSVGSVGElement*>(rootElem);
 }
 
 } // namespace imagelib
 } // namespace mozilla
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2412,17 +2412,17 @@ nsCSSFrameConstructor::ConstructDocEleme
     }
     InitAndRestoreFrame(state, aDocElement, mDocElementContainingBlock, nsnull,
                         contentFrame);
     *aNewFrame = contentFrame;
     processChildren = true;
   }
   else
 #endif
-  if (aDocElement->GetNameSpaceID() == kNameSpaceID_SVG) {
+  if (aDocElement->IsSVG()) {
     if (aDocElement->Tag() == nsGkAtoms::svg) {
       contentFrame = NS_NewSVGOuterSVGFrame(mPresShell, styleContext);
       if (NS_UNLIKELY(!contentFrame)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       InitAndRestoreFrame(state, aDocElement,
                           state.GetGeometricParent(display,
                                                    mDocElementContainingBlock),
--- a/layout/svg/base/src/nsSVGImageFrame.cpp
+++ b/layout/svg/base/src/nsSVGImageFrame.cpp
@@ -378,18 +378,17 @@ nsSVGImageFrame::PaintSVG(nsSVGRenderSta
       if (!imgRootFrame) {
         // bad image (e.g. XML parse error in image's SVG file)
         return NS_OK;
       }
 
       // Grab root node (w/ sanity-check to make sure it exists & is <svg>)
       nsSVGSVGElement* rootSVGElem =
         static_cast<nsSVGSVGElement*>(imgRootFrame->GetContent());
-      if (!rootSVGElem || rootSVGElem->GetNameSpaceID() != kNameSpaceID_SVG ||
-          rootSVGElem->Tag() != nsGkAtoms::svg) {
+      if (!rootSVGElem || !rootSVGElem->IsSVG(nsGkAtoms::svg)) {
         NS_ABORT_IF_FALSE(false, "missing or non-<svg> root node!!");
         return false;
       }
 
       // Override preserveAspectRatio in our helper document
       // XXXdholbert We should technically be overriding the helper doc's clip
       // and overflow properties here, too. See bug 272288 comment 36.
       rootSVGElem->SetImageOverridePreserveAspectRatio(
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -194,17 +194,17 @@ NS_SMILEnabled()
 }
 
 nsSVGSVGElement*
 nsSVGUtils::GetOuterSVGElement(nsSVGElement *aSVGElement)
 {
   nsIContent *element = nsnull;
   nsIContent *ancestor = aSVGElement->GetFlattenedTreeParent();
 
-  while (ancestor && ancestor->GetNameSpaceID() == kNameSpaceID_SVG &&
+  while (ancestor && ancestor->IsSVG() &&
                      ancestor->Tag() != nsGkAtoms::foreignObject) {
     element = ancestor;
     ancestor = element->GetFlattenedTreeParent();
   }
 
   if (element && element->Tag() == nsGkAtoms::svg) {
     return static_cast<nsSVGSVGElement*>(element);
   }
@@ -417,29 +417,29 @@ nsSVGUtils::CoordToFloat(nsPresContext *
   default:
     return 0.0f;
   }
 }
 
 bool
 nsSVGUtils::EstablishesViewport(nsIContent *aContent)
 {
-  return aContent && aContent->GetNameSpaceID() == kNameSpaceID_SVG &&
+  return aContent && aContent->IsSVG() &&
            (aContent->Tag() == nsGkAtoms::svg ||
             aContent->Tag() == nsGkAtoms::image ||
             aContent->Tag() == nsGkAtoms::foreignObject ||
             aContent->Tag() == nsGkAtoms::symbol);
 }
 
 already_AddRefed<nsIDOMSVGElement>
 nsSVGUtils::GetNearestViewportElement(nsIContent *aContent)
 {
   nsIContent *element = aContent->GetFlattenedTreeParent();
 
-  while (element && element->GetNameSpaceID() == kNameSpaceID_SVG) {
+  while (element && element->IsSVG()) {
     if (EstablishesViewport(element)) {
       if (element->Tag() == nsGkAtoms::foreignObject) {
         return nsnull;
       }
       return nsCOMPtr<nsIDOMSVGElement>(do_QueryInterface(element)).forget();
     }
     element = element->GetFlattenedTreeParent();
   }
@@ -476,17 +476,17 @@ nsSVGUtils::GetCTM(nsSVGElement *aElemen
   }
   if (!aScreenCTM) {
     // didn't find a nearestViewportElement
     return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
   }
   if (!ancestor || !ancestor->IsElement()) {
     return matrix;
   }
-  if (ancestor->GetNameSpaceID() == kNameSpaceID_SVG) {
+  if (ancestor->IsSVG()) {
     if (element->Tag() != nsGkAtoms::svg) {
       return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
     }
     return matrix * GetCTM(static_cast<nsSVGElement*>(ancestor), true);
   }
   // XXX this does not take into account CSS transform, or that the non-SVG
   // content that we've hit may itself be inside an SVG foreignObject higher up
   float x = 0.0f, y = 0.0f;
@@ -1484,18 +1484,17 @@ nsSVGRenderState::GetRenderingContext(ns
                             mGfxContext);
   }
   return mRenderingContext;
 }
 
 /* static */ bool
 nsSVGUtils::RootSVGElementHasViewbox(const nsIContent *aRootSVGElem)
 {
-  if (aRootSVGElem->GetNameSpaceID() != kNameSpaceID_SVG ||
-      aRootSVGElem->Tag() != nsGkAtoms::svg) {
+  if (!aRootSVGElem->IsSVG(nsGkAtoms::svg)) {
     NS_ABORT_IF_FALSE(false, "Expecting an SVG <svg> node");
     return false;
   }
 
   const nsSVGSVGElement *svgSvgElem =
     static_cast<const nsSVGSVGElement*>(aRootSVGElem);
 
   return svgSvgElem->HasValidViewbox();