layout/style/nsRuleWalker.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial