Bug 451040 ? Passwords Manager Empty after convert to MozStorage. r=gavin
[wine-gecko.git] / layout / style / nsRuleNode.h
blobbd3724da8cdb15a39d330f327d787ec5af40616d
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 PR_CALLBACK PLDHashNumber
365 ChildrenHashHashKey(PLDHashTable *aTable, const void *aKey);
367 static PR_CALLBACK PRBool
368 ChildrenHashMatchEntry(PLDHashTable *aTable,
369 const PLDHashEntryHdr *aHdr,
370 const void *aKey);
372 static PLDHashTableOps ChildrenHashOps;
374 static PR_CALLBACK 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 void *mChildrenTaggedPtr; // Accessed only through the methods below.
389 enum {
390 kTypeMask = 0x1,
391 kListType = 0x0,
392 kHashType = 0x1
394 enum {
395 // Maximum to have in a list before converting to a hashtable.
396 // XXX Need to optimize this.
397 kMaxChildrenInList = 32
400 PRBool HaveChildren() {
401 return mChildrenTaggedPtr != nsnull;
403 PRBool ChildrenAreHashed() {
404 return (PRWord(mChildrenTaggedPtr) & kTypeMask) == kHashType;
406 nsRuleNode* ChildrenList() {
407 return reinterpret_cast<nsRuleNode*>(mChildrenTaggedPtr);
409 nsRuleNode** ChildrenListPtr() {
410 return reinterpret_cast<nsRuleNode**>(&mChildrenTaggedPtr);
412 PLDHashTable* ChildrenHash() {
413 return (PLDHashTable*) (PRWord(mChildrenTaggedPtr) & ~PRWord(kTypeMask));
415 void SetChildrenList(nsRuleNode *aList) {
416 NS_ASSERTION(!(PRWord(aList) & kTypeMask),
417 "pointer not 2-byte aligned");
418 mChildrenTaggedPtr = aList;
420 void SetChildrenHash(PLDHashTable *aHashtable) {
421 NS_ASSERTION(!(PRWord(aHashtable) & kTypeMask),
422 "pointer not 2-byte aligned");
423 mChildrenTaggedPtr = (void*)(PRWord(aHashtable) | kHashType);
425 void ConvertChildrenToHash();
427 nsCachedStyleData mStyleData; // Any data we cached on the rule node.
429 PRUint32 mDependentBits; // Used to cache the fact that we can look up
430 // cached data under a parent rule.
432 PRUint32 mNoneBits; // Used to cache the fact that the branch to this
433 // node specifies no non-inherited data for a
434 // given struct type. (This usually implies that
435 // the entire branch specifies no non-inherited
436 // data, although not necessarily, if a
437 // non-inherited value is overridden by an
438 // explicit 'inherit' value.) For example, if an
439 // entire rule branch specifies no color
440 // information, then a bit will be set along every
441 // rule node on that branch, so that you can break
442 // out of the rule tree early and just inherit
443 // from the parent style context. The presence of
444 // this bit means we should just get inherited
445 // data from the parent style context, and it is
446 // never used for reset structs since their
447 // Compute*Data functions don't initialize from
448 // inherited data.
450 public:
451 // Overloaded new operator. Initializes the memory to 0 and relies on an arena
452 // (which comes from the presShell) to perform the allocation.
453 NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW;
454 NS_HIDDEN_(void) Destroy() { DestroyInternal(nsnull); }
455 static NS_HIDDEN_(nsILanguageAtomService*) gLangService;
457 protected:
458 NS_HIDDEN_(void) DestroyInternal(nsRuleNode ***aDestroyQueueTail);
459 NS_HIDDEN_(void) PropagateDependentBit(PRUint32 aBit,
460 nsRuleNode* aHighestNode);
461 NS_HIDDEN_(void) PropagateNoneBit(PRUint32 aBit, nsRuleNode* aHighestNode);
463 NS_HIDDEN_(const void*) SetDefaultOnRoot(const nsStyleStructID aSID,
464 nsStyleContext* aContext);
466 NS_HIDDEN_(const void*)
467 WalkRuleTree(const nsStyleStructID aSID, nsStyleContext* aContext,
468 nsRuleData* aRuleData, nsRuleDataStruct* aSpecificData);
470 NS_HIDDEN_(const void*)
471 ComputeDisplayData(void* aStartStruct,
472 const nsRuleDataStruct& aData,
473 nsStyleContext* aContext, nsRuleNode* aHighestNode,
474 RuleDetail aRuleDetail, PRBool aInherited);
476 NS_HIDDEN_(const void*)
477 ComputeVisibilityData(void* aStartStruct,
478 const nsRuleDataStruct& aData,
479 nsStyleContext* aContext, nsRuleNode* aHighestNode,
480 RuleDetail aRuleDetail, PRBool aInherited);
482 NS_HIDDEN_(const void*)
483 ComputeFontData(void* aStartStruct,
484 const nsRuleDataStruct& aData,
485 nsStyleContext* aContext, nsRuleNode* aHighestNode,
486 RuleDetail aRuleDetail, PRBool aInherited);
488 NS_HIDDEN_(const void*)
489 ComputeColorData(void* aStartStruct,
490 const nsRuleDataStruct& aData,
491 nsStyleContext* aContext, nsRuleNode* aHighestNode,
492 RuleDetail aRuleDetail, PRBool aInherited);
494 NS_HIDDEN_(const void*)
495 ComputeBackgroundData(void* aStartStruct,
496 const nsRuleDataStruct& aData,
497 nsStyleContext* aContext, nsRuleNode* aHighestNode,
498 RuleDetail aRuleDetail, PRBool aInherited);
500 NS_HIDDEN_(const void*)
501 ComputeMarginData(void* aStartStruct,
502 const nsRuleDataStruct& aData,
503 nsStyleContext* aContext, nsRuleNode* aHighestNode,
504 RuleDetail aRuleDetail, PRBool aInherited);
506 NS_HIDDEN_(const void*)
507 ComputeBorderData(void* aStartStruct,
508 const nsRuleDataStruct& aData,
509 nsStyleContext* aContext, nsRuleNode* aHighestNode,
510 RuleDetail aRuleDetail, PRBool aInherited);
512 NS_HIDDEN_(const void*)
513 ComputePaddingData(void* aStartStruct,
514 const nsRuleDataStruct& aData,
515 nsStyleContext* aContext, nsRuleNode* aHighestNode,
516 RuleDetail aRuleDetail, PRBool aInherited);
518 NS_HIDDEN_(const void*)
519 ComputeOutlineData(void* aStartStruct,
520 const nsRuleDataStruct& aData,
521 nsStyleContext* aContext, nsRuleNode* aHighestNode,
522 RuleDetail aRuleDetail, PRBool aInherited);
524 NS_HIDDEN_(const void*)
525 ComputeListData(void* aStartStruct,
526 const nsRuleDataStruct& aData,
527 nsStyleContext* aContext, nsRuleNode* aHighestNode,
528 RuleDetail aRuleDetail, PRBool aInherited);
530 NS_HIDDEN_(const void*)
531 ComputePositionData(void* aStartStruct,
532 const nsRuleDataStruct& aData,
533 nsStyleContext* aContext, nsRuleNode* aHighestNode,
534 RuleDetail aRuleDetail, PRBool aInherited);
536 NS_HIDDEN_(const void*)
537 ComputeTableData(void* aStartStruct,
538 const nsRuleDataStruct& aData,
539 nsStyleContext* aContext, nsRuleNode* aHighestNode,
540 RuleDetail aRuleDetail, PRBool aInherited);
542 NS_HIDDEN_(const void*)
543 ComputeTableBorderData(void* aStartStruct,
544 const nsRuleDataStruct& aData,
545 nsStyleContext* aContext, nsRuleNode* aHighestNode,
546 RuleDetail aRuleDetail, PRBool aInherited);
548 NS_HIDDEN_(const void*)
549 ComputeContentData(void* aStartStruct,
550 const nsRuleDataStruct& aData,
551 nsStyleContext* aContext, nsRuleNode* aHighestNode,
552 RuleDetail aRuleDetail, PRBool aInherited);
554 NS_HIDDEN_(const void*)
555 ComputeQuotesData(void* aStartStruct,
556 const nsRuleDataStruct& aData,
557 nsStyleContext* aContext, nsRuleNode* aHighestNode,
558 RuleDetail aRuleDetail, PRBool aInherited);
560 NS_HIDDEN_(const void*)
561 ComputeTextData(void* aStartStruct,
562 const nsRuleDataStruct& aData,
563 nsStyleContext* aContext, nsRuleNode* aHighestNode,
564 RuleDetail aRuleDetail, PRBool aInherited);
566 NS_HIDDEN_(const void*)
567 ComputeTextResetData(void* aStartStruct,
568 const nsRuleDataStruct& aData,
569 nsStyleContext* aContext, nsRuleNode* aHighestNode,
570 RuleDetail aRuleDetail, PRBool aInherited);
572 NS_HIDDEN_(const void*)
573 ComputeUserInterfaceData(void* aStartStruct,
574 const nsRuleDataStruct& aData,
575 nsStyleContext* aContext,
576 nsRuleNode* aHighestNode,
577 RuleDetail aRuleDetail, PRBool aInherited);
579 NS_HIDDEN_(const void*)
580 ComputeUIResetData(void* aStartStruct,
581 const nsRuleDataStruct& aData,
582 nsStyleContext* aContext, nsRuleNode* aHighestNode,
583 RuleDetail aRuleDetail, PRBool aInherited);
585 NS_HIDDEN_(const void*)
586 ComputeXULData(void* aStartStruct,
587 const nsRuleDataStruct& aData,
588 nsStyleContext* aContext, nsRuleNode* aHighestNode,
589 RuleDetail aRuleDetail, PRBool aInherited);
591 NS_HIDDEN_(const void*)
592 ComputeColumnData(void* aStartStruct,
593 const nsRuleDataStruct& aData,
594 nsStyleContext* aContext, nsRuleNode* aHighestNode,
595 RuleDetail aRuleDetail, PRBool aInherited);
597 #ifdef MOZ_SVG
598 NS_HIDDEN_(const void*)
599 ComputeSVGData(void* aStartStruct,
600 const nsRuleDataStruct& aData,
601 nsStyleContext* aContext, nsRuleNode* aHighestNode,
602 RuleDetail aRuleDetail, PRBool aInherited);
604 NS_HIDDEN_(const void*)
605 ComputeSVGResetData(void* aStartStruct,
606 const nsRuleDataStruct& aData,
607 nsStyleContext* aContext, nsRuleNode* aHighestNode,
608 RuleDetail aRuleDetail, PRBool aInherited);
609 #endif
611 // helpers for |ComputeFontData| that need access to |mNoneBits|:
612 static NS_HIDDEN_(void) SetFontSize(nsPresContext* aPresContext,
613 const nsRuleDataFont& aFontData,
614 const nsStyleFont* aFont,
615 const nsStyleFont* aParentFont,
616 nscoord* aSize,
617 const nsFont& aSystemFont,
618 nscoord aParentSize,
619 nscoord aScriptLevelAdjustedParentSize,
620 PRBool aUsedStartStruct,
621 PRBool& aInherited);
623 static NS_HIDDEN_(void) SetFont(nsPresContext* aPresContext,
624 nsStyleContext* aContext,
625 nscoord aMinFontSize,
626 PRUint8 aGenericFontID,
627 const nsRuleDataFont& aFontData,
628 const nsStyleFont* aParentFont,
629 nsStyleFont* aFont,
630 PRBool aStartStruct, PRBool& aInherited);
632 static NS_HIDDEN_(void) SetGenericFont(nsPresContext* aPresContext,
633 nsStyleContext* aContext,
634 PRUint8 aGenericFontID,
635 nscoord aMinFontSize,
636 nsStyleFont* aFont);
638 NS_HIDDEN_(void) AdjustLogicalBoxProp(nsStyleContext* aContext,
639 const nsCSSValue& aLTRSource,
640 const nsCSSValue& aRTLSource,
641 const nsCSSValue& aLTRLogicalValue,
642 const nsCSSValue& aRTLLogicalValue,
643 PRUint8 aSide,
644 nsCSSRect& aValueRect,
645 PRBool& aInherited);
647 inline RuleDetail CheckSpecifiedProperties(const nsStyleStructID aSID, const nsRuleDataStruct& aRuleDataStruct);
649 NS_HIDDEN_(const void*) GetParentData(const nsStyleStructID aSID);
650 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
651 NS_HIDDEN_(const nsStyle##name_*) GetParent##name_();
652 #include "nsStyleStructList.h"
653 #undef STYLE_STRUCT
655 NS_HIDDEN_(const void*) GetDisplayData(nsStyleContext* aContext);
656 NS_HIDDEN_(const void*) GetVisibilityData(nsStyleContext* aContext);
657 NS_HIDDEN_(const void*) GetFontData(nsStyleContext* aContext);
658 NS_HIDDEN_(const void*) GetColorData(nsStyleContext* aContext);
659 NS_HIDDEN_(const void*) GetBackgroundData(nsStyleContext* aContext);
660 NS_HIDDEN_(const void*) GetMarginData(nsStyleContext* aContext);
661 NS_HIDDEN_(const void*) GetBorderData(nsStyleContext* aContext);
662 NS_HIDDEN_(const void*) GetPaddingData(nsStyleContext* aContext);
663 NS_HIDDEN_(const void*) GetOutlineData(nsStyleContext* aContext);
664 NS_HIDDEN_(const void*) GetListData(nsStyleContext* aContext);
665 NS_HIDDEN_(const void*) GetPositionData(nsStyleContext* aContext);
666 NS_HIDDEN_(const void*) GetTableData(nsStyleContext* aContext);
667 NS_HIDDEN_(const void*) GetTableBorderData(nsStyleContext* aContext);
669 NS_HIDDEN_(const void*) GetContentData(nsStyleContext* aContext);
670 NS_HIDDEN_(const void*) GetQuotesData(nsStyleContext* aContext);
671 NS_HIDDEN_(const void*) GetTextData(nsStyleContext* aContext);
672 NS_HIDDEN_(const void*) GetTextResetData(nsStyleContext* aContext);
673 NS_HIDDEN_(const void*) GetUserInterfaceData(nsStyleContext* aContext);
675 NS_HIDDEN_(const void*) GetUIResetData(nsStyleContext* aContext);
676 NS_HIDDEN_(const void*) GetXULData(nsStyleContext* aContext);
677 NS_HIDDEN_(const void*) GetColumnData(nsStyleContext* aContext);
678 #ifdef MOZ_SVG
679 NS_HIDDEN_(const void*) GetSVGData(nsStyleContext* aContext);
680 NS_HIDDEN_(const void*) GetSVGResetData(nsStyleContext* aContext);
681 #endif
683 NS_HIDDEN_(already_AddRefed<nsCSSShadowArray>)
684 GetShadowData(nsCSSValueList* aList,
685 nsStyleContext* aContext,
686 PRBool aUsesSpread,
687 PRBool& inherited);
689 private:
690 nsRuleNode(nsPresContext* aPresContext, nsRuleNode* aParent,
691 nsIStyleRule* aRule, PRUint8 aLevel, PRBool aIsImportant)
692 NS_HIDDEN;
693 ~nsRuleNode() NS_HIDDEN;
695 public:
696 static NS_HIDDEN_(nsRuleNode*) CreateRootNode(nsPresContext* aPresContext);
698 NS_HIDDEN_(nsRuleNode*) Transition(nsIStyleRule* aRule, PRUint8 aLevel,
699 PRPackedBool aIsImportantRule);
700 nsRuleNode* GetParent() const { return mParent; }
701 PRBool IsRoot() const { return mParent == nsnull; }
703 // These PRUint8s are really nsStyleSet::sheetType values.
704 PRUint8 GetLevel() const {
705 NS_ASSERTION(!IsRoot(), "can't call on root");
706 return (mDependentBits & NS_RULE_NODE_LEVEL_MASK) >>
707 NS_RULE_NODE_LEVEL_SHIFT;
709 PRBool IsImportantRule() const {
710 NS_ASSERTION(!IsRoot(), "can't call on root");
711 return (mDependentBits & NS_RULE_NODE_IS_IMPORTANT) != 0;
714 // NOTE: Does not |AddRef|.
715 nsIStyleRule* GetRule() const { return mRule; }
716 // NOTE: Does not |AddRef|.
717 nsPresContext* GetPresContext() const { return mPresContext; }
719 NS_HIDDEN_(const void*) GetStyleData(nsStyleStructID aSID,
720 nsStyleContext* aContext,
721 PRBool aComputeData);
723 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
724 NS_HIDDEN_(const nsStyle##name_*) \
725 GetStyle##name_(nsStyleContext* aContext, \
726 PRBool aComputeData);
727 #include "nsStyleStructList.h"
728 #undef STYLE_STRUCT
731 * Garbage collection. Mark walks up the tree, marking any unmarked
732 * ancestors until it reaches a marked one. Sweep recursively sweeps
733 * the children, destroys any that are unmarked, and clears marks,
734 * returning true if the node on which it was called was destroyed.
736 NS_HIDDEN_(void) Mark();
737 NS_HIDDEN_(PRBool) Sweep();
739 static PRBool
740 HasAuthorSpecifiedRules(nsStyleContext* aStyleContext, PRUint32 ruleTypeMask);
742 // Expose this so media queries can use it
743 static nscoord CalcLengthWithInitialFont(nsPresContext* aPresContext,
744 const nsCSSValue& aValue);
747 #endif