Back to index

lightning-sunbird  0.9+nobinonly
nsCSSRules.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:ts=2:et:sw=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) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   L. David Baron <dbaron@dbaron.org>
00025  *   Boris Zbarsky <bzbarsky@mit.edu>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 #ifndef nsCSSRules_h_
00041 #define nsCSSRules_h_
00042 
00043 #include "nsCSSRule.h"
00044 #include "nsICSSGroupRule.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsAutoPtr.h"
00047 #include "nsISupportsArray.h"
00048 #include "nsIDOMCSSMediaRule.h"
00049 #include "nsIDOMCSSMozDocumentRule.h"
00050 #include "nsString.h"
00051 
00052 class CSSGroupRuleRuleListImpl;
00053 class nsMediaList;
00054 
00055 #define DECL_STYLE_RULE_INHERIT  \
00056 NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
00057 NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
00058 NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
00059 NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule); \
00060 NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00061 
00062 // inherits from nsCSSRule and also implements methods on nsICSSGroupRule
00063 // so they can be shared between nsCSSMediaRule and nsCSSDocumentRule
00064 class nsCSSGroupRule : public nsCSSRule, public nsICSSGroupRule
00065 {
00066 protected:
00067   nsCSSGroupRule();
00068   nsCSSGroupRule(const nsCSSGroupRule& aCopy);
00069   ~nsCSSGroupRule();
00070 
00071   // implement part of nsIStyleRule and nsICSSRule
00072   DECL_STYLE_RULE_INHERIT
00073 
00074   // to help implement nsIStyleRule
00075 #ifdef DEBUG
00076   NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00077 #endif
00078 
00079 public:
00080   // implement nsICSSGroupRule
00081   NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
00082   NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
00083   NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
00084   NS_IMETHOD EnumerateRulesForwards(nsISupportsArrayEnumFunc aFunc, void * aData) const;
00085   NS_IMETHOD DeleteStyleRuleAt(PRUint32 aIndex);
00086   NS_IMETHOD InsertStyleRulesAt(PRUint32 aIndex, nsISupportsArray* aRules);
00087   NS_IMETHOD ReplaceStyleRule(nsICSSRule *aOld, nsICSSRule *aNew);
00088 
00089 protected:
00090   // to help implement nsIDOMCSSRule
00091   nsresult AppendRulesToCssText(nsAString& aCssText);
00092   // to implement methods on nsIDOMCSSRule
00093   nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
00094   nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
00095 
00096   // to implement common methods on nsIDOMCSSMediaRule and
00097   // nsIDOMCSSMozDocumentRule
00098   nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
00099   nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
00100                       PRUint32* _retval);
00101   nsresult DeleteRule(PRUint32 aIndex);
00102 
00103   nsCOMPtr<nsISupportsArray> mRules;
00104   CSSGroupRuleRuleListImpl* mRuleCollection;
00105 };
00106 
00107 class nsCSSMediaRule : public nsCSSGroupRule,
00108                        public nsIDOMCSSMediaRule
00109 {
00110 public:
00111   nsCSSMediaRule();
00112   nsCSSMediaRule(const nsCSSMediaRule& aCopy);
00113   virtual ~nsCSSMediaRule();
00114 
00115   NS_DECL_ISUPPORTS_INHERITED
00116 
00117   // nsIStyleRule methods
00118 #ifdef DEBUG
00119   NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00120 #endif
00121 
00122   // nsICSSRule methods
00123   NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); //override nsCSSGroupRule
00124   NS_IMETHOD GetType(PRInt32& aType) const;
00125   NS_IMETHOD Clone(nsICSSRule*& aClone) const;
00126 
00127   // nsIDOMCSSRule interface
00128   NS_DECL_NSIDOMCSSRULE
00129 
00130   // nsIDOMCSSMediaRule interface
00131   NS_DECL_NSIDOMCSSMEDIARULE
00132 
00133   // rest of nsICSSGroupRule interface
00134   NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext);
00135 
00136   // @media rule methods
00137   nsresult SetMedia(nsMediaList* aMedia);
00138   
00139 protected:
00140   nsCOMPtr<nsMediaList> mMedia;
00141 };
00142 
00143 class nsCSSDocumentRule : public nsCSSGroupRule,
00144                           public nsIDOMCSSMozDocumentRule
00145 {
00146 public:
00147   nsCSSDocumentRule(void);
00148   nsCSSDocumentRule(const nsCSSDocumentRule& aCopy);
00149   virtual ~nsCSSDocumentRule(void);
00150 
00151   NS_DECL_ISUPPORTS_INHERITED
00152 
00153   // nsIStyleRule methods
00154 #ifdef DEBUG
00155   NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00156 #endif
00157 
00158   // nsICSSRule methods
00159   NS_IMETHOD GetType(PRInt32& aType) const;
00160   NS_IMETHOD Clone(nsICSSRule*& aClone) const;
00161 
00162   // nsIDOMCSSRule interface
00163   NS_DECL_NSIDOMCSSRULE
00164 
00165   // nsIDOMCSSMozDocumentRule interface
00166   NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
00167 
00168   // rest of nsICSSGroupRule interface
00169   NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext);
00170 
00171   enum Function {
00172     eURL,
00173     eURLPrefix,
00174     eDomain
00175   };
00176 
00177   struct URL {
00178     Function func;
00179     nsCString url;
00180     URL *next;
00181 
00182     URL() : next(nsnull) {}
00183     URL(const URL& aOther)
00184       : func(aOther.func)
00185       , url(aOther.url)
00186       , next(aOther.next ? new URL(*aOther.next) : nsnull)
00187     {
00188     }
00189     ~URL() { delete next; }
00190   };
00191 
00192   void SetURLs(URL *aURLs) { mURLs = aURLs; }
00193 
00194 protected:
00195   nsAutoPtr<URL> mURLs; // linked list of |struct URL| above.
00196 };
00197 
00198 
00199 #endif /* !defined(nsCSSRules_h_) */