Implement the parentRule property of CSS rules. Bug 37470, r=pierre,

sr=jst
This commit is contained in:
bzbarsky%mit.edu 2001-09-19 14:16:34 +00:00
parent 0c0546f887
commit 47b3292676
10 changed files with 146 additions and 16 deletions

View File

@ -59,13 +59,15 @@ void nsCSSRule::operator delete(void* ptr)
}
nsCSSRule::nsCSSRule(void)
: mSheet(nsnull)
: mSheet(nsnull),
mParentRule(nsnull)
{
NS_INIT_REFCNT();
}
nsCSSRule::nsCSSRule(const nsCSSRule& aCopy)
: mSheet(aCopy.mSheet)
: mSheet(aCopy.mSheet),
mParentRule(aCopy.mParentRule)
{
NS_INIT_REFCNT();
}
@ -96,6 +98,16 @@ nsCSSRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
return NS_OK;
}
NS_IMETHODIMP
nsCSSRule::SetParentRule(nsICSSGroupRule* aRule)
{
// We don't reference count this up reference. The group rule
// will tell us when it's going away or when we're detached from
// it.
mParentRule = aRule;
return NS_OK;
}
NS_IMETHODIMP
nsCSSRule::GetStrength(PRInt32& aStrength) const
{

View File

@ -29,6 +29,7 @@ class nsIStyleSheet;
class nsICSSStyleSheet;
class nsIPresContext;
struct nsRuleData;
class nsICSSGroupRule;
class nsCSSRule {
public:
@ -46,6 +47,8 @@ public:
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
// nsIStyleRule methods
NS_IMETHOD GetStrength(PRInt32& aStrength) const;
@ -58,7 +61,7 @@ protected:
NS_DECL_OWNINGTHREAD // for thread-safety checking
nsICSSStyleSheet* mSheet;
nsICSSGroupRule* mParentRule;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif

View File

@ -57,17 +57,20 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
#define DECL_STYLE_RULE_INHERIT \
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
NS_IMETHOD GetStrength(PRInt32& aStrength) const; \
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
#define IMPL_STYLE_RULE_INHERIT(_class, super) \
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetStyleSheet(nsICSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetStrength(PRInt32& aStrength) const { return super::GetStrength(aStrength); } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
#define IMPL_STYLE_RULE_INHERIT2(_class, super) \
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetStrength(PRInt32& aStrength) const { return super::GetStrength(aStrength); } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
@ -354,7 +357,11 @@ CSSCharsetRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSCharsetRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
@ -642,7 +649,11 @@ CSSImportRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSImportRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
NS_IMETHODIMP
@ -747,6 +758,15 @@ CloneRuleInto(nsISupports* aRule, void* aArray)
return PR_TRUE;
}
PR_STATIC_CALLBACK(PRBool)
SetParentRuleReference(nsISupports* aRule, void* aParentRule)
{
nsICSSRule* rule = (nsICSSRule*)aRule;
nsICSSGroupRule* parentRule = (nsICSSGroupRule*)aParentRule;
rule->SetParentRule(parentRule);
return PR_TRUE;
}
CSSMediaRuleImpl::CSSMediaRuleImpl(const CSSMediaRuleImpl& aCopy)
: nsCSSRule(aCopy),
mMedia(nsnull),
@ -761,6 +781,7 @@ CSSMediaRuleImpl::CSSMediaRuleImpl(const CSSMediaRuleImpl& aCopy)
NS_NewISupportsArray(getter_AddRefs(mRules));
if (mRules) {
aCopy.mRules->EnumerateForwards(CloneRuleInto, mRules);
mRules->EnumerateForwards(SetParentRuleReference, this);
}
}
}
@ -770,6 +791,9 @@ CSSMediaRuleImpl::~CSSMediaRuleImpl(void)
if (mMedia) {
mMedia->DropReference();
}
if (mRules) {
mRules->EnumerateForwards(SetParentRuleReference, nsnull);
}
if (mRuleCollection) {
mRuleCollection->DropReference();
NS_RELEASE(mRuleCollection);
@ -963,6 +987,7 @@ CSSMediaRuleImpl::AppendStyleRule(nsICSSRule* aRule)
if (NS_SUCCEEDED(result) && mRules) {
mRules->AppendElement(aRule);
aRule->SetStyleSheet(mSheet);
aRule->SetParentRule(this);
if (mSheet) {
mSheet->SetModified(PR_TRUE);
}
@ -1024,6 +1049,7 @@ CSSMediaRuleImpl::DeleteStyleRuleAt(PRUint32 aIndex)
nsCOMPtr<nsICSSRule> rule = dont_AddRef((nsICSSRule*)mRules->ElementAt(aIndex));
if (rule) {
rule->SetStyleSheet(nsnull);
rule->SetParentRule(nsnull);
}
return mRules->DeleteElementAt(aIndex);
}
@ -1034,6 +1060,7 @@ CSSMediaRuleImpl::InsertStyleRulesAt(PRUint32 aIndex, nsISupportsArray* aRules)
NS_ENSURE_TRUE(mRules, NS_ERROR_FAILURE);
aRules->EnumerateForwards(SetStyleSheetReference, mSheet);
aRules->EnumerateForwards(SetParentRuleReference, this);
// There is no xpcom-compatible version of InsertElementsAt.... :(
if (! mRules->InsertElementsAt(aRules, aIndex)) {
return NS_ERROR_FAILURE;
@ -1129,7 +1156,11 @@ CSSMediaRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSMediaRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
// nsIDOMCSSMediaRule methods
@ -1444,6 +1475,10 @@ CSSNameSpaceRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSNameSpaceRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}

View File

@ -24,6 +24,7 @@
#include "nsCOMPtr.h"
#include "nsCSSRule.h"
#include "nsICSSStyleRule.h"
#include "nsICSSGroupRule.h"
#include "nsICSSDeclaration.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSParser.h"
@ -1283,6 +1284,8 @@ public:
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
NS_IMETHOD GetType(PRInt32& aType) const;
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
@ -1580,6 +1583,12 @@ CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetParentRule(nsICSSGroupRule* aRule)
{
return nsCSSRule::SetParentRule(aRule);
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetType(PRInt32& aType) const
{
@ -2310,7 +2319,11 @@ CSSStyleRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
NS_IMETHODIMP

View File

@ -26,6 +26,7 @@
#include "nsIStyleRule.h"
class nsICSSStyleSheet;
class nsICSSGroupRule;
// IID for the nsICSSRule interface {b9791e20-1a04-11d3-805a-006008159b5a}
#define NS_ICSS_RULE_IID \
@ -49,6 +50,7 @@ public:
NS_IMETHOD GetType(PRInt32& aType) const = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule) = 0;
NS_IMETHOD Clone(nsICSSRule*& aClone) const = 0;
};

View File

@ -59,13 +59,15 @@ void nsCSSRule::operator delete(void* ptr)
}
nsCSSRule::nsCSSRule(void)
: mSheet(nsnull)
: mSheet(nsnull),
mParentRule(nsnull)
{
NS_INIT_REFCNT();
}
nsCSSRule::nsCSSRule(const nsCSSRule& aCopy)
: mSheet(aCopy.mSheet)
: mSheet(aCopy.mSheet),
mParentRule(aCopy.mParentRule)
{
NS_INIT_REFCNT();
}
@ -96,6 +98,16 @@ nsCSSRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
return NS_OK;
}
NS_IMETHODIMP
nsCSSRule::SetParentRule(nsICSSGroupRule* aRule)
{
// We don't reference count this up reference. The group rule
// will tell us when it's going away or when we're detached from
// it.
mParentRule = aRule;
return NS_OK;
}
NS_IMETHODIMP
nsCSSRule::GetStrength(PRInt32& aStrength) const
{

View File

@ -29,6 +29,7 @@ class nsIStyleSheet;
class nsICSSStyleSheet;
class nsIPresContext;
struct nsRuleData;
class nsICSSGroupRule;
class nsCSSRule {
public:
@ -46,6 +47,8 @@ public:
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
// nsIStyleRule methods
NS_IMETHOD GetStrength(PRInt32& aStrength) const;
@ -58,7 +61,7 @@ protected:
NS_DECL_OWNINGTHREAD // for thread-safety checking
nsICSSStyleSheet* mSheet;
nsICSSGroupRule* mParentRule;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif

View File

@ -57,17 +57,20 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
#define DECL_STYLE_RULE_INHERIT \
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
NS_IMETHOD GetStrength(PRInt32& aStrength) const; \
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
#define IMPL_STYLE_RULE_INHERIT(_class, super) \
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetStyleSheet(nsICSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetStrength(PRInt32& aStrength) const { return super::GetStrength(aStrength); } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
#define IMPL_STYLE_RULE_INHERIT2(_class, super) \
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetStrength(PRInt32& aStrength) const { return super::GetStrength(aStrength); } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
@ -354,7 +357,11 @@ CSSCharsetRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSCharsetRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
@ -642,7 +649,11 @@ CSSImportRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSImportRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
NS_IMETHODIMP
@ -747,6 +758,15 @@ CloneRuleInto(nsISupports* aRule, void* aArray)
return PR_TRUE;
}
PR_STATIC_CALLBACK(PRBool)
SetParentRuleReference(nsISupports* aRule, void* aParentRule)
{
nsICSSRule* rule = (nsICSSRule*)aRule;
nsICSSGroupRule* parentRule = (nsICSSGroupRule*)aParentRule;
rule->SetParentRule(parentRule);
return PR_TRUE;
}
CSSMediaRuleImpl::CSSMediaRuleImpl(const CSSMediaRuleImpl& aCopy)
: nsCSSRule(aCopy),
mMedia(nsnull),
@ -761,6 +781,7 @@ CSSMediaRuleImpl::CSSMediaRuleImpl(const CSSMediaRuleImpl& aCopy)
NS_NewISupportsArray(getter_AddRefs(mRules));
if (mRules) {
aCopy.mRules->EnumerateForwards(CloneRuleInto, mRules);
mRules->EnumerateForwards(SetParentRuleReference, this);
}
}
}
@ -770,6 +791,9 @@ CSSMediaRuleImpl::~CSSMediaRuleImpl(void)
if (mMedia) {
mMedia->DropReference();
}
if (mRules) {
mRules->EnumerateForwards(SetParentRuleReference, nsnull);
}
if (mRuleCollection) {
mRuleCollection->DropReference();
NS_RELEASE(mRuleCollection);
@ -963,6 +987,7 @@ CSSMediaRuleImpl::AppendStyleRule(nsICSSRule* aRule)
if (NS_SUCCEEDED(result) && mRules) {
mRules->AppendElement(aRule);
aRule->SetStyleSheet(mSheet);
aRule->SetParentRule(this);
if (mSheet) {
mSheet->SetModified(PR_TRUE);
}
@ -1024,6 +1049,7 @@ CSSMediaRuleImpl::DeleteStyleRuleAt(PRUint32 aIndex)
nsCOMPtr<nsICSSRule> rule = dont_AddRef((nsICSSRule*)mRules->ElementAt(aIndex));
if (rule) {
rule->SetStyleSheet(nsnull);
rule->SetParentRule(nsnull);
}
return mRules->DeleteElementAt(aIndex);
}
@ -1034,6 +1060,7 @@ CSSMediaRuleImpl::InsertStyleRulesAt(PRUint32 aIndex, nsISupportsArray* aRules)
NS_ENSURE_TRUE(mRules, NS_ERROR_FAILURE);
aRules->EnumerateForwards(SetStyleSheetReference, mSheet);
aRules->EnumerateForwards(SetParentRuleReference, this);
// There is no xpcom-compatible version of InsertElementsAt.... :(
if (! mRules->InsertElementsAt(aRules, aIndex)) {
return NS_ERROR_FAILURE;
@ -1129,7 +1156,11 @@ CSSMediaRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSMediaRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
// nsIDOMCSSMediaRule methods
@ -1444,6 +1475,10 @@ CSSNameSpaceRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSNameSpaceRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}

View File

@ -24,6 +24,7 @@
#include "nsCOMPtr.h"
#include "nsCSSRule.h"
#include "nsICSSStyleRule.h"
#include "nsICSSGroupRule.h"
#include "nsICSSDeclaration.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSParser.h"
@ -1283,6 +1284,8 @@ public:
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
NS_IMETHOD GetType(PRInt32& aType) const;
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
@ -1580,6 +1583,12 @@ CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetParentRule(nsICSSGroupRule* aRule)
{
return nsCSSRule::SetParentRule(aRule);
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetType(PRInt32& aType) const
{
@ -2310,7 +2319,11 @@ CSSStyleRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
NS_IMETHODIMP
CSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
if (mParentRule) {
return CallQueryInterface(mParentRule, aParentRule);
}
*aParentRule = nsnull;
return NS_OK;
}
NS_IMETHODIMP

View File

@ -26,6 +26,7 @@
#include "nsIStyleRule.h"
class nsICSSStyleSheet;
class nsICSSGroupRule;
// IID for the nsICSSRule interface {b9791e20-1a04-11d3-805a-006008159b5a}
#define NS_ICSS_RULE_IID \
@ -49,6 +50,7 @@ public:
NS_IMETHOD GetType(PRInt32& aType) const = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule) = 0;
NS_IMETHOD Clone(nsICSSRule*& aClone) const = 0;
};