Bug 569719 part 9: remove return value from css::Declaration methods that always return NS_OK, and change GetCSSDeclaration to return a css::Declaration instead of an nsresult. r=dbaron

This commit is contained in:
Zack Weinberg 2010-07-23 11:00:34 -07:00
parent e616dd17f4
commit b184cb662d
15 changed files with 130 additions and 203 deletions

View File

@ -1217,10 +1217,8 @@ nsHTMLParanoidFragmentSink::SanitizeStyleRule(nsICSSStyleRule *aRule, nsAutoStri
aRuleText.Truncate();
css::Declaration *style = aRule->GetDeclaration();
if (style) {
nsresult rv = style->RemoveProperty(eCSSProperty_binding);
if (NS_SUCCEEDED(rv)) {
style->ToString(aRuleText);
}
style->RemoveProperty(eCSSProperty_binding);
style->ToString(aRuleText);
}
}

View File

@ -1182,11 +1182,7 @@ MappedAttrParser::CreateStyleRule()
return nsnull; // No mapped attributes were parsed
}
nsCOMPtr<nsICSSStyleRule> rule;
if (NS_FAILED(NS_NewCSSStyleRule(getter_AddRefs(rule), nsnull, mDecl))) {
NS_WARNING("could not create style rule from mapped attributes");
mDecl->RuleAbort(); // deletes declaration
}
nsCOMPtr<nsICSSStyleRule> rule = NS_NewCSSStyleRule(nsnull, mDecl);
mDecl = nsnull; // We no longer own the declaration -- drop our pointer to it
return rule.forget();
}

View File

@ -87,7 +87,7 @@ Declaration::~Declaration()
MOZ_COUNT_DTOR(mozilla::css::Declaration);
}
nsresult
void
Declaration::ValueAppended(nsCSSProperty aProperty)
{
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
@ -95,10 +95,9 @@ Declaration::ValueAppended(nsCSSProperty aProperty)
// order IS important for CSS, so remove and add to the end
mOrder.RemoveElement(aProperty);
mOrder.AppendElement(aProperty);
return NS_OK;
}
nsresult
void
Declaration::RemoveProperty(nsCSSProperty aProperty)
{
nsCSSExpandedDataBlock data;
@ -116,7 +115,6 @@ Declaration::RemoveProperty(nsCSSProperty aProperty)
}
CompressFrom(&data);
return NS_OK;
}
PRBool Declaration::AppendValueToString(nsCSSProperty aProperty,
@ -158,7 +156,7 @@ PRBool Declaration::AppendValueToString(nsCSSProperty aProperty,
return PR_TRUE;
}
nsresult
void
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
{
aValue.Truncate(0);
@ -166,7 +164,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
// simple properties are easy.
if (!nsCSSProps::IsShorthand(aProperty)) {
AppendValueToString(aProperty, aValue);
return NS_OK;
return;
}
// DOM Level 2 Style says (when describing CSS2Properties, although
@ -208,7 +206,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
}
if (!storage) {
// Case (1) above: some subproperties not specified.
return NS_OK;
return;
}
nsCSSUnit unit;
switch (nsCSSProps::kTypeTable[*p]) {
@ -245,21 +243,21 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
}
if (importantCount != 0 && importantCount != totalCount) {
// Case (3), no consistent importance.
return NS_OK;
return;
}
if (initialCount == totalCount) {
// Simplify serialization below by serializing initial up-front.
nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue);
return NS_OK;
return;
}
if (inheritCount == totalCount) {
// Simplify serialization below by serializing inherit up-front.
nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue);
return NS_OK;
return;
}
if (initialCount != 0 || inheritCount != 0) {
// Case (2): partially initial or inherit.
return NS_OK;
return;
}
nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
@ -465,7 +463,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
size->mYValue.GetUnit() != eCSSUnit_Auto) {
// Non-default background-size, so can't be serialized as shorthand.
aValue.Truncate();
return NS_OK;
return;
}
image->mValue.AppendToString(eCSSProperty_background_image, aValue);
aValue.Append(PRUnichar(' '));
@ -497,7 +495,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
// shorthand.
if (clip->mValue != origin->mValue) {
aValue.Truncate();
return NS_OK;
return;
}
aValue.Append(PRUnichar(' '));
@ -516,14 +514,14 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
if (repeat || attachment || position || clip || origin || size) {
// Uneven length lists, so can't be serialized as shorthand.
aValue.Truncate();
return NS_OK;
return;
}
break;
}
if (!repeat || !attachment || !position || !clip || !origin || !size) {
// Uneven length lists, so can't be serialized as shorthand.
aValue.Truncate();
return NS_OK;
return;
}
aValue.Append(PRUnichar(','));
aValue.Append(PRUnichar(' '));
@ -581,7 +579,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
featureSettings.GetUnit() != eCSSUnit_System_Font ||
languageOverride.GetUnit() != eCSSUnit_System_Font) {
// This can't be represented as a shorthand.
return NS_OK;
return;
}
systemFont->AppendToString(eCSSProperty__x_system_font, aValue);
} else {
@ -594,7 +592,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
sizeAdjust.GetUnit() != eCSSUnit_None ||
featureSettings.GetUnit() != eCSSUnit_Normal ||
languageOverride.GetUnit() != eCSSUnit_Normal) {
return NS_OK;
return;
}
if (style.GetUnit() != eCSSUnit_Enumerated ||
@ -704,7 +702,6 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
NS_NOTREACHED("no other shorthands");
break;
}
return NS_OK;
}
PRBool
@ -769,7 +766,7 @@ Declaration::AppendPropertyAndValueToString(nsCSSProperty aProperty,
aResult.AppendLiteral("; ");
}
nsresult
void
Declaration::ToString(nsAString& aString) const
{
nsCSSCompressedDataBlock *systemFontData =
@ -862,7 +859,6 @@ Declaration::ToString(nsAString& aString) const
// if the string is not empty, we have a trailing whitespace we should remove
aString.Truncate(aString.Length() - 1);
}
return NS_OK;
}
#ifdef DEBUG
@ -878,7 +874,7 @@ void Declaration::List(FILE* out, PRInt32 aIndent) const
}
#endif
nsresult
void
Declaration::GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const
{
aReturn.Truncate();
@ -888,8 +884,6 @@ Declaration::GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
}
}
return NS_OK;
}
Declaration*
@ -898,12 +892,11 @@ Declaration::Clone() const
return new Declaration(*this);
}
PRBool
void
Declaration::InitializeEmpty()
{
NS_ASSERTION(!mData && !mImportantData, "already initialized");
mData = nsCSSCompressedDataBlock::CreateEmptyBlock();
return mData != nsnull;
}
PRBool

View File

@ -83,11 +83,11 @@ public:
* |mOrder| whenever a property is parsed into an expanded data block
* for this declaration. aProperty must not be a shorthand.
*/
nsresult ValueAppended(nsCSSProperty aProperty);
void ValueAppended(nsCSSProperty aProperty);
nsresult RemoveProperty(nsCSSProperty aProperty);
void RemoveProperty(nsCSSProperty aProperty);
nsresult GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
void GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
PRBool HasImportantData() const { return mImportantData != nsnull; }
PRBool GetValueIsImportant(nsCSSProperty aProperty) const;
@ -96,9 +96,9 @@ public:
PRUint32 Count() const {
return mOrder.Length();
}
nsresult GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const;
void GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const;
nsresult ToString(nsAString& aString) const;
void ToString(nsAString& aString) const;
Declaration* Clone() const;
@ -106,10 +106,9 @@ public:
nsCSSCompressedDataBlock* GetImportantBlock() const { return mImportantData; }
/**
* Initialize this declaration as holding no data. Return false on
* out-of-memory.
* Initialize this declaration as holding no data. Cannot fail.
*/
PRBool InitializeEmpty();
void InitializeEmpty();
/**
* Transfer all of the state from |aExpandedData| into this declaration.

View File

@ -560,10 +560,7 @@ nsCSSCompressedDataBlock::Destroy()
nsCSSCompressedDataBlock::CreateEmptyBlock()
{
nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock();
if (!result)
return nsnull;
result->mBlockEnd = result->Block();
result->AddRef();
return result;
}

View File

@ -1006,16 +1006,8 @@ CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
css::Declaration* declaration = ParseDeclarationBlock(haveBraces);
if (declaration) {
// Create a style rule for the declaration
nsICSSStyleRule* rule = nsnull;
nsresult rv = NS_NewCSSStyleRule(&rule, nsnull, declaration);
if (NS_FAILED(rv)) {
declaration->RuleAbort();
ReleaseScanner();
return rv;
}
*aResult = rule;
}
else {
*aResult = NS_NewCSSStyleRule(nsnull, declaration).get();
} else {
*aResult = nsnull;
}
@ -2436,13 +2428,7 @@ CSSParserImpl::ParseRuleSet(RuleAppendFunc aAppendFunc, void* aData,
// Translate the selector list and declaration block into style data
nsCOMPtr<nsICSSStyleRule> rule;
NS_NewCSSStyleRule(getter_AddRefs(rule), slist, declaration);
if (!rule) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
delete slist;
return PR_FALSE;
}
nsCOMPtr<nsICSSStyleRule> rule = NS_NewCSSStyleRule(slist, declaration);
rule->SetLineNumber(linenum);
(*aAppendFunc)(rule, aData);

View File

@ -959,8 +959,7 @@ public:
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
void DropReference(void);
virtual nsresult GetCSSDeclaration(css::Declaration **aDecl,
PRBool aAllocate);
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
@ -1048,18 +1047,14 @@ DOMCSSDeclarationImpl::DropReference(void)
mRule = nsnull;
}
nsresult
DOMCSSDeclarationImpl::GetCSSDeclaration(css::Declaration **aDecl,
PRBool aAllocate)
css::Declaration*
DOMCSSDeclarationImpl::GetCSSDeclaration(PRBool aAllocate)
{
if (mRule) {
*aDecl = mRule->GetDeclaration();
return mRule->GetDeclaration();
} else {
return nsnull;
}
else {
*aDecl = nsnull;
}
return NS_OK;
}
/*
@ -1643,17 +1638,12 @@ CSSStyleRuleImpl::SetSelectorText(const nsAString& aSelectorText)
return NS_OK;
}
nsresult
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
nsCSSSelectorList* aSelector,
already_AddRefed<nsICSSStyleRule>
NS_NewCSSStyleRule(nsCSSSelectorList* aSelector,
css::Declaration* aDeclaration)
{
NS_PRECONDITION(aDeclaration, "must have a declaration");
CSSStyleRuleImpl *it = new CSSStyleRuleImpl(aSelector, aDeclaration);
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aInstancePtrResult = it);
return NS_OK;
NS_ADDREF(it);
return it;
}

View File

@ -410,11 +410,11 @@ nsComputedDOMStyle::GetPresShellForContent(nsIContent* aContent)
// nsDOMCSSDeclaration abstract methods which should never be called
// on a nsComputedDOMStyle object, but must be defined to avoid
// compile errors.
nsresult
nsComputedDOMStyle::GetCSSDeclaration(css::Declaration**, PRBool)
css::Declaration*
nsComputedDOMStyle::GetCSSDeclaration(PRBool)
{
NS_RUNTIMEABORT("called nsComputedDOMStyle::GetCSSDeclaration");
return NS_ERROR_FAILURE;
return nsnull;
}
nsresult

View File

@ -104,7 +104,7 @@ public:
// nsDOMCSSDeclaration abstract methods which should never be called
// on a nsComputedDOMStyle object, but must be defined to avoid
// compile errors.
virtual nsresult GetCSSDeclaration(mozilla::css::Declaration**, PRBool);
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool);
virtual nsresult DeclarationChanged();
virtual nsIDocument* DocToUpdate();
virtual nsresult GetCSSParsingEnvironment(nsIURI**, nsIURI**, nsIPrincipal**,

View File

@ -128,51 +128,46 @@ nsDOMCSSAttributeDeclaration::DocToUpdate()
return mContent->GetOwnerDoc();
}
nsresult
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(css::Declaration **aDecl,
PRBool aAllocate)
css::Declaration*
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate)
{
nsresult result = NS_OK;
if (!mContent)
return nsnull;
*aDecl = nsnull;
if (mContent) {
nsICSSStyleRule* cssRule =
nsICSSStyleRule* cssRule;
#ifdef MOZ_SMIL
mIsSMILOverride ? mContent->GetSMILOverrideStyleRule() :
if (mIsSMILOverride)
cssRule = mContent->GetSMILOverrideStyleRule();
else
#endif // MOZ_SMIL
mContent->GetInlineStyleRule();
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
}
else if (aAllocate) {
css::Declaration *decl = new css::Declaration();
if (!decl)
return NS_ERROR_OUT_OF_MEMORY;
if (!decl->InitializeEmpty()) {
decl->RuleAbort();
return NS_ERROR_OUT_OF_MEMORY;
}
cssRule = mContent->GetInlineStyleRule();
nsCOMPtr<nsICSSStyleRule> newRule;
result = NS_NewCSSStyleRule(getter_AddRefs(newRule), nsnull, decl);
if (NS_FAILED(result)) {
decl->RuleAbort();
return result;
}
result =
#ifdef MOZ_SMIL
mIsSMILOverride ?
mContent->SetSMILOverrideStyleRule(newRule, PR_FALSE) :
#endif // MOZ_SMIL
mContent->SetInlineStyleRule(newRule, PR_FALSE);
if (NS_SUCCEEDED(result)) {
*aDecl = decl;
}
}
if (cssRule) {
return cssRule->GetDeclaration();
}
if (!aAllocate) {
return nsnull;
}
return result;
// cannot fail
css::Declaration *decl = new css::Declaration();
decl->InitializeEmpty();
nsCOMPtr<nsICSSStyleRule> newRule = NS_NewCSSStyleRule(nsnull, decl);
// this *can* fail (inside SetAttrAndNotify, at least).
nsresult rv;
#ifdef MOZ_SMIL
if (mIsSMILOverride)
rv = mContent->SetSMILOverrideStyleRule(newRule, PR_FALSE);
else
#endif // MOZ_SMIL
rv = mContent->SetInlineStyleRule(newRule, PR_FALSE);
if (NS_FAILED(rv)) {
return nsnull; // the decl will be destroyed along with the style rule
}
return decl;
}
/*

View File

@ -69,8 +69,7 @@ public:
// If GetCSSDeclaration returns non-null, then the decl it returns
// is owned by our current style rule.
virtual nsresult GetCSSDeclaration(mozilla::css::Declaration **aDecl,
PRBool aAllocate);
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,

View File

@ -79,15 +79,13 @@ nsDOMCSSDeclaration::GetPropertyValue(const nsCSSProperty aPropID,
NS_PRECONDITION(aPropID != eCSSProperty_UNKNOWN,
"Should never pass eCSSProperty_UNKNOWN around");
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
aValue.Truncate();
if (decl) {
result = decl->GetValue(aPropID, aValue);
decl->GetValue(aPropID, aValue);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
@ -107,9 +105,8 @@ nsDOMCSSDeclaration::SetPropertyValue(const nsCSSProperty aPropID,
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssText(nsAString& aCssText)
{
css::Declaration* decl;
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
aCssText.Truncate();
GetCSSDeclaration(&decl, PR_FALSE);
if (decl) {
decl->ToString(aCssText);
@ -121,12 +118,12 @@ nsDOMCSSDeclaration::GetCssText(nsAString& aCssText)
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
{
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_TRUE);
css::Declaration* decl = GetCSSDeclaration(PR_TRUE);
if (!decl) {
return result;
return NS_ERROR_FAILURE;
}
nsresult result;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
@ -151,19 +148,17 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
PRBool changed;
result = cssParser.ParseDeclarations(aCssText, sheetURI, baseURI,
sheetPrincipal, decl, &changed);
if (NS_SUCCEEDED(result) && changed) {
result = DeclarationChanged();
if (NS_FAILED(result) || !changed) {
return result;
}
return result;
return DeclarationChanged();
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
{
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
if (decl) {
*aLength = decl->Count();
@ -171,7 +166,7 @@ nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
*aLength = 0;
}
return result;
return NS_OK;
}
NS_IMETHODIMP
@ -189,19 +184,18 @@ nsDOMCSSDeclaration::GetPropertyCSSValue(const nsAString& aPropertyName,
NS_IMETHODIMP
nsDOMCSSDeclaration::Item(PRUint32 aIndex, nsAString& aReturn)
{
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
aReturn.SetLength(0);
if (decl) {
result = decl->GetNthProperty(aIndex, aReturn);
decl->GetNthProperty(aIndex, aReturn);
}
return result;
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
NS_IMETHODIMP
nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
nsAString& aReturn)
{
const nsCSSProperty propID = nsCSSProps::LookupProperty(aPropertyName);
@ -209,28 +203,27 @@ nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
aReturn.Truncate();
return NS_OK;
}
return GetPropertyValue(propID, aReturn);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetPropertyPriority(const nsAString& aPropertyName,
NS_IMETHODIMP
nsDOMCSSDeclaration::GetPropertyPriority(const nsAString& aPropertyName,
nsAString& aReturn)
{
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_FALSE);
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
aReturn.Truncate();
if (decl && decl->GetValueIsImportant(aPropertyName)) {
aReturn.AssignLiteral("important");
aReturn.AssignLiteral("important");
}
return result;
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
const nsAString& aValue,
NS_IMETHODIMP
nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
const nsAString& aValue,
const nsAString& aPriority)
{
// In the common (and fast) cases we can use the property id
@ -267,12 +260,11 @@ nsDOMCSSDeclaration::RemoveProperty(const nsAString& aPropertyName,
aReturn.Truncate();
return NS_OK;
}
nsresult rv = GetPropertyValue(propID, aReturn);
NS_ENSURE_SUCCESS(rv, rv);
rv = RemoveProperty(propID);
return rv;
return RemoveProperty(propID);
}
nsresult
@ -280,12 +272,12 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
const nsAString& aPropValue,
PRBool aIsImportant)
{
css::Declaration* decl;
nsresult result = GetCSSDeclaration(&decl, PR_TRUE);
css::Declaration* decl = GetCSSDeclaration(PR_TRUE);
if (!decl) {
return result;
return NS_ERROR_FAILURE;
}
nsresult result;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
@ -310,20 +302,19 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
result = cssParser.ParseProperty(aPropID, aPropValue, sheetURI, baseURI,
sheetPrincipal, decl, &changed,
aIsImportant);
if (NS_SUCCEEDED(result) && changed) {
result = DeclarationChanged();
if (NS_FAILED(result) || !changed) {
return result;
}
return result;
return DeclarationChanged();
}
nsresult
nsDOMCSSDeclaration::RemoveProperty(const nsCSSProperty aPropID)
{
css::Declaration* decl;
nsresult rv = GetCSSDeclaration(&decl, PR_FALSE);
css::Declaration* decl = GetCSSDeclaration(PR_FALSE);
if (!decl) {
return rv;
return NS_OK; // no decl, so nothing to remove
}
// For nsDOMCSSAttributeDeclaration, DeclarationChanged will lead to
@ -333,18 +324,8 @@ nsDOMCSSDeclaration::RemoveProperty(const nsCSSProperty aPropID)
// rule (see stack in bug 209575).
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), PR_TRUE);
rv = decl->RemoveProperty(aPropID);
if (NS_SUCCEEDED(rv)) {
rv = DeclarationChanged();
} else {
// RemoveProperty used to throw in all sorts of situations -- e.g.
// if the property was a shorthand one. Do not propagate its return
// value to callers. (XXX or should we propagate it again now?)
rv = NS_OK;
}
return rv;
decl->RemoveProperty(aPropID);
return DeclarationChanged();
}
// nsIDOMCSS2Properties

View File

@ -91,11 +91,10 @@ public:
NS_DECL_NSIDOMNSCSS2PROPERTIES
protected:
// Always fills in the out parameter, even on failure, and if the out
// parameter is null the nsresult will be the correct thing to
// propagate.
virtual nsresult GetCSSDeclaration(mozilla::css::Declaration **aDecl,
PRBool aAllocate) = 0;
// This method can return null regardless of the value of aAllocate;
// however, a null return should only be considered a failure
// if aAllocate is true.
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate) = 0;
virtual nsresult DeclarationChanged() = 0;
// Document that we must call BeginUpdate/EndUpdate on around the
// calls to DeclarationChanged and the style rule mutation that leads

View File

@ -339,9 +339,8 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleRule, NS_ICSS_STYLE_RULE_IID)
nsresult
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
nsCSSSelectorList* aSelector,
already_AddRefed<nsICSSStyleRule>
NS_NewCSSStyleRule(nsCSSSelectorList* aSelector,
mozilla::css::Declaration* aDeclaration);
#endif /* nsICSSStyleRule_h___ */

View File

@ -1610,11 +1610,11 @@ BuildStyleRule(nsCSSProperty aProperty,
{
// Set up an empty CSS Declaration
css::Declaration* declaration = new css::Declaration();
declaration->InitializeEmpty();
PRBool changed; // ignored, but needed as outparam for ParseProperty
nsIDocument* doc = aTargetElement->GetOwnerDoc();
nsCOMPtr<nsIURI> baseURI = aTargetElement->GetBaseURI();
nsCOMPtr<nsICSSStyleRule> styleRule;
nsCSSParser parser(doc->CSSLoader());
if (aUseSVGMode) {
@ -1628,26 +1628,21 @@ BuildStyleRule(nsCSSProperty aProperty,
nsCSSProperty propertyToCheck = nsCSSProps::IsShorthand(aProperty) ?
nsCSSProps::SubpropertyEntryFor(aProperty)[0] : aProperty;
// The next clause performs the following, in sequence: Initialize our
// declaration, get a parser, parse property, check that parsing succeeded,
// and build a rule for the resulting declaration. If any of these steps
// fails, we bail out and delete the declaration.
if (!declaration->InitializeEmpty() ||
!parser ||
// Get a parser, parse the property, and check for CSS parsing errors.
// If any of these steps fails, we bail out and delete the declaration.
if (!parser ||
NS_FAILED(parser.ParseProperty(aProperty, aSpecifiedValue,
doc->GetDocumentURI(), baseURI,
aTargetElement->NodePrincipal(),
declaration, &changed, PR_FALSE)) ||
// check whether property parsed without CSS parsing errors
!declaration->HasNonImportantValueFor(propertyToCheck) ||
NS_FAILED(NS_NewCSSStyleRule(getter_AddRefs(styleRule), nsnull,
declaration))) {
!declaration->HasNonImportantValueFor(propertyToCheck)) {
NS_WARNING("failure in BuildStyleRule");
declaration->RuleAbort(); // deletes declaration
return nsnull;
}
return styleRule.forget();
return NS_NewCSSStyleRule(nsnull, declaration);
}
inline