diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index f337039727ef..f681e74f974c 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -482,16 +482,60 @@ NS_IMETHODIMP nsHTMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult
return NS_OK;
}
-void nsHTMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet)
+void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook for sheet ordering
{
- if ((nsnull != mStyleAttrStyleSheet) && (aSheet != mStyleAttrStyleSheet)) {
- aSet->InsertDocStyleSheetAfter(aSheet, mStyleAttrStyleSheet);
+ if (aSheet == mAttrStyleSheet) { // always first
+ mStyleSheets.InsertElementAt(aSheet, 0);
+ }
+ else if (aSheet == mStyleAttrStyleSheet) { // always last
+ mStyleSheets.AppendElement(aSheet);
}
else {
- aSet->InsertDocStyleSheetBefore(aSheet, nsnull); // put it in front
+ if (mStyleAttrStyleSheet == mStyleSheets.ElementAt(mStyleSheets.Count() - 1)) {
+ // keep attr sheet last
+ mStyleSheets.InsertElementAt(aSheet, mStyleSheets.Count() - 1);
+ }
+ else {
+ mStyleSheets.AppendElement(aSheet);
+ }
}
}
+NS_IMETHODIMP
+nsHTMLDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify)
+{
+ NS_PRECONDITION(nsnull != aSheet, "null ptr");
+ mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet
+
+ NS_ADDREF(aSheet);
+ aSheet->SetOwningDocument(this);
+
+ PRBool enabled = PR_TRUE;
+ aSheet->GetEnabled(enabled);
+
+ PRInt32 count;
+ PRInt32 index;
+ if (enabled) {
+ count = mPresShells.Count();
+ for (index = 0; index < count; index++) {
+ nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
+ nsIStyleSet* set = shell->GetStyleSet();
+ if (nsnull != set) {
+ set->AddDocStyleSheet(aSheet, this);
+ NS_RELEASE(set);
+ }
+ }
+ }
+ if (aNotify) { // notify here even if disabled, there may have been others that weren't notified
+ count = mObservers.Count();
+ for (index = 0; index < count; index++) {
+ nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
+ observer->StyleSheetAdded(this, aSheet);
+ }
+ }
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsHTMLDocument::GetBaseURL(nsIURL*& aURL) const
@@ -573,6 +617,37 @@ nsHTMLDocument::SetDTDMode(nsDTDMode aMode)
return NS_OK;
}
+NS_IMETHODIMP
+nsHTMLDocument::SetHeaderData(nsIAtom* aHeaderField, const nsString& aData)
+{
+ nsresult result = nsMarkupDocument::SetHeaderData(aHeaderField, aData);
+
+ if (NS_SUCCEEDED(result)) {
+ if (aHeaderField == nsHTMLAtoms::headerDefaultStyle) {
+ // switch alternate style sheets based on default
+ nsAutoString type;
+ nsAutoString title;
+ nsAutoString textHtml("text/html");
+ PRInt32 index;
+ PRInt32 count = mStyleSheets.Count();
+ for (index = 0; index < count; index++) {
+ nsIStyleSheet* sheet = (nsIStyleSheet*)mStyleSheets.ElementAt(index);
+ sheet->GetType(type);
+ if (PR_FALSE == type.Equals(textHtml)) {
+ sheet->GetTitle(title);
+ if (0 < title.Length()) { // if sheet has title
+ PRBool disabled = ((0 == aData.Length()) ||
+ (PR_FALSE == aData.EqualsIgnoreCase(title)));
+ SetStyleSheetDisabledState(sheet, disabled);
+ }
+ }
+ }
+ }
+ }
+ return result;
+}
+
+
NS_IMETHODIMP
nsHTMLDocument::ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer)
diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h
index cacc08e82470..6fd2d6765bb6 100644
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -64,6 +64,8 @@ public:
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet);
NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet);
+ NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
+
NS_IMETHOD GetBaseURL(nsIURL*& aURL) const;
NS_IMETHOD SetBaseURL(const nsString& aURLSpec);
NS_IMETHOD GetBaseTarget(nsString& aTarget) const;
@@ -72,6 +74,8 @@ public:
NS_IMETHOD GetDTDMode(nsDTDMode& aMode);
NS_IMETHOD SetDTDMode(nsDTDMode aMode);
+ NS_IMETHOD SetHeaderData(nsIAtom* aHeaderField, const nsString& aData);
+
NS_IMETHOD ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
NS_IMETHOD ContentInserted(nsIContent* aContainer,
@@ -155,7 +159,7 @@ protected:
void DeleteNamedItems();
nsIContent *MatchName(nsIContent *aContent, const nsString& aName);
- virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);
+ virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet);
static PRBool MatchLinks(nsIContent *aContent);
static PRBool MatchAnchors(nsIContent *aContent);
diff --git a/layout/html/document/src/nsHTMLDocument.cpp b/layout/html/document/src/nsHTMLDocument.cpp
index f337039727ef..f681e74f974c 100644
--- a/layout/html/document/src/nsHTMLDocument.cpp
+++ b/layout/html/document/src/nsHTMLDocument.cpp
@@ -482,16 +482,60 @@ NS_IMETHODIMP nsHTMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult
return NS_OK;
}
-void nsHTMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet)
+void nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook for sheet ordering
{
- if ((nsnull != mStyleAttrStyleSheet) && (aSheet != mStyleAttrStyleSheet)) {
- aSet->InsertDocStyleSheetAfter(aSheet, mStyleAttrStyleSheet);
+ if (aSheet == mAttrStyleSheet) { // always first
+ mStyleSheets.InsertElementAt(aSheet, 0);
+ }
+ else if (aSheet == mStyleAttrStyleSheet) { // always last
+ mStyleSheets.AppendElement(aSheet);
}
else {
- aSet->InsertDocStyleSheetBefore(aSheet, nsnull); // put it in front
+ if (mStyleAttrStyleSheet == mStyleSheets.ElementAt(mStyleSheets.Count() - 1)) {
+ // keep attr sheet last
+ mStyleSheets.InsertElementAt(aSheet, mStyleSheets.Count() - 1);
+ }
+ else {
+ mStyleSheets.AppendElement(aSheet);
+ }
}
}
+NS_IMETHODIMP
+nsHTMLDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify)
+{
+ NS_PRECONDITION(nsnull != aSheet, "null ptr");
+ mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet
+
+ NS_ADDREF(aSheet);
+ aSheet->SetOwningDocument(this);
+
+ PRBool enabled = PR_TRUE;
+ aSheet->GetEnabled(enabled);
+
+ PRInt32 count;
+ PRInt32 index;
+ if (enabled) {
+ count = mPresShells.Count();
+ for (index = 0; index < count; index++) {
+ nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
+ nsIStyleSet* set = shell->GetStyleSet();
+ if (nsnull != set) {
+ set->AddDocStyleSheet(aSheet, this);
+ NS_RELEASE(set);
+ }
+ }
+ }
+ if (aNotify) { // notify here even if disabled, there may have been others that weren't notified
+ count = mObservers.Count();
+ for (index = 0; index < count; index++) {
+ nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
+ observer->StyleSheetAdded(this, aSheet);
+ }
+ }
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsHTMLDocument::GetBaseURL(nsIURL*& aURL) const
@@ -573,6 +617,37 @@ nsHTMLDocument::SetDTDMode(nsDTDMode aMode)
return NS_OK;
}
+NS_IMETHODIMP
+nsHTMLDocument::SetHeaderData(nsIAtom* aHeaderField, const nsString& aData)
+{
+ nsresult result = nsMarkupDocument::SetHeaderData(aHeaderField, aData);
+
+ if (NS_SUCCEEDED(result)) {
+ if (aHeaderField == nsHTMLAtoms::headerDefaultStyle) {
+ // switch alternate style sheets based on default
+ nsAutoString type;
+ nsAutoString title;
+ nsAutoString textHtml("text/html");
+ PRInt32 index;
+ PRInt32 count = mStyleSheets.Count();
+ for (index = 0; index < count; index++) {
+ nsIStyleSheet* sheet = (nsIStyleSheet*)mStyleSheets.ElementAt(index);
+ sheet->GetType(type);
+ if (PR_FALSE == type.Equals(textHtml)) {
+ sheet->GetTitle(title);
+ if (0 < title.Length()) { // if sheet has title
+ PRBool disabled = ((0 == aData.Length()) ||
+ (PR_FALSE == aData.EqualsIgnoreCase(title)));
+ SetStyleSheetDisabledState(sheet, disabled);
+ }
+ }
+ }
+ }
+ }
+ return result;
+}
+
+
NS_IMETHODIMP
nsHTMLDocument::ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer)
diff --git a/layout/html/document/src/nsHTMLDocument.h b/layout/html/document/src/nsHTMLDocument.h
index cacc08e82470..6fd2d6765bb6 100644
--- a/layout/html/document/src/nsHTMLDocument.h
+++ b/layout/html/document/src/nsHTMLDocument.h
@@ -64,6 +64,8 @@ public:
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet);
NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aStyleSheet);
+ NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
+
NS_IMETHOD GetBaseURL(nsIURL*& aURL) const;
NS_IMETHOD SetBaseURL(const nsString& aURLSpec);
NS_IMETHOD GetBaseTarget(nsString& aTarget) const;
@@ -72,6 +74,8 @@ public:
NS_IMETHOD GetDTDMode(nsDTDMode& aMode);
NS_IMETHOD SetDTDMode(nsDTDMode aMode);
+ NS_IMETHOD SetHeaderData(nsIAtom* aHeaderField, const nsString& aData);
+
NS_IMETHOD ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
NS_IMETHOD ContentInserted(nsIContent* aContainer,
@@ -155,7 +159,7 @@ protected:
void DeleteNamedItems();
nsIContent *MatchName(nsIContent *aContent, const nsString& aName);
- virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);
+ virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet);
static PRBool MatchLinks(nsIContent *aContent);
static PRBool MatchAnchors(nsIContent *aContent);