1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Daniel Glazman <glazman@netscape.com>
24 * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * representation of CSS style rules (selectors+declaration) and CSS
45 #ifndef nsICSSStyleRule_h___
46 #define nsICSSStyleRule_h___
49 #include "nsICSSRule.h"
52 #include "nsCSSProps.h"
53 #include "nsCSSValue.h"
57 class nsCSSDeclaration
;
58 class nsICSSStyleSheet
;
62 nsAtomList(nsIAtom
* aAtom
);
63 nsAtomList(const nsString
& aAtomValue
);
66 /** Do a deep clone. Should be used only on the first in the linked list. */
67 nsAtomList
* Clone() const { return Clone(PR_TRUE
); }
69 nsCOMPtr
<nsIAtom
> mAtom
;
72 nsAtomList
* Clone(PRBool aDeep
) const;
74 // These are not supported and are not implemented!
75 nsAtomList(const nsAtomList
& aCopy
);
76 nsAtomList
& operator=(const nsAtomList
& aCopy
);
79 struct nsPseudoClassList
{
81 nsPseudoClassList(nsIAtom
* aAtom
);
82 nsPseudoClassList(nsIAtom
* aAtom
, const PRUnichar
*aString
);
83 nsPseudoClassList(nsIAtom
* aAtom
, const PRInt32
*aIntPair
);
84 ~nsPseudoClassList(void);
86 /** Do a deep clone. Should be used only on the first in the linked list. */
87 nsPseudoClassList
* Clone() const { return Clone(PR_TRUE
); }
89 nsCOMPtr
<nsIAtom
> mAtom
;
91 // For a given value of mAtom, we have either:
92 // a. no value, which means mMemory is always null
93 // (if neither of the conditions for (b) or (c) is true)
94 // b. a string value, which means mString/mMemory is non-null
95 // (if nsCSSPseudoClasses::HasStringArg(mAtom))
96 // c. an integer pair value, which means mNumbers/mMemory is non-null
97 // (if nsCSSPseudoClasses::HasNthPairArg(mAtom))
98 void* mMemory
; // both pointer types use NS_Alloc/NS_Free
102 nsPseudoClassList
* mNext
;
104 nsPseudoClassList
* Clone(PRBool aDeep
) const;
106 // These are not supported and are not implemented!
107 nsPseudoClassList(const nsPseudoClassList
& aCopy
);
108 nsPseudoClassList
& operator=(const nsPseudoClassList
& aCopy
);
111 #define NS_ATTR_FUNC_SET 0 // [attr]
112 #define NS_ATTR_FUNC_EQUALS 1 // [attr=value]
113 #define NS_ATTR_FUNC_INCLUDES 2 // [attr~=value] (space separated)
114 #define NS_ATTR_FUNC_DASHMATCH 3 // [attr|=value] ('-' truncated)
115 #define NS_ATTR_FUNC_BEGINSMATCH 4 // [attr^=value] (begins with)
116 #define NS_ATTR_FUNC_ENDSMATCH 5 // [attr$=value] (ends with)
117 #define NS_ATTR_FUNC_CONTAINSMATCH 6 // [attr*=value] (contains substring)
119 struct nsAttrSelector
{
121 nsAttrSelector(PRInt32 aNameSpace
, const nsString
& aAttr
);
122 nsAttrSelector(PRInt32 aNameSpace
, const nsString
& aAttr
, PRUint8 aFunction
,
123 const nsString
& aValue
, PRBool aCaseSensitive
);
124 nsAttrSelector(PRInt32 aNameSpace
, nsIAtom
* aAttr
, PRUint8 aFunction
,
125 const nsString
& aValue
, PRBool aCaseSensitive
);
126 ~nsAttrSelector(void);
128 /** Do a deep clone. Should be used only on the first in the linked list. */
129 nsAttrSelector
* Clone() const { return Clone(PR_TRUE
); }
132 nsCOMPtr
<nsIAtom
> mAttr
;
134 PRPackedBool mCaseSensitive
;
136 nsAttrSelector
* mNext
;
138 nsAttrSelector
* Clone(PRBool aDeep
) const;
140 // These are not supported and are not implemented!
141 nsAttrSelector(const nsAttrSelector
& aCopy
);
142 nsAttrSelector
& operator=(const nsAttrSelector
& aCopy
);
145 struct nsCSSSelector
{
148 ~nsCSSSelector(void);
150 /** Do a deep clone. Should be used only on the first in the linked list. */
151 nsCSSSelector
* Clone() const { return Clone(PR_TRUE
, PR_TRUE
); }
154 void SetNameSpace(PRInt32 aNameSpace
);
155 void SetTag(const nsString
& aTag
);
156 void AddID(const nsString
& aID
);
157 void AddClass(const nsString
& aClass
);
158 void AddPseudoClass(nsIAtom
* aPseudoClass
);
159 void AddPseudoClass(nsIAtom
* aPseudoClass
, const PRUnichar
* aString
);
160 void AddPseudoClass(nsIAtom
* aPseudoClass
, const PRInt32
* aIntPair
);
161 void AddAttribute(PRInt32 aNameSpace
, const nsString
& aAttr
);
162 void AddAttribute(PRInt32 aNameSpace
, const nsString
& aAttr
, PRUint8 aFunc
,
163 const nsString
& aValue
, PRBool aCaseSensitive
);
164 void SetOperator(PRUnichar aOperator
);
166 PRInt32
CalcWeight(void) const;
168 void ToString(nsAString
& aString
, nsICSSStyleSheet
* aSheet
,
169 PRBool aAppend
= PR_FALSE
) const;
172 void AddPseudoClassInternal(nsPseudoClassList
*aPseudoClass
);
173 nsCSSSelector
* Clone(PRBool aDeepNext
, PRBool aDeepNegations
) const;
175 void AppendNegationToString(nsAString
& aString
);
176 void ToStringInternal(nsAString
& aString
, nsICSSStyleSheet
* aSheet
,
177 PRBool aIsPseudoElem
,
178 PRBool aIsNegated
) const;
179 // Returns true if this selector can have a namespace specified (which
180 // happens if and only if the default namespace would apply to this
182 PRBool
CanBeNamespaced(PRBool aIsNegated
) const;
186 nsCOMPtr
<nsIAtom
> mTag
;
188 nsAtomList
* mClassList
;
189 nsPseudoClassList
* mPseudoClassList
; // atom for the pseudo, string for
190 // the argument to functional pseudos
191 nsAttrSelector
* mAttrList
;
193 nsCSSSelector
* mNegations
;
195 nsCSSSelector
* mNext
;
197 // These are not supported and are not implemented!
198 nsCSSSelector(const nsCSSSelector
& aCopy
);
199 nsCSSSelector
& operator=(const nsCSSSelector
& aCopy
);
203 * A selector list is the unit of selectors that each style rule has.
204 * For example, "P B, H1 B { ... }" would be a selector list with two
205 * items (where each |nsCSSSelectorList| object's |mSelectors| has
206 * an |mNext| for the P or H1). We represent them as linked lists.
208 struct nsCSSSelectorList
{
209 nsCSSSelectorList(void);
210 ~nsCSSSelectorList(void);
213 * Push the selector pointed to by |aSelector| on to the beginning of
214 * |mSelectors|, setting its |mNext| to the current value of |mSelectors|.
215 * This nulls out aSelector.
217 * The caller is responsible for updating |mWeight|.
219 void AddSelector(nsAutoPtr
<nsCSSSelector
>& aSelector
);
222 * Should be used only on the first in the list
224 void ToString(nsAString
& aResult
, nsICSSStyleSheet
* aSheet
);
227 * Do a deep clone. Should be used only on the first in the list.
229 nsCSSSelectorList
* Clone() const { return Clone(PR_TRUE
); }
231 nsCSSSelector
* mSelectors
;
233 nsCSSSelectorList
* mNext
;
235 nsCSSSelectorList
* Clone(PRBool aDeep
) const;
237 // These are not supported and are not implemented!
238 nsCSSSelectorList(const nsCSSSelectorList
& aCopy
);
239 nsCSSSelectorList
& operator=(const nsCSSSelectorList
& aCopy
);
242 // IID for the nsICSSStyleRule interface {00803ccc-66e8-4ec8-a037-45e901bb5304}
243 #define NS_ICSS_STYLE_RULE_IID \
244 {0x00803ccc, 0x66e8, 0x4ec8, {0xa0, 0x37, 0x45, 0xe9, 0x01, 0xbb, 0x53, 0x04}}
246 class nsICSSStyleRule
: public nsICSSRule
{
248 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_IID
)
250 // null for style attribute
251 virtual nsCSSSelectorList
* Selector(void) = 0;
253 virtual PRUint32
GetLineNumber(void) const = 0;
254 virtual void SetLineNumber(PRUint32 aLineNumber
) = 0;
256 virtual nsCSSDeclaration
* GetDeclaration(void) const = 0;
259 * Return a new |nsIStyleRule| instance that replaces the current one,
260 * due to a change in the |nsCSSDeclaration|. Due to the
261 * |nsIStyleRule| contract of immutability, this must be called if the
262 * declaration is modified.
264 * |DeclarationChanged| handles replacing the object in the container
265 * sheet or group rule if |aHandleContainer| is true.
267 virtual already_AddRefed
<nsICSSStyleRule
>
268 DeclarationChanged(PRBool aHandleContainer
) = 0;
270 virtual already_AddRefed
<nsIStyleRule
> GetImportantRule(void) = 0;
272 // hooks for DOM rule
273 virtual nsresult
GetCssText(nsAString
& aCssText
) = 0;
274 virtual nsresult
SetCssText(const nsAString
& aCssText
) = 0;
275 virtual nsresult
GetParentStyleSheet(nsICSSStyleSheet
** aSheet
) = 0;
276 virtual nsresult
GetParentRule(nsICSSGroupRule
** aParentRule
) = 0;
277 virtual nsresult
GetSelectorText(nsAString
& aSelectorText
) = 0;
278 virtual nsresult
SetSelectorText(const nsAString
& aSelectorText
) = 0;
281 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSStyleRule
, NS_ICSS_STYLE_RULE_IID
)
284 NS_NewCSSStyleRule(nsICSSStyleRule
** aInstancePtrResult
,
285 nsCSSSelectorList
* aSelector
,
286 nsCSSDeclaration
* aDeclaration
);
288 #endif /* nsICSSStyleRule_h___ */