1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * a class that walks the lexicographic tree of rule nodes as style
11 #ifndef nsRuleWalker_h_
12 #define nsRuleWalker_h_
14 #include "nsRuleNode.h"
15 #include "nsIStyleRule.h"
16 #include "StyleRule.h"
20 nsRuleNode
* CurrentNode() { return mCurrent
; }
21 void SetCurrentNode(nsRuleNode
* aNode
) {
22 NS_ASSERTION(aNode
, "Must have node here!");
27 void DoForward(nsIStyleRule
* aRule
) {
28 mCurrent
= mCurrent
->Transition(aRule
, mLevel
, mImportance
);
29 NS_POSTCONDITION(mCurrent
, "Transition messed up");
33 void Forward(nsIStyleRule
* aRule
) {
34 NS_PRECONDITION(!nsRefPtr
<mozilla::css::StyleRule
>(do_QueryObject(aRule
)),
35 "Calling the wrong Forward() overload");
38 void Forward(mozilla::css::StyleRule
* aRule
) {
40 mCheckForImportantRules
=
41 mCheckForImportantRules
&& !aRule
->GetImportantRule();
43 // ForwardOnPossiblyCSSRule should only be used by callers that have
44 // an explicit list of rules they need to walk, with the list
45 // already containing any important rules they care about.
46 void ForwardOnPossiblyCSSRule(nsIStyleRule
* aRule
) {
50 void Reset() { mCurrent
= mRoot
; }
52 bool AtRoot() { return mCurrent
== mRoot
; }
54 void SetLevel(uint8_t aLevel
, bool aImportance
,
55 bool aCheckForImportantRules
) {
56 NS_ASSERTION(!aCheckForImportantRules
|| !aImportance
,
57 "Shouldn't be checking for important rules while walking "
60 mImportance
= aImportance
;
61 mCheckForImportantRules
= aCheckForImportantRules
;
63 uint8_t GetLevel() const { return mLevel
; }
64 bool GetImportance() const { return mImportance
; }
65 bool GetCheckForImportantRules() const { return mCheckForImportantRules
; }
67 bool AuthorStyleDisabled() const { return mAuthorStyleDisabled
; }
69 // We define the visited-relevant link to be the link that is the
70 // nearest self-or-ancestor to the node being matched.
71 enum VisitedHandlingType
{
72 // Do rule matching as though all links are unvisited.
73 eRelevantLinkUnvisited
,
74 // Do rule matching as though the relevant link is visited and all
75 // other links are unvisited.
77 // Do rule matching as though a rule should match if it would match
78 // given any set of visitedness states. (used by users other than
80 eLinksVisitedOrUnvisited
84 nsRuleNode
* mCurrent
; // Our current position. Never null.
85 nsRuleNode
* mRoot
; // The root of the tree we're walking.
86 uint8_t mLevel
; // an nsStyleSet::sheetType
88 bool mCheckForImportantRules
; // If true, check for important rules as
89 // we walk and set to false if we find
91 bool mAuthorStyleDisabled
;
94 nsRuleWalker(nsRuleNode
* aRoot
, bool aAuthorStyleDisabled
)
97 , mAuthorStyleDisabled(aAuthorStyleDisabled
)
99 NS_ASSERTION(mCurrent
, "Caller screwed up and gave us null node");
100 MOZ_COUNT_CTOR(nsRuleWalker
);
102 ~nsRuleWalker() { MOZ_COUNT_DTOR(nsRuleWalker
); }
105 #endif /* !defined(nsRuleWalker_h_) */