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 * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * internal abstract interface for containers (roughly origins within
41 * the CSS cascade) that provide style rules matching an element or
45 #ifndef nsIStyleRuleProcessor_h___
46 #define nsIStyleRuleProcessor_h___
50 #include "nsISupports.h"
51 #include "nsPresContext.h" // for nsCompatability
52 #include "nsILinkHandler.h"
54 #include "nsChangeHint.h"
60 class nsICSSPseudoComparator
;
64 // The implementation of the constructor and destructor are currently in
65 // nsCSSRuleProcessor.cpp.
67 struct RuleProcessorData
{
68 RuleProcessorData(nsPresContext
* aPresContext
,
70 nsRuleWalker
* aRuleWalker
,
71 nsCompatibility
* aCompat
= nsnull
);
73 // NOTE: not |virtual|
76 // This should be used for all heap-allocation of RuleProcessorData
77 static RuleProcessorData
* Create(nsPresContext
* aPresContext
,
79 nsRuleWalker
* aRuleWalker
,
80 nsCompatibility aCompat
)
82 if (NS_LIKELY(aPresContext
)) {
83 return new (aPresContext
) RuleProcessorData(aPresContext
, aContent
,
84 aRuleWalker
, &aCompat
);
87 return new RuleProcessorData(aPresContext
, aContent
, aRuleWalker
,
92 nsPresContext
* pc
= mPresContext
;
94 this->~RuleProcessorData();
95 pc
->FreeToShell(sizeof(RuleProcessorData
), this);
102 void* operator new(size_t sz
, RuleProcessorData
* aSlot
) CPP_THROW_NEW
{
106 void* operator new(size_t sz
, nsPresContext
* aContext
) CPP_THROW_NEW
{
107 return aContext
->AllocateFromShell(sz
);
109 void* operator new(size_t sz
) CPP_THROW_NEW
{
110 return ::operator new(sz
);
113 const nsString
* GetLang();
115 // Returns a 1-based index of the child in its parent. If the child
116 // is not in its parent's child list (i.e., it is anonymous content),
118 // If aCheckEdgeOnly is true, the function will return 1 if the result
119 // is 1, and something other than 1 (maybe or maybe not a valid
120 // result) otherwise.
121 PRInt32
GetNthIndex(PRBool aIsOfType
, PRBool aIsFromEnd
,
122 PRBool aCheckEdgeOnly
);
124 nsPresContext
* mPresContext
;
125 nsIContent
* mContent
; // weak ref
126 nsIContent
* mParentContent
; // if content, content->GetParent(); weak ref
127 nsRuleWalker
* mRuleWalker
; // Used to add rules to our results.
128 nsIContent
* mScopedRoot
; // Root of scoped stylesheet (set and unset by the supplier of the scoped stylesheet
130 nsIAtom
* mContentTag
; // if content, then content->GetTag()
131 nsIAtom
* mContentID
; // if styled content, then weak reference to styledcontent->GetID()
132 PRPackedBool mIsHTMLContent
; // if content, then does QI on HTMLContent, true or false
133 PRPackedBool mIsLink
; // if content, calls nsStyleUtil::IsHTMLLink or nsStyleUtil::IsLink
134 PRPackedBool mHasAttributes
; // if content, content->GetAttrCount() > 0
135 nsCompatibility mCompatMode
; // Possibly remove use of this in SelectorMatches?
136 nsLinkState mLinkState
; // if a link, this is the state, otherwise unknown
137 PRInt32 mEventState
; // if content, eventStateMgr->GetContentState()
138 PRInt32 mNameSpaceID
; // if content, content->GetNameSapce()
139 const nsAttrValue
* mClasses
; // if styled content, styledcontent->GetClasses()
140 // mPreviousSiblingData and mParentData are always RuleProcessorData
141 // and never a derived class. They are allocated lazily, when
142 // selectors require matching of prior siblings or ancestors.
143 RuleProcessorData
* mPreviousSiblingData
;
144 RuleProcessorData
* mParentData
;
147 nsAutoString
*mLanguage
; // NULL means we haven't found out the language yet
149 // This node's index for :nth-child(), :nth-last-child(),
150 // :nth-of-type(), :nth-last-of-type(). If -2, needs to be computed.
151 // If -1, needs to be computed but known not to be 1.
152 // If 0, the node is not at any index in its parent.
153 // The first subscript is 0 for -child and 1 for -of-type, the second
154 // subscript is 0 for nth- and 1 for nth-last-.
155 PRInt32 mNthIndices
[2][2];
158 struct ElementRuleProcessorData
: public RuleProcessorData
{
159 ElementRuleProcessorData(nsPresContext
* aPresContext
,
160 nsIContent
* aContent
,
161 nsRuleWalker
* aRuleWalker
)
162 : RuleProcessorData(aPresContext
,aContent
,aRuleWalker
)
164 NS_PRECONDITION(aPresContext
, "null pointer");
165 NS_PRECONDITION(aContent
, "null pointer");
166 NS_PRECONDITION(aRuleWalker
, "null pointer");
170 struct PseudoRuleProcessorData
: public RuleProcessorData
{
171 PseudoRuleProcessorData(nsPresContext
* aPresContext
,
172 nsIContent
* aParentContent
,
174 nsICSSPseudoComparator
* aComparator
,
175 nsRuleWalker
* aRuleWalker
)
176 : RuleProcessorData(aPresContext
, aParentContent
, aRuleWalker
)
178 NS_PRECONDITION(aPresContext
, "null pointer");
179 NS_PRECONDITION(aPseudoTag
, "null pointer");
180 NS_PRECONDITION(aRuleWalker
, "null pointer");
181 mPseudoTag
= aPseudoTag
;
182 mComparator
= aComparator
;
186 nsICSSPseudoComparator
* mComparator
;
189 struct StateRuleProcessorData
: public RuleProcessorData
{
190 StateRuleProcessorData(nsPresContext
* aPresContext
,
191 nsIContent
* aContent
,
193 : RuleProcessorData(aPresContext
, aContent
, nsnull
),
194 mStateMask(aStateMask
)
196 NS_PRECONDITION(aPresContext
, "null pointer");
197 NS_PRECONDITION(aContent
, "null pointer");
199 const PRInt32 mStateMask
; // |HasStateDependentStyle| for which state(s)?
200 // Constants defined in nsIEventStateManager.h .
203 struct AttributeRuleProcessorData
: public RuleProcessorData
{
204 AttributeRuleProcessorData(nsPresContext
* aPresContext
,
205 nsIContent
* aContent
,
209 : RuleProcessorData(aPresContext
, aContent
, nsnull
),
210 mAttribute(aAttribute
),
212 mStateMask(aStateMask
)
214 NS_PRECONDITION(aPresContext
, "null pointer");
215 NS_PRECONDITION(aContent
, "null pointer");
217 nsIAtom
* mAttribute
; // |HasAttributeDependentStyle| for which attribute?
218 PRInt32 mModType
; // The type of modification (see nsIDOMMutationEvent).
219 PRUint32 mStateMask
; // The states that changed with the attr change.
223 // IID for the nsIStyleRuleProcessor interface {015575fe-7b6c-11d3-ba05-001083023c2b}
224 #define NS_ISTYLE_RULE_PROCESSOR_IID \
225 {0x015575fe, 0x7b6c, 0x11d3, {0xba, 0x05, 0x00, 0x10, 0x83, 0x02, 0x3c, 0x2b}}
227 /* The style rule processor interface is a mechanism to separate the matching
228 * of style rules from style sheet instances.
229 * Simple style sheets can and will act as their own processor.
230 * Sheets where rule ordering interlaces between multiple sheets, will need to
231 * share a single rule processor between them (CSS sheets do this for cascading order)
233 * @see nsIStyleRule (for significantly more detailed comments)
235 class nsIStyleRuleProcessor
: public nsISupports
{
237 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID
)
240 // nsCOMArray<nsIStyleRuleProcessor>::nsCOMArrayEnumFunc
241 typedef PRBool (* PR_CALLBACK EnumFunc
)(nsIStyleRuleProcessor
*, void*);
244 * Find the |nsIStyleRule|s matching the given content node and
245 * position the given |nsRuleWalker| at the |nsRuleNode| in the rule
246 * tree representing that ordered list of rules (with higher
247 * precedence being farther from the root of the lexicographic tree).
249 NS_IMETHOD
RulesMatching(ElementRuleProcessorData
* aData
) = 0;
252 * Just like the previous |RulesMatching|, except for a given content
253 * node <em>and pseudo-element</em>.
255 NS_IMETHOD
RulesMatching(PseudoRuleProcessorData
* aData
) = 0;
258 * Return how (as described by nsReStyleHint) style can depend on a
259 * change of the given content state on the given content node. This
260 * test is used for optimization only, and may err on the side of
261 * reporting more dependencies than really exist.
263 * Event states are defined in nsIEventStateManager.h.
265 NS_IMETHOD
HasStateDependentStyle(StateRuleProcessorData
* aData
,
266 nsReStyleHint
* aResult
) = 0;
269 * Return how (as described by nsReStyleHint) style can depend on the
270 * presence or value of the given attribute for the given content
271 * node. This test is used for optimization only, and may err on the
272 * side of reporting more dependencies than really exist.
274 NS_IMETHOD
HasAttributeDependentStyle(AttributeRuleProcessorData
* aData
,
275 nsReStyleHint
* aResult
) = 0;
278 * Do any processing that needs to happen as a result of a change in
279 * the characteristics of the medium, and return whether this rule
280 * processor's rules have changed (e.g., because of media queries).
282 NS_IMETHOD
MediumFeaturesChanged(nsPresContext
* aPresContext
,
283 PRBool
* aRulesChanged
) = 0;
286 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRuleProcessor
,
287 NS_ISTYLE_RULE_PROCESSOR_IID
)
289 #endif /* nsIStyleRuleProcessor_h___ */