Bug 708846 - Clean up the SVG namespace checks to use nsIContent::IsSVG() instead; r=longsonr

This commit is contained in:
Brian O'Keefe 2011-12-15 14:47:03 +00:00
parent ef45bcacdc
commit 1513850d8f
14 changed files with 34 additions and 40 deletions

View File

@ -1199,13 +1199,11 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode,
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);
}

View File

@ -78,8 +78,8 @@ enum nsLinkState {
// 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
@ -327,6 +327,10 @@ public:
return IsInNamespace(kNameSpaceID_SVG);
}
inline bool IsSVG(nsIAtom* aTag) const {
return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
}
inline bool IsXUL() const {
return IsInNamespace(kNameSpaceID_XUL);
}
@ -335,6 +339,10 @@ public:
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

View File

@ -796,13 +796,12 @@ 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)) {
@ -822,10 +821,10 @@ nsXMLContentSerializer::IsJavaScript(nsIContent * aContent, nsIAtom* aAttrNameAt
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);
}

View File

@ -160,8 +160,7 @@ 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);
}
}
@ -179,7 +178,7 @@ SVGMotionSMILAnimationFunction::
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;
}

View File

@ -1230,7 +1230,7 @@ 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;

View File

@ -228,9 +228,7 @@ nsSVGMpathElement::GetReferencedPath()
}
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;
@ -289,9 +287,7 @@ nsSVGMpathElement::UnlinkHrefTarget(bool aNotifyParent)
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);

View File

@ -1086,7 +1086,7 @@ nsSVGSVGElement::WillBeOutermostSVG(nsIContent* aParent,
{
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).

View File

@ -249,7 +249,7 @@ protected:
*/
bool IsInner() const {
const nsIContent *parent = GetFlattenedTreeParent();
return parent && parent->GetNameSpaceID() == kNameSpaceID_SVG &&
return parent && parent->IsSVG() &&
parent->Tag() != nsGkAtoms::foreignObject;
}

View File

@ -1167,8 +1167,7 @@ nsXMLContentSink::HandleEndElement(const PRUnichar *aName,
}
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))) {

View File

@ -272,8 +272,7 @@ 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();

View File

@ -457,9 +457,7 @@ SVGDocumentWrapper::GetRootSVGElem()
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;
}

View File

@ -2417,7 +2417,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle
}
else
#endif
if (aDocElement->GetNameSpaceID() == kNameSpaceID_SVG) {
if (aDocElement->IsSVG()) {
if (aDocElement->Tag() == nsGkAtoms::svg) {
contentFrame = NS_NewSVGOuterSVGFrame(mPresShell, styleContext);
if (NS_UNLIKELY(!contentFrame)) {

View File

@ -383,8 +383,7 @@ nsSVGImageFrame::PaintSVG(nsSVGRenderState *aContext,
// 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;
}

View File

@ -199,7 +199,7 @@ 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();
@ -422,7 +422,7 @@ nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
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 ||
@ -434,7 +434,7 @@ 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;
@ -481,7 +481,7 @@ nsSVGUtils::GetCTM(nsSVGElement *aElement, bool aScreenCTM)
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
}
@ -1489,8 +1489,7 @@ nsSVGRenderState::GetRenderingContext(nsIFrame *aFrame)
/* 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;
}