Added a HTMLDocumentColor special-case rule for the HTML element. This is set when either the bgColor or fgColor is set on a HTML document.

This commit is contained in:
vidur%netscape.com 1999-07-07 04:53:36 +00:00
Родитель 8aa9c1594f
Коммит 97f3a5f03b
4 изменённых файлов: 505 добавлений и 60 удалений

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

@ -53,10 +53,10 @@ static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
class HTMLAnchorRule : public nsIStyleRule {
class HTMLColorRule : public nsIStyleRule {
public:
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLAnchorRule();
HTMLColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLColorRule();
NS_DECL_ISUPPORTS
@ -75,34 +75,46 @@ public:
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
class HTMLDocumentColorRule : public HTMLColorRule {
public:
HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLDocumentColorRule();
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
nscolor mBackgroundColor;
PRBool mForegroundSet;
PRBool mBackgroundSet;
};
HTMLColorRule::HTMLColorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
HTMLAnchorRule::~HTMLAnchorRule()
HTMLColorRule::~HTMLColorRule()
{
}
NS_IMPL_ISUPPORTS(HTMLAnchorRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(HTMLColorRule, kIStyleRuleIID);
NS_IMETHODIMP
HTMLAnchorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
HTMLColorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::HashValue(PRUint32& aValue) const
HTMLColorRule::HashValue(PRUint32& aValue) const
{
aValue = (PRUint32)(mColor);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
HTMLColorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
@ -111,20 +123,20 @@ HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength) const
HTMLColorRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
@ -135,11 +147,39 @@ HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresCon
}
NS_IMETHODIMP
HTMLAnchorRule::List(FILE* out, PRInt32 aIndent) const
HTMLColorRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
HTMLDocumentColorRule::HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet)
: HTMLColorRule(aSheet)
{
mForegroundSet = PR_FALSE;
mBackgroundSet = PR_FALSE;
}
HTMLDocumentColorRule::~HTMLDocumentColorRule()
{
}
NS_IMETHODIMP
HTMLDocumentColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
if (nsnull != styleColor) {
if (mForegroundSet) {
styleColor->mColor = mColor;
}
if (mBackgroundSet) {
styleColor->mBackgroundColor = mBackgroundColor;
styleColor->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
}
}
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
@ -361,9 +401,16 @@ public:
// nsIHTMLStyleSheet api
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
NS_IMETHOD Reset(nsIURI* aURL);
NS_IMETHOD GetLinkColor(nscolor& aColor);
NS_IMETHOD GetActiveLinkColor(nscolor& aColor);
NS_IMETHOD GetVisitedLinkColor(nscolor& aColor);
NS_IMETHOD GetDocumentForegroundColor(nscolor& aColor);
NS_IMETHOD GetDocumentBackgroundColor(nscolor& aColor);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
NS_IMETHOD SetDocumentForegroundColor(nscolor aColor);
NS_IMETHOD SetDocumentBackgroundColor(nscolor aColor);
// Attribute management methods, aAttributes is an in/out param
NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent,
@ -400,9 +447,10 @@ protected:
nsIURI* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
HTMLColorRule* mLinkRule;
HTMLColorRule* mVisitedRule;
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
nsHashtable mMappedAttrTable;
};
@ -450,7 +498,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
mDocument(nsnull),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull)
mActiveRule(nsnull),
mDocumentColorRule(nsnull)
{
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
@ -479,6 +528,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
if (nsnull != mDocumentColorRule) {
mDocumentColorRule->mSheet = nsnull;
NS_RELEASE(mDocumentColorRule);
}
if (nsnull != mTableBackgroundRule) {
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
@ -652,6 +705,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
matchCount++;
}
}
else if (tag == nsHTMLAtoms::html) {
if (mDocumentColorRule) {
aResults->AppendElement(mDocumentColorRule);
matchCount++;
}
}
NS_IF_RELEASE(tag);
} // end html namespace
@ -831,10 +890,67 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetLinkColor(nscolor& aColor)
{
if (nsnull == mLinkRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mLinkRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetActiveLinkColor(nscolor& aColor)
{
if (nsnull == mActiveRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mActiveRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetVisitedLinkColor(nscolor& aColor)
{
if (nsnull == mVisitedRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mVisitedRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentForegroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mForegroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentBackgroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mBackgroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mBackgroundColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule(this);
mLinkRule = new HTMLColorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -844,10 +960,11 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule(this);
mActiveRule = new HTMLColorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -860,7 +977,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule(this);
mVisitedRule = new HTMLColorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -870,6 +987,34 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentForegroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mColor = aColor;
mDocumentColorRule->mForegroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentBackgroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mBackgroundColor = aColor;
mDocumentColorRule->mBackgroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
{
if (aAttributes) {

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

@ -53,10 +53,10 @@ static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
class HTMLAnchorRule : public nsIStyleRule {
class HTMLColorRule : public nsIStyleRule {
public:
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLAnchorRule();
HTMLColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLColorRule();
NS_DECL_ISUPPORTS
@ -75,34 +75,46 @@ public:
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
class HTMLDocumentColorRule : public HTMLColorRule {
public:
HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLDocumentColorRule();
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
nscolor mBackgroundColor;
PRBool mForegroundSet;
PRBool mBackgroundSet;
};
HTMLColorRule::HTMLColorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
HTMLAnchorRule::~HTMLAnchorRule()
HTMLColorRule::~HTMLColorRule()
{
}
NS_IMPL_ISUPPORTS(HTMLAnchorRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(HTMLColorRule, kIStyleRuleIID);
NS_IMETHODIMP
HTMLAnchorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
HTMLColorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::HashValue(PRUint32& aValue) const
HTMLColorRule::HashValue(PRUint32& aValue) const
{
aValue = (PRUint32)(mColor);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
HTMLColorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
@ -111,20 +123,20 @@ HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength) const
HTMLColorRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
@ -135,11 +147,39 @@ HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresCon
}
NS_IMETHODIMP
HTMLAnchorRule::List(FILE* out, PRInt32 aIndent) const
HTMLColorRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
HTMLDocumentColorRule::HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet)
: HTMLColorRule(aSheet)
{
mForegroundSet = PR_FALSE;
mBackgroundSet = PR_FALSE;
}
HTMLDocumentColorRule::~HTMLDocumentColorRule()
{
}
NS_IMETHODIMP
HTMLDocumentColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
if (nsnull != styleColor) {
if (mForegroundSet) {
styleColor->mColor = mColor;
}
if (mBackgroundSet) {
styleColor->mBackgroundColor = mBackgroundColor;
styleColor->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
}
}
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
@ -361,9 +401,16 @@ public:
// nsIHTMLStyleSheet api
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
NS_IMETHOD Reset(nsIURI* aURL);
NS_IMETHOD GetLinkColor(nscolor& aColor);
NS_IMETHOD GetActiveLinkColor(nscolor& aColor);
NS_IMETHOD GetVisitedLinkColor(nscolor& aColor);
NS_IMETHOD GetDocumentForegroundColor(nscolor& aColor);
NS_IMETHOD GetDocumentBackgroundColor(nscolor& aColor);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
NS_IMETHOD SetDocumentForegroundColor(nscolor aColor);
NS_IMETHOD SetDocumentBackgroundColor(nscolor aColor);
// Attribute management methods, aAttributes is an in/out param
NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent,
@ -400,9 +447,10 @@ protected:
nsIURI* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
HTMLColorRule* mLinkRule;
HTMLColorRule* mVisitedRule;
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
nsHashtable mMappedAttrTable;
};
@ -450,7 +498,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
mDocument(nsnull),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull)
mActiveRule(nsnull),
mDocumentColorRule(nsnull)
{
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
@ -479,6 +528,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
if (nsnull != mDocumentColorRule) {
mDocumentColorRule->mSheet = nsnull;
NS_RELEASE(mDocumentColorRule);
}
if (nsnull != mTableBackgroundRule) {
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
@ -652,6 +705,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
matchCount++;
}
}
else if (tag == nsHTMLAtoms::html) {
if (mDocumentColorRule) {
aResults->AppendElement(mDocumentColorRule);
matchCount++;
}
}
NS_IF_RELEASE(tag);
} // end html namespace
@ -831,10 +890,67 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetLinkColor(nscolor& aColor)
{
if (nsnull == mLinkRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mLinkRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetActiveLinkColor(nscolor& aColor)
{
if (nsnull == mActiveRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mActiveRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetVisitedLinkColor(nscolor& aColor)
{
if (nsnull == mVisitedRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mVisitedRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentForegroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mForegroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentBackgroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mBackgroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mBackgroundColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule(this);
mLinkRule = new HTMLColorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -844,10 +960,11 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule(this);
mActiveRule = new HTMLColorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -860,7 +977,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule(this);
mVisitedRule = new HTMLColorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -870,6 +987,34 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentForegroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mColor = aColor;
mDocumentColorRule->mForegroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentBackgroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mBackgroundColor = aColor;
mDocumentColorRule->mBackgroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
{
if (aAttributes) {

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

@ -38,9 +38,16 @@ class nsIHTMLStyleSheet : public nsIStyleSheet {
public:
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument) = 0;
NS_IMETHOD Reset(nsIURI* aURL) = 0;
NS_IMETHOD GetLinkColor(nscolor& aColor) = 0;
NS_IMETHOD SetLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetActiveLinkColor(nscolor& aColor) = 0;
NS_IMETHOD SetActiveLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetVisitedLinkColor(nscolor& aColor) = 0;
NS_IMETHOD SetVisitedLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetDocumentForegroundColor(nscolor& aColor) = 0;
NS_IMETHOD SetDocumentForegroundColor(nscolor aColor) = 0;
NS_IMETHOD GetDocumentBackgroundColor(nscolor& aColor) = 0;
NS_IMETHOD SetDocumentBackgroundColor(nscolor aColor) = 0;
// Attribute management methods
NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent,
@ -71,4 +78,7 @@ extern NS_HTML nsresult
extern NS_HTML nsresult
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult);
#define NS_HTML_STYLE_PROPERTY_NOT_THERE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT,2)
#endif /* nsIHTMLStyleSheet_h___ */

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

@ -53,10 +53,10 @@ static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
class HTMLAnchorRule : public nsIStyleRule {
class HTMLColorRule : public nsIStyleRule {
public:
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLAnchorRule();
HTMLColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLColorRule();
NS_DECL_ISUPPORTS
@ -75,34 +75,46 @@ public:
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
class HTMLDocumentColorRule : public HTMLColorRule {
public:
HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet);
virtual ~HTMLDocumentColorRule();
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
nscolor mBackgroundColor;
PRBool mForegroundSet;
PRBool mBackgroundSet;
};
HTMLColorRule::HTMLColorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
HTMLAnchorRule::~HTMLAnchorRule()
HTMLColorRule::~HTMLColorRule()
{
}
NS_IMPL_ISUPPORTS(HTMLAnchorRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(HTMLColorRule, kIStyleRuleIID);
NS_IMETHODIMP
HTMLAnchorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
HTMLColorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::HashValue(PRUint32& aValue) const
HTMLColorRule::HashValue(PRUint32& aValue) const
{
aValue = (PRUint32)(mColor);
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
HTMLColorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
@ -111,20 +123,20 @@ HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength) const
HTMLColorRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapFontStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
HTMLColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
@ -135,11 +147,39 @@ HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresCon
}
NS_IMETHODIMP
HTMLAnchorRule::List(FILE* out, PRInt32 aIndent) const
HTMLColorRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
HTMLDocumentColorRule::HTMLDocumentColorRule(nsIHTMLStyleSheet* aSheet)
: HTMLColorRule(aSheet)
{
mForegroundSet = PR_FALSE;
mBackgroundSet = PR_FALSE;
}
HTMLDocumentColorRule::~HTMLDocumentColorRule()
{
}
NS_IMETHODIMP
HTMLDocumentColorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
if (nsnull != styleColor) {
if (mForegroundSet) {
styleColor->mColor = mColor;
}
if (mBackgroundSet) {
styleColor->mBackgroundColor = mBackgroundColor;
styleColor->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
}
}
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
@ -361,9 +401,16 @@ public:
// nsIHTMLStyleSheet api
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
NS_IMETHOD Reset(nsIURI* aURL);
NS_IMETHOD GetLinkColor(nscolor& aColor);
NS_IMETHOD GetActiveLinkColor(nscolor& aColor);
NS_IMETHOD GetVisitedLinkColor(nscolor& aColor);
NS_IMETHOD GetDocumentForegroundColor(nscolor& aColor);
NS_IMETHOD GetDocumentBackgroundColor(nscolor& aColor);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
NS_IMETHOD SetDocumentForegroundColor(nscolor aColor);
NS_IMETHOD SetDocumentBackgroundColor(nscolor aColor);
// Attribute management methods, aAttributes is an in/out param
NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent,
@ -400,9 +447,10 @@ protected:
nsIURI* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
HTMLColorRule* mLinkRule;
HTMLColorRule* mVisitedRule;
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
nsHashtable mMappedAttrTable;
};
@ -450,7 +498,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
mDocument(nsnull),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull)
mActiveRule(nsnull),
mDocumentColorRule(nsnull)
{
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
@ -479,6 +528,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
if (nsnull != mDocumentColorRule) {
mDocumentColorRule->mSheet = nsnull;
NS_RELEASE(mDocumentColorRule);
}
if (nsnull != mTableBackgroundRule) {
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
@ -652,6 +705,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
matchCount++;
}
}
else if (tag == nsHTMLAtoms::html) {
if (mDocumentColorRule) {
aResults->AppendElement(mDocumentColorRule);
matchCount++;
}
}
NS_IF_RELEASE(tag);
} // end html namespace
@ -831,10 +890,67 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetLinkColor(nscolor& aColor)
{
if (nsnull == mLinkRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mLinkRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetActiveLinkColor(nscolor& aColor)
{
if (nsnull == mActiveRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mActiveRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetVisitedLinkColor(nscolor& aColor)
{
if (nsnull == mVisitedRule) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mVisitedRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentForegroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mForegroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::GetDocumentBackgroundColor(nscolor& aColor)
{
if ((nsnull == mDocumentColorRule) ||
!mDocumentColorRule->mBackgroundSet) {
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
}
else {
aColor = mDocumentColorRule->mBackgroundColor;
return NS_OK;
}
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule(this);
mLinkRule = new HTMLColorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -844,10 +960,11 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule(this);
mActiveRule = new HTMLColorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -860,7 +977,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule(this);
mVisitedRule = new HTMLColorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -870,6 +987,34 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentForegroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mColor = aColor;
mDocumentColorRule->mForegroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetDocumentBackgroundColor(nscolor aColor)
{
if (nsnull == mDocumentColorRule) {
mDocumentColorRule = new HTMLDocumentColorRule(this);
if (nsnull == mDocumentColorRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDocumentColorRule);
}
mDocumentColorRule->mBackgroundColor = aColor;
mDocumentColorRule->mBackgroundSet = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
{
if (aAttributes) {