зеркало из https://github.com/mozilla/pjs.git
Bug 270251 - nsSVGElement::UpdateContentStyleRule issues.
Patch by jlurz24@gmail.com, r=sicking, sr=bz.
This commit is contained in:
Родитель
05f4f336d8
Коммит
88ec41b5e3
|
@ -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"
|
||||||
|
@ -713,18 +714,50 @@ nsSVGElement::UpdateContentStyleRule()
|
||||||
{
|
{
|
||||||
NS_ASSERTION(!mContentStyleRule, "we already have a content style rule");
|
NS_ASSERTION(!mContentStyleRule, "we already have a content style rule");
|
||||||
|
|
||||||
nsCSSDeclaration* declaration = new nsCSSDeclaration();
|
// Bail early if there are no child attributes.
|
||||||
if (!declaration || !declaration->InitializeEmpty()) {
|
// If this code were moved into the for-loop we could
|
||||||
NS_ERROR("could not initialize nsCSSDeclaration");
|
// avoid creating an mDeclaration even when there
|
||||||
|
// are non-style related attributes. See bug 270251.
|
||||||
|
if (mAttrsAndChildren.AttrCount() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nsIDocument* doc = GetOwnerDoc();
|
||||||
|
if (!doc) {
|
||||||
|
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*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче