зеркало из https://github.com/mozilla/pjs.git
added important rule support
factored declaration processing to a static method
This commit is contained in:
Родитель
52187d340b
Коммит
d1deab28e2
|
@ -135,6 +135,101 @@ void nsCSSSelector::Set(const nsString& aTag, const nsString& aID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- CSSImportantRule -------------------------------
|
||||||
|
|
||||||
|
static nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
|
||||||
|
class CSSImportantRule : public nsIStyleRule {
|
||||||
|
public:
|
||||||
|
CSSImportantRule(nsICSSDeclaration* aDeclaration);
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~CSSImportantRule(void);
|
||||||
|
|
||||||
|
nsICSSDeclaration* mDeclaration;
|
||||||
|
};
|
||||||
|
|
||||||
|
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
|
||||||
|
: mDeclaration(aDeclaration)
|
||||||
|
{
|
||||||
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSImportantRule::~CSSImportantRule(void)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(CSSImportantRule, kIStyleRuleIID);
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
|
||||||
|
{
|
||||||
|
aResult = PRBool(aRule == this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::HashValue(PRUint32& aValue) const
|
||||||
|
{
|
||||||
|
aValue = PRUint32(mDeclaration);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 1;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
||||||
|
{
|
||||||
|
// Indent
|
||||||
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||||
|
|
||||||
|
fputs("! Important rule ", out);
|
||||||
|
if (nsnull != mDeclaration) {
|
||||||
|
mDeclaration->List(out);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fputs("{ null declaration }", out);
|
||||||
|
}
|
||||||
|
fputs("\n", out);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- nsCSSStyleRule -------------------------------
|
// -- nsCSSStyleRule -------------------------------
|
||||||
|
|
||||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||||
|
@ -151,6 +246,8 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
virtual nsCSSSelector* FirstSelector(void);
|
virtual nsCSSSelector* FirstSelector(void);
|
||||||
virtual void AddSelector(const nsCSSSelector& aSelector);
|
virtual void AddSelector(const nsCSSSelector& aSelector);
|
||||||
|
@ -162,11 +259,7 @@ public:
|
||||||
virtual PRInt32 GetWeight(void) const;
|
virtual PRInt32 GetWeight(void) const;
|
||||||
virtual void SetWeight(PRInt32 aWeight);
|
virtual void SetWeight(PRInt32 aWeight);
|
||||||
|
|
||||||
virtual nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
virtual nsIStyleRule* GetImportantRule(void);
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
virtual PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
|
|
||||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
@ -184,9 +277,10 @@ protected:
|
||||||
PRUint32 mInHeap : 1;
|
PRUint32 mInHeap : 1;
|
||||||
PRUint32 mRefCnt : 31;
|
PRUint32 mRefCnt : 31;
|
||||||
|
|
||||||
nsCSSSelector mSelector;
|
nsCSSSelector mSelector;
|
||||||
nsICSSDeclaration* mDeclaration;
|
nsICSSDeclaration* mDeclaration;
|
||||||
PRInt32 mWeight;
|
PRInt32 mWeight;
|
||||||
|
CSSImportantRule* mImportantRule;
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
PRInt32 mInstance;
|
PRInt32 mInstance;
|
||||||
#endif
|
#endif
|
||||||
|
@ -234,7 +328,8 @@ static const PRInt32 kInstrument = 1075;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
||||||
: mSelector(aSelector), mDeclaration(nsnull), mWeight(0)
|
: mSelector(aSelector), mDeclaration(nsnull),
|
||||||
|
mWeight(0), mImportantRule(nsnull)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
|
@ -253,6 +348,7 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
||||||
delete selector;
|
delete selector;
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
--gInstanceCount;
|
--gInstanceCount;
|
||||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||||
|
@ -355,6 +451,14 @@ CSSStyleRuleImpl::HashValue(PRUint32& aValue) const
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSStyleRuleImpl::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
||||||
{
|
{
|
||||||
return &mSelector;
|
return &mSelector;
|
||||||
|
@ -406,6 +510,7 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
||||||
|
|
||||||
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
||||||
{
|
{
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
mDeclaration = aDeclaration;
|
mDeclaration = aDeclaration;
|
||||||
NS_IF_ADDREF(mDeclaration);
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
@ -421,9 +526,24 @@ void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
|
||||||
mWeight = aWeight;
|
mWeight = aWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
||||||
const nsStyleFont* aFont,
|
{
|
||||||
nsIPresContext* aPresContext)
|
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
|
||||||
|
nsICSSDeclaration* important;
|
||||||
|
mDeclaration->GetImportantValues(important);
|
||||||
|
if (nsnull != important) {
|
||||||
|
mImportantRule = new CSSImportantRule(important);
|
||||||
|
NS_ADDREF(mImportantRule);
|
||||||
|
NS_RELEASE(important);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_IF_ADDREF(mImportantRule);
|
||||||
|
return mImportantRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
nscoord CalcLength(const nsCSSValue& aValue,
|
||||||
|
const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
||||||
if (aValue.IsFixedLengthUnit()) {
|
if (aValue.IsFixedLengthUnit()) {
|
||||||
|
@ -467,9 +587,9 @@ nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
||||||
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
||||||
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
||||||
|
|
||||||
PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
nsIPresContext* aPresContext)
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
PRBool result = PR_TRUE;
|
PRBool result = PR_TRUE;
|
||||||
if (aValue.GetUnit() == eCSSUnit_Null) {
|
if (aValue.GetUnit() == eCSSUnit_Null) {
|
||||||
|
@ -516,11 +636,18 @@ PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
if (nsnull != mDeclaration) {
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
if (nsnull != aDeclaration) {
|
||||||
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
||||||
|
|
||||||
nsCSSFont* ourFont;
|
nsCSSFont* ourFont;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
||||||
if (nsnull != ourFont) {
|
if (nsnull != ourFont) {
|
||||||
const nsStyleFont* parentFont = font;
|
const nsStyleFont* parentFont = font;
|
||||||
nsIStyleContext* parentContext = aContext->GetParent();
|
nsIStyleContext* parentContext = aContext->GetParent();
|
||||||
|
@ -629,7 +756,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSText* ourText;
|
nsCSSText* ourText;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
if (NS_OK == aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
||||||
if (nsnull != ourText) {
|
if (nsnull != ourText) {
|
||||||
// Get our text style and our parent's text style
|
// Get our text style and our parent's text style
|
||||||
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
||||||
|
@ -679,7 +806,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSDisplay* ourDisplay;
|
nsCSSDisplay* ourDisplay;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
if (NS_OK == aDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
||||||
if (nsnull != ourDisplay) {
|
if (nsnull != ourDisplay) {
|
||||||
// Get our style and our parent's style
|
// Get our style and our parent's style
|
||||||
nsStyleDisplay* display = (nsStyleDisplay*)
|
nsStyleDisplay* display = (nsStyleDisplay*)
|
||||||
|
@ -778,7 +905,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
|
|
||||||
|
|
||||||
nsCSSColor* ourColor;
|
nsCSSColor* ourColor;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
if (NS_OK == aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
||||||
if (nsnull != ourColor) {
|
if (nsnull != ourColor) {
|
||||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||||
|
|
||||||
|
@ -879,7 +1006,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSMargin* ourMargin;
|
nsCSSMargin* ourMargin;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
if (NS_OK == aDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
||||||
if (nsnull != ourMargin) {
|
if (nsnull != ourMargin) {
|
||||||
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
||||||
|
@ -972,7 +1099,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSPosition* ourPosition;
|
nsCSSPosition* ourPosition;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
if (NS_OK == aDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
||||||
if (nsnull != ourPosition) {
|
if (nsnull != ourPosition) {
|
||||||
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
||||||
|
|
||||||
|
@ -1004,7 +1131,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSList* ourList;
|
nsCSSList* ourList;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
if (NS_OK == aDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
||||||
if (nsnull != ourList) {
|
if (nsnull != ourList) {
|
||||||
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
||||||
|
|
||||||
|
@ -1029,7 +1156,6 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,101 @@ void nsCSSSelector::Set(const nsString& aTag, const nsString& aID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- CSSImportantRule -------------------------------
|
||||||
|
|
||||||
|
static nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
|
||||||
|
class CSSImportantRule : public nsIStyleRule {
|
||||||
|
public:
|
||||||
|
CSSImportantRule(nsICSSDeclaration* aDeclaration);
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~CSSImportantRule(void);
|
||||||
|
|
||||||
|
nsICSSDeclaration* mDeclaration;
|
||||||
|
};
|
||||||
|
|
||||||
|
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
|
||||||
|
: mDeclaration(aDeclaration)
|
||||||
|
{
|
||||||
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSImportantRule::~CSSImportantRule(void)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(CSSImportantRule, kIStyleRuleIID);
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
|
||||||
|
{
|
||||||
|
aResult = PRBool(aRule == this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::HashValue(PRUint32& aValue) const
|
||||||
|
{
|
||||||
|
aValue = PRUint32(mDeclaration);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 1;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
||||||
|
{
|
||||||
|
// Indent
|
||||||
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||||
|
|
||||||
|
fputs("! Important rule ", out);
|
||||||
|
if (nsnull != mDeclaration) {
|
||||||
|
mDeclaration->List(out);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fputs("{ null declaration }", out);
|
||||||
|
}
|
||||||
|
fputs("\n", out);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- nsCSSStyleRule -------------------------------
|
// -- nsCSSStyleRule -------------------------------
|
||||||
|
|
||||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||||
|
@ -151,6 +246,8 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
virtual nsCSSSelector* FirstSelector(void);
|
virtual nsCSSSelector* FirstSelector(void);
|
||||||
virtual void AddSelector(const nsCSSSelector& aSelector);
|
virtual void AddSelector(const nsCSSSelector& aSelector);
|
||||||
|
@ -162,11 +259,7 @@ public:
|
||||||
virtual PRInt32 GetWeight(void) const;
|
virtual PRInt32 GetWeight(void) const;
|
||||||
virtual void SetWeight(PRInt32 aWeight);
|
virtual void SetWeight(PRInt32 aWeight);
|
||||||
|
|
||||||
virtual nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
virtual nsIStyleRule* GetImportantRule(void);
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
virtual PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
|
|
||||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
@ -184,9 +277,10 @@ protected:
|
||||||
PRUint32 mInHeap : 1;
|
PRUint32 mInHeap : 1;
|
||||||
PRUint32 mRefCnt : 31;
|
PRUint32 mRefCnt : 31;
|
||||||
|
|
||||||
nsCSSSelector mSelector;
|
nsCSSSelector mSelector;
|
||||||
nsICSSDeclaration* mDeclaration;
|
nsICSSDeclaration* mDeclaration;
|
||||||
PRInt32 mWeight;
|
PRInt32 mWeight;
|
||||||
|
CSSImportantRule* mImportantRule;
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
PRInt32 mInstance;
|
PRInt32 mInstance;
|
||||||
#endif
|
#endif
|
||||||
|
@ -234,7 +328,8 @@ static const PRInt32 kInstrument = 1075;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
||||||
: mSelector(aSelector), mDeclaration(nsnull), mWeight(0)
|
: mSelector(aSelector), mDeclaration(nsnull),
|
||||||
|
mWeight(0), mImportantRule(nsnull)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
|
@ -253,6 +348,7 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
||||||
delete selector;
|
delete selector;
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
--gInstanceCount;
|
--gInstanceCount;
|
||||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||||
|
@ -355,6 +451,14 @@ CSSStyleRuleImpl::HashValue(PRUint32& aValue) const
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSStyleRuleImpl::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
||||||
{
|
{
|
||||||
return &mSelector;
|
return &mSelector;
|
||||||
|
@ -406,6 +510,7 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
||||||
|
|
||||||
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
||||||
{
|
{
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
mDeclaration = aDeclaration;
|
mDeclaration = aDeclaration;
|
||||||
NS_IF_ADDREF(mDeclaration);
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
@ -421,9 +526,24 @@ void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
|
||||||
mWeight = aWeight;
|
mWeight = aWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
||||||
const nsStyleFont* aFont,
|
{
|
||||||
nsIPresContext* aPresContext)
|
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
|
||||||
|
nsICSSDeclaration* important;
|
||||||
|
mDeclaration->GetImportantValues(important);
|
||||||
|
if (nsnull != important) {
|
||||||
|
mImportantRule = new CSSImportantRule(important);
|
||||||
|
NS_ADDREF(mImportantRule);
|
||||||
|
NS_RELEASE(important);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_IF_ADDREF(mImportantRule);
|
||||||
|
return mImportantRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
nscoord CalcLength(const nsCSSValue& aValue,
|
||||||
|
const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
||||||
if (aValue.IsFixedLengthUnit()) {
|
if (aValue.IsFixedLengthUnit()) {
|
||||||
|
@ -467,9 +587,9 @@ nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
||||||
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
||||||
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
||||||
|
|
||||||
PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
nsIPresContext* aPresContext)
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
PRBool result = PR_TRUE;
|
PRBool result = PR_TRUE;
|
||||||
if (aValue.GetUnit() == eCSSUnit_Null) {
|
if (aValue.GetUnit() == eCSSUnit_Null) {
|
||||||
|
@ -516,11 +636,18 @@ PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
if (nsnull != mDeclaration) {
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
if (nsnull != aDeclaration) {
|
||||||
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
||||||
|
|
||||||
nsCSSFont* ourFont;
|
nsCSSFont* ourFont;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
||||||
if (nsnull != ourFont) {
|
if (nsnull != ourFont) {
|
||||||
const nsStyleFont* parentFont = font;
|
const nsStyleFont* parentFont = font;
|
||||||
nsIStyleContext* parentContext = aContext->GetParent();
|
nsIStyleContext* parentContext = aContext->GetParent();
|
||||||
|
@ -629,7 +756,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSText* ourText;
|
nsCSSText* ourText;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
if (NS_OK == aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
||||||
if (nsnull != ourText) {
|
if (nsnull != ourText) {
|
||||||
// Get our text style and our parent's text style
|
// Get our text style and our parent's text style
|
||||||
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
||||||
|
@ -679,7 +806,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSDisplay* ourDisplay;
|
nsCSSDisplay* ourDisplay;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
if (NS_OK == aDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
||||||
if (nsnull != ourDisplay) {
|
if (nsnull != ourDisplay) {
|
||||||
// Get our style and our parent's style
|
// Get our style and our parent's style
|
||||||
nsStyleDisplay* display = (nsStyleDisplay*)
|
nsStyleDisplay* display = (nsStyleDisplay*)
|
||||||
|
@ -778,7 +905,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
|
|
||||||
|
|
||||||
nsCSSColor* ourColor;
|
nsCSSColor* ourColor;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
if (NS_OK == aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
||||||
if (nsnull != ourColor) {
|
if (nsnull != ourColor) {
|
||||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||||
|
|
||||||
|
@ -879,7 +1006,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSMargin* ourMargin;
|
nsCSSMargin* ourMargin;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
if (NS_OK == aDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
||||||
if (nsnull != ourMargin) {
|
if (nsnull != ourMargin) {
|
||||||
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
||||||
|
@ -972,7 +1099,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSPosition* ourPosition;
|
nsCSSPosition* ourPosition;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
if (NS_OK == aDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
||||||
if (nsnull != ourPosition) {
|
if (nsnull != ourPosition) {
|
||||||
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
||||||
|
|
||||||
|
@ -1004,7 +1131,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSList* ourList;
|
nsCSSList* ourList;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
if (NS_OK == aDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
||||||
if (nsnull != ourList) {
|
if (nsnull != ourList) {
|
||||||
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
||||||
|
|
||||||
|
@ -1029,7 +1156,6 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,101 @@ void nsCSSSelector::Set(const nsString& aTag, const nsString& aID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- CSSImportantRule -------------------------------
|
||||||
|
|
||||||
|
static nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
|
||||||
|
class CSSImportantRule : public nsIStyleRule {
|
||||||
|
public:
|
||||||
|
CSSImportantRule(nsICSSDeclaration* aDeclaration);
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~CSSImportantRule(void);
|
||||||
|
|
||||||
|
nsICSSDeclaration* mDeclaration;
|
||||||
|
};
|
||||||
|
|
||||||
|
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
|
||||||
|
: mDeclaration(aDeclaration)
|
||||||
|
{
|
||||||
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSImportantRule::~CSSImportantRule(void)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(CSSImportantRule, kIStyleRuleIID);
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
|
||||||
|
{
|
||||||
|
aResult = PRBool(aRule == this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::HashValue(PRUint32& aValue) const
|
||||||
|
{
|
||||||
|
aValue = PRUint32(mDeclaration);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 1;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
||||||
|
{
|
||||||
|
// Indent
|
||||||
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||||
|
|
||||||
|
fputs("! Important rule ", out);
|
||||||
|
if (nsnull != mDeclaration) {
|
||||||
|
mDeclaration->List(out);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fputs("{ null declaration }", out);
|
||||||
|
}
|
||||||
|
fputs("\n", out);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- nsCSSStyleRule -------------------------------
|
// -- nsCSSStyleRule -------------------------------
|
||||||
|
|
||||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||||
|
@ -151,6 +246,8 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
|
||||||
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
||||||
|
|
||||||
virtual nsCSSSelector* FirstSelector(void);
|
virtual nsCSSSelector* FirstSelector(void);
|
||||||
virtual void AddSelector(const nsCSSSelector& aSelector);
|
virtual void AddSelector(const nsCSSSelector& aSelector);
|
||||||
|
@ -162,11 +259,7 @@ public:
|
||||||
virtual PRInt32 GetWeight(void) const;
|
virtual PRInt32 GetWeight(void) const;
|
||||||
virtual void SetWeight(PRInt32 aWeight);
|
virtual void SetWeight(PRInt32 aWeight);
|
||||||
|
|
||||||
virtual nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
|
virtual nsIStyleRule* GetImportantRule(void);
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
virtual PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
|
||||||
nsIPresContext* aPresContext);
|
|
||||||
|
|
||||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||||
|
|
||||||
|
@ -184,9 +277,10 @@ protected:
|
||||||
PRUint32 mInHeap : 1;
|
PRUint32 mInHeap : 1;
|
||||||
PRUint32 mRefCnt : 31;
|
PRUint32 mRefCnt : 31;
|
||||||
|
|
||||||
nsCSSSelector mSelector;
|
nsCSSSelector mSelector;
|
||||||
nsICSSDeclaration* mDeclaration;
|
nsICSSDeclaration* mDeclaration;
|
||||||
PRInt32 mWeight;
|
PRInt32 mWeight;
|
||||||
|
CSSImportantRule* mImportantRule;
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
PRInt32 mInstance;
|
PRInt32 mInstance;
|
||||||
#endif
|
#endif
|
||||||
|
@ -234,7 +328,8 @@ static const PRInt32 kInstrument = 1075;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
||||||
: mSelector(aSelector), mDeclaration(nsnull), mWeight(0)
|
: mSelector(aSelector), mDeclaration(nsnull),
|
||||||
|
mWeight(0), mImportantRule(nsnull)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
|
@ -253,6 +348,7 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
||||||
delete selector;
|
delete selector;
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
#ifdef DEBUG_REFS
|
#ifdef DEBUG_REFS
|
||||||
--gInstanceCount;
|
--gInstanceCount;
|
||||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||||
|
@ -355,6 +451,14 @@ CSSStyleRuleImpl::HashValue(PRUint32& aValue) const
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strength is an out-of-band weighting, useful for mapping CSS ! important
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CSSStyleRuleImpl::GetStrength(PRInt32& aStrength)
|
||||||
|
{
|
||||||
|
aStrength = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
||||||
{
|
{
|
||||||
return &mSelector;
|
return &mSelector;
|
||||||
|
@ -406,6 +510,7 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
||||||
|
|
||||||
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
||||||
{
|
{
|
||||||
|
NS_IF_RELEASE(mImportantRule);
|
||||||
NS_IF_RELEASE(mDeclaration);
|
NS_IF_RELEASE(mDeclaration);
|
||||||
mDeclaration = aDeclaration;
|
mDeclaration = aDeclaration;
|
||||||
NS_IF_ADDREF(mDeclaration);
|
NS_IF_ADDREF(mDeclaration);
|
||||||
|
@ -421,9 +526,24 @@ void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
|
||||||
mWeight = aWeight;
|
mWeight = aWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
||||||
const nsStyleFont* aFont,
|
{
|
||||||
nsIPresContext* aPresContext)
|
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
|
||||||
|
nsICSSDeclaration* important;
|
||||||
|
mDeclaration->GetImportantValues(important);
|
||||||
|
if (nsnull != important) {
|
||||||
|
mImportantRule = new CSSImportantRule(important);
|
||||||
|
NS_ADDREF(mImportantRule);
|
||||||
|
NS_RELEASE(important);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_IF_ADDREF(mImportantRule);
|
||||||
|
return mImportantRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
nscoord CalcLength(const nsCSSValue& aValue,
|
||||||
|
const nsStyleFont* aFont,
|
||||||
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
||||||
if (aValue.IsFixedLengthUnit()) {
|
if (aValue.IsFixedLengthUnit()) {
|
||||||
|
@ -467,9 +587,9 @@ nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue,
|
||||||
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
|
||||||
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
|
||||||
|
|
||||||
PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||||
PRInt32 aMask, const nsStyleFont* aFont,
|
PRInt32 aMask, const nsStyleFont* aFont,
|
||||||
nsIPresContext* aPresContext)
|
nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
PRBool result = PR_TRUE;
|
PRBool result = PR_TRUE;
|
||||||
if (aValue.GetUnit() == eCSSUnit_Null) {
|
if (aValue.GetUnit() == eCSSUnit_Null) {
|
||||||
|
@ -516,11 +636,18 @@ PRBool CSSStyleRuleImpl::SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
{
|
{
|
||||||
if (nsnull != mDeclaration) {
|
MapDeclarationInto(mDeclaration, aContext, aPresContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
|
||||||
|
nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||||
|
{
|
||||||
|
if (nsnull != aDeclaration) {
|
||||||
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
|
||||||
|
|
||||||
nsCSSFont* ourFont;
|
nsCSSFont* ourFont;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
||||||
if (nsnull != ourFont) {
|
if (nsnull != ourFont) {
|
||||||
const nsStyleFont* parentFont = font;
|
const nsStyleFont* parentFont = font;
|
||||||
nsIStyleContext* parentContext = aContext->GetParent();
|
nsIStyleContext* parentContext = aContext->GetParent();
|
||||||
|
@ -629,7 +756,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSText* ourText;
|
nsCSSText* ourText;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
if (NS_OK == aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
||||||
if (nsnull != ourText) {
|
if (nsnull != ourText) {
|
||||||
// Get our text style and our parent's text style
|
// Get our text style and our parent's text style
|
||||||
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
|
||||||
|
@ -679,7 +806,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSDisplay* ourDisplay;
|
nsCSSDisplay* ourDisplay;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
if (NS_OK == aDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
|
||||||
if (nsnull != ourDisplay) {
|
if (nsnull != ourDisplay) {
|
||||||
// Get our style and our parent's style
|
// Get our style and our parent's style
|
||||||
nsStyleDisplay* display = (nsStyleDisplay*)
|
nsStyleDisplay* display = (nsStyleDisplay*)
|
||||||
|
@ -778,7 +905,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
|
|
||||||
|
|
||||||
nsCSSColor* ourColor;
|
nsCSSColor* ourColor;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
if (NS_OK == aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
||||||
if (nsnull != ourColor) {
|
if (nsnull != ourColor) {
|
||||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||||
|
|
||||||
|
@ -879,7 +1006,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSMargin* ourMargin;
|
nsCSSMargin* ourMargin;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
if (NS_OK == aDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
|
||||||
if (nsnull != ourMargin) {
|
if (nsnull != ourMargin) {
|
||||||
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
||||||
|
@ -972,7 +1099,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSPosition* ourPosition;
|
nsCSSPosition* ourPosition;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
if (NS_OK == aDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
|
||||||
if (nsnull != ourPosition) {
|
if (nsnull != ourPosition) {
|
||||||
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
|
||||||
|
|
||||||
|
@ -1004,7 +1131,7 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCSSList* ourList;
|
nsCSSList* ourList;
|
||||||
if (NS_OK == mDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
if (NS_OK == aDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
||||||
if (nsnull != ourList) {
|
if (nsnull != ourList) {
|
||||||
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
|
||||||
|
|
||||||
|
@ -1029,7 +1156,6 @@ CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче