nsresult nsDOMCSSAttributeDeclaration::SetCSSDeclaration(css::Declaration* aDecl) { NS_ASSERTION(mElement, "Must have Element to set the declaration!"); css::StyleRule* oldRule = mIsSMILOverride ? mElement->GetSMILOverrideStyleRule() : mElement->GetInlineStyleRule(); NS_ASSERTION(oldRule, "Element must have rule"); nsRefPtr<css::StyleRule> newRule = oldRule->DeclarationChanged(aDecl, false); if (!newRule) { return NS_ERROR_OUT_OF_MEMORY; } return mIsSMILOverride ? mElement->SetSMILOverrideStyleRule(newRule, true) : mElement->SetInlineStyleRule(newRule, nullptr, true); }
css::Declaration* nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate) { if (!mElement) return nsnull; css::StyleRule* cssRule; #ifdef MOZ_SMIL if (mIsSMILOverride) cssRule = mElement->GetSMILOverrideStyleRule(); else #endif // MOZ_SMIL cssRule = mElement->GetInlineStyleRule(); if (cssRule) { return cssRule->GetDeclaration(); } if (!aAllocate) { return nsnull; } // cannot fail css::Declaration *decl = new css::Declaration(); decl->InitializeEmpty(); nsRefPtr<css::StyleRule> newRule = NS_NewCSSStyleRule(nsnull, decl); // this *can* fail (inside SetAttrAndNotify, at least). nsresult rv; #ifdef MOZ_SMIL if (mIsSMILOverride) rv = mElement->SetSMILOverrideStyleRule(newRule, PR_FALSE); else #endif // MOZ_SMIL rv = mElement->SetInlineStyleRule(newRule, PR_FALSE); if (NS_FAILED(rv)) { return nsnull; // the decl will be destroyed along with the style rule } return decl; }
nsresult nsDOMCSSAttributeDeclaration::SetCSSDeclaration(css::Declaration* aDecl) { NS_ASSERTION(mElement, "Must have Element to set the declaration!"); css::StyleRule* oldRule = #ifdef MOZ_SMIL mIsSMILOverride ? mElement->GetSMILOverrideStyleRule() : #endif // MOZ_SMIL mElement->GetInlineStyleRule(); NS_ASSERTION(oldRule, "Element must have rule"); nsRefPtr<css::StyleRule> newRule = oldRule->DeclarationChanged(aDecl, PR_FALSE); if (!newRule) { return NS_ERROR_OUT_OF_MEMORY; } return #ifdef MOZ_SMIL mIsSMILOverride ? mElement->SetSMILOverrideStyleRule(newRule, PR_TRUE) : #endif // MOZ_SMIL mElement->SetInlineStyleRule(newRule, PR_TRUE); }
css::Declaration* nsDOMCSSAttributeDeclaration::GetCSSDeclaration(bool aAllocate) { if (!mElement) return nullptr; css::StyleRule* cssRule; if (mIsSMILOverride) cssRule = mElement->GetSMILOverrideStyleRule(); else cssRule = mElement->GetInlineStyleRule(); if (cssRule) { return cssRule->GetDeclaration(); } if (!aAllocate) { return nullptr; } // cannot fail css::Declaration *decl = new css::Declaration(); decl->InitializeEmpty(); nsRefPtr<css::StyleRule> newRule = new css::StyleRule(nullptr, decl); // this *can* fail (inside SetAttrAndNotify, at least). nsresult rv; if (mIsSMILOverride) rv = mElement->SetSMILOverrideStyleRule(newRule, false); else rv = mElement->SetInlineStyleRule(newRule, nullptr, false); if (NS_FAILED(rv)) { return nullptr; // the decl will be destroyed along with the style rule } return decl; }