зеркало из https://github.com/mozilla/pjs.git
Fixing bugs in skin switching.
This commit is contained in:
Родитель
1065a83626
Коммит
8b528f224c
|
@ -71,6 +71,8 @@
|
|||
#include "nsIIOService.h"
|
||||
#include "nsIResProtocolHandler.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsGFXCIID.h"
|
||||
#include "nsIImageManager.h"
|
||||
#include "prio.h"
|
||||
|
||||
static char kChromePrefix[] = "chrome://";
|
||||
|
@ -82,6 +84,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
|
||||
static NS_DEFINE_CID(kImageManagerCID, NS_IMAGEMANAGER_CID);
|
||||
|
||||
class nsChromeRegistry;
|
||||
|
||||
|
@ -977,9 +980,28 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
|
|||
}
|
||||
}
|
||||
|
||||
// Flush the image cache.
|
||||
NS_WITH_SERVICE(nsIImageManager, imageManager, kImageManagerCID, &rv);
|
||||
if (imageManager)
|
||||
imageManager->FlushCache();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PRBool IsChromeURI(nsIURI* aURI)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString protocol;
|
||||
rv = aURI->GetScheme(getter_Copies(protocol));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (PL_strcmp(protocol, "chrome") == 0) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
||||
{
|
||||
// Get the DOM document.
|
||||
|
@ -994,6 +1016,42 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
|
||||
nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument);
|
||||
if (xulDoc) {
|
||||
// Deal with the backstop sheets first.
|
||||
PRInt32 shellCount = document->GetNumberOfShells();
|
||||
for (PRInt32 k = 0; k < shellCount; k++) {
|
||||
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(document->GetShellAt(k));
|
||||
if (shell) {
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
shell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
if (styleSet) {
|
||||
// Reload only the chrome URL backstop style sheets.
|
||||
nsCOMPtr<nsISupportsArray> backstops;
|
||||
NS_NewISupportsArray(getter_AddRefs(backstops));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> newBackstopSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(newBackstopSheets));
|
||||
|
||||
PRInt32 bc = styleSet->GetNumberOfBackstopStyleSheets();
|
||||
for (PRInt32 l = 0; l < bc; l++) {
|
||||
nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetBackstopStyleSheetAt(l));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
sheet->GetURL(*getter_AddRefs(uri));
|
||||
|
||||
if (IsChromeURI(uri)) {
|
||||
// Reload the sheet.
|
||||
nsCOMPtr<nsICSSStyleSheet> newSheet;
|
||||
LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet));
|
||||
if (newSheet)
|
||||
newBackstopSheets->AppendElement(newSheet);
|
||||
}
|
||||
else // Just use the same sheet.
|
||||
newBackstopSheets->AppendElement(sheet);
|
||||
}
|
||||
|
||||
styleSet->ReplaceBackstopStyleSheets(newBackstopSheets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(document);
|
||||
nsCOMPtr<nsICSSLoader> cssLoader;
|
||||
|
@ -1003,6 +1061,18 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
nsCOMPtr<nsISupportsArray> urls;
|
||||
NS_NewISupportsArray(getter_AddRefs(urls));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> oldSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(oldSheets));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> newSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(newSheets));
|
||||
|
||||
nsCOMPtr<nsIHTMLStyleSheet> attrSheet;
|
||||
container->GetAttributeStyleSheet(getter_AddRefs(attrSheet));
|
||||
|
||||
nsCOMPtr<nsIHTMLCSSStyleSheet> inlineSheet;
|
||||
container->GetInlineStyleSheet(getter_AddRefs(inlineSheet));
|
||||
|
||||
PRInt32 count = document->GetNumberOfStyleSheets();
|
||||
|
||||
// Iterate over the style sheets.
|
||||
|
@ -1012,11 +1082,6 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
|
||||
// Make sure we aren't the special style sheets that never change. We
|
||||
// want to skip those.
|
||||
nsCOMPtr<nsIHTMLStyleSheet> attrSheet;
|
||||
container->GetAttributeStyleSheet(getter_AddRefs(attrSheet));
|
||||
|
||||
nsCOMPtr<nsIHTMLCSSStyleSheet> inlineSheet;
|
||||
container->GetInlineStyleSheet(getter_AddRefs(inlineSheet));
|
||||
|
||||
nsCOMPtr<nsIStyleSheet> attr = do_QueryInterface(attrSheet);
|
||||
nsCOMPtr<nsIStyleSheet> inl = do_QueryInterface(inlineSheet);
|
||||
|
@ -1028,9 +1093,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
urls->AppendElement(uri);
|
||||
|
||||
// Remove the sheet.
|
||||
count--;
|
||||
i--;
|
||||
document->RemoveStyleSheet(styleSheet);
|
||||
oldSheets->AppendElement(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1041,30 +1104,19 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
for (PRUint32 j = 0; j < urlCount; j++) {
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(urls->ElementAt(j));
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(supports);
|
||||
ProcessStyleSheet(url, cssLoader, document);
|
||||
nsCOMPtr<nsICSSStyleSheet> newSheet;
|
||||
LoadStyleSheetWithURL(url, getter_AddRefs(newSheet));
|
||||
if (newSheet)
|
||||
newSheets->AppendElement(newSheet);
|
||||
}
|
||||
|
||||
// Now notify the document that multiple sheets have been added and removed.
|
||||
document->UpdateStyleSheets(oldSheets, newSheets);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeRegistry::ProcessStyleSheet(nsIURL* aURL, nsICSSLoader* aLoader, nsIDocument* aDocument)
|
||||
{
|
||||
PRBool doneLoading;
|
||||
nsresult rv = aLoader->LoadStyleLink(nsnull, // anElement
|
||||
aURL,
|
||||
nsAutoString(), // aTitle
|
||||
nsAutoString(), // aMedia
|
||||
kNameSpaceID_Unknown,
|
||||
aDocument->GetNumberOfStyleSheets(),
|
||||
nsnull,
|
||||
doneLoading, // Ignore doneLoading. Don't care.
|
||||
nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(char *aDocURI,
|
||||
const PRUnichar *aOverlayURI,
|
||||
PRBool aIsOverlay,
|
||||
|
@ -1921,13 +1973,8 @@ nsChromeRegistry::GetBackstopSheets(nsISupportsArray **aResult)
|
|||
|
||||
void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL)
|
||||
{
|
||||
// Load the style sheet
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIXULPrototypeCache, xulCache, "component://netscape/rdf/xul-prototype-cache", &rv);
|
||||
|
||||
nsCOMPtr<nsIURL> url;
|
||||
rv = nsComponentManager::CreateInstance("component://netscape/network/standard-url",
|
||||
nsresult rv = nsComponentManager::CreateInstance("component://netscape/network/standard-url",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
|
@ -1935,8 +1982,18 @@ void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString
|
|||
return;
|
||||
|
||||
url->SetSpec(aURL);
|
||||
|
||||
LoadStyleSheetWithURL(url, aSheet);
|
||||
}
|
||||
|
||||
void nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
|
||||
{
|
||||
// Load the style sheet
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIXULPrototypeCache, xulCache, "component://netscape/rdf/xul-prototype-cache", &rv);
|
||||
|
||||
nsCOMPtr<nsICSSStyleSheet> sheet;
|
||||
rv = xulCache->GetStyleSheet(url, getter_AddRefs(sheet));
|
||||
rv = xulCache->GetStyleSheet(aURL, getter_AddRefs(sheet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && sheet) {
|
||||
sheet->Clone(*aSheet);
|
||||
|
@ -1950,8 +2007,8 @@ void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString
|
|||
getter_AddRefs(loader));
|
||||
if(loader) {
|
||||
PRBool complete;
|
||||
rv = loader->LoadAgentSheet(url, *aSheet, complete,
|
||||
nsnull);
|
||||
rv = loader->LoadAgentSheet(aURL, *aSheet, complete,
|
||||
nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ protected:
|
|||
PRBool aIsOverlay, PRBool aUseProfile, PRBool aRemove);
|
||||
|
||||
void LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString & aURL);
|
||||
void LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet);
|
||||
|
||||
void GetUserSheetURL(nsCString & aURL);
|
||||
|
||||
private:
|
||||
|
@ -83,8 +85,6 @@ private:
|
|||
|
||||
NS_IMETHOD RefreshWindow(nsIDOMWindow* aWindow);
|
||||
|
||||
NS_IMETHOD ProcessStyleSheet(nsIURL* aURL, nsICSSLoader* aLoader, nsIDocument* aDocument);
|
||||
|
||||
NS_IMETHOD GetArcs(nsIRDFDataSource* aDataSource,
|
||||
const nsCString& aType,
|
||||
nsISimpleEnumerator** aResult);
|
||||
|
|
|
@ -61,6 +61,7 @@ class nsINodeInfoManager;
|
|||
class nsIDOMDocument;
|
||||
class nsIDOMDocumentType;
|
||||
class nsIBindingManager;
|
||||
class nsISupportsArray;
|
||||
|
||||
// IID for the nsIDocument interface
|
||||
#define NS_IDOCUMENT_IID \
|
||||
|
@ -223,6 +224,8 @@ public:
|
|||
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) = 0;
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) = 0;
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
PRBool mDisabled) = 0;
|
||||
|
|
|
@ -1362,6 +1362,21 @@ void nsDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook
|
|||
mStyleSheets.AppendElement(aSheet);
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
@ -1373,20 +1388,10 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
AddStyleSheetToStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetAdded(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
@ -1396,6 +1401,21 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
}
|
||||
}
|
||||
|
||||
void nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
@ -1405,20 +1425,10 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
RemoveStyleSheetFromStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
@ -1431,6 +1441,63 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
NS_RELEASE(aSheet);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets)
|
||||
{
|
||||
PRUint32 oldCount;
|
||||
aOldSheets->Count(&oldCount);
|
||||
nsCOMPtr<nsIStyleSheet> sheet;
|
||||
for (PRUint32 i = 0; i < oldCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aOldSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
mStyleSheets.RemoveElement(sheet);
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
RemoveStyleSheetFromStyleSets(sheet);
|
||||
}
|
||||
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
nsIStyleSheet* sheetPtr = sheet.get();
|
||||
NS_RELEASE(sheetPtr);
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 newCount;
|
||||
aNewSheets->Count(&newCount);
|
||||
for (i = 0; i < newCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aNewSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
InternalAddStyleSheet(sheet);
|
||||
nsIStyleSheet* sheetPtr = sheet;
|
||||
NS_ADDREF(sheetPtr);
|
||||
sheet->SetOwningDocument(this);
|
||||
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
AddStyleSheetToStyleSets(sheet);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, sheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
|
||||
{ // subclass hook for sheet ordering
|
||||
|
|
|
@ -266,6 +266,11 @@ public:
|
|||
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets);
|
||||
virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
PRBool mDisabled);
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfBackstopStyleSheets();
|
||||
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex);
|
||||
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets);
|
||||
|
||||
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
|
@ -560,6 +561,15 @@ nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
|
|||
return sheet;
|
||||
}
|
||||
|
||||
void
|
||||
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
|
||||
{
|
||||
ClearRuleProcessors();
|
||||
NS_IF_RELEASE(mBackstopSheets);
|
||||
mBackstopSheets = aNewBackstopSheets;
|
||||
NS_IF_ADDREF(mBackstopSheets);
|
||||
}
|
||||
|
||||
struct RulesMatchingData {
|
||||
RulesMatchingData(nsIPresContext* aPresContext,
|
||||
nsIAtom* aMedium,
|
||||
|
|
|
@ -1094,6 +1094,22 @@ nsXULDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet)
|
|||
return mStyleSheets.IndexOf(aSheet);
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
|
@ -1133,20 +1149,10 @@ nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count, i;
|
||||
|
||||
count = mPresShells.Count();
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
shell->GetStyleSet(getter_AddRefs(set));
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
AddStyleSheetToStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (i = 0; i < mObservers.Count(); i++) {
|
||||
for (PRInt32 i = 0; i < mObservers.Count(); i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
|
||||
observer->StyleSheetAdded(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(i)) {
|
||||
|
@ -1156,6 +1162,102 @@ nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets)
|
||||
{
|
||||
PRUint32 oldCount;
|
||||
aOldSheets->Count(&oldCount);
|
||||
nsCOMPtr<nsIStyleSheet> sheet;
|
||||
for (PRUint32 i = 0; i < oldCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aOldSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
mStyleSheets.RemoveElement(sheet);
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
RemoveStyleSheetFromStyleSets(sheet);
|
||||
}
|
||||
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
nsIStyleSheet* sheetPtr = sheet.get();
|
||||
NS_RELEASE(sheetPtr);
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 newCount;
|
||||
aNewSheets->Count(&newCount);
|
||||
for (i = 0; i < newCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aNewSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
if (sheet == mAttrStyleSheet.get()) { // always first
|
||||
mStyleSheets.InsertElementAt(sheet, 0);
|
||||
}
|
||||
else if (sheet == (nsIHTMLCSSStyleSheet*)mInlineStyleSheet) { // always last
|
||||
mStyleSheets.AppendElement(sheet);
|
||||
}
|
||||
else {
|
||||
if ((nsIHTMLCSSStyleSheet*)mInlineStyleSheet == mStyleSheets.ElementAt(mStyleSheets.Count() - 1)) {
|
||||
// keep attr sheet last
|
||||
mStyleSheets.InsertElementAt(sheet, mStyleSheets.Count() - 1);
|
||||
}
|
||||
else {
|
||||
mStyleSheets.AppendElement(sheet);
|
||||
}
|
||||
|
||||
// Put the style sheet into the XUL cache if the XUL cache is
|
||||
// actually enabled and the document is chrome.
|
||||
if (gXULUtils->UseXULCache() && IsChromeURI(mDocumentURL)) {
|
||||
nsCOMPtr<nsICSSStyleSheet> css = do_QueryInterface(sheet);
|
||||
if (css) {
|
||||
gXULCache->PutStyleSheet(css);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsIStyleSheet* sheetPtr = sheet;
|
||||
NS_ADDREF(sheetPtr);
|
||||
sheet->SetOwningDocument(this);
|
||||
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
AddStyleSheetToStyleSets(sheet);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, sheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
|
@ -1166,20 +1268,10 @@ nsXULDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
RemoveStyleSheetFromStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
|
|
@ -188,6 +188,10 @@ public:
|
|||
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets);
|
||||
void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
|
||||
void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
|
||||
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
|
|
|
@ -61,6 +61,7 @@ class nsINodeInfoManager;
|
|||
class nsIDOMDocument;
|
||||
class nsIDOMDocumentType;
|
||||
class nsIBindingManager;
|
||||
class nsISupportsArray;
|
||||
|
||||
// IID for the nsIDocument interface
|
||||
#define NS_IDOCUMENT_IID \
|
||||
|
@ -223,6 +224,8 @@ public:
|
|||
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) = 0;
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) = 0;
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
PRBool mDisabled) = 0;
|
||||
|
|
|
@ -38,6 +38,7 @@ class nsIFrameManager;
|
|||
|
||||
#include "nsVoidArray.h"
|
||||
class nsISizeOfHandler;
|
||||
class nsISupportsArray;
|
||||
|
||||
// IID for the nsIStyleSet interface {e59396b0-b244-11d1-8031-006008159b5a}
|
||||
#define NS_ISTYLE_SET_IID \
|
||||
|
@ -72,6 +73,7 @@ public:
|
|||
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
virtual PRInt32 GetNumberOfBackstopStyleSheets() = 0;
|
||||
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex) = 0;
|
||||
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets) = 0;
|
||||
|
||||
// get a style context for a non-pseudo frame
|
||||
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
|
|
|
@ -1362,6 +1362,21 @@ void nsDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook
|
|||
mStyleSheets.AppendElement(aSheet);
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
@ -1373,20 +1388,10 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
AddStyleSheetToStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetAdded(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
@ -1396,6 +1401,21 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
}
|
||||
}
|
||||
|
||||
void nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
@ -1405,20 +1425,10 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
RemoveStyleSheetFromStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
@ -1431,6 +1441,63 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
NS_RELEASE(aSheet);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets)
|
||||
{
|
||||
PRUint32 oldCount;
|
||||
aOldSheets->Count(&oldCount);
|
||||
nsCOMPtr<nsIStyleSheet> sheet;
|
||||
for (PRUint32 i = 0; i < oldCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aOldSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
mStyleSheets.RemoveElement(sheet);
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
RemoveStyleSheetFromStyleSets(sheet);
|
||||
}
|
||||
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
nsIStyleSheet* sheetPtr = sheet.get();
|
||||
NS_RELEASE(sheetPtr);
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 newCount;
|
||||
aNewSheets->Count(&newCount);
|
||||
for (i = 0; i < newCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aNewSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
InternalAddStyleSheet(sheet);
|
||||
nsIStyleSheet* sheetPtr = sheet;
|
||||
NS_ADDREF(sheetPtr);
|
||||
sheet->SetOwningDocument(this);
|
||||
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
AddStyleSheetToStyleSets(sheet);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, sheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
|
||||
{ // subclass hook for sheet ordering
|
||||
|
|
|
@ -266,6 +266,11 @@ public:
|
|||
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets);
|
||||
virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
PRBool mDisabled);
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfBackstopStyleSheets();
|
||||
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex);
|
||||
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets);
|
||||
|
||||
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
|
@ -560,6 +561,15 @@ nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
|
|||
return sheet;
|
||||
}
|
||||
|
||||
void
|
||||
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
|
||||
{
|
||||
ClearRuleProcessors();
|
||||
NS_IF_RELEASE(mBackstopSheets);
|
||||
mBackstopSheets = aNewBackstopSheets;
|
||||
NS_IF_ADDREF(mBackstopSheets);
|
||||
}
|
||||
|
||||
struct RulesMatchingData {
|
||||
RulesMatchingData(nsIPresContext* aPresContext,
|
||||
nsIAtom* aMedium,
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfBackstopStyleSheets();
|
||||
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex);
|
||||
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets);
|
||||
|
||||
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
|
@ -560,6 +561,15 @@ nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
|
|||
return sheet;
|
||||
}
|
||||
|
||||
void
|
||||
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
|
||||
{
|
||||
ClearRuleProcessors();
|
||||
NS_IF_RELEASE(mBackstopSheets);
|
||||
mBackstopSheets = aNewBackstopSheets;
|
||||
NS_IF_ADDREF(mBackstopSheets);
|
||||
}
|
||||
|
||||
struct RulesMatchingData {
|
||||
RulesMatchingData(nsIPresContext* aPresContext,
|
||||
nsIAtom* aMedium,
|
||||
|
|
|
@ -71,6 +71,8 @@
|
|||
#include "nsIIOService.h"
|
||||
#include "nsIResProtocolHandler.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsGFXCIID.h"
|
||||
#include "nsIImageManager.h"
|
||||
#include "prio.h"
|
||||
|
||||
static char kChromePrefix[] = "chrome://";
|
||||
|
@ -82,6 +84,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|||
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
|
||||
static NS_DEFINE_CID(kImageManagerCID, NS_IMAGEMANAGER_CID);
|
||||
|
||||
class nsChromeRegistry;
|
||||
|
||||
|
@ -977,9 +980,28 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
|
|||
}
|
||||
}
|
||||
|
||||
// Flush the image cache.
|
||||
NS_WITH_SERVICE(nsIImageManager, imageManager, kImageManagerCID, &rv);
|
||||
if (imageManager)
|
||||
imageManager->FlushCache();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PRBool IsChromeURI(nsIURI* aURI)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString protocol;
|
||||
rv = aURI->GetScheme(getter_Copies(protocol));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (PL_strcmp(protocol, "chrome") == 0) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
||||
{
|
||||
// Get the DOM document.
|
||||
|
@ -994,6 +1016,42 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
|
||||
nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(domDocument);
|
||||
if (xulDoc) {
|
||||
// Deal with the backstop sheets first.
|
||||
PRInt32 shellCount = document->GetNumberOfShells();
|
||||
for (PRInt32 k = 0; k < shellCount; k++) {
|
||||
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(document->GetShellAt(k));
|
||||
if (shell) {
|
||||
nsCOMPtr<nsIStyleSet> styleSet;
|
||||
shell->GetStyleSet(getter_AddRefs(styleSet));
|
||||
if (styleSet) {
|
||||
// Reload only the chrome URL backstop style sheets.
|
||||
nsCOMPtr<nsISupportsArray> backstops;
|
||||
NS_NewISupportsArray(getter_AddRefs(backstops));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> newBackstopSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(newBackstopSheets));
|
||||
|
||||
PRInt32 bc = styleSet->GetNumberOfBackstopStyleSheets();
|
||||
for (PRInt32 l = 0; l < bc; l++) {
|
||||
nsCOMPtr<nsIStyleSheet> sheet = getter_AddRefs(styleSet->GetBackstopStyleSheetAt(l));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
sheet->GetURL(*getter_AddRefs(uri));
|
||||
|
||||
if (IsChromeURI(uri)) {
|
||||
// Reload the sheet.
|
||||
nsCOMPtr<nsICSSStyleSheet> newSheet;
|
||||
LoadStyleSheetWithURL(uri, getter_AddRefs(newSheet));
|
||||
if (newSheet)
|
||||
newBackstopSheets->AppendElement(newSheet);
|
||||
}
|
||||
else // Just use the same sheet.
|
||||
newBackstopSheets->AppendElement(sheet);
|
||||
}
|
||||
|
||||
styleSet->ReplaceBackstopStyleSheets(newBackstopSheets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(document);
|
||||
nsCOMPtr<nsICSSLoader> cssLoader;
|
||||
|
@ -1003,6 +1061,18 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
nsCOMPtr<nsISupportsArray> urls;
|
||||
NS_NewISupportsArray(getter_AddRefs(urls));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> oldSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(oldSheets));
|
||||
|
||||
nsCOMPtr<nsISupportsArray> newSheets;
|
||||
NS_NewISupportsArray(getter_AddRefs(newSheets));
|
||||
|
||||
nsCOMPtr<nsIHTMLStyleSheet> attrSheet;
|
||||
container->GetAttributeStyleSheet(getter_AddRefs(attrSheet));
|
||||
|
||||
nsCOMPtr<nsIHTMLCSSStyleSheet> inlineSheet;
|
||||
container->GetInlineStyleSheet(getter_AddRefs(inlineSheet));
|
||||
|
||||
PRInt32 count = document->GetNumberOfStyleSheets();
|
||||
|
||||
// Iterate over the style sheets.
|
||||
|
@ -1012,11 +1082,6 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
|
||||
// Make sure we aren't the special style sheets that never change. We
|
||||
// want to skip those.
|
||||
nsCOMPtr<nsIHTMLStyleSheet> attrSheet;
|
||||
container->GetAttributeStyleSheet(getter_AddRefs(attrSheet));
|
||||
|
||||
nsCOMPtr<nsIHTMLCSSStyleSheet> inlineSheet;
|
||||
container->GetInlineStyleSheet(getter_AddRefs(inlineSheet));
|
||||
|
||||
nsCOMPtr<nsIStyleSheet> attr = do_QueryInterface(attrSheet);
|
||||
nsCOMPtr<nsIStyleSheet> inl = do_QueryInterface(inlineSheet);
|
||||
|
@ -1028,9 +1093,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
urls->AppendElement(uri);
|
||||
|
||||
// Remove the sheet.
|
||||
count--;
|
||||
i--;
|
||||
document->RemoveStyleSheet(styleSheet);
|
||||
oldSheets->AppendElement(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1041,30 +1104,19 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
|||
for (PRUint32 j = 0; j < urlCount; j++) {
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(urls->ElementAt(j));
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(supports);
|
||||
ProcessStyleSheet(url, cssLoader, document);
|
||||
nsCOMPtr<nsICSSStyleSheet> newSheet;
|
||||
LoadStyleSheetWithURL(url, getter_AddRefs(newSheet));
|
||||
if (newSheet)
|
||||
newSheets->AppendElement(newSheet);
|
||||
}
|
||||
|
||||
// Now notify the document that multiple sheets have been added and removed.
|
||||
document->UpdateStyleSheets(oldSheets, newSheets);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChromeRegistry::ProcessStyleSheet(nsIURL* aURL, nsICSSLoader* aLoader, nsIDocument* aDocument)
|
||||
{
|
||||
PRBool doneLoading;
|
||||
nsresult rv = aLoader->LoadStyleLink(nsnull, // anElement
|
||||
aURL,
|
||||
nsAutoString(), // aTitle
|
||||
nsAutoString(), // aMedia
|
||||
kNameSpaceID_Unknown,
|
||||
aDocument->GetNumberOfStyleSheets(),
|
||||
nsnull,
|
||||
doneLoading, // Ignore doneLoading. Don't care.
|
||||
nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(char *aDocURI,
|
||||
const PRUnichar *aOverlayURI,
|
||||
PRBool aIsOverlay,
|
||||
|
@ -1921,13 +1973,8 @@ nsChromeRegistry::GetBackstopSheets(nsISupportsArray **aResult)
|
|||
|
||||
void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL)
|
||||
{
|
||||
// Load the style sheet
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIXULPrototypeCache, xulCache, "component://netscape/rdf/xul-prototype-cache", &rv);
|
||||
|
||||
nsCOMPtr<nsIURL> url;
|
||||
rv = nsComponentManager::CreateInstance("component://netscape/network/standard-url",
|
||||
nsresult rv = nsComponentManager::CreateInstance("component://netscape/network/standard-url",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
|
@ -1935,8 +1982,18 @@ void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString
|
|||
return;
|
||||
|
||||
url->SetSpec(aURL);
|
||||
|
||||
LoadStyleSheetWithURL(url, aSheet);
|
||||
}
|
||||
|
||||
void nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
|
||||
{
|
||||
// Load the style sheet
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIXULPrototypeCache, xulCache, "component://netscape/rdf/xul-prototype-cache", &rv);
|
||||
|
||||
nsCOMPtr<nsICSSStyleSheet> sheet;
|
||||
rv = xulCache->GetStyleSheet(url, getter_AddRefs(sheet));
|
||||
rv = xulCache->GetStyleSheet(aURL, getter_AddRefs(sheet));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && sheet) {
|
||||
sheet->Clone(*aSheet);
|
||||
|
@ -1950,8 +2007,8 @@ void nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString
|
|||
getter_AddRefs(loader));
|
||||
if(loader) {
|
||||
PRBool complete;
|
||||
rv = loader->LoadAgentSheet(url, *aSheet, complete,
|
||||
nsnull);
|
||||
rv = loader->LoadAgentSheet(aURL, *aSheet, complete,
|
||||
nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ protected:
|
|||
PRBool aIsOverlay, PRBool aUseProfile, PRBool aRemove);
|
||||
|
||||
void LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString & aURL);
|
||||
void LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet);
|
||||
|
||||
void GetUserSheetURL(nsCString & aURL);
|
||||
|
||||
private:
|
||||
|
@ -83,8 +85,6 @@ private:
|
|||
|
||||
NS_IMETHOD RefreshWindow(nsIDOMWindow* aWindow);
|
||||
|
||||
NS_IMETHOD ProcessStyleSheet(nsIURL* aURL, nsICSSLoader* aLoader, nsIDocument* aDocument);
|
||||
|
||||
NS_IMETHOD GetArcs(nsIRDFDataSource* aDataSource,
|
||||
const nsCString& aType,
|
||||
nsISimpleEnumerator** aResult);
|
||||
|
|
|
@ -1094,6 +1094,22 @@ nsXULDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet)
|
|||
return mStyleSheets.IndexOf(aSheet);
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
|
@ -1133,20 +1149,10 @@ nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count, i;
|
||||
|
||||
count = mPresShells.Count();
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
shell->GetStyleSet(getter_AddRefs(set));
|
||||
if (set) {
|
||||
set->AddDocStyleSheet(aSheet, this);
|
||||
}
|
||||
}
|
||||
AddStyleSheetToStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (i = 0; i < mObservers.Count(); i++) {
|
||||
for (PRInt32 i = 0; i < mObservers.Count(); i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
|
||||
observer->StyleSheetAdded(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(i)) {
|
||||
|
@ -1156,6 +1162,102 @@ nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets)
|
||||
{
|
||||
PRUint32 oldCount;
|
||||
aOldSheets->Count(&oldCount);
|
||||
nsCOMPtr<nsIStyleSheet> sheet;
|
||||
for (PRUint32 i = 0; i < oldCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aOldSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
mStyleSheets.RemoveElement(sheet);
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
RemoveStyleSheetFromStyleSets(sheet);
|
||||
}
|
||||
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
nsIStyleSheet* sheetPtr = sheet.get();
|
||||
NS_RELEASE(sheetPtr);
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 newCount;
|
||||
aNewSheets->Count(&newCount);
|
||||
for (i = 0; i < newCount; i++) {
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
aNewSheets->GetElementAt(i, getter_AddRefs(supp));
|
||||
sheet = do_QueryInterface(supp);
|
||||
if (sheet) {
|
||||
if (sheet == mAttrStyleSheet.get()) { // always first
|
||||
mStyleSheets.InsertElementAt(sheet, 0);
|
||||
}
|
||||
else if (sheet == (nsIHTMLCSSStyleSheet*)mInlineStyleSheet) { // always last
|
||||
mStyleSheets.AppendElement(sheet);
|
||||
}
|
||||
else {
|
||||
if ((nsIHTMLCSSStyleSheet*)mInlineStyleSheet == mStyleSheets.ElementAt(mStyleSheets.Count() - 1)) {
|
||||
// keep attr sheet last
|
||||
mStyleSheets.InsertElementAt(sheet, mStyleSheets.Count() - 1);
|
||||
}
|
||||
else {
|
||||
mStyleSheets.AppendElement(sheet);
|
||||
}
|
||||
|
||||
// Put the style sheet into the XUL cache if the XUL cache is
|
||||
// actually enabled and the document is chrome.
|
||||
if (gXULUtils->UseXULCache() && IsChromeURI(mDocumentURL)) {
|
||||
nsCOMPtr<nsICSSStyleSheet> css = do_QueryInterface(sheet);
|
||||
if (css) {
|
||||
gXULCache->PutStyleSheet(css);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsIStyleSheet* sheetPtr = sheet;
|
||||
NS_ADDREF(sheetPtr);
|
||||
sheet->SetOwningDocument(this);
|
||||
|
||||
PRBool enabled = PR_TRUE;
|
||||
sheet->GetEnabled(enabled);
|
||||
if (enabled) {
|
||||
AddStyleSheetToStyleSets(sheet);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, sheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
|
||||
{
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXULDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
|
@ -1166,20 +1268,10 @@ nsXULDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|||
aSheet->GetEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsCOMPtr<nsIStyleSet> set;
|
||||
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
||||
if (set) {
|
||||
set->RemoveDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
RemoveStyleSheetFromStyleSets(aSheet);
|
||||
|
||||
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
||||
for (index = 0; index < mObservers.Count(); index++) {
|
||||
for (PRInt32 index = 0; index < mObservers.Count(); index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetRemoved(this, aSheet);
|
||||
if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) {
|
||||
|
|
|
@ -188,6 +188,10 @@ public:
|
|||
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
|
||||
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets);
|
||||
void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
|
||||
void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
|
||||
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
|
|
Загрузка…
Ссылка в новой задаче