зеркало из https://github.com/mozilla/pjs.git
Bug 331481 - don't create unnecessary css rules. r+sr=roc
This commit is contained in:
Родитель
5469ae5567
Коммит
2ecf8d98aa
|
@ -618,13 +618,6 @@ 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;
|
|
||||||
|
|
||||||
nsIDocument* doc = GetOwnerDoc();
|
nsIDocument* doc = GetOwnerDoc();
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
NS_ERROR("SVG element without owner document");
|
NS_ERROR("SVG element without owner document");
|
||||||
|
@ -633,41 +626,12 @@ nsSVGElement::UpdateContentStyleRule()
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
||||||
nsIURI *docURI = doc->GetDocumentURI();
|
nsIURI *docURI = doc->GetDocumentURI();
|
||||||
|
|
||||||
// Create the nsCSSDeclaration.
|
|
||||||
nsCSSDeclaration* declaration = new nsCSSDeclaration();
|
|
||||||
if (!declaration) {
|
|
||||||
NS_WARNING("Failed to allocate nsCSSDeclaration");
|
|
||||||
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->CSSLoader();
|
nsICSSLoader* cssLoader = doc->CSSLoader();
|
||||||
|
|
||||||
nsCOMPtr<nsICSSParser> parser;
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
rv = cssLoader->GetParserFor(nsnull, getter_AddRefs(parser));
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
NS_WARNING("failed to get a css parser");
|
|
||||||
declaration->RuleAbort();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SVG and CSS differ slightly in their interpretation of some of
|
nsCSSDeclaration* declaration = nsnull;
|
||||||
// the attributes. SVG allows attributes of the form: font-size="5"
|
nsCOMPtr<nsICSSParser> parser;
|
||||||
// (style="font-size: 5" if using a style attribute)
|
|
||||||
// where CSS requires units: font-size="5pt" (style="font-size: 5pt")
|
nsresult rv = NS_OK;
|
||||||
// Set a flag to pass information to the parser so that we can use
|
|
||||||
// the CSS parser to parse the font-size attribute. Note that this
|
|
||||||
// does *not* effect the use of CSS stylesheets, which will still
|
|
||||||
// require units
|
|
||||||
parser->SetSVGMode(PR_TRUE);
|
|
||||||
|
|
||||||
PRUint32 attrCount = mAttrsAndChildren.AttrCount();
|
PRUint32 attrCount = mAttrsAndChildren.AttrCount();
|
||||||
for (PRUint32 i = 0; i < attrCount; ++i) {
|
for (PRUint32 i = 0; i < attrCount; ++i) {
|
||||||
|
@ -675,6 +639,38 @@ nsSVGElement::UpdateContentStyleRule()
|
||||||
if (!attrName->IsAtom() || !IsAttributeMapped(attrName->Atom()))
|
if (!attrName->IsAtom() || !IsAttributeMapped(attrName->Atom()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!declaration) {
|
||||||
|
// Create the nsCSSDeclaration.
|
||||||
|
declaration = new nsCSSDeclaration();
|
||||||
|
if (!declaration) {
|
||||||
|
NS_WARNING("Failed to allocate nsCSSDeclaration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!declaration->InitializeEmpty()) {
|
||||||
|
NS_WARNING("could not initialize nsCSSDeclaration");
|
||||||
|
declaration->RuleAbort(); // deletes declaration
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to fetch the CSS Parser from the document.
|
||||||
|
rv = cssLoader->GetParserFor(nsnull, getter_AddRefs(parser));
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
NS_WARNING("failed to get a css parser");
|
||||||
|
declaration->RuleAbort(); // deletes declaration
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SVG and CSS differ slightly in their interpretation of some of
|
||||||
|
// the attributes. SVG allows attributes of the form: font-size="5"
|
||||||
|
// (style="font-size: 5" if using a style attribute)
|
||||||
|
// where CSS requires units: font-size="5pt" (style="font-size: 5pt")
|
||||||
|
// Set a flag to pass information to the parser so that we can use
|
||||||
|
// the CSS parser to parse the font-size attribute. Note that this
|
||||||
|
// does *not* effect the use of CSS stylesheets, which will still
|
||||||
|
// require units
|
||||||
|
parser->SetSVGMode(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
attrName->Atom()->ToString(name);
|
attrName->Atom()->ToString(name);
|
||||||
|
|
||||||
|
@ -686,16 +682,18 @@ nsSVGElement::UpdateContentStyleRule()
|
||||||
docURI, baseURI,
|
docURI, baseURI,
|
||||||
declaration, &changed);
|
declaration, &changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule), nsnull, declaration);
|
if (declaration) {
|
||||||
if (NS_FAILED(rv)) {
|
rv = NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule), nsnull, declaration);
|
||||||
NS_WARNING("could not create contentstylerule");
|
if (NS_FAILED(rv)) {
|
||||||
declaration->RuleAbort();
|
NS_WARNING("could not create contentstylerule");
|
||||||
|
declaration->RuleAbort(); // deletes declaration
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recycle the parser
|
||||||
|
parser->SetSVGMode(PR_FALSE);
|
||||||
|
cssLoader->RecycleParser(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recycle the parser
|
|
||||||
parser->SetSVGMode(PR_FALSE);
|
|
||||||
cssLoader->RecycleParser(parser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsISVGValue*
|
nsISVGValue*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче