Checked in for fantasai@escape.com. Bug 43220 "author !important rules override user !important rules in user.css". Add User sheets. Rename Backstop sheets into UserAgent. Fix cascading order. r=pierre/sr=hyatt.

This commit is contained in:
pierre@netscape.com
2001-11-06 10:04:05 +00:00
parent 70eb12ef79
commit 027a59a148
13 changed files with 804 additions and 416 deletions

View File

@@ -98,7 +98,7 @@ interface nsIChromeRegistry : nsISupports
void installPackage(in string baseURL, in boolean useProfile); void installPackage(in string baseURL, in boolean useProfile);
void uninstallPackage(in wstring packageName, in boolean useProfile); void uninstallPackage(in wstring packageName, in boolean useProfile);
void getBackstopSheets(in nsIDocShell docShell, out nsISupportsArray styleSheets); void getAgentSheets(in nsIDocShell docShell, out nsISupportsArray styleSheets);
void getUserSheets(in boolean useChromeSheets, out nsISupportsArray styleSheets); void getUserSheets(in boolean useChromeSheets, out nsISupportsArray styleSheets);
boolean allowScriptsForSkin(in nsIURI url); boolean allowScriptsForSkin(in nsIURI url);

View File

@@ -1194,7 +1194,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument); nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument);
if (xulDoc) { if (xulDoc) {
// Deal with the backstop sheets first. // Deal with the agent sheets first.
PRInt32 shellCount = document->GetNumberOfShells(); PRInt32 shellCount = document->GetNumberOfShells();
for (PRInt32 k = 0; k < shellCount; k++) { for (PRInt32 k = 0; k < shellCount; k++) {
nsCOMPtr<nsIPresShell> shell; nsCOMPtr<nsIPresShell> shell;
@@ -1204,18 +1204,18 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
rv = shell->GetStyleSet(getter_AddRefs(styleSet)); rv = shell->GetStyleSet(getter_AddRefs(styleSet));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (styleSet) { if (styleSet) {
// Reload only the chrome URL backstop style sheets. // Reload only the chrome URL agent style sheets.
nsCOMPtr<nsISupportsArray> backstops; nsCOMPtr<nsISupportsArray> agents;
rv = NS_NewISupportsArray(getter_AddRefs(backstops)); rv = NS_NewISupportsArray(getter_AddRefs(agents));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> newBackstopSheets; nsCOMPtr<nsISupportsArray> newAgentSheets;
rv = NS_NewISupportsArray(getter_AddRefs(newBackstopSheets)); rv = NS_NewISupportsArray(getter_AddRefs(newAgentSheets));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
PRInt32 bc = styleSet->GetNumberOfBackstopStyleSheets(); PRInt32 bc = styleSet->GetNumberOfAgentStyleSheets();
for (PRInt32 l = 0; l < bc; l++) { for (PRInt32 l = 0; l < bc; l++) {
nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetBackstopStyleSheetAt(l)); nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetAgentStyleSheetAt(l));
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
rv = sheet->GetURL(*getter_AddRefs(uri)); rv = sheet->GetURL(*getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1226,17 +1226,17 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (newSheet) { if (newSheet) {
rv = newBackstopSheets->AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; rv = newAgentSheets->AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
else { // Just use the same sheet. else { // Just use the same sheet.
rv = newBackstopSheets->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE; rv = newAgentSheets->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
styleSet->ReplaceBackstopStyleSheets(newBackstopSheets); styleSet->ReplaceAgentStyleSheets(newAgentSheets);
} }
} }
} }
@@ -2722,7 +2722,7 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult) nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult)
{ {
nsresult rv = NS_NewISupportsArray(aResult); nsresult rv = NS_NewISupportsArray(aResult);

View File

@@ -3924,28 +3924,26 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
sheets->Count(&count); sheets->Count(&count);
for(PRUint32 i=0; i<count; i++) { for(PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); sheets->GetElementAt(i, getter_AddRefs(sheet));
// XXX For now, append as backstop until we figure out something (*aStyleSet)->AppendUserStyleSheet(sheet);
// better to do.
(*aStyleSet)->AppendBackstopStyleSheet(sheet);
} }
} }
// Append chrome sheets (scrollbars + forms). // Append chrome sheets (scrollbars + forms).
nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer)); nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));
chromeRegistry->GetBackstopSheets(ds, getter_AddRefs(sheets)); chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets));
if(sheets){ if(sheets){
nsCOMPtr<nsICSSStyleSheet> sheet; nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count; PRUint32 count;
sheets->Count(&count); sheets->Count(&count);
for(PRUint32 i=0; i<count; i++) { for(PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); sheets->GetElementAt(i, getter_AddRefs(sheet));
(*aStyleSet)->AppendBackstopStyleSheet(sheet); (*aStyleSet)->AppendAgentStyleSheet(sheet);
} }
} }
} }
if (mUAStyleSheet) { if (mUAStyleSheet) {
(*aStyleSet)->AppendBackstopStyleSheet(mUAStyleSheet); (*aStyleSet)->AppendAgentStyleSheet(mUAStyleSheet);
} }
} }
return NS_OK; return NS_OK;

View File

@@ -99,15 +99,25 @@ public:
virtual PRInt32 GetNumberOfDocStyleSheets(); virtual PRInt32 GetNumberOfDocStyleSheets();
virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex); virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex);
virtual void AppendBackstopStyleSheet(nsIStyleSheet* aSheet); virtual void AppendUserStyleSheet(nsIStyleSheet* aSheet);
virtual void InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet); nsIStyleSheet* aAfterSheet);
virtual void InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet); nsIStyleSheet* aBeforeSheet);
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet); virtual void RemoveUserStyleSheet(nsIStyleSheet* aSheet);
virtual PRInt32 GetNumberOfBackstopStyleSheets(); virtual PRInt32 GetNumberOfUserStyleSheets();
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex); virtual nsIStyleSheet* GetUserStyleSheetAt(PRInt32 aIndex);
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets); virtual void ReplaceUserStyleSheets(nsISupportsArray* aNewSheets);
virtual void AppendAgentStyleSheet(nsIStyleSheet* aSheet);
virtual void InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet);
virtual void InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet);
virtual void RemoveAgentStyleSheet(nsIStyleSheet* aSheet);
virtual PRInt32 GetNumberOfAgentStyleSheets();
virtual nsIStyleSheet* GetAgentStyleSheetAt(PRInt32 aIndex);
virtual void ReplaceAgentStyleSheets(nsISupportsArray* aNewSheets);
NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable); NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable);
@@ -238,8 +248,6 @@ public:
#endif #endif
virtual void ResetUniqueStyleItems(void); virtual void ResetUniqueStyleItems(void);
void AddImportantRules(nsRuleNode* aRuleNode);
#ifdef MOZ_PERF_METRICS #ifdef MOZ_PERF_METRICS
NS_DECL_NSITIMERECORDER NS_DECL_NSITIMERECORDER
#endif #endif
@@ -260,17 +268,21 @@ private:
protected: protected:
virtual ~StyleSetImpl(); virtual ~StyleSetImpl();
PRBool EnsureArray(nsISupportsArray** aArray); PRBool EnsureArray(nsCOMPtr<nsISupportsArray> &aArray);
void RecycleArray(nsISupportsArray** aArray); void RecycleArray(nsCOMPtr<nsISupportsArray> &aArray);
void EnsureRuleWalker(nsIPresContext* aPresContext); void EnsureRuleWalker(nsIPresContext* aPresContext);
void ClearRuleProcessors(void); void ClearRuleProcessors(void);
void ClearOverrideRuleProcessors(void); void ClearAgentRuleProcessors(void);
void ClearBackstopRuleProcessors(void); void ClearUserRuleProcessors(void);
void ClearDocRuleProcessors(void); void ClearDocRuleProcessors(void);
void ClearOverrideRuleProcessors(void);
nsresult GatherRuleProcessors(void); nsresult GatherRuleProcessors(void);
void AddImportantRules(nsRuleNode* aCurrLevelNode, nsRuleNode* aLastPrevLevelNode);
void FileRules(nsISupportsArrayEnumFunc aCollectorFunc, void* aData, nsIContent* aContent);
nsIStyleContext* GetContext(nsIPresContext* aPresContext, nsIStyleContext* GetContext(nsIPresContext* aPresContext,
nsIStyleContext* aParentContext, nsIStyleContext* aParentContext,
@@ -281,15 +293,17 @@ protected:
void ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent); void ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent);
#endif #endif
nsISupportsArray* mOverrideSheets; // most significant first nsCOMPtr<nsISupportsArray> mOverrideSheets; // most significant first
nsISupportsArray* mDocSheets; // " " nsCOMPtr<nsISupportsArray> mDocSheets; // " "
nsISupportsArray* mBackstopSheets; // " " nsCOMPtr<nsISupportsArray> mUserSheets; // " "
nsCOMPtr<nsISupportsArray> mAgentSheets; // " "
nsISupportsArray* mBackstopRuleProcessors; // least significant first nsCOMPtr<nsISupportsArray> mAgentRuleProcessors; // least significant first
nsISupportsArray* mDocRuleProcessors; // " " nsCOMPtr<nsISupportsArray> mUserRuleProcessors; // " "
nsISupportsArray* mOverrideRuleProcessors; // " " nsCOMPtr<nsISupportsArray> mDocRuleProcessors; // " "
nsCOMPtr<nsISupportsArray> mOverrideRuleProcessors; // " "
nsISupportsArray* mRecycler; nsCOMPtr<nsISupportsArray> mRecycler;
nsIStyleFrameConstruction* mFrameConstructor; nsIStyleFrameConstruction* mFrameConstructor;
nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling
@@ -313,16 +327,8 @@ nsrefcnt StyleSetImpl::gInstances = 0;
nsIURI *StyleSetImpl::gQuirkURI = 0; nsIURI *StyleSetImpl::gQuirkURI = 0;
StyleSetImpl::StyleSetImpl() StyleSetImpl::StyleSetImpl()
: mOverrideSheets(nsnull), : mFrameConstructor(nsnull),
mDocSheets(nsnull),
mBackstopSheets(nsnull),
mBackstopRuleProcessors(nsnull),
mDocRuleProcessors(nsnull),
mOverrideRuleProcessors(nsnull),
mRecycler(nsnull),
mFrameConstructor(nsnull),
mQuirkStyleSheet(nsnull), mQuirkStyleSheet(nsnull),
mStyleRuleSupplier(nsnull),
mRuleTree(nsnull), mRuleTree(nsnull),
mRuleWalker(nsnull) mRuleWalker(nsnull)
#ifdef MOZ_PERF_METRICS #ifdef MOZ_PERF_METRICS
@@ -340,14 +346,7 @@ StyleSetImpl::StyleSetImpl()
StyleSetImpl::~StyleSetImpl() StyleSetImpl::~StyleSetImpl()
{ {
NS_IF_RELEASE(mOverrideSheets);
NS_IF_RELEASE(mDocSheets);
NS_IF_RELEASE(mBackstopSheets);
NS_IF_RELEASE(mBackstopRuleProcessors);
NS_IF_RELEASE(mDocRuleProcessors);
NS_IF_RELEASE(mOverrideRuleProcessors);
NS_IF_RELEASE(mFrameConstructor); NS_IF_RELEASE(mFrameConstructor);
NS_IF_RELEASE(mRecycler);
NS_IF_RELEASE(mQuirkStyleSheet); NS_IF_RELEASE(mQuirkStyleSheet);
if (--gInstances == 0) if (--gInstances == 0)
{ {
@@ -361,13 +360,13 @@ NS_IMPL_ISUPPORTS1(StyleSetImpl, nsIStyleSet)
NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder) NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder)
#endif #endif
PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray) PRBool StyleSetImpl::EnsureArray(nsCOMPtr<nsISupportsArray> &aArray)
{ {
if (nsnull == *aArray) { if (nsnull == aArray) {
(*aArray) = mRecycler; aArray = mRecycler;
mRecycler = nsnull; mRecycler = nsnull;
if (nsnull == *aArray) { if (nsnull == aArray) {
if (NS_OK != NS_NewISupportsArray(aArray)) { if (NS_OK != NS_NewISupportsArray(getter_AddRefs(aArray))) {
return PR_FALSE; return PR_FALSE;
} }
} }
@@ -376,45 +375,53 @@ PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray)
} }
void void
StyleSetImpl::RecycleArray(nsISupportsArray** aArray) StyleSetImpl::RecycleArray(nsCOMPtr<nsISupportsArray> &aArray)
{ {
if (! mRecycler) { if (!mRecycler) {
mRecycler = *aArray; // take ref mRecycler = aArray; // take ref
mRecycler->Clear(); mRecycler->Clear();
*aArray = nsnull; aArray = nsnull;
} }
else { // already have a recycled array else { // already have a recycled array
NS_RELEASE(*aArray); aArray = nsnull;
} }
} }
void void
StyleSetImpl::ClearRuleProcessors(void) StyleSetImpl::ClearRuleProcessors(void)
{ {
ClearBackstopRuleProcessors(); ClearAgentRuleProcessors();
ClearUserRuleProcessors();
ClearDocRuleProcessors(); ClearDocRuleProcessors();
ClearOverrideRuleProcessors(); ClearOverrideRuleProcessors();
} }
void void
StyleSetImpl::ClearBackstopRuleProcessors(void) StyleSetImpl::ClearAgentRuleProcessors(void)
{ {
if (mBackstopRuleProcessors) if (mAgentRuleProcessors)
RecycleArray(&mBackstopRuleProcessors); RecycleArray(mAgentRuleProcessors);
} }
void void
StyleSetImpl::ClearUserRuleProcessors(void)
{
if (mUserRuleProcessors)
RecycleArray(mUserRuleProcessors);
}
void
StyleSetImpl::ClearDocRuleProcessors(void) StyleSetImpl::ClearDocRuleProcessors(void)
{ {
if (mDocRuleProcessors) if (mDocRuleProcessors)
RecycleArray(&mDocRuleProcessors); RecycleArray(mDocRuleProcessors);
} }
void void
StyleSetImpl::ClearOverrideRuleProcessors(void) StyleSetImpl::ClearOverrideRuleProcessors(void)
{ {
if (mOverrideRuleProcessors) if (mOverrideRuleProcessors)
RecycleArray(&mOverrideRuleProcessors); RecycleArray(mOverrideRuleProcessors);
} }
struct RuleProcessorData { struct RuleProcessorData {
@@ -449,38 +456,50 @@ nsresult
StyleSetImpl::GatherRuleProcessors(void) StyleSetImpl::GatherRuleProcessors(void)
{ {
nsresult result = NS_ERROR_OUT_OF_MEMORY; nsresult result = NS_ERROR_OUT_OF_MEMORY;
if (mBackstopSheets && !mBackstopRuleProcessors) { if (mAgentSheets && !mAgentRuleProcessors) {
if (EnsureArray(&mBackstopRuleProcessors)) { if (EnsureArray(mAgentRuleProcessors)) {
RuleProcessorData data(mBackstopRuleProcessors); RuleProcessorData data(mAgentRuleProcessors);
mBackstopSheets->EnumerateBackwards(EnumRuleProcessor, &data); mAgentSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mBackstopRuleProcessors->Count(&count); mAgentRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mBackstopRuleProcessors); RecycleArray(mAgentRuleProcessors);
}
} else return result;
}
if (mUserSheets && !mUserRuleProcessors) {
if (EnsureArray(mUserRuleProcessors)) {
RuleProcessorData data(mUserRuleProcessors);
mUserSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count;
mUserRuleProcessors->Count(&count);
if (0 == count) {
RecycleArray(mUserRuleProcessors);
} }
} else return result; } else return result;
} }
if (mDocSheets && !mDocRuleProcessors) { if (mDocSheets && !mDocRuleProcessors) {
if (EnsureArray(&mDocRuleProcessors)) { if (EnsureArray(mDocRuleProcessors)) {
RuleProcessorData data(mDocRuleProcessors); RuleProcessorData data(mDocRuleProcessors);
mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data); mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mDocRuleProcessors->Count(&count); mDocRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mDocRuleProcessors); RecycleArray(mDocRuleProcessors);
} }
} else return result; } else return result;
} }
if (mOverrideSheets && !mOverrideRuleProcessors) { if (mOverrideSheets && !mOverrideRuleProcessors) {
if (EnsureArray(&mOverrideRuleProcessors)) { if (EnsureArray(mOverrideRuleProcessors)) {
RuleProcessorData data(mOverrideRuleProcessors); RuleProcessorData data(mOverrideRuleProcessors);
mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data); mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mOverrideRuleProcessors->Count(&count); mOverrideRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mOverrideRuleProcessors); RecycleArray(mOverrideRuleProcessors);
} }
} else return result; } else return result;
} }
@@ -494,7 +513,7 @@ StyleSetImpl::GatherRuleProcessors(void)
void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
mOverrideSheets->AppendElement(aSheet); mOverrideSheets->AppendElement(aSheet);
ClearOverrideRuleProcessors(); ClearOverrideRuleProcessors();
@@ -505,7 +524,7 @@ void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) nsIStyleSheet* aAfterSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet); PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet);
mOverrideSheets->InsertElementAt(aSheet, ++index); mOverrideSheets->InsertElementAt(aSheet, ++index);
@@ -517,7 +536,7 @@ void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) nsIStyleSheet* aBeforeSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet); PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet);
mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
@@ -560,7 +579,7 @@ nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex)
void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
{ {
NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg"); NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg");
if (EnsureArray(&mDocSheets)) { if (EnsureArray(mDocSheets)) {
mDocSheets->RemoveElement(aSheet); mDocSheets->RemoveElement(aSheet);
// lowest index last // lowest index last
PRInt32 newDocIndex = 0; PRInt32 newDocIndex = 0;
@@ -623,74 +642,147 @@ nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex)
return sheet; return sheet;
} }
// ------ backstop sheets // ------ user sheets
void StyleSetImpl::AppendBackstopStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::AppendUserStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
mBackstopSheets->AppendElement(aSheet); mUserSheets->AppendElement(aSheet);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet, void StyleSetImpl::InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) nsIStyleSheet* aAfterSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
PRInt32 index = mBackstopSheets->IndexOf(aAfterSheet); PRInt32 index = mUserSheets->IndexOf(aAfterSheet);
mBackstopSheets->InsertElementAt(aSheet, ++index); mUserSheets->InsertElementAt(aSheet, ++index);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet, void StyleSetImpl::InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) nsIStyleSheet* aBeforeSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
PRInt32 index = mBackstopSheets->IndexOf(aBeforeSheet); PRInt32 index = mUserSheets->IndexOf(aBeforeSheet);
mBackstopSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); mUserSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::RemoveUserStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (nsnull != mBackstopSheets) { if (nsnull != mUserSheets) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets() PRInt32 StyleSetImpl::GetNumberOfUserStyleSheets()
{ {
if (nsnull != mBackstopSheets) { if (nsnull != mUserSheets) {
PRUint32 cnt; PRUint32 cnt;
nsresult rv = mBackstopSheets->Count(&cnt); nsresult rv = mUserSheets->Count(&cnt);
if (NS_FAILED(rv)) return 0; // XXX error? if (NS_FAILED(rv)) return 0; // XXX error?
return cnt; return cnt;
} }
return 0; return 0;
} }
nsIStyleSheet* StyleSetImpl::GetUserStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mUserSheets) {
sheet = (nsIStyleSheet*)mUserSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceUserStyleSheets(nsISupportsArray* aNewUserSheets)
{
ClearUserRuleProcessors();
mUserSheets = aNewUserSheets;
}
// ------ agent sheets
void StyleSetImpl::AppendAgentStyleSheet(nsIStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
mAgentSheets->AppendElement(aSheet);
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
PRInt32 index = mAgentSheets->IndexOf(aAfterSheet);
mAgentSheets->InsertElementAt(aSheet, ++index);
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
PRInt32 index = mAgentSheets->IndexOf(aBeforeSheet);
mAgentSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::RemoveAgentStyleSheet(nsIStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (nsnull != mAgentSheets) {
mAgentSheets->RemoveElement(aSheet);
ClearAgentRuleProcessors();
}
}
PRInt32 StyleSetImpl::GetNumberOfAgentStyleSheets()
{
if (nsnull != mAgentSheets) {
PRUint32 cnt;
nsresult rv = mAgentSheets->Count(&cnt);
if (NS_FAILED(rv)) return 0; // XXX error?
return cnt;
}
return 0;
}
NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable) NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (nsnull == mQuirkStyleSheet) { if (nsnull == mQuirkStyleSheet) {
// first find the quirk sheet: // first find the quirk sheet:
// - run through all of the backstop sheets and check for a CSSStyleSheet that // - run through all of the agent sheets and check for a CSSStyleSheet that
// has the URL we want // has the URL we want
PRUint32 i, nSheets = GetNumberOfBackstopStyleSheets(); PRUint32 i, nSheets = GetNumberOfAgentStyleSheets();
for (i=0; i< nSheets; i++) { for (i=0; i< nSheets; i++) {
nsCOMPtr<nsIStyleSheet> sheet; nsCOMPtr<nsIStyleSheet> sheet;
sheet = getter_AddRefs(GetBackstopStyleSheetAt(i)); sheet = getter_AddRefs(GetAgentStyleSheetAt(i));
if (sheet) { if (sheet) {
nsCOMPtr<nsICSSStyleSheet> cssSheet; nsCOMPtr<nsICSSStyleSheet> cssSheet;
sheet->QueryInterface(NS_GET_IID(nsICSSStyleSheet), getter_AddRefs(cssSheet)); sheet->QueryInterface(NS_GET_IID(nsICSSStyleSheet), getter_AddRefs(cssSheet));
@@ -723,6 +815,22 @@ NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable)
return rv; return rv;
} }
nsIStyleSheet* StyleSetImpl::GetAgentStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mAgentSheets) {
sheet = (nsIStyleSheet*)mAgentSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceAgentStyleSheets(nsISupportsArray* aNewAgentSheets)
{
ClearAgentRuleProcessors();
mAgentSheets = aNewAgentSheets;
}
NS_IMETHODIMP NS_IMETHODIMP
StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled) StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
{ {
@@ -731,23 +839,6 @@ StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
return NS_OK; return NS_OK;
} }
nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mBackstopSheets) {
sheet = (nsIStyleSheet*)mBackstopSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
{
ClearBackstopRuleProcessors();
NS_IF_RELEASE(mBackstopSheets);
mBackstopSheets = aNewBackstopSheets;
NS_IF_ADDREF(mBackstopSheets);
}
struct RulesMatchingData { struct RulesMatchingData {
RulesMatchingData(nsIPresContext* aPresContext, RulesMatchingData(nsIPresContext* aPresContext,
@@ -812,16 +903,16 @@ nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
} }
void void
StyleSetImpl::AddImportantRules(nsRuleNode* aCurrNode) StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode,
nsRuleNode* aLastPrevLevelNode)
{ {
// XXX Note: this is still incorrect from a cascade standpoint, but if (!aCurrLevelNode || aCurrLevelNode == aLastPrevLevelNode)
// it preserves the existing incorrect cascade behavior. return;
nsRuleNode* parent = aCurrNode->GetParent();
if (parent) AddImportantRules(aCurrLevelNode->GetParent(), aLastPrevLevelNode);
AddImportantRules(parent);
nsCOMPtr<nsIStyleRule> rule;; nsCOMPtr<nsIStyleRule> rule;;
aCurrNode->GetRule(getter_AddRefs(rule)); aCurrLevelNode->GetRule(getter_AddRefs(rule));
nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule)); nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
if (cssRule) { if (cssRule) {
nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule()); nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule());
@@ -830,6 +921,61 @@ StyleSetImpl::AddImportantRules(nsRuleNode* aCurrNode)
} }
} }
void
StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc,
void* aData,
nsIContent* aContent)
{
// Cascading order:
// [least important]
// 1. UA normal rules = Agent normal
// 2. User normal rules = User normal
// 3. Author normal rules = Document normal
// 4. Override normal rules = Override normal
// 5. Author !important rules = Document !important
// 6. Override !important rules = Override !important
// 7. User !important rules = User !important
// 8. UA !important rules = Agent !important
// [most important]
nsRuleNode* lastAgentRN = nsnull;
if (mAgentRuleProcessors) {
mAgentRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastAgentRN = mRuleWalker->GetCurrentNode();
}
nsRuleNode* lastUserRN = lastAgentRN;
if (mUserRuleProcessors) {
mUserRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastUserRN = mRuleWalker->GetCurrentNode();
}
nsRuleNode* lastDocRN = lastUserRN;
PRBool useRuleProcessors = PR_TRUE;
if (mStyleRuleSupplier) {
// We can supply additional document-level sheets that should be walked.
mStyleRuleSupplier->WalkRules(this, aCollectorFunc, aData, aContent);
mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors);
}
if (mDocRuleProcessors) {
mDocRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
}
lastDocRN = mRuleWalker->GetCurrentNode();
nsRuleNode* lastOvrRN = lastDocRN;
if (mOverrideRuleProcessors) {
mOverrideRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastOvrRN = mRuleWalker->GetCurrentNode();
}
AddImportantRules(lastDocRN, lastUserRN); //doc
AddImportantRules(lastOvrRN, lastDocRN); //ovr
AddImportantRules(lastUserRN, lastAgentRN); //user
AddImportantRules(lastAgentRN, nsnull); //agent
}
#ifdef NS_DEBUG #ifdef NS_DEBUG
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \ #define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
nsrefcnt count = ptr->AddRef(); \ nsrefcnt count = ptr->AddRef(); \
@@ -866,16 +1012,15 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext,
if (aContent && aPresContext) { if (aContent && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
RulesMatchingData data(aPresContext, medium, aContent, aParentContext, mRuleWalker); RulesMatchingData data(aPresContext, medium, aContent, aParentContext, mRuleWalker);
WalkRuleProcessors(EnumRulesMatching, &data, aContent); FileRules(EnumRulesMatching, &data, aContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique);
// Now reset the walker back to the root of the tree. // Now reset the walker back to the root of the tree.
@@ -902,8 +1047,9 @@ nsIStyleContext* StyleSetImpl::ResolveStyleForNonElement(
if (aPresContext) { if (aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || if (mAgentRuleProcessors ||
mDocRuleProcessors || mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) { mOverrideRuleProcessors) {
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique);
@@ -975,17 +1121,17 @@ nsIStyleContext* StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContex
if (aPseudoTag && aPresContext) { if (aPseudoTag && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
PseudoRulesMatchingData data(aPresContext, medium, aParentContent, PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
aPseudoTag, aParentContext, aComparator, mRuleWalker); aPseudoTag, aParentContext, aComparator, mRuleWalker);
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent); FileRules(EnumPseudoRulesMatching, &data, aParentContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique); result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique);
// Now reset the walker back to the root of the tree. // Now reset the walker back to the root of the tree.
@@ -1017,17 +1163,17 @@ nsIStyleContext* StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext,
if (aPseudoTag && aPresContext) { if (aPseudoTag && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
PseudoRulesMatchingData data(aPresContext, medium, aParentContent, PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
aPseudoTag, aParentContext, nsnull, mRuleWalker); aPseudoTag, aParentContext, nsnull, mRuleWalker);
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent); FileRules(EnumPseudoRulesMatching, &data, aParentContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
if (!mRuleWalker->AtRoot()) if (!mRuleWalker->AtRoot())
result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique); result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique);
@@ -1212,8 +1358,9 @@ StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
GatherRuleProcessors(); GatherRuleProcessors();
if (aContent->IsContentOfType(nsIContent::eELEMENT) && if (aContent->IsContentOfType(nsIContent::eELEMENT) &&
(mBackstopRuleProcessors || (mAgentRuleProcessors ||
mDocRuleProcessors || mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors)) { mOverrideRuleProcessors)) {
nsIAtom* medium = nsnull; nsIAtom* medium = nsnull;
aPresContext->GetMedium(&medium); aPresContext->GetMedium(&medium);
@@ -1421,7 +1568,8 @@ void StyleSetImpl::List(FILE* out, PRInt32 aIndent)
{ {
// List(out, aIndent, mOverrideSheets); // List(out, aIndent, mOverrideSheets);
List(out, aIndent, mDocSheets); List(out, aIndent, mDocSheets);
// List(out, aIndent, mBackstopSheets); // List(out, aIndent, mUserSheets);
// List(out, aIndent, mAgentSheets);
} }
@@ -1616,7 +1764,9 @@ StyleSetImpl::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
if ((mDocSheets && !mDocSheets->EnumerateForwards(EnumAffectsStyle, &pair)) || if ((mDocSheets && !mDocSheets->EnumerateForwards(EnumAffectsStyle, &pair)) ||
(mOverrideSheets && !mOverrideSheets->EnumerateForwards(EnumAffectsStyle, (mOverrideSheets && !mOverrideSheets->EnumerateForwards(EnumAffectsStyle,
&pair)) || &pair)) ||
(mBackstopSheets && !mBackstopSheets->EnumerateForwards(EnumAffectsStyle, (mUserSheets && !mUserSheets->EnumerateForwards(EnumAffectsStyle,
&pair)) ||
(mAgentSheets && !mAgentSheets->EnumerateForwards(EnumAffectsStyle,
&pair))) { &pair))) {
aAffects = PR_TRUE; aAffects = PR_TRUE;
} else { } else {
@@ -1636,7 +1786,7 @@ StyleSetImpl::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
* and the FrameConstructor overhead * and the FrameConstructor overhead
* *
* Contained / Aggregated data (not reported as StyleSetImpl's size): * Contained / Aggregated data (not reported as StyleSetImpl's size):
* 1) Override Sheets, DocSheets, BackstopSheets, RuleProcessors, Recycler * 1) Override Sheets, DocSheets, UserSheets, AgentSheets, RuleProcessors, Recycler
* are all delegated to. * are all delegated to.
* *
* Children / siblings / parents: * Children / siblings / parents:
@@ -1668,11 +1818,17 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
if (mDocSheets && uniqueItems->AddItem(mDocSheets)){ if (mDocSheets && uniqueItems->AddItem(mDocSheets)){
aSize += sizeof(*mDocSheets); aSize += sizeof(*mDocSheets);
} }
if (mBackstopSheets && uniqueItems->AddItem(mBackstopSheets)){ if (mUserSheets && uniqueItems->AddItem(mUserSheets)){
aSize += sizeof(*mBackstopSheets); aSize += sizeof(*mUserSheets);
} }
if (mBackstopRuleProcessors && uniqueItems->AddItem(mBackstopRuleProcessors)){ if (mAgentSheets && uniqueItems->AddItem(mAgentSheets)){
aSize += sizeof(*mBackstopRuleProcessors); aSize += sizeof(*mAgentSheets);
}
if (mAgentRuleProcessors && uniqueItems->AddItem(mAgentRuleProcessors)){
aSize += sizeof(*mAgentRuleProcessors);
}
if (mUserRuleProcessors && uniqueItems->AddItem(mUserRuleProcessors)){
aSize += sizeof(*mUserRuleProcessors);
} }
if (mDocRuleProcessors && uniqueItems->AddItem(mDocRuleProcessors)){ if (mDocRuleProcessors && uniqueItems->AddItem(mDocRuleProcessors)){
aSize += sizeof(*mDocRuleProcessors); aSize += sizeof(*mDocRuleProcessors);
@@ -1717,9 +1873,19 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
NS_IF_RELEASE(pSheet); NS_IF_RELEASE(pSheet);
} }
numSheets = GetNumberOfBackstopStyleSheets(); numSheets = GetNumberOfUserStyleSheets();
for(curSheet=0; curSheet < numSheets; curSheet++){ for(curSheet=0; curSheet < numSheets; curSheet++){
nsIStyleSheet* pSheet = GetBackstopStyleSheetAt(curSheet); nsIStyleSheet* pSheet = GetUserStyleSheetAt(curSheet);
if(pSheet){
localSize=0;
pSheet->SizeOf(aSizeOfHandler, localSize);
}
NS_IF_RELEASE(pSheet);
}
numSheets = GetNumberOfAgentStyleSheets();
for(curSheet=0; curSheet < numSheets; curSheet++){
nsIStyleSheet* pSheet = GetAgentStyleSheetAt(curSheet);
if(pSheet){ if(pSheet){
localSize=0; localSize=0;
pSheet->SizeOf(aSizeOfHandler, localSize); pSheet->SizeOf(aSizeOfHandler, localSize);
@@ -1729,11 +1895,23 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
/////////////////////////////////////////////// ///////////////////////////////////////////////
// rule processors // rule processors
PRUint32 numRuleProcessors,curRuleProcessor; PRUint32 numRuleProcessors,curRuleProcessor;
if(mBackstopRuleProcessors){ if(mAgentRuleProcessors){
mBackstopRuleProcessors->Count(&numRuleProcessors); mAgentRuleProcessors->Count(&numRuleProcessors);
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){ for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
nsIStyleRuleProcessor* processor = nsIStyleRuleProcessor* processor =
(nsIStyleRuleProcessor* )mBackstopRuleProcessors->ElementAt(curRuleProcessor); (nsIStyleRuleProcessor* )mAgentRuleProcessors->ElementAt(curRuleProcessor);
if(processor){
localSize=0;
processor->SizeOf(aSizeOfHandler, localSize);
}
NS_IF_RELEASE(processor);
}
}
if(mUserRuleProcessors){
mUserRuleProcessors->Count(&numRuleProcessors);
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
nsIStyleRuleProcessor* processor =
(nsIStyleRuleProcessor* )mUserRuleProcessors->ElementAt(curRuleProcessor);
if(processor){ if(processor){
localSize=0; localSize=0;
processor->SizeOf(aSizeOfHandler, localSize); processor->SizeOf(aSizeOfHandler, localSize);
@@ -1792,9 +1970,13 @@ void
StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData, StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
nsIContent* aContent) nsIContent* aContent)
{ {
// Walk the backstop rules first. // Walk the agent rules first.
if (mBackstopRuleProcessors) if (mAgentRuleProcessors)
mBackstopRuleProcessors->EnumerateForwards(aFunc, aData); mAgentRuleProcessors->EnumerateForwards(aFunc, aData);
// Walk the user rules next.
if (mUserRuleProcessors)
mUserRuleProcessors->EnumerateForwards(aFunc, aData);
PRBool useRuleProcessors = PR_TRUE; PRBool useRuleProcessors = PR_TRUE;
if (mStyleRuleSupplier) { if (mStyleRuleSupplier) {
@@ -1803,7 +1985,7 @@ StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors); mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors);
} }
// Walk the doc rules next. // Now walk the doc rules.
if (mDocRuleProcessors && useRuleProcessors) if (mDocRuleProcessors && useRuleProcessors)
mDocRuleProcessors->EnumerateForwards(aFunc, aData); mDocRuleProcessors->EnumerateForwards(aFunc, aData);

View File

@@ -3924,28 +3924,26 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
sheets->Count(&count); sheets->Count(&count);
for(PRUint32 i=0; i<count; i++) { for(PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); sheets->GetElementAt(i, getter_AddRefs(sheet));
// XXX For now, append as backstop until we figure out something (*aStyleSet)->AppendUserStyleSheet(sheet);
// better to do.
(*aStyleSet)->AppendBackstopStyleSheet(sheet);
} }
} }
// Append chrome sheets (scrollbars + forms). // Append chrome sheets (scrollbars + forms).
nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer)); nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));
chromeRegistry->GetBackstopSheets(ds, getter_AddRefs(sheets)); chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets));
if(sheets){ if(sheets){
nsCOMPtr<nsICSSStyleSheet> sheet; nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count; PRUint32 count;
sheets->Count(&count); sheets->Count(&count);
for(PRUint32 i=0; i<count; i++) { for(PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); sheets->GetElementAt(i, getter_AddRefs(sheet));
(*aStyleSet)->AppendBackstopStyleSheet(sheet); (*aStyleSet)->AppendAgentStyleSheet(sheet);
} }
} }
} }
if (mUAStyleSheet) { if (mUAStyleSheet) {
(*aStyleSet)->AppendBackstopStyleSheet(mUAStyleSheet); (*aStyleSet)->AppendAgentStyleSheet(mUAStyleSheet);
} }
} }
return NS_OK; return NS_OK;

View File

@@ -168,14 +168,14 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
// supporting bugs 31816, 20760, 22963 // supporting bugs 31816, 20760, 22963
// define USE_OVERRIDE to put prefs in as an override stylesheet // define USE_OVERRIDE to put prefs in as an override stylesheet
// otherwise they go in as a Backstop stylesheets // otherwise they go in as a Agent stylesheets
// - OVERRIDE is better for text and bg colors, but bad for link colors, // - OVERRIDE is better for text and bg colors, but bad for link colors,
// so eventually, we should probably have a backstop and an override and // so eventually, we should probably have an agent and an override and
// put the link colors in the backstop and the text and bg colors in the override, // put the link colors in the agent and the text and bg colors in the override,
// but using the backstop stylesheet with !important rules solves 95% of the // but using the agent stylesheet with !important rules solves 95% of the
// problem and should suffice for RTM // problem and should suffice for RTM
// //
// XXX: use backstop stylesheet of link colors and link underline, // XXX: use agent stylesheet of link colors and link underline,
// user override stylesheet for forcing background and text colors, post RTM // user override stylesheet for forcing background and text colors, post RTM
// //
// #define PREFS_USE_OVERRIDE // #define PREFS_USE_OVERRIDE
@@ -2065,8 +2065,8 @@ PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
} }
// now the link rules (must come after the color rules, or links will not be correct color!) // now the link rules (must come after the color rules, or links will not be correct color!)
// XXX - when there is both an override and backstop pref stylesheet this won't matter, // XXX - when there is both an override and agent pref stylesheet this won't matter,
// as the color rules will be overrides and the links rules will be backstop // as the color rules will be overrides and the links rules will be agent
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = SetPrefLinkRules(); result = SetPrefLinkRules();
} }
@@ -2115,7 +2115,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets(); PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets();
#else #else
PRInt32 numBefore = mStyleSet->GetNumberOfBackstopStyleSheets(); PRInt32 numBefore = mStyleSet->GetNumberOfAgentStyleSheets();
#endif #endif
NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!"); NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!");
#endif #endif
@@ -2123,7 +2123,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet); mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet);
#else #else
mStyleSet->RemoveBackstopStyleSheet(mPrefStyleSheet); mStyleSet->RemoveAgentStyleSheet(mPrefStyleSheet);
#endif #endif
#ifdef DEBUG_attinasi #ifdef DEBUG_attinasi
@@ -2131,7 +2131,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(), NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(),
"Pref stylesheet was not removed"); "Pref stylesheet was not removed");
#else #else
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfBackstopStyleSheets(), NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfAgentStyleSheets(),
"Pref stylesheet was not removed"); "Pref stylesheet was not removed");
#endif #endif
printf("PrefStyleSheet removed\n"); printf("PrefStyleSheet removed\n");
@@ -2161,7 +2161,7 @@ nsresult PresShell::CreatePreferenceStyleSheet(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet); mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet);
#else #else
mStyleSet->AppendBackstopStyleSheet(mPrefStyleSheet); mStyleSet->AppendAgentStyleSheet(mPrefStyleSheet);
#endif #endif
} }
} }
@@ -2214,7 +2214,7 @@ nsresult PresShell::SetPrefColorRules(void)
// create a rule for background and foreground color and // create a rule for background and foreground color and
// add it to the style sheet // add it to the style sheet
// - the rule is !important so it overrides all but author // - the rule is !important so it overrides all but author
// important rules (when put into a backstop stylesheet) and // important rules (when put into an agent stylesheet) and
// all (even author important) when put into an override stylesheet // all (even author important) when put into an override stylesheet
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -2268,9 +2268,9 @@ nsresult PresShell::SetPrefLinkRules(void)
// support default link colors: // support default link colors:
// this means the link colors need to be overridable, // this means the link colors need to be overridable,
// which they are if we put them in the backstop stylesheet, // which they are if we put them in the agent stylesheet,
// though if using an override sheet this will cause authors grief still // though if using an override sheet this will cause authors grief still
// In the backstop stylesheet, they are !important when we are ignoring document colors // In the agent stylesheet, they are !important when we are ignoring document colors
// //
// XXX: do active links and visited links get another color? // XXX: do active links and visited links get another color?
// They were red in the html.css rules // They were red in the html.css rules
@@ -2322,7 +2322,7 @@ nsresult PresShell::SetPrefLinkRules(void)
// create a rule to make underlining happen // create a rule to make underlining happen
// ':link, :visited {text-decoration:[underline|none];}' // ':link, :visited {text-decoration:[underline|none];}'
// no need for important, we want these to be overridable // no need for important, we want these to be overridable
// NOTE: these must go in the backstop stylesheet or they cannot be // NOTE: these must go in the agent stylesheet or they cannot be
// overridden by authors // overridden by authors
#ifdef DEBUG_attinasi #ifdef DEBUG_attinasi
printf (" - Creating rules for enabling link underlines\n"); printf (" - Creating rules for enabling link underlines\n");
@@ -6230,13 +6230,22 @@ PresShell::CloneStyleSet(nsIStyleSet* aSet, nsIStyleSet** aResult)
NS_RELEASE(ss); NS_RELEASE(ss);
} }
} }
n = aSet->GetNumberOfUserStyleSheets();
n = aSet->GetNumberOfBackstopStyleSheets();
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
nsIStyleSheet* ss; nsIStyleSheet* ss;
ss = aSet->GetBackstopStyleSheetAt(i); ss = aSet->GetUserStyleSheetAt(i);
if (nsnull != ss) { if (nsnull != ss) {
clone->AppendBackstopStyleSheet(ss); clone->AppendUserStyleSheet(ss);
NS_RELEASE(ss);
}
}
n = aSet->GetNumberOfAgentStyleSheets();
for (i = 0; i < n; i++) {
nsIStyleSheet* ss;
ss = aSet->GetAgentStyleSheetAt(i);
if (nsnull != ss) {
clone->AppendAgentStyleSheet(ss);
NS_RELEASE(ss); NS_RELEASE(ss);
} }
} }

View File

@@ -86,15 +86,25 @@ public:
virtual PRInt32 GetNumberOfDocStyleSheets() = 0; virtual PRInt32 GetNumberOfDocStyleSheets() = 0;
virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex) = 0; virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex) = 0;
virtual void AppendBackstopStyleSheet(nsIStyleSheet* aSheet) = 0; virtual void AppendUserStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual void InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) = 0; nsIStyleSheet* aAfterSheet) = 0;
virtual void InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) = 0; nsIStyleSheet* aBeforeSheet) = 0;
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet) = 0; virtual void RemoveUserStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual PRInt32 GetNumberOfBackstopStyleSheets() = 0; virtual PRInt32 GetNumberOfUserStyleSheets() = 0;
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex) = 0; virtual nsIStyleSheet* GetUserStyleSheetAt(PRInt32 aIndex) = 0;
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets) = 0; virtual void ReplaceUserStyleSheets(nsISupportsArray* aNewSheets) = 0;
virtual void AppendAgentStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual void InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) = 0;
virtual void InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) = 0;
virtual void RemoveAgentStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual PRInt32 GetNumberOfAgentStyleSheets() = 0;
virtual nsIStyleSheet* GetAgentStyleSheetAt(PRInt32 aIndex) = 0;
virtual void ReplaceAgentStyleSheets(nsISupportsArray* aNewSheets) = 0;
virtual nsresult GetRuleTree(nsRuleNode** aResult) = 0; virtual nsresult GetRuleTree(nsRuleNode** aResult) = 0;
virtual nsresult ClearCachedDataInRuleTree(nsIStyleRule* aRule) = 0; virtual nsresult ClearCachedDataInRuleTree(nsIStyleRule* aRule) = 0;

View File

@@ -168,14 +168,14 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
// supporting bugs 31816, 20760, 22963 // supporting bugs 31816, 20760, 22963
// define USE_OVERRIDE to put prefs in as an override stylesheet // define USE_OVERRIDE to put prefs in as an override stylesheet
// otherwise they go in as a Backstop stylesheets // otherwise they go in as a Agent stylesheets
// - OVERRIDE is better for text and bg colors, but bad for link colors, // - OVERRIDE is better for text and bg colors, but bad for link colors,
// so eventually, we should probably have a backstop and an override and // so eventually, we should probably have an agent and an override and
// put the link colors in the backstop and the text and bg colors in the override, // put the link colors in the agent and the text and bg colors in the override,
// but using the backstop stylesheet with !important rules solves 95% of the // but using the agent stylesheet with !important rules solves 95% of the
// problem and should suffice for RTM // problem and should suffice for RTM
// //
// XXX: use backstop stylesheet of link colors and link underline, // XXX: use agent stylesheet of link colors and link underline,
// user override stylesheet for forcing background and text colors, post RTM // user override stylesheet for forcing background and text colors, post RTM
// //
// #define PREFS_USE_OVERRIDE // #define PREFS_USE_OVERRIDE
@@ -2065,8 +2065,8 @@ PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
} }
// now the link rules (must come after the color rules, or links will not be correct color!) // now the link rules (must come after the color rules, or links will not be correct color!)
// XXX - when there is both an override and backstop pref stylesheet this won't matter, // XXX - when there is both an override and agent pref stylesheet this won't matter,
// as the color rules will be overrides and the links rules will be backstop // as the color rules will be overrides and the links rules will be agent
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = SetPrefLinkRules(); result = SetPrefLinkRules();
} }
@@ -2115,7 +2115,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets(); PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets();
#else #else
PRInt32 numBefore = mStyleSet->GetNumberOfBackstopStyleSheets(); PRInt32 numBefore = mStyleSet->GetNumberOfAgentStyleSheets();
#endif #endif
NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!"); NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!");
#endif #endif
@@ -2123,7 +2123,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet); mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet);
#else #else
mStyleSet->RemoveBackstopStyleSheet(mPrefStyleSheet); mStyleSet->RemoveAgentStyleSheet(mPrefStyleSheet);
#endif #endif
#ifdef DEBUG_attinasi #ifdef DEBUG_attinasi
@@ -2131,7 +2131,7 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(), NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(),
"Pref stylesheet was not removed"); "Pref stylesheet was not removed");
#else #else
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfBackstopStyleSheets(), NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfAgentStyleSheets(),
"Pref stylesheet was not removed"); "Pref stylesheet was not removed");
#endif #endif
printf("PrefStyleSheet removed\n"); printf("PrefStyleSheet removed\n");
@@ -2161,7 +2161,7 @@ nsresult PresShell::CreatePreferenceStyleSheet(void)
#ifdef PREFS_USE_OVERRIDE #ifdef PREFS_USE_OVERRIDE
mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet); mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet);
#else #else
mStyleSet->AppendBackstopStyleSheet(mPrefStyleSheet); mStyleSet->AppendAgentStyleSheet(mPrefStyleSheet);
#endif #endif
} }
} }
@@ -2214,7 +2214,7 @@ nsresult PresShell::SetPrefColorRules(void)
// create a rule for background and foreground color and // create a rule for background and foreground color and
// add it to the style sheet // add it to the style sheet
// - the rule is !important so it overrides all but author // - the rule is !important so it overrides all but author
// important rules (when put into a backstop stylesheet) and // important rules (when put into an agent stylesheet) and
// all (even author important) when put into an override stylesheet // all (even author important) when put into an override stylesheet
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -2268,9 +2268,9 @@ nsresult PresShell::SetPrefLinkRules(void)
// support default link colors: // support default link colors:
// this means the link colors need to be overridable, // this means the link colors need to be overridable,
// which they are if we put them in the backstop stylesheet, // which they are if we put them in the agent stylesheet,
// though if using an override sheet this will cause authors grief still // though if using an override sheet this will cause authors grief still
// In the backstop stylesheet, they are !important when we are ignoring document colors // In the agent stylesheet, they are !important when we are ignoring document colors
// //
// XXX: do active links and visited links get another color? // XXX: do active links and visited links get another color?
// They were red in the html.css rules // They were red in the html.css rules
@@ -2322,7 +2322,7 @@ nsresult PresShell::SetPrefLinkRules(void)
// create a rule to make underlining happen // create a rule to make underlining happen
// ':link, :visited {text-decoration:[underline|none];}' // ':link, :visited {text-decoration:[underline|none];}'
// no need for important, we want these to be overridable // no need for important, we want these to be overridable
// NOTE: these must go in the backstop stylesheet or they cannot be // NOTE: these must go in the agent stylesheet or they cannot be
// overridden by authors // overridden by authors
#ifdef DEBUG_attinasi #ifdef DEBUG_attinasi
printf (" - Creating rules for enabling link underlines\n"); printf (" - Creating rules for enabling link underlines\n");
@@ -6230,13 +6230,22 @@ PresShell::CloneStyleSet(nsIStyleSet* aSet, nsIStyleSet** aResult)
NS_RELEASE(ss); NS_RELEASE(ss);
} }
} }
n = aSet->GetNumberOfUserStyleSheets();
n = aSet->GetNumberOfBackstopStyleSheets();
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
nsIStyleSheet* ss; nsIStyleSheet* ss;
ss = aSet->GetBackstopStyleSheetAt(i); ss = aSet->GetUserStyleSheetAt(i);
if (nsnull != ss) { if (nsnull != ss) {
clone->AppendBackstopStyleSheet(ss); clone->AppendUserStyleSheet(ss);
NS_RELEASE(ss);
}
}
n = aSet->GetNumberOfAgentStyleSheets();
for (i = 0; i < n; i++) {
nsIStyleSheet* ss;
ss = aSet->GetAgentStyleSheetAt(i);
if (nsnull != ss) {
clone->AppendAgentStyleSheet(ss);
NS_RELEASE(ss); NS_RELEASE(ss);
} }
} }

View File

@@ -99,15 +99,25 @@ public:
virtual PRInt32 GetNumberOfDocStyleSheets(); virtual PRInt32 GetNumberOfDocStyleSheets();
virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex); virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex);
virtual void AppendBackstopStyleSheet(nsIStyleSheet* aSheet); virtual void AppendUserStyleSheet(nsIStyleSheet* aSheet);
virtual void InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet); nsIStyleSheet* aAfterSheet);
virtual void InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet, virtual void InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet); nsIStyleSheet* aBeforeSheet);
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet); virtual void RemoveUserStyleSheet(nsIStyleSheet* aSheet);
virtual PRInt32 GetNumberOfBackstopStyleSheets(); virtual PRInt32 GetNumberOfUserStyleSheets();
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex); virtual nsIStyleSheet* GetUserStyleSheetAt(PRInt32 aIndex);
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets); virtual void ReplaceUserStyleSheets(nsISupportsArray* aNewSheets);
virtual void AppendAgentStyleSheet(nsIStyleSheet* aSheet);
virtual void InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet);
virtual void InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet);
virtual void RemoveAgentStyleSheet(nsIStyleSheet* aSheet);
virtual PRInt32 GetNumberOfAgentStyleSheets();
virtual nsIStyleSheet* GetAgentStyleSheetAt(PRInt32 aIndex);
virtual void ReplaceAgentStyleSheets(nsISupportsArray* aNewSheets);
NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable); NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable);
@@ -238,8 +248,6 @@ public:
#endif #endif
virtual void ResetUniqueStyleItems(void); virtual void ResetUniqueStyleItems(void);
void AddImportantRules(nsRuleNode* aRuleNode);
#ifdef MOZ_PERF_METRICS #ifdef MOZ_PERF_METRICS
NS_DECL_NSITIMERECORDER NS_DECL_NSITIMERECORDER
#endif #endif
@@ -260,17 +268,21 @@ private:
protected: protected:
virtual ~StyleSetImpl(); virtual ~StyleSetImpl();
PRBool EnsureArray(nsISupportsArray** aArray); PRBool EnsureArray(nsCOMPtr<nsISupportsArray> &aArray);
void RecycleArray(nsISupportsArray** aArray); void RecycleArray(nsCOMPtr<nsISupportsArray> &aArray);
void EnsureRuleWalker(nsIPresContext* aPresContext); void EnsureRuleWalker(nsIPresContext* aPresContext);
void ClearRuleProcessors(void); void ClearRuleProcessors(void);
void ClearOverrideRuleProcessors(void); void ClearAgentRuleProcessors(void);
void ClearBackstopRuleProcessors(void); void ClearUserRuleProcessors(void);
void ClearDocRuleProcessors(void); void ClearDocRuleProcessors(void);
void ClearOverrideRuleProcessors(void);
nsresult GatherRuleProcessors(void); nsresult GatherRuleProcessors(void);
void AddImportantRules(nsRuleNode* aCurrLevelNode, nsRuleNode* aLastPrevLevelNode);
void FileRules(nsISupportsArrayEnumFunc aCollectorFunc, void* aData, nsIContent* aContent);
nsIStyleContext* GetContext(nsIPresContext* aPresContext, nsIStyleContext* GetContext(nsIPresContext* aPresContext,
nsIStyleContext* aParentContext, nsIStyleContext* aParentContext,
@@ -281,15 +293,17 @@ protected:
void ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent); void ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent);
#endif #endif
nsISupportsArray* mOverrideSheets; // most significant first nsCOMPtr<nsISupportsArray> mOverrideSheets; // most significant first
nsISupportsArray* mDocSheets; // " " nsCOMPtr<nsISupportsArray> mDocSheets; // " "
nsISupportsArray* mBackstopSheets; // " " nsCOMPtr<nsISupportsArray> mUserSheets; // " "
nsCOMPtr<nsISupportsArray> mAgentSheets; // " "
nsISupportsArray* mBackstopRuleProcessors; // least significant first nsCOMPtr<nsISupportsArray> mAgentRuleProcessors; // least significant first
nsISupportsArray* mDocRuleProcessors; // " " nsCOMPtr<nsISupportsArray> mUserRuleProcessors; // " "
nsISupportsArray* mOverrideRuleProcessors; // " " nsCOMPtr<nsISupportsArray> mDocRuleProcessors; // " "
nsCOMPtr<nsISupportsArray> mOverrideRuleProcessors; // " "
nsISupportsArray* mRecycler; nsCOMPtr<nsISupportsArray> mRecycler;
nsIStyleFrameConstruction* mFrameConstructor; nsIStyleFrameConstruction* mFrameConstructor;
nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling
@@ -313,16 +327,8 @@ nsrefcnt StyleSetImpl::gInstances = 0;
nsIURI *StyleSetImpl::gQuirkURI = 0; nsIURI *StyleSetImpl::gQuirkURI = 0;
StyleSetImpl::StyleSetImpl() StyleSetImpl::StyleSetImpl()
: mOverrideSheets(nsnull), : mFrameConstructor(nsnull),
mDocSheets(nsnull),
mBackstopSheets(nsnull),
mBackstopRuleProcessors(nsnull),
mDocRuleProcessors(nsnull),
mOverrideRuleProcessors(nsnull),
mRecycler(nsnull),
mFrameConstructor(nsnull),
mQuirkStyleSheet(nsnull), mQuirkStyleSheet(nsnull),
mStyleRuleSupplier(nsnull),
mRuleTree(nsnull), mRuleTree(nsnull),
mRuleWalker(nsnull) mRuleWalker(nsnull)
#ifdef MOZ_PERF_METRICS #ifdef MOZ_PERF_METRICS
@@ -340,14 +346,7 @@ StyleSetImpl::StyleSetImpl()
StyleSetImpl::~StyleSetImpl() StyleSetImpl::~StyleSetImpl()
{ {
NS_IF_RELEASE(mOverrideSheets);
NS_IF_RELEASE(mDocSheets);
NS_IF_RELEASE(mBackstopSheets);
NS_IF_RELEASE(mBackstopRuleProcessors);
NS_IF_RELEASE(mDocRuleProcessors);
NS_IF_RELEASE(mOverrideRuleProcessors);
NS_IF_RELEASE(mFrameConstructor); NS_IF_RELEASE(mFrameConstructor);
NS_IF_RELEASE(mRecycler);
NS_IF_RELEASE(mQuirkStyleSheet); NS_IF_RELEASE(mQuirkStyleSheet);
if (--gInstances == 0) if (--gInstances == 0)
{ {
@@ -361,13 +360,13 @@ NS_IMPL_ISUPPORTS1(StyleSetImpl, nsIStyleSet)
NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder) NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder)
#endif #endif
PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray) PRBool StyleSetImpl::EnsureArray(nsCOMPtr<nsISupportsArray> &aArray)
{ {
if (nsnull == *aArray) { if (nsnull == aArray) {
(*aArray) = mRecycler; aArray = mRecycler;
mRecycler = nsnull; mRecycler = nsnull;
if (nsnull == *aArray) { if (nsnull == aArray) {
if (NS_OK != NS_NewISupportsArray(aArray)) { if (NS_OK != NS_NewISupportsArray(getter_AddRefs(aArray))) {
return PR_FALSE; return PR_FALSE;
} }
} }
@@ -376,45 +375,53 @@ PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray)
} }
void void
StyleSetImpl::RecycleArray(nsISupportsArray** aArray) StyleSetImpl::RecycleArray(nsCOMPtr<nsISupportsArray> &aArray)
{ {
if (! mRecycler) { if (!mRecycler) {
mRecycler = *aArray; // take ref mRecycler = aArray; // take ref
mRecycler->Clear(); mRecycler->Clear();
*aArray = nsnull; aArray = nsnull;
} }
else { // already have a recycled array else { // already have a recycled array
NS_RELEASE(*aArray); aArray = nsnull;
} }
} }
void void
StyleSetImpl::ClearRuleProcessors(void) StyleSetImpl::ClearRuleProcessors(void)
{ {
ClearBackstopRuleProcessors(); ClearAgentRuleProcessors();
ClearUserRuleProcessors();
ClearDocRuleProcessors(); ClearDocRuleProcessors();
ClearOverrideRuleProcessors(); ClearOverrideRuleProcessors();
} }
void void
StyleSetImpl::ClearBackstopRuleProcessors(void) StyleSetImpl::ClearAgentRuleProcessors(void)
{ {
if (mBackstopRuleProcessors) if (mAgentRuleProcessors)
RecycleArray(&mBackstopRuleProcessors); RecycleArray(mAgentRuleProcessors);
} }
void void
StyleSetImpl::ClearUserRuleProcessors(void)
{
if (mUserRuleProcessors)
RecycleArray(mUserRuleProcessors);
}
void
StyleSetImpl::ClearDocRuleProcessors(void) StyleSetImpl::ClearDocRuleProcessors(void)
{ {
if (mDocRuleProcessors) if (mDocRuleProcessors)
RecycleArray(&mDocRuleProcessors); RecycleArray(mDocRuleProcessors);
} }
void void
StyleSetImpl::ClearOverrideRuleProcessors(void) StyleSetImpl::ClearOverrideRuleProcessors(void)
{ {
if (mOverrideRuleProcessors) if (mOverrideRuleProcessors)
RecycleArray(&mOverrideRuleProcessors); RecycleArray(mOverrideRuleProcessors);
} }
struct RuleProcessorData { struct RuleProcessorData {
@@ -449,38 +456,50 @@ nsresult
StyleSetImpl::GatherRuleProcessors(void) StyleSetImpl::GatherRuleProcessors(void)
{ {
nsresult result = NS_ERROR_OUT_OF_MEMORY; nsresult result = NS_ERROR_OUT_OF_MEMORY;
if (mBackstopSheets && !mBackstopRuleProcessors) { if (mAgentSheets && !mAgentRuleProcessors) {
if (EnsureArray(&mBackstopRuleProcessors)) { if (EnsureArray(mAgentRuleProcessors)) {
RuleProcessorData data(mBackstopRuleProcessors); RuleProcessorData data(mAgentRuleProcessors);
mBackstopSheets->EnumerateBackwards(EnumRuleProcessor, &data); mAgentSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mBackstopRuleProcessors->Count(&count); mAgentRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mBackstopRuleProcessors); RecycleArray(mAgentRuleProcessors);
}
} else return result;
}
if (mUserSheets && !mUserRuleProcessors) {
if (EnsureArray(mUserRuleProcessors)) {
RuleProcessorData data(mUserRuleProcessors);
mUserSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count;
mUserRuleProcessors->Count(&count);
if (0 == count) {
RecycleArray(mUserRuleProcessors);
} }
} else return result; } else return result;
} }
if (mDocSheets && !mDocRuleProcessors) { if (mDocSheets && !mDocRuleProcessors) {
if (EnsureArray(&mDocRuleProcessors)) { if (EnsureArray(mDocRuleProcessors)) {
RuleProcessorData data(mDocRuleProcessors); RuleProcessorData data(mDocRuleProcessors);
mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data); mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mDocRuleProcessors->Count(&count); mDocRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mDocRuleProcessors); RecycleArray(mDocRuleProcessors);
} }
} else return result; } else return result;
} }
if (mOverrideSheets && !mOverrideRuleProcessors) { if (mOverrideSheets && !mOverrideRuleProcessors) {
if (EnsureArray(&mOverrideRuleProcessors)) { if (EnsureArray(mOverrideRuleProcessors)) {
RuleProcessorData data(mOverrideRuleProcessors); RuleProcessorData data(mOverrideRuleProcessors);
mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data); mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data);
PRUint32 count; PRUint32 count;
mOverrideRuleProcessors->Count(&count); mOverrideRuleProcessors->Count(&count);
if (0 == count) { if (0 == count) {
RecycleArray(&mOverrideRuleProcessors); RecycleArray(mOverrideRuleProcessors);
} }
} else return result; } else return result;
} }
@@ -494,7 +513,7 @@ StyleSetImpl::GatherRuleProcessors(void)
void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
mOverrideSheets->AppendElement(aSheet); mOverrideSheets->AppendElement(aSheet);
ClearOverrideRuleProcessors(); ClearOverrideRuleProcessors();
@@ -505,7 +524,7 @@ void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) nsIStyleSheet* aAfterSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet); PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet);
mOverrideSheets->InsertElementAt(aSheet, ++index); mOverrideSheets->InsertElementAt(aSheet, ++index);
@@ -517,7 +536,7 @@ void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) nsIStyleSheet* aBeforeSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mOverrideSheets)) { if (EnsureArray(mOverrideSheets)) {
mOverrideSheets->RemoveElement(aSheet); mOverrideSheets->RemoveElement(aSheet);
PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet); PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet);
mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
@@ -560,7 +579,7 @@ nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex)
void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
{ {
NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg"); NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg");
if (EnsureArray(&mDocSheets)) { if (EnsureArray(mDocSheets)) {
mDocSheets->RemoveElement(aSheet); mDocSheets->RemoveElement(aSheet);
// lowest index last // lowest index last
PRInt32 newDocIndex = 0; PRInt32 newDocIndex = 0;
@@ -623,74 +642,147 @@ nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex)
return sheet; return sheet;
} }
// ------ backstop sheets // ------ user sheets
void StyleSetImpl::AppendBackstopStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::AppendUserStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
mBackstopSheets->AppendElement(aSheet); mUserSheets->AppendElement(aSheet);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet, void StyleSetImpl::InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet) nsIStyleSheet* aAfterSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
PRInt32 index = mBackstopSheets->IndexOf(aAfterSheet); PRInt32 index = mUserSheets->IndexOf(aAfterSheet);
mBackstopSheets->InsertElementAt(aSheet, ++index); mUserSheets->InsertElementAt(aSheet, ++index);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet, void StyleSetImpl::InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet) nsIStyleSheet* aBeforeSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(&mBackstopSheets)) { if (EnsureArray(mUserSheets)) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
PRInt32 index = mBackstopSheets->IndexOf(aBeforeSheet); PRInt32 index = mUserSheets->IndexOf(aBeforeSheet);
mBackstopSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0)); mUserSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet) void StyleSetImpl::RemoveUserStyleSheet(nsIStyleSheet* aSheet)
{ {
NS_PRECONDITION(nsnull != aSheet, "null arg"); NS_PRECONDITION(nsnull != aSheet, "null arg");
if (nsnull != mBackstopSheets) { if (nsnull != mUserSheets) {
mBackstopSheets->RemoveElement(aSheet); mUserSheets->RemoveElement(aSheet);
ClearBackstopRuleProcessors(); ClearUserRuleProcessors();
} }
} }
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets() PRInt32 StyleSetImpl::GetNumberOfUserStyleSheets()
{ {
if (nsnull != mBackstopSheets) { if (nsnull != mUserSheets) {
PRUint32 cnt; PRUint32 cnt;
nsresult rv = mBackstopSheets->Count(&cnt); nsresult rv = mUserSheets->Count(&cnt);
if (NS_FAILED(rv)) return 0; // XXX error? if (NS_FAILED(rv)) return 0; // XXX error?
return cnt; return cnt;
} }
return 0; return 0;
} }
nsIStyleSheet* StyleSetImpl::GetUserStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mUserSheets) {
sheet = (nsIStyleSheet*)mUserSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceUserStyleSheets(nsISupportsArray* aNewUserSheets)
{
ClearUserRuleProcessors();
mUserSheets = aNewUserSheets;
}
// ------ agent sheets
void StyleSetImpl::AppendAgentStyleSheet(nsIStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
mAgentSheets->AppendElement(aSheet);
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
nsIStyleSheet* aAfterSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
PRInt32 index = mAgentSheets->IndexOf(aAfterSheet);
mAgentSheets->InsertElementAt(aSheet, ++index);
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
nsIStyleSheet* aBeforeSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (EnsureArray(mAgentSheets)) {
mAgentSheets->RemoveElement(aSheet);
PRInt32 index = mAgentSheets->IndexOf(aBeforeSheet);
mAgentSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
ClearAgentRuleProcessors();
}
}
void StyleSetImpl::RemoveAgentStyleSheet(nsIStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
if (nsnull != mAgentSheets) {
mAgentSheets->RemoveElement(aSheet);
ClearAgentRuleProcessors();
}
}
PRInt32 StyleSetImpl::GetNumberOfAgentStyleSheets()
{
if (nsnull != mAgentSheets) {
PRUint32 cnt;
nsresult rv = mAgentSheets->Count(&cnt);
if (NS_FAILED(rv)) return 0; // XXX error?
return cnt;
}
return 0;
}
NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable) NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (nsnull == mQuirkStyleSheet) { if (nsnull == mQuirkStyleSheet) {
// first find the quirk sheet: // first find the quirk sheet:
// - run through all of the backstop sheets and check for a CSSStyleSheet that // - run through all of the agent sheets and check for a CSSStyleSheet that
// has the URL we want // has the URL we want
PRUint32 i, nSheets = GetNumberOfBackstopStyleSheets(); PRUint32 i, nSheets = GetNumberOfAgentStyleSheets();
for (i=0; i< nSheets; i++) { for (i=0; i< nSheets; i++) {
nsCOMPtr<nsIStyleSheet> sheet; nsCOMPtr<nsIStyleSheet> sheet;
sheet = getter_AddRefs(GetBackstopStyleSheetAt(i)); sheet = getter_AddRefs(GetAgentStyleSheetAt(i));
if (sheet) { if (sheet) {
nsCOMPtr<nsICSSStyleSheet> cssSheet; nsCOMPtr<nsICSSStyleSheet> cssSheet;
sheet->QueryInterface(NS_GET_IID(nsICSSStyleSheet), getter_AddRefs(cssSheet)); sheet->QueryInterface(NS_GET_IID(nsICSSStyleSheet), getter_AddRefs(cssSheet));
@@ -723,6 +815,22 @@ NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable)
return rv; return rv;
} }
nsIStyleSheet* StyleSetImpl::GetAgentStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mAgentSheets) {
sheet = (nsIStyleSheet*)mAgentSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceAgentStyleSheets(nsISupportsArray* aNewAgentSheets)
{
ClearAgentRuleProcessors();
mAgentSheets = aNewAgentSheets;
}
NS_IMETHODIMP NS_IMETHODIMP
StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled) StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
{ {
@@ -731,23 +839,6 @@ StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
return NS_OK; return NS_OK;
} }
nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
{
nsIStyleSheet* sheet = nsnull;
if (nsnull != mBackstopSheets) {
sheet = (nsIStyleSheet*)mBackstopSheets->ElementAt(aIndex);
}
return sheet;
}
void
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
{
ClearBackstopRuleProcessors();
NS_IF_RELEASE(mBackstopSheets);
mBackstopSheets = aNewBackstopSheets;
NS_IF_ADDREF(mBackstopSheets);
}
struct RulesMatchingData { struct RulesMatchingData {
RulesMatchingData(nsIPresContext* aPresContext, RulesMatchingData(nsIPresContext* aPresContext,
@@ -812,16 +903,16 @@ nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
} }
void void
StyleSetImpl::AddImportantRules(nsRuleNode* aCurrNode) StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode,
nsRuleNode* aLastPrevLevelNode)
{ {
// XXX Note: this is still incorrect from a cascade standpoint, but if (!aCurrLevelNode || aCurrLevelNode == aLastPrevLevelNode)
// it preserves the existing incorrect cascade behavior. return;
nsRuleNode* parent = aCurrNode->GetParent();
if (parent) AddImportantRules(aCurrLevelNode->GetParent(), aLastPrevLevelNode);
AddImportantRules(parent);
nsCOMPtr<nsIStyleRule> rule;; nsCOMPtr<nsIStyleRule> rule;;
aCurrNode->GetRule(getter_AddRefs(rule)); aCurrLevelNode->GetRule(getter_AddRefs(rule));
nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule)); nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
if (cssRule) { if (cssRule) {
nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule()); nsCOMPtr<nsIStyleRule> impRule = getter_AddRefs(cssRule->GetImportantRule());
@@ -830,6 +921,61 @@ StyleSetImpl::AddImportantRules(nsRuleNode* aCurrNode)
} }
} }
void
StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc,
void* aData,
nsIContent* aContent)
{
// Cascading order:
// [least important]
// 1. UA normal rules = Agent normal
// 2. User normal rules = User normal
// 3. Author normal rules = Document normal
// 4. Override normal rules = Override normal
// 5. Author !important rules = Document !important
// 6. Override !important rules = Override !important
// 7. User !important rules = User !important
// 8. UA !important rules = Agent !important
// [most important]
nsRuleNode* lastAgentRN = nsnull;
if (mAgentRuleProcessors) {
mAgentRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastAgentRN = mRuleWalker->GetCurrentNode();
}
nsRuleNode* lastUserRN = lastAgentRN;
if (mUserRuleProcessors) {
mUserRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastUserRN = mRuleWalker->GetCurrentNode();
}
nsRuleNode* lastDocRN = lastUserRN;
PRBool useRuleProcessors = PR_TRUE;
if (mStyleRuleSupplier) {
// We can supply additional document-level sheets that should be walked.
mStyleRuleSupplier->WalkRules(this, aCollectorFunc, aData, aContent);
mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors);
}
if (mDocRuleProcessors) {
mDocRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
}
lastDocRN = mRuleWalker->GetCurrentNode();
nsRuleNode* lastOvrRN = lastDocRN;
if (mOverrideRuleProcessors) {
mOverrideRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
lastOvrRN = mRuleWalker->GetCurrentNode();
}
AddImportantRules(lastDocRN, lastUserRN); //doc
AddImportantRules(lastOvrRN, lastDocRN); //ovr
AddImportantRules(lastUserRN, lastAgentRN); //user
AddImportantRules(lastAgentRN, nsnull); //agent
}
#ifdef NS_DEBUG #ifdef NS_DEBUG
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \ #define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
nsrefcnt count = ptr->AddRef(); \ nsrefcnt count = ptr->AddRef(); \
@@ -866,16 +1012,15 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext,
if (aContent && aPresContext) { if (aContent && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
RulesMatchingData data(aPresContext, medium, aContent, aParentContext, mRuleWalker); RulesMatchingData data(aPresContext, medium, aContent, aParentContext, mRuleWalker);
WalkRuleProcessors(EnumRulesMatching, &data, aContent); FileRules(EnumRulesMatching, &data, aContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique);
// Now reset the walker back to the root of the tree. // Now reset the walker back to the root of the tree.
@@ -902,8 +1047,9 @@ nsIStyleContext* StyleSetImpl::ResolveStyleForNonElement(
if (aPresContext) { if (aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || if (mAgentRuleProcessors ||
mDocRuleProcessors || mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) { mOverrideRuleProcessors) {
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique);
@@ -975,17 +1121,17 @@ nsIStyleContext* StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContex
if (aPseudoTag && aPresContext) { if (aPseudoTag && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
PseudoRulesMatchingData data(aPresContext, medium, aParentContent, PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
aPseudoTag, aParentContext, aComparator, mRuleWalker); aPseudoTag, aParentContext, aComparator, mRuleWalker);
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent); FileRules(EnumPseudoRulesMatching, &data, aParentContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique); result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique);
// Now reset the walker back to the root of the tree. // Now reset the walker back to the root of the tree.
@@ -1017,17 +1163,17 @@ nsIStyleContext* StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext,
if (aPseudoTag && aPresContext) { if (aPseudoTag && aPresContext) {
GatherRuleProcessors(); GatherRuleProcessors();
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { if (mAgentRuleProcessors ||
mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors) {
nsCOMPtr<nsIAtom> medium; nsCOMPtr<nsIAtom> medium;
aPresContext->GetMedium(getter_AddRefs(medium)); aPresContext->GetMedium(getter_AddRefs(medium));
EnsureRuleWalker(aPresContext); EnsureRuleWalker(aPresContext);
PseudoRulesMatchingData data(aPresContext, medium, aParentContent, PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
aPseudoTag, aParentContext, nsnull, mRuleWalker); aPseudoTag, aParentContext, nsnull, mRuleWalker);
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent); FileRules(EnumPseudoRulesMatching, &data, aParentContent);
// Walk all of the rules and add in the !important counterparts.
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
AddImportantRules(ruleNode);
if (!mRuleWalker->AtRoot()) if (!mRuleWalker->AtRoot())
result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique); result = GetContext(aPresContext, aParentContext, aPseudoTag, aForceUnique);
@@ -1212,8 +1358,9 @@ StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
GatherRuleProcessors(); GatherRuleProcessors();
if (aContent->IsContentOfType(nsIContent::eELEMENT) && if (aContent->IsContentOfType(nsIContent::eELEMENT) &&
(mBackstopRuleProcessors || (mAgentRuleProcessors ||
mDocRuleProcessors || mUserRuleProcessors ||
mDocRuleProcessors ||
mOverrideRuleProcessors)) { mOverrideRuleProcessors)) {
nsIAtom* medium = nsnull; nsIAtom* medium = nsnull;
aPresContext->GetMedium(&medium); aPresContext->GetMedium(&medium);
@@ -1421,7 +1568,8 @@ void StyleSetImpl::List(FILE* out, PRInt32 aIndent)
{ {
// List(out, aIndent, mOverrideSheets); // List(out, aIndent, mOverrideSheets);
List(out, aIndent, mDocSheets); List(out, aIndent, mDocSheets);
// List(out, aIndent, mBackstopSheets); // List(out, aIndent, mUserSheets);
// List(out, aIndent, mAgentSheets);
} }
@@ -1616,7 +1764,9 @@ StyleSetImpl::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
if ((mDocSheets && !mDocSheets->EnumerateForwards(EnumAffectsStyle, &pair)) || if ((mDocSheets && !mDocSheets->EnumerateForwards(EnumAffectsStyle, &pair)) ||
(mOverrideSheets && !mOverrideSheets->EnumerateForwards(EnumAffectsStyle, (mOverrideSheets && !mOverrideSheets->EnumerateForwards(EnumAffectsStyle,
&pair)) || &pair)) ||
(mBackstopSheets && !mBackstopSheets->EnumerateForwards(EnumAffectsStyle, (mUserSheets && !mUserSheets->EnumerateForwards(EnumAffectsStyle,
&pair)) ||
(mAgentSheets && !mAgentSheets->EnumerateForwards(EnumAffectsStyle,
&pair))) { &pair))) {
aAffects = PR_TRUE; aAffects = PR_TRUE;
} else { } else {
@@ -1636,7 +1786,7 @@ StyleSetImpl::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
* and the FrameConstructor overhead * and the FrameConstructor overhead
* *
* Contained / Aggregated data (not reported as StyleSetImpl's size): * Contained / Aggregated data (not reported as StyleSetImpl's size):
* 1) Override Sheets, DocSheets, BackstopSheets, RuleProcessors, Recycler * 1) Override Sheets, DocSheets, UserSheets, AgentSheets, RuleProcessors, Recycler
* are all delegated to. * are all delegated to.
* *
* Children / siblings / parents: * Children / siblings / parents:
@@ -1668,11 +1818,17 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
if (mDocSheets && uniqueItems->AddItem(mDocSheets)){ if (mDocSheets && uniqueItems->AddItem(mDocSheets)){
aSize += sizeof(*mDocSheets); aSize += sizeof(*mDocSheets);
} }
if (mBackstopSheets && uniqueItems->AddItem(mBackstopSheets)){ if (mUserSheets && uniqueItems->AddItem(mUserSheets)){
aSize += sizeof(*mBackstopSheets); aSize += sizeof(*mUserSheets);
} }
if (mBackstopRuleProcessors && uniqueItems->AddItem(mBackstopRuleProcessors)){ if (mAgentSheets && uniqueItems->AddItem(mAgentSheets)){
aSize += sizeof(*mBackstopRuleProcessors); aSize += sizeof(*mAgentSheets);
}
if (mAgentRuleProcessors && uniqueItems->AddItem(mAgentRuleProcessors)){
aSize += sizeof(*mAgentRuleProcessors);
}
if (mUserRuleProcessors && uniqueItems->AddItem(mUserRuleProcessors)){
aSize += sizeof(*mUserRuleProcessors);
} }
if (mDocRuleProcessors && uniqueItems->AddItem(mDocRuleProcessors)){ if (mDocRuleProcessors && uniqueItems->AddItem(mDocRuleProcessors)){
aSize += sizeof(*mDocRuleProcessors); aSize += sizeof(*mDocRuleProcessors);
@@ -1717,9 +1873,19 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
NS_IF_RELEASE(pSheet); NS_IF_RELEASE(pSheet);
} }
numSheets = GetNumberOfBackstopStyleSheets(); numSheets = GetNumberOfUserStyleSheets();
for(curSheet=0; curSheet < numSheets; curSheet++){ for(curSheet=0; curSheet < numSheets; curSheet++){
nsIStyleSheet* pSheet = GetBackstopStyleSheetAt(curSheet); nsIStyleSheet* pSheet = GetUserStyleSheetAt(curSheet);
if(pSheet){
localSize=0;
pSheet->SizeOf(aSizeOfHandler, localSize);
}
NS_IF_RELEASE(pSheet);
}
numSheets = GetNumberOfAgentStyleSheets();
for(curSheet=0; curSheet < numSheets; curSheet++){
nsIStyleSheet* pSheet = GetAgentStyleSheetAt(curSheet);
if(pSheet){ if(pSheet){
localSize=0; localSize=0;
pSheet->SizeOf(aSizeOfHandler, localSize); pSheet->SizeOf(aSizeOfHandler, localSize);
@@ -1729,11 +1895,23 @@ void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
/////////////////////////////////////////////// ///////////////////////////////////////////////
// rule processors // rule processors
PRUint32 numRuleProcessors,curRuleProcessor; PRUint32 numRuleProcessors,curRuleProcessor;
if(mBackstopRuleProcessors){ if(mAgentRuleProcessors){
mBackstopRuleProcessors->Count(&numRuleProcessors); mAgentRuleProcessors->Count(&numRuleProcessors);
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){ for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
nsIStyleRuleProcessor* processor = nsIStyleRuleProcessor* processor =
(nsIStyleRuleProcessor* )mBackstopRuleProcessors->ElementAt(curRuleProcessor); (nsIStyleRuleProcessor* )mAgentRuleProcessors->ElementAt(curRuleProcessor);
if(processor){
localSize=0;
processor->SizeOf(aSizeOfHandler, localSize);
}
NS_IF_RELEASE(processor);
}
}
if(mUserRuleProcessors){
mUserRuleProcessors->Count(&numRuleProcessors);
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
nsIStyleRuleProcessor* processor =
(nsIStyleRuleProcessor* )mUserRuleProcessors->ElementAt(curRuleProcessor);
if(processor){ if(processor){
localSize=0; localSize=0;
processor->SizeOf(aSizeOfHandler, localSize); processor->SizeOf(aSizeOfHandler, localSize);
@@ -1792,9 +1970,13 @@ void
StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData, StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
nsIContent* aContent) nsIContent* aContent)
{ {
// Walk the backstop rules first. // Walk the agent rules first.
if (mBackstopRuleProcessors) if (mAgentRuleProcessors)
mBackstopRuleProcessors->EnumerateForwards(aFunc, aData); mAgentRuleProcessors->EnumerateForwards(aFunc, aData);
// Walk the user rules next.
if (mUserRuleProcessors)
mUserRuleProcessors->EnumerateForwards(aFunc, aData);
PRBool useRuleProcessors = PR_TRUE; PRBool useRuleProcessors = PR_TRUE;
if (mStyleRuleSupplier) { if (mStyleRuleSupplier) {
@@ -1803,7 +1985,7 @@ StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors); mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors);
} }
// Walk the doc rules next. // Now walk the doc rules.
if (mDocRuleProcessors && useRuleProcessors) if (mDocRuleProcessors && useRuleProcessors)
mDocRuleProcessors->EnumerateForwards(aFunc, aData); mDocRuleProcessors->EnumerateForwards(aFunc, aData);

View File

@@ -23,7 +23,7 @@
?Release@nsOverlayEnumerator@@UAGKXZ ; 174 ?Release@nsOverlayEnumerator@@UAGKXZ ; 174
?GetOverlays@nsChromeRegistry@@UAGIPAVnsIURI@@PAPAVnsISimpleEnumerator@@@Z ; 133 ?GetOverlays@nsChromeRegistry@@UAGIPAVnsIURI@@PAPAVnsISimpleEnumerator@@@Z ; 133
?GetUserSheets@nsChromeRegistry@@UAGIHPAPAVnsISupportsArray@@@Z ; 115 ?GetUserSheets@nsChromeRegistry@@UAGIHPAPAVnsISupportsArray@@@Z ; 115
?GetBackstopSheets@nsChromeRegistry@@UAGIPAPAVnsISupportsArray@@@Z ; 115 ?GetAgentSheets@nsChromeRegistry@@UAGIPAPAVnsISupportsArray@@@Z ; 115
?AddRef@nsCachedChromeChannel@@UAGKXZ ; 88 ?AddRef@nsCachedChromeChannel@@UAGKXZ ; 88
?Release@nsCachedChromeChannel@@UAGKXZ ; 88 ?Release@nsCachedChromeChannel@@UAGKXZ ; 88
?QueryInterface@nsCachedChromeChannel@@UAGIABUnsID@@PAPAX@Z ; 74 ?QueryInterface@nsCachedChromeChannel@@UAGIABUnsID@@PAPAX@Z ; 74

View File

@@ -98,7 +98,7 @@ interface nsIChromeRegistry : nsISupports
void installPackage(in string baseURL, in boolean useProfile); void installPackage(in string baseURL, in boolean useProfile);
void uninstallPackage(in wstring packageName, in boolean useProfile); void uninstallPackage(in wstring packageName, in boolean useProfile);
void getBackstopSheets(in nsIDocShell docShell, out nsISupportsArray styleSheets); void getAgentSheets(in nsIDocShell docShell, out nsISupportsArray styleSheets);
void getUserSheets(in boolean useChromeSheets, out nsISupportsArray styleSheets); void getUserSheets(in boolean useChromeSheets, out nsISupportsArray styleSheets);
boolean allowScriptsForSkin(in nsIURI url); boolean allowScriptsForSkin(in nsIURI url);

View File

@@ -1194,7 +1194,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument); nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument);
if (xulDoc) { if (xulDoc) {
// Deal with the backstop sheets first. // Deal with the agent sheets first.
PRInt32 shellCount = document->GetNumberOfShells(); PRInt32 shellCount = document->GetNumberOfShells();
for (PRInt32 k = 0; k < shellCount; k++) { for (PRInt32 k = 0; k < shellCount; k++) {
nsCOMPtr<nsIPresShell> shell; nsCOMPtr<nsIPresShell> shell;
@@ -1204,18 +1204,18 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
rv = shell->GetStyleSet(getter_AddRefs(styleSet)); rv = shell->GetStyleSet(getter_AddRefs(styleSet));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (styleSet) { if (styleSet) {
// Reload only the chrome URL backstop style sheets. // Reload only the chrome URL agent style sheets.
nsCOMPtr<nsISupportsArray> backstops; nsCOMPtr<nsISupportsArray> agents;
rv = NS_NewISupportsArray(getter_AddRefs(backstops)); rv = NS_NewISupportsArray(getter_AddRefs(agents));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> newBackstopSheets; nsCOMPtr<nsISupportsArray> newAgentSheets;
rv = NS_NewISupportsArray(getter_AddRefs(newBackstopSheets)); rv = NS_NewISupportsArray(getter_AddRefs(newAgentSheets));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
PRInt32 bc = styleSet->GetNumberOfBackstopStyleSheets(); PRInt32 bc = styleSet->GetNumberOfAgentStyleSheets();
for (PRInt32 l = 0; l < bc; l++) { for (PRInt32 l = 0; l < bc; l++) {
nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetBackstopStyleSheetAt(l)); nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetAgentStyleSheetAt(l));
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
rv = sheet->GetURL(*getter_AddRefs(uri)); rv = sheet->GetURL(*getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1226,17 +1226,17 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet)); rv = LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (newSheet) { if (newSheet) {
rv = newBackstopSheets->AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; rv = newAgentSheets->AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
else { // Just use the same sheet. else { // Just use the same sheet.
rv = newBackstopSheets->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE; rv = newAgentSheets->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
styleSet->ReplaceBackstopStyleSheets(newBackstopSheets); styleSet->ReplaceAgentStyleSheets(newAgentSheets);
} }
} }
} }
@@ -2722,7 +2722,7 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult) nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult)
{ {
nsresult rv = NS_NewISupportsArray(aResult); nsresult rv = NS_NewISupportsArray(aResult);

View File

@@ -4616,9 +4616,9 @@ Init__21nsCSSFrameConstructorP11nsIDocument
HasGfxScrollbars__21nsCSSFrameConstructor HasGfxScrollbars__21nsCSSFrameConstructor
GetItemType__10nsDocShellPi GetItemType__10nsDocShellPi
GetUserSheets__16nsChromeRegistryiPP16nsISupportsArray GetUserSheets__16nsChromeRegistryiPP16nsISupportsArray
GetBackstopSheets__16nsChromeRegistryP11nsIDocShellPP16nsISupportsArray GetAgentSheets__16nsChromeRegistryP11nsIDocShellPP16nsISupportsArray
AppendBackstopStyleSheet__12StyleSetImplP13nsIStyleSheet AppendAgentStyleSheet__12StyleSetImplP13nsIStyleSheet
ClearBackstopRuleProcessors__12StyleSetImpl ClearAgentRuleProcessors__12StyleSetImpl
CreateShell__14nsHTMLDocumentP14nsIPresContextP14nsIViewManagerP11nsIStyleSetPP12nsIPresShell CreateShell__14nsHTMLDocumentP14nsIPresContextP14nsIViewManagerP11nsIStyleSetPP12nsIPresShell
CreateShell__16nsMarkupDocumentP14nsIPresContextP14nsIViewManagerP11nsIStyleSetPP12nsIPresShell CreateShell__16nsMarkupDocumentP14nsIPresContextP14nsIViewManagerP11nsIStyleSetPP12nsIPresShell
GetIID__12nsIPresShell GetIID__12nsIPresShell
@@ -4723,8 +4723,8 @@ SetPreferenceStyleRules__9PresShelli
SetCompatibilityMode__13nsPresContext15nsCompatibility SetCompatibilityMode__13nsPresContext15nsCompatibility
GetStyleSet__9PresShellPP11nsIStyleSet GetStyleSet__9PresShellPP11nsIStyleSet
EnableQuirkStyleSheet__12StyleSetImpli EnableQuirkStyleSheet__12StyleSetImpli
GetNumberOfBackstopStyleSheets__12StyleSetImpl GetNumberOfAgentStyleSheets__12StyleSetImpl
GetBackstopStyleSheetAt__12StyleSetImpli GetAgentStyleSheetAt__12StyleSetImpli
GetIID__16nsICSSStyleSheet GetIID__16nsICSSStyleSheet
QueryInterface__17CSSStyleSheetImplRC4nsIDPPv QueryInterface__17CSSStyleSheetImplRC4nsIDPPv
SetEnabled__17CSSStyleSheetImpli SetEnabled__17CSSStyleSheetImpli
@@ -12487,7 +12487,7 @@ Stop__13nsPresContexti
_._24nsDocViewerFocusListener _._24nsDocViewerFocusListener
_._28nsDocViewerSelectionListener _._28nsDocViewerSelectionListener
_._9PresShell _._9PresShell
RemoveBackstopStyleSheet__12StyleSetImplP13nsIStyleSheet RemoveAgentStyleSheet__12StyleSetImplP13nsIStyleSheet
_._17CSSStyleSheetImpl _._17CSSStyleSheetImpl
RemoveSheet__18CSSStyleSheetInnerP16nsICSSStyleSheet RemoveSheet__18CSSStyleSheetInnerP16nsICSSStyleSheet
_._18CSSStyleSheetInner _._18CSSStyleSheetInner