1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsRuleWalker.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * a class that walks the lexicographic tree of rule nodes as style 1.11 + * rules are matched 1.12 + */ 1.13 + 1.14 +#ifndef nsRuleWalker_h_ 1.15 +#define nsRuleWalker_h_ 1.16 + 1.17 +#include "nsRuleNode.h" 1.18 +#include "nsIStyleRule.h" 1.19 +#include "StyleRule.h" 1.20 + 1.21 +class nsRuleWalker { 1.22 +public: 1.23 + nsRuleNode* CurrentNode() { return mCurrent; } 1.24 + void SetCurrentNode(nsRuleNode* aNode) { 1.25 + NS_ASSERTION(aNode, "Must have node here!"); 1.26 + mCurrent = aNode; 1.27 + } 1.28 + 1.29 +protected: 1.30 + void DoForward(nsIStyleRule* aRule) { 1.31 + mCurrent = mCurrent->Transition(aRule, mLevel, mImportance); 1.32 + NS_POSTCONDITION(mCurrent, "Transition messed up"); 1.33 + } 1.34 + 1.35 +public: 1.36 + void Forward(nsIStyleRule* aRule) { 1.37 + NS_PRECONDITION(!nsRefPtr<mozilla::css::StyleRule>(do_QueryObject(aRule)), 1.38 + "Calling the wrong Forward() overload"); 1.39 + DoForward(aRule); 1.40 + } 1.41 + void Forward(mozilla::css::StyleRule* aRule) { 1.42 + DoForward(aRule); 1.43 + mCheckForImportantRules = 1.44 + mCheckForImportantRules && !aRule->GetImportantRule(); 1.45 + } 1.46 + // ForwardOnPossiblyCSSRule should only be used by callers that have 1.47 + // an explicit list of rules they need to walk, with the list 1.48 + // already containing any important rules they care about. 1.49 + void ForwardOnPossiblyCSSRule(nsIStyleRule* aRule) { 1.50 + DoForward(aRule); 1.51 + } 1.52 + 1.53 + void Reset() { mCurrent = mRoot; } 1.54 + 1.55 + bool AtRoot() { return mCurrent == mRoot; } 1.56 + 1.57 + void SetLevel(uint8_t aLevel, bool aImportance, 1.58 + bool aCheckForImportantRules) { 1.59 + NS_ASSERTION(!aCheckForImportantRules || !aImportance, 1.60 + "Shouldn't be checking for important rules while walking " 1.61 + "important rules"); 1.62 + mLevel = aLevel; 1.63 + mImportance = aImportance; 1.64 + mCheckForImportantRules = aCheckForImportantRules; 1.65 + } 1.66 + uint8_t GetLevel() const { return mLevel; } 1.67 + bool GetImportance() const { return mImportance; } 1.68 + bool GetCheckForImportantRules() const { return mCheckForImportantRules; } 1.69 + 1.70 + bool AuthorStyleDisabled() const { return mAuthorStyleDisabled; } 1.71 + 1.72 + // We define the visited-relevant link to be the link that is the 1.73 + // nearest self-or-ancestor to the node being matched. 1.74 + enum VisitedHandlingType { 1.75 + // Do rule matching as though all links are unvisited. 1.76 + eRelevantLinkUnvisited, 1.77 + // Do rule matching as though the relevant link is visited and all 1.78 + // other links are unvisited. 1.79 + eRelevantLinkVisited, 1.80 + // Do rule matching as though a rule should match if it would match 1.81 + // given any set of visitedness states. (used by users other than 1.82 + // nsRuleWalker) 1.83 + eLinksVisitedOrUnvisited 1.84 + }; 1.85 + 1.86 +private: 1.87 + nsRuleNode* mCurrent; // Our current position. Never null. 1.88 + nsRuleNode* mRoot; // The root of the tree we're walking. 1.89 + uint8_t mLevel; // an nsStyleSet::sheetType 1.90 + bool mImportance; 1.91 + bool mCheckForImportantRules; // If true, check for important rules as 1.92 + // we walk and set to false if we find 1.93 + // one. 1.94 + bool mAuthorStyleDisabled; 1.95 + 1.96 +public: 1.97 + nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled) 1.98 + : mCurrent(aRoot) 1.99 + , mRoot(aRoot) 1.100 + , mAuthorStyleDisabled(aAuthorStyleDisabled) 1.101 + { 1.102 + NS_ASSERTION(mCurrent, "Caller screwed up and gave us null node"); 1.103 + MOZ_COUNT_CTOR(nsRuleWalker); 1.104 + } 1.105 + ~nsRuleWalker() { MOZ_COUNT_DTOR(nsRuleWalker); } 1.106 +}; 1.107 + 1.108 +#endif /* !defined(nsRuleWalker_h_) */