Back to index

lightning-sunbird  0.9+nobinonly
nsCSSStyleSheet.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 // vim:cindent:tabstop=2:expandtab:shiftwidth=2:
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   L. David Baron <dbaron@dbaron.org>
00025  *   Pierre Phaneuf <pp@ludusdesign.com>
00026  *   Daniel Glazman <glazman@netscape.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #ifndef nsCSSStyleSheet_h_
00043 #define nsCSSStyleSheet_h_
00044 
00045 #include "nscore.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsAutoPtr.h"
00048 #include "nsICSSStyleSheet.h"
00049 #include "nsIDOMCSSStyleSheet.h"
00050 #include "nsICSSLoaderObserver.h"
00051 #include "nsVoidArray.h"
00052 
00053 class nsIURI;
00054 class nsISupportsArray;
00055 class nsMediaList;
00056 
00057 // -------------------------------
00058 // CSS Style Sheet Inner Data Container
00059 //
00060 
00061 class nsCSSStyleSheetInner {
00062 public:
00063   nsCSSStyleSheetInner(nsICSSStyleSheet* aParentSheet);
00064   nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy, nsICSSStyleSheet* aParentSheet);
00065   virtual ~nsCSSStyleSheetInner();
00066 
00067   virtual nsCSSStyleSheetInner* CloneFor(nsICSSStyleSheet* aParentSheet);
00068   virtual void AddSheet(nsICSSStyleSheet* aParentSheet);
00069   virtual void RemoveSheet(nsICSSStyleSheet* aParentSheet);
00070 
00071   virtual void RebuildNameSpaces();
00072 
00073   nsAutoVoidArray        mSheets;
00074   nsCOMPtr<nsIURI>       mSheetURI; // for error reports, etc.
00075   nsCOMPtr<nsIURI>       mOriginalSheetURI;  // for GetHref.  Can be null.
00076   nsCOMPtr<nsIURI>       mBaseURI; // for resolving relative URIs
00077   nsISupportsArray*      mOrderedRules;
00078   nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
00079   PRPackedBool           mComplete;
00080 };
00081 
00082 
00083 // -------------------------------
00084 // CSS Style Sheet
00085 //
00086 
00087 class CSSImportsCollectionImpl;
00088 class CSSRuleListImpl;
00089 static PRBool CascadeSheetRulesInto(nsICSSStyleSheet* aSheet, void* aData);
00090 
00091 class nsCSSStyleSheet : public nsICSSStyleSheet_MOZILLA_1_8_BRANCH, 
00092                         public nsIDOMCSSStyleSheet,
00093                         public nsICSSLoaderObserver
00094 {
00095 public:
00096   nsCSSStyleSheet();
00097 
00098   NS_DECL_ISUPPORTS
00099 
00100   // nsIStyleSheet interface
00101   NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const;
00102   NS_IMETHOD GetBaseURI(nsIURI** aBaseURI) const;
00103   NS_IMETHOD GetTitle(nsString& aTitle) const;
00104   NS_IMETHOD GetType(nsString& aType) const;
00105   NS_IMETHOD_(PRBool) UseForMedium(nsPresContext* aPresContext) const;
00106   NS_IMETHOD_(PRBool) HasRules() const;
00107   NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
00108   NS_IMETHOD SetEnabled(PRBool aEnabled);
00109   NS_IMETHOD GetComplete(PRBool& aComplete) const;
00110   NS_IMETHOD SetComplete();
00111   NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const;  // may be null
00112   NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;  // may be null
00113   NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
00114 #ifdef DEBUG
00115   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00116 #endif
00117   
00118   // nsICSSStyleSheet interface
00119   NS_IMETHOD ContainsStyleSheet(nsIURI* aURL, PRBool& aContains,
00120                                 nsIStyleSheet** aTheChild=nsnull);
00121   NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aSheet);
00122   NS_IMETHOD InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
00123   NS_IMETHOD PrependStyleRule(nsICSSRule* aRule);
00124   NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
00125   NS_IMETHOD ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
00126   NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
00127   NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
00128   NS_IMETHOD DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
00129   NS_IMETHOD InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
00130   NS_IMETHOD ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
00131   NS_IMETHOD StyleSheetCount(PRInt32& aCount) const;
00132   NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
00133   NS_IMETHOD SetURIs(nsIURI* aSheetURI, nsIURI* aBaseURI);
00134   NS_IMETHOD SetTitle(const nsAString& aTitle);
00135   NS_IMETHOD SetMedia(nsMediaList* aMedia);
00136   NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
00137   NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule);
00138   NS_IMETHOD GetOwnerRule(nsICSSImportRule** aOwnerRule);
00139   virtual NS_HIDDEN_(nsXMLNameSpaceMap*) GetNameSpaceMap() const;
00140   NS_IMETHOD Clone(nsICSSStyleSheet* aCloneParent,
00141                    nsICSSImportRule* aCloneOwnerRule,
00142                    nsIDocument* aCloneDocument,
00143                    nsIDOMNode* aCloneOwningNode,
00144                    nsICSSStyleSheet** aClone) const;
00145   NS_IMETHOD IsModified(PRBool* aSheetModified) const;
00146   NS_IMETHOD SetModified(PRBool aModified);
00147   NS_IMETHOD AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
00148   NS_IMETHOD DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
00149 
00150   // nsICSSStyleSheet_MOZILLA_1_8_BRANCH interface
00151   NS_IMETHOD SetURIs18(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
00152                        nsIURI* aBaseURI);
00153 
00154   // nsICSSLoaderObserver interface
00155   NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify);
00156   
00157   nsresult EnsureUniqueInner();
00158 
00159   // nsIDOMStyleSheet interface
00160   NS_DECL_NSIDOMSTYLESHEET
00161 
00162   // nsIDOMCSSStyleSheet interface
00163   NS_DECL_NSIDOMCSSSTYLESHEET
00164 
00165 private:
00166   nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
00167                   nsICSSStyleSheet* aParentToUse,
00168                   nsICSSImportRule* aOwnerRuleToUse,
00169                   nsIDocument* aDocumentToUse,
00170                   nsIDOMNode* aOwningNodeToUse);
00171   
00172   // These are not supported and are not implemented! 
00173   nsCSSStyleSheet(const nsCSSStyleSheet& aCopy); 
00174   nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy); 
00175 
00176 protected:
00177   virtual ~nsCSSStyleSheet();
00178 
00179   void ClearRuleCascades();
00180 
00181   nsresult WillDirty();
00182   void     DidDirty();
00183 
00184 protected:
00185   nsString              mTitle;
00186   nsCOMPtr<nsMediaList> mMedia;
00187   nsCSSStyleSheet*      mFirstChild;
00188   nsCSSStyleSheet*      mNext;
00189   nsICSSStyleSheet*     mParent;    // weak ref
00190   nsICSSImportRule*     mOwnerRule; // weak ref
00191 
00192   CSSImportsCollectionImpl* mImportsCollection;
00193   CSSRuleListImpl*      mRuleCollection;
00194   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
00195   nsIDOMNode*           mOwningNode; // weak ref
00196   PRPackedBool          mDisabled;
00197   PRPackedBool          mDirty; // has been modified 
00198 
00199   nsCSSStyleSheetInner* mInner;
00200 
00201   nsAutoVoidArray*      mRuleProcessors;
00202 
00203   friend class nsMediaList;
00204   friend PRBool CascadeSheetRulesInto(nsICSSStyleSheet* aSheet, void* aData);
00205 };
00206 
00207 #endif /* !defined(nsCSSStyleSheet_h_) */