Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / layout / style / nsRuleNode.h
blob1aee6a2177c76ebe855d023be205d9de2494d039
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
13 * License.
15 * The Original Code is Mozilla Communicator client 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.
22 * Contributor(s):
23 * Original Author: David W. Hyatt (hyatt@netscape.com)
24 * L. David Baron <dbaron@dbaron.org>
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 * a node in the lexicographic tree of rules that match an element,
42 * responsible for converting the rules' information into computed style
45 #ifndef nsRuleNode_h___
46 #define nsRuleNode_h___
48 #include "nsPresContext.h"
49 #include "nsStyleStruct.h"
51 class nsStyleContext;
52 struct PLDHashTable;
53 class nsILanguageAtomService;
54 struct nsRuleData;
55 class nsIStyleRule;
56 struct nsCSSStruct;
57 struct nsCSSValueList;
58 // Copy of typedef that's in nsCSSStruct.h, for compilation speed.
59 typedef nsCSSStruct nsRuleDataStruct;
61 struct nsRuleDataFont;
62 class nsCSSValue;
63 struct nsCSSRect;
65 struct nsInheritedStyleData
68 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args) \
69 nsStyle##name * m##name##Data;
70 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args)
72 #include "nsStyleStructList.h"
74 #undef STYLE_STRUCT_INHERITED
75 #undef STYLE_STRUCT_RESET
77 void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
78 return aContext->AllocateFromShell(sz);
81 void ClearInheritedData(PRUint32 aBits) {
82 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args) \
83 if (m##name##Data && (aBits & NS_STYLE_INHERIT_BIT(name))) \
84 m##name##Data = nsnull;
85 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args)
87 #include "nsStyleStructList.h"
89 #undef STYLE_STRUCT_INHERITED
90 #undef STYLE_STRUCT_RESET
93 void Destroy(PRUint32 aBits, nsPresContext* aContext) {
94 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args) \
95 if (m##name##Data && !(aBits & NS_STYLE_INHERIT_BIT(name))) \
96 m##name##Data->Destroy(aContext);
97 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args)
99 #include "nsStyleStructList.h"
101 #undef STYLE_STRUCT_INHERITED
102 #undef STYLE_STRUCT_RESET
104 aContext->FreeToShell(sizeof(nsInheritedStyleData), this);
107 nsInheritedStyleData() {
108 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args) \
109 m##name##Data = nsnull;
110 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args)
112 #include "nsStyleStructList.h"
114 #undef STYLE_STRUCT_INHERITED
115 #undef STYLE_STRUCT_RESET
120 struct nsResetStyleData
122 nsResetStyleData()
124 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args) \
125 m##name##Data = nsnull;
126 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args)
128 #include "nsStyleStructList.h"
130 #undef STYLE_STRUCT_RESET
131 #undef STYLE_STRUCT_INHERITED
134 void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
135 return aContext->AllocateFromShell(sz);
138 void ClearInheritedData(PRUint32 aBits) {
139 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args) \
140 if (m##name##Data && (aBits & NS_STYLE_INHERIT_BIT(name))) \
141 m##name##Data = nsnull;
142 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args)
144 #include "nsStyleStructList.h"
146 #undef STYLE_STRUCT_RESET
147 #undef STYLE_STRUCT_INHERITED
150 void Destroy(PRUint32 aBits, nsPresContext* aContext) {
151 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args) \
152 if (m##name##Data && !(aBits & NS_STYLE_INHERIT_BIT(name))) \
153 m##name##Data->Destroy(aContext);
154 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args)
156 #include "nsStyleStructList.h"
158 #undef STYLE_STRUCT_RESET
159 #undef STYLE_STRUCT_INHERITED
161 aContext->FreeToShell(sizeof(nsResetStyleData), this);
164 #define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args) \
165 nsStyle##name * m##name##Data;
166 #define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args)
168 #include "nsStyleStructList.h"
170 #undef STYLE_STRUCT_RESET
171 #undef STYLE_STRUCT_INHERITED
175 struct nsCachedStyleData
177 struct StyleStructInfo {
178 ptrdiff_t mCachedStyleDataOffset;
179 ptrdiff_t mInheritResetOffset;
180 PRBool mIsReset;
183 static StyleStructInfo gInfo[];
185 nsInheritedStyleData* mInheritedData;
186 nsResetStyleData* mResetData;
188 static PRBool IsReset(const nsStyleStructID& aSID) {
189 return gInfo[aSID].mIsReset;
192 static PRUint32 GetBitForSID(const nsStyleStructID& aSID) {
193 return 1 << aSID;
196 NS_HIDDEN_(void*) NS_FASTCALL GetStyleData(const nsStyleStructID& aSID) {
197 // Each struct is stored at this.m##type##Data->m##name##Data where
198 // |type| is either Inherit or Reset, and |name| is the name of the
199 // style struct. The |gInfo| stores the offset of the appropriate
200 // m##type##Data for the struct within nsCachedStyleData (|this|)
201 // and the offset of the appropriate m##name##Data within the
202 // m##type##Data. Note that if we don't have any reset structs,
203 // then mResetData is null, and likewise for mInheritedData. This
204 // saves us from having to go through the long if-else cascade into
205 // which most compilers will turn a case statement.
207 // NOTE: nsStyleContext::SetStyle works roughly the same way.
209 const StyleStructInfo& info = gInfo[aSID];
211 // Get either &mInheritedData or &mResetData.
212 char* resetOrInheritSlot = reinterpret_cast<char*>(this) + info.mCachedStyleDataOffset;
214 // Get either mInheritedData or mResetData.
215 char* resetOrInherit = reinterpret_cast<char*>(*reinterpret_cast<void**>(resetOrInheritSlot));
217 void* data = nsnull;
218 if (resetOrInherit) {
219 // If we have the mInheritedData or mResetData, then we might have
220 // the struct, so get it.
221 char* dataSlot = resetOrInherit + info.mInheritResetOffset;
222 data = *reinterpret_cast<void**>(dataSlot);
224 return data;
227 // Typesafe and faster versions of the above
228 #define STYLE_STRUCT_INHERITED(name_, checkdata_cb_, ctor_args_) \
229 NS_HIDDEN_(nsStyle##name_ *) NS_FASTCALL GetStyle##name_ () { \
230 return mInheritedData ? mInheritedData->m##name_##Data : nsnull; \
232 #define STYLE_STRUCT_RESET(name_, checkdata_cb_, ctor_args_) \
233 NS_HIDDEN_(nsStyle##name_ *) NS_FASTCALL GetStyle##name_ () { \
234 return mResetData ? mResetData->m##name_##Data : nsnull; \
236 #include "nsStyleStructList.h"
237 #undef STYLE_STRUCT_RESET
238 #undef STYLE_STRUCT_INHERITED
240 NS_HIDDEN_(void) ClearInheritedData(PRUint32 aBits) {
241 if (mResetData)
242 mResetData->ClearInheritedData(aBits);
243 if (mInheritedData)
244 mInheritedData->ClearInheritedData(aBits);
247 NS_HIDDEN_(void) Destroy(PRUint32 aBits, nsPresContext* aContext) {
248 if (mResetData)
249 mResetData->Destroy(aBits, aContext);
250 if (mInheritedData)
251 mInheritedData->Destroy(aBits, aContext);
252 mResetData = nsnull;
253 mInheritedData = nsnull;
256 nsCachedStyleData() :mInheritedData(nsnull), mResetData(nsnull) {}
257 ~nsCachedStyleData() {}
261 * nsRuleNode is a node in a lexicographic tree (the "rule tree")
262 * indexed by style rules (implementations of nsIStyleRule).
264 * The rule tree is owned by the nsStyleSet and is destroyed when the
265 * presentation of the document goes away. It is garbage-collected
266 * (using mark-and-sweep garbage collection) during the lifetime of the
267 * document (when dynamic changes cause the destruction of enough style
268 * contexts). Rule nodes are marked if they are pointed to by a style
269 * context or one of their descendants is.
271 * An nsStyleContext, which represents the computed style data for an
272 * element, points to an nsRuleNode. The path from the root of the rule
273 * tree to the nsStyleContext's mRuleNode gives the list of the rules
274 * matched, from least important in the cascading order to most
275 * important in the cascading order.
277 * The reason for using a lexicographic tree is that it allows for
278 * sharing of style data, which saves both memory (for storing the
279 * computed style data) and time (for computing them). This sharing
280 * depends on the computed style data being stored in structs (nsStyle*)
281 * that contain only properties that are inherited by default
282 * ("inherited structs") or structs that contain only properties that
283 * are not inherited by default ("reset structs"). The optimization
284 * depends on the normal case being that style rules specify relatively
285 * few properties and even that elements generally have relatively few
286 * properties specified. This allows sharing in the following ways:
287 * 1. [mainly reset structs] When a style data struct will contain the
288 * same computed value for any elements that match the same set of
289 * rules (common for reset structs), it can be stored on the
290 * nsRuleNode instead of on the nsStyleContext.
291 * 2. [only? reset structs] When (1) occurs, and an nsRuleNode doesn't
292 * have any rules that change the values in the struct, the
293 * nsRuleNode can share that struct with its parent nsRuleNode.
294 * 3. [mainly inherited structs] When an element doesn't match any
295 * rules that change the value of a property (or, in the edge case,
296 * when all the values specified are 'inherit'), the nsStyleContext
297 * can use the same nsStyle* struct as its parent nsStyleContext.
299 * Since the data represented by an nsIStyleRule are immutable, the data
300 * represented by an nsRuleNode are also immutable.
303 class nsRuleNode {
304 public:
305 enum RuleDetail {
306 eRuleNone, // No props have been specified at all.
307 eRulePartialReset, // At least one prop with a non-"inherit" value
308 // has been specified. No props have been
309 // specified with an "inherit" value. At least
310 // one prop remains unspecified.
311 eRulePartialMixed, // At least one prop with a non-"inherit" value
312 // has been specified. Some props may also have
313 // been specified with an "inherit" value. At
314 // least one prop remains unspecified.
315 eRulePartialInherited, // Only props with "inherit" values have
316 // have been specified. At least one prop
317 // remains unspecified.
318 eRuleFullReset, // All props have been specified. None has an
319 // "inherit" value.
320 eRuleFullMixed, // All props have been specified. At least one has
321 // a non-"inherit" value.
322 eRuleFullInherited // All props have been specified with "inherit"
323 // values.
326 private:
327 nsPresContext* mPresContext; // Our pres context.
329 nsRuleNode* mParent; // A pointer to the parent node in the tree.
330 // This enables us to walk backwards from the
331 // most specific rule matched to the least
332 // specific rule (which is the optimal order to
333 // use for lookups of style properties.
334 nsIStyleRule* mRule; // [STRONG] A pointer to our specific rule.
336 nsRuleNode* mNextSibling; // This value should be used only by the
337 // parent, since the parent may store
338 // children in a hash, which means this
339 // pointer is not meaningful. Order of
340 // siblings is also not meaningful.
342 struct Key {
343 nsIStyleRule* mRule;
344 PRUint8 mLevel;
345 PRPackedBool mIsImportantRule;
347 Key(nsIStyleRule* aRule, PRUint8 aLevel, PRPackedBool aIsImportantRule)
348 : mRule(aRule), mLevel(aLevel), mIsImportantRule(aIsImportantRule)
351 PRBool operator==(const Key& aOther) const
353 return mRule == aOther.mRule &&
354 mLevel == aOther.mLevel &&
355 mIsImportantRule == aOther.mIsImportantRule;
358 PRBool operator!=(const Key& aOther) const
360 return !(*this == aOther);
364 static PLDHashNumber
365 ChildrenHashHashKey(PLDHashTable *aTable, const void *aKey);
367 static PRBool
368 ChildrenHashMatchEntry(PLDHashTable *aTable,
369 const PLDHashEntryHdr *aHdr,
370 const void *aKey);
372 static PLDHashTableOps ChildrenHashOps;
374 static PLDHashOperator
375 EnqueueRuleNodeChildren(PLDHashTable *table, PLDHashEntryHdr *hdr,
376 PRUint32 number, void *arg);
378 Key GetKey() const {
379 return Key(mRule, GetLevel(), IsImportantRule());
382 // The children of this node are stored in either a hashtable or list
383 // that maps from rules to our nsRuleNode children. When matching
384 // rules, we use this mapping to transition from node to node
385 // (constructing new nodes as needed to flesh out the tree).
387 union {
388 void* asVoid;
389 nsRuleNode* asList;
390 PLDHashTable* asHash;
391 } mChildren; // Accessed only through the methods below.
393 enum {
394 kTypeMask = 0x1,
395 kListType = 0x0,
396 kHashType = 0x1
398 enum {
399 // Maximum to have in a list before converting to a hashtable.
400 // XXX Need to optimize this.
401 kMaxChildrenInList = 32
404 PRBool HaveChildren() {
405 return mChildren.asVoid != nsnull;
407 PRBool ChildrenAreHashed() {
408 return (PRWord(mChildren.asVoid) & kTypeMask) == kHashType;
410 nsRuleNode* ChildrenList() {
411 return mChildren.asList;
413 nsRuleNode** ChildrenListPtr() {
414 return &mChildren.asList;
416 PLDHashTable* ChildrenHash() {
417 return (PLDHashTable*) (PRWord(mChildren.asHash) & ~PRWord(kTypeMask));
419 void SetChildrenList(nsRuleNode *aList) {
420 NS_ASSERTION(!(PRWord(aList) & kTypeMask),
421 "pointer not 2-byte aligned");
422 mChildren.asList = aList;
424 void SetChildrenHash(PLDHashTable *aHashtable) {
425 NS_ASSERTION(!(PRWord(aHashtable) & kTypeMask),
426 "pointer not 2-byte aligned");
427 mChildren.asHash = (PLDHashTable*)(PRWord(aHashtable) | kHashType);
429 void ConvertChildrenToHash();
431 nsCachedStyleData mStyleData; // Any data we cached on the rule node.
433 PRUint32 mDependentBits; // Used to cache the fact that we can look up
434 // cached data under a parent rule.
436 PRUint32 mNoneBits; // Used to cache the fact that the branch to this
437 // node specifies no non-inherited data for a
438 // given struct type. (This usually implies that
439 // the entire branch specifies no non-inherited
440 // data, although not necessarily, if a
441 // non-inherited value is overridden by an
442 // explicit 'inherit' value.) For example, if an
443 // entire rule branch specifies no color
444 // information, then a bit will be set along every
445 // rule node on that branch, so that you can break
446 // out of the rule tree early and just inherit
447 // from the parent style context. The presence of
448 // this bit means we should just get inherited
449 // data from the parent style context, and it is
450 // never used for reset structs since their
451 // Compute*Data functions don't initialize from
452 // inherited data.
454 public:
455 // Overloaded new operator. Initializes the memory to 0 and relies on an arena
456 // (which comes from the presShell) to perform the allocation.
457 NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW;
458 NS_HIDDEN_(void) Destroy() { DestroyInternal(nsnull); }
459 static NS_HIDDEN_(nsILanguageAtomService*) gLangService;
461 protected:
462 NS_HIDDEN_(void) DestroyInternal(nsRuleNode ***aDestroyQueueTail);
463 NS_HIDDEN_(void) PropagateDependentBit(PRUint32 aBit,
464 nsRuleNode* aHighestNode);
465 NS_HIDDEN_(void) PropagateNoneBit(PRUint32 aBit, nsRuleNode* aHighestNode);
467 NS_HIDDEN_(const void*) SetDefaultOnRoot(const nsStyleStructID aSID,
468 nsStyleContext* aContext);
470 NS_HIDDEN_(const void*)
471 WalkRuleTree(const nsStyleStructID aSID, nsStyleContext* aContext,
472 nsRuleData* aRuleData, nsRuleDataStruct* aSpecificData);
474 NS_HIDDEN_(const void*)
475 ComputeDisplayData(void* aStartStruct,
476 const nsRuleDataStruct& aData,
477 nsStyleContext* aContext, nsRuleNode* aHighestNode,
478 RuleDetail aRuleDetail, PRBool aInherited);
480 NS_HIDDEN_(const void*)
481 ComputeVisibilityData(void* aStartStruct,
482 const nsRuleDataStruct& aData,
483 nsStyleContext* aContext, nsRuleNode* aHighestNode,
484 RuleDetail aRuleDetail, PRBool aInherited);
486 NS_HIDDEN_(const void*)
487 ComputeFontData(void* aStartStruct,
488 const nsRuleDataStruct& aData,
489 nsStyleContext* aContext, nsRuleNode* aHighestNode,
490 RuleDetail aRuleDetail, PRBool aInherited);
492 NS_HIDDEN_(const void*)
493 ComputeColorData(void* aStartStruct,
494 const nsRuleDataStruct& aData,
495 nsStyleContext* aContext, nsRuleNode* aHighestNode,
496 RuleDetail aRuleDetail, PRBool aInherited);
498 NS_HIDDEN_(const void*)
499 ComputeBackgroundData(void* aStartStruct,
500 const nsRuleDataStruct& aData,
501 nsStyleContext* aContext, nsRuleNode* aHighestNode,
502 RuleDetail aRuleDetail, PRBool aInherited);
504 NS_HIDDEN_(const void*)
505 ComputeMarginData(void* aStartStruct,
506 const nsRuleDataStruct& aData,
507 nsStyleContext* aContext, nsRuleNode* aHighestNode,
508 RuleDetail aRuleDetail, PRBool aInherited);
510 NS_HIDDEN_(const void*)
511 ComputeBorderData(void* aStartStruct,
512 const nsRuleDataStruct& aData,
513 nsStyleContext* aContext, nsRuleNode* aHighestNode,
514 RuleDetail aRuleDetail, PRBool aInherited);
516 NS_HIDDEN_(const void*)
517 ComputePaddingData(void* aStartStruct,
518 const nsRuleDataStruct& aData,
519 nsStyleContext* aContext, nsRuleNode* aHighestNode,
520 RuleDetail aRuleDetail, PRBool aInherited);
522 NS_HIDDEN_(const void*)
523 ComputeOutlineData(void* aStartStruct,
524 const nsRuleDataStruct& aData,
525 nsStyleContext* aContext, nsRuleNode* aHighestNode,
526 RuleDetail aRuleDetail, PRBool aInherited);
528 NS_HIDDEN_(const void*)
529 ComputeListData(void* aStartStruct,
530 const nsRuleDataStruct& aData,
531 nsStyleContext* aContext, nsRuleNode* aHighestNode,
532 RuleDetail aRuleDetail, PRBool aInherited);
534 NS_HIDDEN_(const void*)
535 ComputePositionData(void* aStartStruct,
536 const nsRuleDataStruct& aData,
537 nsStyleContext* aContext, nsRuleNode* aHighestNode,
538 RuleDetail aRuleDetail, PRBool aInherited);
540 NS_HIDDEN_(const void*)
541 ComputeTableData(void* aStartStruct,
542 const nsRuleDataStruct& aData,
543 nsStyleContext* aContext, nsRuleNode* aHighestNode,
544 RuleDetail aRuleDetail, PRBool aInherited);
546 NS_HIDDEN_(const void*)
547 ComputeTableBorderData(void* aStartStruct,
548 const nsRuleDataStruct& aData,
549 nsStyleContext* aContext, nsRuleNode* aHighestNode,
550 RuleDetail aRuleDetail, PRBool aInherited);
552 NS_HIDDEN_(const void*)
553 ComputeContentData(void* aStartStruct,
554 const nsRuleDataStruct& aData,
555 nsStyleContext* aContext, nsRuleNode* aHighestNode,
556 RuleDetail aRuleDetail, PRBool aInherited);
558 NS_HIDDEN_(const void*)
559 ComputeQuotesData(void* aStartStruct,
560 const nsRuleDataStruct& aData,
561 nsStyleContext* aContext, nsRuleNode* aHighestNode,
562 RuleDetail aRuleDetail, PRBool aInherited);
564 NS_HIDDEN_(const void*)
565 ComputeTextData(void* aStartStruct,
566 const nsRuleDataStruct& aData,
567 nsStyleContext* aContext, nsRuleNode* aHighestNode,
568 RuleDetail aRuleDetail, PRBool aInherited);
570 NS_HIDDEN_(const void*)
571 ComputeTextResetData(void* aStartStruct,
572 const nsRuleDataStruct& aData,
573 nsStyleContext* aContext, nsRuleNode* aHighestNode,
574 RuleDetail aRuleDetail, PRBool aInherited);
576 NS_HIDDEN_(const void*)
577 ComputeUserInterfaceData(void* aStartStruct,
578 const nsRuleDataStruct& aData,
579 nsStyleContext* aContext,
580 nsRuleNode* aHighestNode,
581 RuleDetail aRuleDetail, PRBool aInherited);
583 NS_HIDDEN_(const void*)
584 ComputeUIResetData(void* aStartStruct,
585 const nsRuleDataStruct& aData,
586 nsStyleContext* aContext, nsRuleNode* aHighestNode,
587 RuleDetail aRuleDetail, PRBool aInherited);
589 NS_HIDDEN_(const void*)
590 ComputeXULData(void* aStartStruct,
591 const nsRuleDataStruct& aData,
592 nsStyleContext* aContext, nsRuleNode* aHighestNode,
593 RuleDetail aRuleDetail, PRBool aInherited);
595 NS_HIDDEN_(const void*)
596 ComputeColumnData(void* aStartStruct,
597 const nsRuleDataStruct& aData,
598 nsStyleContext* aContext, nsRuleNode* aHighestNode,
599 RuleDetail aRuleDetail, PRBool aInherited);
601 #ifdef MOZ_SVG
602 NS_HIDDEN_(const void*)
603 ComputeSVGData(void* aStartStruct,
604 const nsRuleDataStruct& aData,
605 nsStyleContext* aContext, nsRuleNode* aHighestNode,
606 RuleDetail aRuleDetail, PRBool aInherited);
608 NS_HIDDEN_(const void*)
609 ComputeSVGResetData(void* aStartStruct,
610 const nsRuleDataStruct& aData,
611 nsStyleContext* aContext, nsRuleNode* aHighestNode,
612 RuleDetail aRuleDetail, PRBool aInherited);
613 #endif
615 // helpers for |ComputeFontData| that need access to |mNoneBits|:
616 static NS_HIDDEN_(void) SetFontSize(nsPresContext* aPresContext,
617 const nsRuleDataFont& aFontData,
618 const nsStyleFont* aFont,
619 const nsStyleFont* aParentFont,
620 nscoord* aSize,
621 const nsFont& aSystemFont,
622 nscoord aParentSize,
623 nscoord aScriptLevelAdjustedParentSize,
624 PRBool aUsedStartStruct,
625 PRBool& aInherited);
627 static NS_HIDDEN_(void) SetFont(nsPresContext* aPresContext,
628 nsStyleContext* aContext,
629 nscoord aMinFontSize,
630 PRUint8 aGenericFontID,
631 const nsRuleDataFont& aFontData,
632 const nsStyleFont* aParentFont,
633 nsStyleFont* aFont,
634 PRBool aStartStruct, PRBool& aInherited);
636 static NS_HIDDEN_(void) SetGenericFont(nsPresContext* aPresContext,
637 nsStyleContext* aContext,
638 PRUint8 aGenericFontID,
639 nscoord aMinFontSize,
640 nsStyleFont* aFont);
642 NS_HIDDEN_(void) AdjustLogicalBoxProp(nsStyleContext* aContext,
643 const nsCSSValue& aLTRSource,
644 const nsCSSValue& aRTLSource,
645 const nsCSSValue& aLTRLogicalValue,
646 const nsCSSValue& aRTLLogicalValue,
647 PRUint8 aSide,
648 nsCSSRect& aValueRect,
649 PRBool& aInherited);
651 inline RuleDetail CheckSpecifiedProperties(const nsStyleStructID aSID, const nsRuleDataStruct& aRuleDataStruct);
653 NS_HIDDEN_(const void*) GetParentData(const nsStyleStructID aSID);
654 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
655 NS_HIDDEN_(const nsStyle##name_*) GetParent##name_();
656 #include "nsStyleStructList.h"
657 #undef STYLE_STRUCT
659 NS_HIDDEN_(const void*) GetDisplayData(nsStyleContext* aContext);
660 NS_HIDDEN_(const void*) GetVisibilityData(nsStyleContext* aContext);
661 NS_HIDDEN_(const void*) GetFontData(nsStyleContext* aContext);
662 NS_HIDDEN_(const void*) GetColorData(nsStyleContext* aContext);
663 NS_HIDDEN_(const void*) GetBackgroundData(nsStyleContext* aContext);
664 NS_HIDDEN_(const void*) GetMarginData(nsStyleContext* aContext);
665 NS_HIDDEN_(const void*) GetBorderData(nsStyleContext* aContext);
666 NS_HIDDEN_(const void*) GetPaddingData(nsStyleContext* aContext);
667 NS_HIDDEN_(const void*) GetOutlineData(nsStyleContext* aContext);
668 NS_HIDDEN_(const void*) GetListData(nsStyleContext* aContext);
669 NS_HIDDEN_(const void*) GetPositionData(nsStyleContext* aContext);
670 NS_HIDDEN_(const void*) GetTableData(nsStyleContext* aContext);
671 NS_HIDDEN_(const void*) GetTableBorderData(nsStyleContext* aContext);
673 NS_HIDDEN_(const void*) GetContentData(nsStyleContext* aContext);
674 NS_HIDDEN_(const void*) GetQuotesData(nsStyleContext* aContext);
675 NS_HIDDEN_(const void*) GetTextData(nsStyleContext* aContext);
676 NS_HIDDEN_(const void*) GetTextResetData(nsStyleContext* aContext);
677 NS_HIDDEN_(const void*) GetUserInterfaceData(nsStyleContext* aContext);
679 NS_HIDDEN_(const void*) GetUIResetData(nsStyleContext* aContext);
680 NS_HIDDEN_(const void*) GetXULData(nsStyleContext* aContext);
681 NS_HIDDEN_(const void*) GetColumnData(nsStyleContext* aContext);
682 #ifdef MOZ_SVG
683 NS_HIDDEN_(const void*) GetSVGData(nsStyleContext* aContext);
684 NS_HIDDEN_(const void*) GetSVGResetData(nsStyleContext* aContext);
685 #endif
687 NS_HIDDEN_(already_AddRefed<nsCSSShadowArray>)
688 GetShadowData(nsCSSValueList* aList,
689 nsStyleContext* aContext,
690 PRBool aUsesSpread,
691 PRBool& inherited);
693 private:
694 nsRuleNode(nsPresContext* aPresContext, nsRuleNode* aParent,
695 nsIStyleRule* aRule, PRUint8 aLevel, PRBool aIsImportant)
696 NS_HIDDEN;
697 ~nsRuleNode() NS_HIDDEN;
699 public:
700 static NS_HIDDEN_(nsRuleNode*) CreateRootNode(nsPresContext* aPresContext);
702 NS_HIDDEN_(nsRuleNode*) Transition(nsIStyleRule* aRule, PRUint8 aLevel,
703 PRPackedBool aIsImportantRule);
704 nsRuleNode* GetParent() const { return mParent; }
705 PRBool IsRoot() const { return mParent == nsnull; }
707 // These PRUint8s are really nsStyleSet::sheetType values.
708 PRUint8 GetLevel() const {
709 NS_ASSERTION(!IsRoot(), "can't call on root");
710 return (mDependentBits & NS_RULE_NODE_LEVEL_MASK) >>
711 NS_RULE_NODE_LEVEL_SHIFT;
713 PRBool IsImportantRule() const {
714 NS_ASSERTION(!IsRoot(), "can't call on root");
715 return (mDependentBits & NS_RULE_NODE_IS_IMPORTANT) != 0;
718 // NOTE: Does not |AddRef|.
719 nsIStyleRule* GetRule() const { return mRule; }
720 // NOTE: Does not |AddRef|.
721 nsPresContext* GetPresContext() const { return mPresContext; }
723 NS_HIDDEN_(const void*) GetStyleData(nsStyleStructID aSID,
724 nsStyleContext* aContext,
725 PRBool aComputeData);
727 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
728 NS_HIDDEN_(const nsStyle##name_*) \
729 GetStyle##name_(nsStyleContext* aContext, \
730 PRBool aComputeData);
731 #include "nsStyleStructList.h"
732 #undef STYLE_STRUCT
735 * Garbage collection. Mark walks up the tree, marking any unmarked
736 * ancestors until it reaches a marked one. Sweep recursively sweeps
737 * the children, destroys any that are unmarked, and clears marks,
738 * returning true if the node on which it was called was destroyed.
740 NS_HIDDEN_(void) Mark();
741 NS_HIDDEN_(PRBool) Sweep();
743 static PRBool
744 HasAuthorSpecifiedRules(nsStyleContext* aStyleContext, PRUint32 ruleTypeMask);
746 // Expose this so media queries can use it
747 static nscoord CalcLengthWithInitialFont(nsPresContext* aPresContext,
748 const nsCSSValue& aValue);
749 // Expose this so nsTransformFunctions can use it.
750 static nscoord CalcLength(const nsCSSValue& aValue,
751 nsStyleContext* aStyleContext,
752 nsPresContext* aPresContext,
753 PRBool& aInherited);
756 #endif