Bug 270251 - nsSVGElement::UpdateContentStyleRule issues.

Patch by jlurz24@gmail.com, r=sicking, sr=bz.
This commit is contained in:
tor%cs.brown.edu 2004-12-18 12:14:32 +00:00
Родитель 05f4f336d8
Коммит 88ec41b5e3
1 изменённых файлов: 51 добавлений и 9 удалений

Просмотреть файл

@ -59,6 +59,7 @@
#include "nsCSSDeclaration.h" #include "nsCSSDeclaration.h"
#include "nsCSSProps.h" #include "nsCSSProps.h"
#include "nsICSSParser.h" #include "nsICSSParser.h"
#include "nsICSSLoader.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
#include "nsNodeInfoManager.h" #include "nsNodeInfoManager.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
@ -712,19 +713,51 @@ void
nsSVGElement::UpdateContentStyleRule() nsSVGElement::UpdateContentStyleRule()
{ {
NS_ASSERTION(!mContentStyleRule, "we already have a content style rule"); NS_ASSERTION(!mContentStyleRule, "we already have a content style rule");
// Bail early if there are no child attributes.
// If this code were moved into the for-loop we could
// avoid creating an mDeclaration even when there
// are non-style related attributes. See bug 270251.
if (mAttrsAndChildren.AttrCount() == 0)
return;
nsCSSDeclaration* declaration = new nsCSSDeclaration(); nsIDocument* doc = GetOwnerDoc();
if (!declaration || !declaration->InitializeEmpty()) { if (!doc) {
NS_ERROR("could not initialize nsCSSDeclaration"); NS_ERROR("SVG element without owner document");
return; return;
} }
nsCOMPtr<nsIURI> baseURI = GetBaseURI(); nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsIURI *docURI = GetOwnerDoc()->GetDocumentURI(); nsIURI *docURI = doc->GetDocumentURI();
nsCOMPtr<nsICSSParser> parser;
NS_NewCSSParser(getter_AddRefs(parser)); // Create the nsCSSDeclaration.
if (!parser) nsCSSDeclaration* declaration = new nsCSSDeclaration();
if (!declaration) {
NS_WARNING("Failed to allocate nsCSSDeclaration");
return; return;
}
if(!declaration->InitializeEmpty()) {
NS_WARNING("could not initialize nsCSSDeclaration");
declaration->RuleAbort();
return;
}
// Try to fetch the CSS Parser from the document.
nsICSSLoader* cssLoader = doc->GetCSSLoader();
nsCOMPtr<nsICSSParser> parser;
nsresult rv = NS_OK;
if (cssLoader) {
rv = cssLoader->GetParserFor(nsnull, getter_AddRefs(parser));
} else {
rv = NS_NewCSSParser(getter_AddRefs(parser));
}
if (NS_FAILED(rv)) {
NS_WARNING("failed to get or create a css parser");
declaration->RuleAbort();
return;
}
// SVG and CSS differ slightly in their interpretation of some of // SVG and CSS differ slightly in their interpretation of some of
// the attributes. SVG allows attributes of the form: font-size="5" // the attributes. SVG allows attributes of the form: font-size="5"
@ -754,8 +787,17 @@ nsSVGElement::UpdateContentStyleRule()
declaration, &changed); declaration, &changed);
} }
NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule), nsnull, declaration); rv = NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule), nsnull, declaration);
NS_ASSERTION(mContentStyleRule, "could not create contentstylerule"); if (NS_FAILED(rv)) {
NS_WARNING("could not create contentstylerule");
declaration->RuleAbort();
}
// Recycle the parser if it a CSS loader exists.
if (cssLoader) {
parser->SetSVGMode(PR_FALSE);
cssLoader->RecycleParser(parser);
}
} }
nsISVGValue* nsISVGValue*