Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLStyleSheet.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
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  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 #ifndef nsHTMLStyleSheet_h_
00040 #define nsHTMLStyleSheet_h_
00041 
00042 #include "nsIStyleSheet.h"
00043 #include "nsIStyleRuleProcessor.h"
00044 #include "nsIStyleRule.h"
00045 #include "pldhash.h"
00046 #include "nsCOMPtr.h"
00047 class nsMappedAttributes;
00048 
00049 class nsHTMLStyleSheet : public nsIStyleSheet, public nsIStyleRuleProcessor {
00050 public:
00051   nsHTMLStyleSheet(void);
00052   nsresult Init();
00053 
00054   NS_DECL_ISUPPORTS
00055 
00056   // nsIStyleSheet api
00057   NS_IMETHOD GetSheetURI(nsIURI** aSheetURL) const;
00058   NS_IMETHOD GetBaseURI(nsIURI** aBaseURL) const;
00059   NS_IMETHOD GetTitle(nsString& aTitle) const;
00060   NS_IMETHOD GetType(nsString& aType) const;
00061   NS_IMETHOD_(PRBool) UseForMedium(nsPresContext* aPresContext) const;
00062   NS_IMETHOD_(PRBool) HasRules() const;
00063   NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
00064   NS_IMETHOD SetEnabled(PRBool aEnabled);
00065   NS_IMETHOD GetComplete(PRBool& aComplete) const;
00066   NS_IMETHOD SetComplete();
00067   NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const;  // will be null
00068   NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
00069   NS_IMETHOD SetOwningDocument(nsIDocument* aDocumemt);
00070 #ifdef DEBUG
00071   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00072 #endif
00073 
00074   // nsIStyleRuleProcessor API
00075   NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData);
00076   NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData);
00077   NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
00078                                     nsReStyleHint* aResult);
00079   NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
00080                                         nsReStyleHint* aResult);
00081 
00082   nsresult Init(nsIURI* aURL, nsIDocument* aDocument);
00083   nsresult Reset(nsIURI* aURL);
00084   nsresult GetLinkColor(nscolor& aColor);
00085   nsresult GetActiveLinkColor(nscolor& aColor);
00086   nsresult GetVisitedLinkColor(nscolor& aColor);
00087   nsresult SetLinkColor(nscolor aColor);
00088   nsresult SetActiveLinkColor(nscolor aColor);
00089   nsresult SetVisitedLinkColor(nscolor aColor);
00090 
00091   // Mapped Attribute management methods
00092   already_AddRefed<nsMappedAttributes>
00093     UniqueMappedAttributes(nsMappedAttributes* aMapped);
00094   void DropMappedAttributes(nsMappedAttributes* aMapped);
00095 
00096 
00097 private: 
00098   // These are not supported and are not implemented! 
00099   nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy); 
00100   nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy); 
00101 
00102   ~nsHTMLStyleSheet();
00103 
00104   class HTMLColorRule;
00105   friend class HTMLColorRule;
00106   class HTMLColorRule : public nsIStyleRule {
00107   public:
00108     HTMLColorRule() {}
00109 
00110     NS_DECL_ISUPPORTS
00111 
00112     // nsIStyleRule interface
00113     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00114   #ifdef DEBUG
00115     NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00116   #endif
00117 
00118     nscolor             mColor;
00119   };
00120 
00121 
00122   class GenericTableRule;
00123   friend class GenericTableRule;
00124   class GenericTableRule: public nsIStyleRule {
00125   public:
00126     GenericTableRule() {}
00127 
00128     NS_DECL_ISUPPORTS
00129 
00130     // nsIStyleRule interface
00131     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00132   #ifdef DEBUG
00133     NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00134   #endif
00135   };
00136 
00137   // this rule handles <th> inheritance
00138   class TableTHRule;
00139   friend class TableTHRule;
00140   class TableTHRule: public GenericTableRule {
00141   public:
00142     TableTHRule() {}
00143 
00144     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00145   };
00146 
00147   // this rule handles borders on a <thead>, <tbody>, <tfoot> when rules
00148   // is set on its <table>
00149   class TableTbodyRule;
00150   friend class TableTbodyRule;
00151   class TableTbodyRule: public GenericTableRule {
00152   public:
00153     TableTbodyRule() {}
00154 
00155     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00156   };
00157 
00158   // this rule handles borders on a <row> when rules is set on its <table>
00159   class TableRowRule;
00160   friend class TableRowRule;
00161   class TableRowRule: public GenericTableRule {
00162   public:
00163     TableRowRule() {}
00164 
00165     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00166   };
00167 
00168   // this rule handles borders on a <colgroup> when rules is set on its <table>
00169   class TableColgroupRule;
00170   friend class TableColgroupRule;
00171   class TableColgroupRule: public GenericTableRule {
00172   public:
00173     TableColgroupRule() {}
00174 
00175     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00176   };
00177 
00178   // this rule handles borders on a <col> when rules is set on its <table>.
00179   // This should only be used for <col>s which are in a colgroup or anonymous
00180   // cols.
00181   class TableColRule;
00182   friend class TableColRule;
00183   class TableColRule: public GenericTableRule {
00184   public:
00185     TableColRule() {}
00186 
00187     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00188   };
00189 
00190   // this rule handles borders on a <col> when rules is set on its <table>.
00191   // This should only be used for <col>s which are not in a colgroup.
00192   class TableUngroupedColRule;
00193   friend class TableUngroupedColRule;
00194   class TableUngroupedColRule: public GenericTableRule {
00195   public:
00196     TableUngroupedColRule() {}
00197 
00198     NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00199   };
00200 
00201   nsIURI*              mURL;
00202   nsIDocument*         mDocument;
00203   HTMLColorRule*       mLinkRule;
00204   HTMLColorRule*       mVisitedRule;
00205   HTMLColorRule*       mActiveRule;
00206   HTMLColorRule*       mDocumentColorRule;
00207   TableTbodyRule*      mTableTbodyRule;
00208   TableRowRule*        mTableRowRule;
00209   TableColgroupRule*   mTableColgroupRule;
00210   TableColRule*        mTableColRule;
00211   TableUngroupedColRule* mTableUngroupedColRule;
00212   TableTHRule*         mTableTHRule;
00213 
00214   PLDHashTable         mMappedAttrTable;
00215 };
00216 
00217 // XXX convenience method. Calls Initialize() automatically.
00218 nsresult
00219 NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL, 
00220                      nsIDocument* aDocument);
00221 
00222 nsresult
00223 NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult);
00224 
00225 #endif /* !defined(nsHTMLStyleSheet_h_) */