Back to index

lightning-sunbird  0.9+nobinonly
nsICSSStyleRule.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Daniel Glazman <glazman@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsICSSStyleRule_h___
00039 #define nsICSSStyleRule_h___
00040 
00041 //#include <stdio.h>
00042 #include "nsICSSRule.h"
00043 #include "nsString.h"
00044 #include "nsCOMPtr.h"
00045 #include "nsCSSProps.h"
00046 #include "nsCSSValue.h"
00047 #include "nsIAtom.h"
00048 
00049 class nsIAtom;
00050 class nsCSSDeclaration;
00051 class nsICSSStyleSheet;
00052 
00053 struct nsAtomList {
00054 public:
00055   nsAtomList(nsIAtom* aAtom);
00056   nsAtomList(const nsString& aAtomValue);
00057   ~nsAtomList(void);
00058 
00060   nsAtomList* Clone() const { return Clone(PR_TRUE); }
00061 
00062   nsCOMPtr<nsIAtom> mAtom;
00063   nsAtomList*       mNext;
00064 private: 
00065   nsAtomList* Clone(PRBool aDeep) const;
00066 
00067   // These are not supported and are not implemented! 
00068   nsAtomList(const nsAtomList& aCopy);
00069   nsAtomList& operator=(const nsAtomList& aCopy); 
00070 };
00071 
00072 struct nsAtomStringList {
00073 public:
00074   nsAtomStringList(nsIAtom* aAtom, const PRUnichar *aString = nsnull);
00075   nsAtomStringList(const nsString& aAtomValue, const PRUnichar *aString = nsnull);
00076   ~nsAtomStringList(void);
00077 
00079   nsAtomStringList* Clone() const { return Clone(PR_TRUE); }
00080 
00081   nsCOMPtr<nsIAtom> mAtom;
00082   PRUnichar*        mString;
00083   nsAtomStringList* mNext;
00084 private: 
00085   nsAtomStringList* Clone(PRBool aDeep) const;
00086 
00087   // These are not supported and are not implemented! 
00088   nsAtomStringList(const nsAtomStringList& aCopy);
00089   nsAtomStringList& operator=(const nsAtomStringList& aCopy); 
00090 };
00091 
00092 #define NS_ATTR_FUNC_SET        0     // [attr]
00093 #define NS_ATTR_FUNC_EQUALS     1     // [attr=value]
00094 #define NS_ATTR_FUNC_INCLUDES   2     // [attr~=value] (space separated)
00095 #define NS_ATTR_FUNC_DASHMATCH  3     // [attr|=value] ('-' truncated)
00096 #define NS_ATTR_FUNC_BEGINSMATCH  4   // [attr^=value] (begins with)
00097 #define NS_ATTR_FUNC_ENDSMATCH  5     // [attr$=value] (ends with)
00098 #define NS_ATTR_FUNC_CONTAINSMATCH 6  // [attr*=value] (contains substring)
00099 
00100 struct nsAttrSelector {
00101 public:
00102   nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr);
00103   nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunction, 
00104                  const nsString& aValue, PRBool aCaseSensitive);
00105   nsAttrSelector(PRInt32 aNameSpace, nsIAtom* aAttr, PRUint8 aFunction, 
00106                  const nsString& aValue, PRBool aCaseSensitive);
00107   ~nsAttrSelector(void);
00108 
00110   nsAttrSelector* Clone() const { return Clone(PR_TRUE); }
00111 
00112   PRInt32         mNameSpace;
00113   nsCOMPtr<nsIAtom> mAttr;
00114   PRUint8         mFunction;
00115   PRPackedBool    mCaseSensitive;
00116   nsString        mValue;
00117   nsAttrSelector* mNext;
00118 private: 
00119   nsAttrSelector* Clone(PRBool aDeep) const;
00120 
00121   // These are not supported and are not implemented! 
00122   nsAttrSelector(const nsAttrSelector& aCopy);
00123   nsAttrSelector& operator=(const nsAttrSelector& aCopy); 
00124 };
00125 
00126 struct nsCSSSelector {
00127 public:
00128   nsCSSSelector(void);
00129   ~nsCSSSelector(void);
00130 
00132   nsCSSSelector* Clone() const { return Clone(PR_TRUE, PR_TRUE); }
00133 
00134   void Reset(void);
00135   void SetNameSpace(PRInt32 aNameSpace);
00136   void SetTag(const nsString& aTag);
00137   void AddID(const nsString& aID);
00138   void AddClass(const nsString& aClass);
00139   void AddPseudoClass(const nsString& aPseudoClass, const PRUnichar* aString = nsnull);
00140   void AddPseudoClass(nsIAtom* aPseudoClass, const PRUnichar* aString = nsnull);
00141   void AddAttribute(PRInt32 aNameSpace, const nsString& aAttr);
00142   void AddAttribute(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunc, 
00143                     const nsString& aValue, PRBool aCaseSensitive);
00144   void SetOperator(PRUnichar aOperator);
00145 
00146   PRInt32 CalcWeight(void) const;
00147 
00148   void ToString(nsAString& aString, nsICSSStyleSheet* aSheet,
00149                 PRBool aAppend = PR_FALSE) const;
00150 
00151 private:
00152   nsCSSSelector* Clone(PRBool aDeepNext, PRBool aDeepNegations) const;
00153 
00154   void AppendNegationToString(nsAString& aString);
00155   void ToStringInternal(nsAString& aString, nsICSSStyleSheet* aSheet,
00156                         PRBool aIsPseudoElem,
00157                         PRIntn aNegatedIndex) const;
00158 
00159 public:
00160   PRInt32         mNameSpace;
00161   nsCOMPtr<nsIAtom> mTag;
00162   nsAtomList*     mIDList;
00163   nsAtomList*     mClassList;
00164   nsAtomStringList* mPseudoClassList; // atom for the pseudo, string for
00165                                       // the argument to functional pseudos
00166   nsAttrSelector* mAttrList;
00167   PRUnichar       mOperator;
00168   nsCSSSelector*  mNegations;
00169 
00170   nsCSSSelector*  mNext;
00171 private: 
00172   // These are not supported and are not implemented! 
00173   nsCSSSelector(const nsCSSSelector& aCopy);
00174   nsCSSSelector& operator=(const nsCSSSelector& aCopy); 
00175 };
00176 
00183 struct nsCSSSelectorList {
00184   nsCSSSelectorList(void);
00185   ~nsCSSSelectorList(void);
00186 
00193   void AddSelector(const nsCSSSelector& aSelector);
00194 
00198   void ToString(nsAString& aResult, nsICSSStyleSheet* aSheet);
00199 
00203   nsCSSSelectorList* Clone() const { return Clone(PR_TRUE); }
00204 
00205   nsCSSSelector*     mSelectors;
00206   PRInt32            mWeight;
00207   nsCSSSelectorList* mNext;
00208 private: 
00209   nsCSSSelectorList* Clone(PRBool aDeep) const;
00210 
00211   // These are not supported and are not implemented! 
00212   nsCSSSelectorList(const nsCSSSelectorList& aCopy);
00213   nsCSSSelectorList& operator=(const nsCSSSelectorList& aCopy); 
00214 };
00215 
00216 // IID for the nsICSSStyleRule interface {00803ccc-66e8-4ec8-a037-45e901bb5304}
00217 #define NS_ICSS_STYLE_RULE_IID     \
00218 {0x00803ccc, 0x66e8, 0x4ec8, {0xa0, 0x37, 0x45, 0xe9, 0x01, 0xbb, 0x53, 0x04}}
00219 
00220 class nsICSSStyleRule : public nsICSSRule {
00221 public:
00222   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_IID)
00223 
00224   // null for style attribute
00225   virtual nsCSSSelectorList* Selector(void) = 0;
00226 
00227   virtual PRUint32 GetLineNumber(void) const = 0;
00228   virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
00229 
00230   virtual nsCSSDeclaration* GetDeclaration(void) const = 0;
00231 
00241   virtual already_AddRefed<nsICSSStyleRule>
00242     DeclarationChanged(PRBool aHandleContainer) = 0;
00243 
00244   virtual already_AddRefed<nsIStyleRule> GetImportantRule(void) = 0;
00245 
00246   // hooks for DOM rule
00247   virtual nsresult GetCssText(nsAString& aCssText) = 0;
00248   virtual nsresult SetCssText(const nsAString& aCssText) = 0;
00249   virtual nsresult GetParentStyleSheet(nsICSSStyleSheet** aSheet) = 0;
00250   virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule) = 0;
00251   virtual nsresult GetSelectorText(nsAString& aSelectorText) = 0;
00252   virtual nsresult SetSelectorText(const nsAString& aSelectorText) = 0;
00253 };
00254 
00255 nsresult
00256 NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
00257                    nsCSSSelectorList* aSelector,
00258                    nsCSSDeclaration* aDeclaration);
00259 
00260 #endif /* nsICSSStyleRule_h___ */