Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / layout / style / nsRuleWalker.h
bloba9480a91efe8de238a5ffadc32472c9948cbc4df
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/. */
6 /*
7 * a class that walks the lexicographic tree of rule nodes as style
8 * rules are matched
9 */
11 #ifndef nsRuleWalker_h_
12 #define nsRuleWalker_h_
14 #include "nsRuleNode.h"
15 #include "nsIStyleRule.h"
16 #include "StyleRule.h"
18 class nsRuleWalker {
19 public:
20 nsRuleNode* CurrentNode() { return mCurrent; }
21 void SetCurrentNode(nsRuleNode* aNode) {
22 NS_ASSERTION(aNode, "Must have node here!");
23 mCurrent = aNode;
26 protected:
27 void DoForward(nsIStyleRule* aRule) {
28 mCurrent = mCurrent->Transition(aRule, mLevel, mImportance);
29 NS_POSTCONDITION(mCurrent, "Transition messed up");
32 public:
33 void Forward(nsIStyleRule* aRule) {
34 NS_PRECONDITION(!nsRefPtr<mozilla::css::StyleRule>(do_QueryObject(aRule)),
35 "Calling the wrong Forward() overload");
36 DoForward(aRule);
38 void Forward(mozilla::css::StyleRule* aRule) {
39 DoForward(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) {
47 DoForward(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 "
58 "important rules");
59 mLevel = aLevel;
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.
76 eRelevantLinkVisited,
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
79 // nsRuleWalker)
80 eLinksVisitedOrUnvisited
83 private:
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
87 bool mImportance;
88 bool mCheckForImportantRules; // If true, check for important rules as
89 // we walk and set to false if we find
90 // one.
91 bool mAuthorStyleDisabled;
93 public:
94 nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled)
95 : mCurrent(aRoot)
96 , mRoot(aRoot)
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_) */