Make GetImportantRule and GetISupportsValue return already_AddRefed.

Bug 171808, r=jkeiser, sr=dbaron
This commit is contained in:
bzbarsky%mit.edu 2002-10-09 01:59:43 +00:00
Родитель 279ffda515
Коммит 093137e9f2
11 изменённых файлов: 61 добавлений и 79 удалений

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

@ -42,6 +42,7 @@
#include "nsColor.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
@ -200,7 +201,7 @@ public:
PRInt32 GetPixelValue(void) const;
float GetPercentValue(void) const;
nsAString& GetStringValue(nsAString& aBuffer) const;
nsISupports* GetISupportsValue(void) const;
already_AddRefed<nsISupports> GetISupportsValue(void) const;
nscolor GetColorValue(void) const;
/**
@ -332,7 +333,7 @@ inline nsAString& nsHTMLValue::GetStringValue(nsAString& aBuffer) const
return aBuffer;
}
inline nsISupports* nsHTMLValue::GetISupportsValue(void) const
inline already_AddRefed<nsISupports> nsHTMLValue::GetISupportsValue(void) const
{
NS_ASSERTION(mUnit == eHTMLUnit_ISupports, "not an ISupports value");
if (mUnit == eHTMLUnit_ISupports) {

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

@ -973,7 +973,7 @@ StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode,
aCurrLevelNode->GetRule(getter_AddRefs(rule));
nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
if (cssRule) {
nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule());
nsCOMPtr<nsIStyleRule> impRule = cssRule->GetImportantRule();
if (impRule)
mRuleWalker->Forward(impRule);
}

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

@ -2535,20 +2535,18 @@ nsGenericHTMLElement::AttributeToString(nsIAtom* aAttribute,
{
if (nsHTMLAtoms::style == aAttribute) {
if (eHTMLUnit_ISupports == aValue.GetUnit()) {
nsIStyleRule* rule = (nsIStyleRule*) aValue.GetISupportsValue();
if (rule) {
nsICSSStyleRule* cssRule;
if (NS_OK == rule->QueryInterface(NS_GET_IID(nsICSSStyleRule), (void**)&cssRule)) {
nsCSSDeclaration* decl = cssRule->GetDeclaration();
if (nsnull != decl) {
decl->ToString(aResult);
}
NS_RELEASE(cssRule);
nsCOMPtr<nsISupports> rule = aValue.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule);
if (cssRule) {
nsCSSDeclaration* decl = cssRule->GetDeclaration();
if (decl) {
decl->ToString(aResult);
} else {
aResult.Truncate();
}
else {
aResult.Assign(NS_LITERAL_STRING("Unknown rule type"));
}
NS_RELEASE(rule);
}
else {
aResult.Assign(NS_LITERAL_STRING("Unknown rule type"));
}
return NS_CONTENT_ATTR_HAS_VALUE;
}

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

@ -1194,9 +1194,9 @@ DOMCSSDeclarationImpl::DropReference(void)
nsresult
DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
PRBool aAllocate)
PRBool aAllocate)
{
if (nsnull != mRule) {
if (mRule) {
*aDecl = mRule->GetDeclaration();
}
else {
@ -1209,7 +1209,7 @@ DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
DOMCSSDeclarationImpl::SetCSSDeclaration(nsCSSDeclaration *aDecl)
{
if (nsnull != mRule) {
if (mRule) {
mRule->SetDeclaration(aDecl);
}
@ -1414,7 +1414,7 @@ public:
virtual PRInt32 GetWeight(void) const;
virtual void SetWeight(PRInt32 aWeight);
virtual nsIStyleRule* GetImportantRule(void);
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void);
// hook for inspector
virtual nsresult GetValue(nsCSSProperty aProperty, nsCSSValue& aValue);
@ -1645,11 +1645,11 @@ void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
mWeight = aWeight;
}
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
already_AddRefed<nsIStyleRule> CSSStyleRuleImpl::GetImportantRule(void)
{
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
if (!mImportantRule && mDeclaration) {
nsCSSDeclaration* important = mDeclaration->GetImportantValues();
if (nsnull != important) {
if (important) {
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
}

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

@ -125,35 +125,30 @@ nsresult
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
PRBool aAllocate)
{
nsHTMLValue val;
nsIStyleRule* rule;
nsICSSStyleRule* cssRule;
nsresult result = NS_OK;
*aDecl = nsnull;
if (nsnull != mContent) {
if (mContent) {
nsHTMLValue val;
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (eHTMLUnit_ISupports == val.GetUnit()) {
rule = (nsIStyleRule*) val.GetISupportsValue();
result = rule->QueryInterface(NS_GET_IID(nsICSSStyleRule), (void**)&cssRule);
if (NS_OK == result) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
NS_RELEASE(cssRule);
}
NS_RELEASE(rule);
}
else if (PR_TRUE == aAllocate) {
else if (aAllocate) {
result = NS_NewCSSDeclaration(aDecl);
if (NS_OK == result) {
result = NS_NewCSSStyleRule(&cssRule, nsCSSSelector());
nsCOMPtr<nsICSSStyleRule> cssRule;
result = NS_NewCSSStyleRule(getter_AddRefs(cssRule), nsCSSSelector());
if (NS_OK == result) {
cssRule->SetDeclaration(*aDecl);
cssRule->SetWeight(0x7fffffff);
rule = (nsIStyleRule *)cssRule;
result = mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(cssRule),
PR_FALSE);
NS_RELEASE(cssRule);
}
else {
(*aDecl)->RuleAbort();
@ -169,21 +164,17 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
nsDOMCSSAttributeDeclaration::SetCSSDeclaration(nsCSSDeclaration *aDecl)
{
nsHTMLValue val;
nsIStyleRule* rule;
nsICSSStyleRule* cssRule;
nsresult result = NS_OK;
if (nsnull != mContent) {
if (mContent) {
nsHTMLValue val;
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (eHTMLUnit_ISupports == val.GetUnit()) {
rule = (nsIStyleRule*) val.GetISupportsValue();
result = rule->QueryInterface(NS_GET_IID(nsICSSStyleRule), (void**)&cssRule);
if (NS_OK == result) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
cssRule->SetDeclaration(aDecl);
NS_RELEASE(cssRule);
}
NS_RELEASE(rule);
}
}

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

@ -184,7 +184,7 @@ public:
virtual PRInt32 GetWeight(void) const = 0;
virtual void SetWeight(PRInt32 aWeight) = 0;
virtual nsIStyleRule* GetImportantRule(void) = 0;
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void) = 0;
// Hook for inspector.
virtual nsresult GetValue(nsCSSProperty aProperty, nsCSSValue& aValue) = 0;

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

@ -42,6 +42,7 @@
#include "nsColor.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
@ -200,7 +201,7 @@ public:
PRInt32 GetPixelValue(void) const;
float GetPercentValue(void) const;
nsAString& GetStringValue(nsAString& aBuffer) const;
nsISupports* GetISupportsValue(void) const;
already_AddRefed<nsISupports> GetISupportsValue(void) const;
nscolor GetColorValue(void) const;
/**
@ -332,7 +333,7 @@ inline nsAString& nsHTMLValue::GetStringValue(nsAString& aBuffer) const
return aBuffer;
}
inline nsISupports* nsHTMLValue::GetISupportsValue(void) const
inline already_AddRefed<nsISupports> nsHTMLValue::GetISupportsValue(void) const
{
NS_ASSERTION(mUnit == eHTMLUnit_ISupports, "not an ISupports value");
if (mUnit == eHTMLUnit_ISupports) {

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

@ -1194,9 +1194,9 @@ DOMCSSDeclarationImpl::DropReference(void)
nsresult
DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
PRBool aAllocate)
PRBool aAllocate)
{
if (nsnull != mRule) {
if (mRule) {
*aDecl = mRule->GetDeclaration();
}
else {
@ -1209,7 +1209,7 @@ DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
DOMCSSDeclarationImpl::SetCSSDeclaration(nsCSSDeclaration *aDecl)
{
if (nsnull != mRule) {
if (mRule) {
mRule->SetDeclaration(aDecl);
}
@ -1414,7 +1414,7 @@ public:
virtual PRInt32 GetWeight(void) const;
virtual void SetWeight(PRInt32 aWeight);
virtual nsIStyleRule* GetImportantRule(void);
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void);
// hook for inspector
virtual nsresult GetValue(nsCSSProperty aProperty, nsCSSValue& aValue);
@ -1645,11 +1645,11 @@ void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
mWeight = aWeight;
}
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
already_AddRefed<nsIStyleRule> CSSStyleRuleImpl::GetImportantRule(void)
{
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
if (!mImportantRule && mDeclaration) {
nsCSSDeclaration* important = mDeclaration->GetImportantValues();
if (nsnull != important) {
if (important) {
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
}

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

@ -125,35 +125,30 @@ nsresult
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
PRBool aAllocate)
{
nsHTMLValue val;
nsIStyleRule* rule;
nsICSSStyleRule* cssRule;
nsresult result = NS_OK;
*aDecl = nsnull;
if (nsnull != mContent) {
if (mContent) {
nsHTMLValue val;
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (eHTMLUnit_ISupports == val.GetUnit()) {
rule = (nsIStyleRule*) val.GetISupportsValue();
result = rule->QueryInterface(NS_GET_IID(nsICSSStyleRule), (void**)&cssRule);
if (NS_OK == result) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
NS_RELEASE(cssRule);
}
NS_RELEASE(rule);
}
else if (PR_TRUE == aAllocate) {
else if (aAllocate) {
result = NS_NewCSSDeclaration(aDecl);
if (NS_OK == result) {
result = NS_NewCSSStyleRule(&cssRule, nsCSSSelector());
nsCOMPtr<nsICSSStyleRule> cssRule;
result = NS_NewCSSStyleRule(getter_AddRefs(cssRule), nsCSSSelector());
if (NS_OK == result) {
cssRule->SetDeclaration(*aDecl);
cssRule->SetWeight(0x7fffffff);
rule = (nsIStyleRule *)cssRule;
result = mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(cssRule),
PR_FALSE);
NS_RELEASE(cssRule);
}
else {
(*aDecl)->RuleAbort();
@ -169,21 +164,17 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
nsDOMCSSAttributeDeclaration::SetCSSDeclaration(nsCSSDeclaration *aDecl)
{
nsHTMLValue val;
nsIStyleRule* rule;
nsICSSStyleRule* cssRule;
nsresult result = NS_OK;
if (nsnull != mContent) {
if (mContent) {
nsHTMLValue val;
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (eHTMLUnit_ISupports == val.GetUnit()) {
rule = (nsIStyleRule*) val.GetISupportsValue();
result = rule->QueryInterface(NS_GET_IID(nsICSSStyleRule), (void**)&cssRule);
if (NS_OK == result) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
cssRule->SetDeclaration(aDecl);
NS_RELEASE(cssRule);
}
NS_RELEASE(rule);
}
}

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

@ -184,7 +184,7 @@ public:
virtual PRInt32 GetWeight(void) const = 0;
virtual void SetWeight(PRInt32 aWeight) = 0;
virtual nsIStyleRule* GetImportantRule(void) = 0;
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void) = 0;
// Hook for inspector.
virtual nsresult GetValue(nsCSSProperty aProperty, nsCSSValue& aValue) = 0;

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

@ -973,7 +973,7 @@ StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode,
aCurrLevelNode->GetRule(getter_AddRefs(rule));
nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
if (cssRule) {
nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule());
nsCOMPtr<nsIStyleRule> impRule = cssRule->GetImportantRule();
if (impRule)
mRuleWalker->Forward(impRule);
}