2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/*
|
|
|
|
* a class that walks the lexicographic tree of rule nodes as style
|
|
|
|
* rules are matched
|
|
|
|
*/
|
|
|
|
|
2010-04-03 01:58:27 +00:00
|
|
|
#ifndef nsRuleWalker_h_
|
|
|
|
#define nsRuleWalker_h_
|
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsRuleNode.h"
|
2010-04-03 01:58:27 +00:00
|
|
|
#include "nsIStyleRule.h"
|
2011-05-23 20:45:44 +00:00
|
|
|
#include "StyleRule.h"
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
class nsRuleWalker {
|
2001-05-31 22:19:43 +00:00
|
|
|
public:
|
2009-12-12 06:36:34 +00:00
|
|
|
nsRuleNode* CurrentNode() { return mCurrent; }
|
|
|
|
void SetCurrentNode(nsRuleNode* aNode) {
|
|
|
|
NS_ASSERTION(aNode, "Must have node here!");
|
|
|
|
mCurrent = aNode;
|
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2011-05-25 20:54:30 +00:00
|
|
|
protected:
|
2011-05-23 20:45:44 +00:00
|
|
|
void DoForward(nsIStyleRule* aRule) {
|
2009-12-12 06:36:34 +00:00
|
|
|
mCurrent = mCurrent->Transition(aRule, mLevel, mImportance);
|
2011-05-23 20:45:44 +00:00
|
|
|
NS_POSTCONDITION(mCurrent, "Transition messed up");
|
|
|
|
}
|
|
|
|
|
2011-05-25 20:54:30 +00:00
|
|
|
public:
|
2011-05-23 20:45:44 +00:00
|
|
|
void Forward(nsIStyleRule* aRule) {
|
2011-05-25 20:54:30 +00:00
|
|
|
NS_PRECONDITION(!nsRefPtr<mozilla::css::StyleRule>(do_QueryObject(aRule)),
|
|
|
|
"Calling the wrong Forward() overload");
|
2011-05-23 20:45:44 +00:00
|
|
|
DoForward(aRule);
|
|
|
|
}
|
|
|
|
void Forward(mozilla::css::StyleRule* aRule) {
|
|
|
|
DoForward(aRule);
|
2009-12-12 06:36:34 +00:00
|
|
|
mCheckForImportantRules =
|
|
|
|
mCheckForImportantRules && !aRule->GetImportantRule();
|
2001-10-24 00:01:09 +00:00
|
|
|
}
|
2011-05-25 20:54:30 +00:00
|
|
|
// ForwardOnPossiblyCSSRule should only be used by callers that have
|
|
|
|
// an explicit list of rules they need to walk, with the list
|
|
|
|
// already containing any important rules they care about.
|
|
|
|
void ForwardOnPossiblyCSSRule(nsIStyleRule* aRule) {
|
|
|
|
DoForward(aRule);
|
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
void Reset() { mCurrent = mRoot; }
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool AtRoot() { return mCurrent == mRoot; }
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetLevel(uint8_t aLevel, bool aImportance,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCheckForImportantRules) {
|
2009-12-10 22:36:02 +00:00
|
|
|
NS_ASSERTION(!aCheckForImportantRules || !aImportance,
|
|
|
|
"Shouldn't be checking for important rules while walking "
|
|
|
|
"important rules");
|
2007-05-16 21:08:51 +00:00
|
|
|
mLevel = aLevel;
|
|
|
|
mImportance = aImportance;
|
2009-12-10 22:36:02 +00:00
|
|
|
mCheckForImportantRules = aCheckForImportantRules;
|
2007-05-16 21:08:51 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t GetLevel() const { return mLevel; }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetImportance() const { return mImportance; }
|
|
|
|
bool GetCheckForImportantRules() const { return mCheckForImportantRules; }
|
2007-05-16 21:08:51 +00:00
|
|
|
|
2013-03-28 02:47:25 +00:00
|
|
|
bool AuthorStyleDisabled() const { return mAuthorStyleDisabled; }
|
|
|
|
|
2010-04-03 01:58:27 +00:00
|
|
|
// We define the visited-relevant link to be the link that is the
|
|
|
|
// nearest self-or-ancestor to the node being matched.
|
|
|
|
enum VisitedHandlingType {
|
|
|
|
// Do rule matching as though all links are unvisited.
|
|
|
|
eRelevantLinkUnvisited,
|
|
|
|
// Do rule matching as though the relevant link is visited and all
|
|
|
|
// other links are unvisited.
|
|
|
|
eRelevantLinkVisited,
|
|
|
|
// Do rule matching as though a rule should match if it would match
|
|
|
|
// given any set of visitedness states. (used by users other than
|
|
|
|
// nsRuleWalker)
|
|
|
|
eLinksVisitedOrUnvisited
|
|
|
|
};
|
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
private:
|
2009-12-12 06:36:34 +00:00
|
|
|
nsRuleNode* mCurrent; // Our current position. Never null.
|
2001-10-24 00:01:09 +00:00
|
|
|
nsRuleNode* mRoot; // The root of the tree we're walking.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mLevel; // an nsStyleSet::sheetType
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mImportance;
|
|
|
|
bool mCheckForImportantRules; // If true, check for important rules as
|
2013-03-28 02:47:25 +00:00
|
|
|
// we walk and set to false if we find
|
|
|
|
// one.
|
|
|
|
bool mAuthorStyleDisabled;
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
public:
|
2013-03-28 02:47:25 +00:00
|
|
|
nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled)
|
2010-04-03 01:58:27 +00:00
|
|
|
: mCurrent(aRoot)
|
|
|
|
, mRoot(aRoot)
|
2013-03-28 02:47:25 +00:00
|
|
|
, mAuthorStyleDisabled(aAuthorStyleDisabled)
|
2010-04-03 01:58:27 +00:00
|
|
|
{
|
2009-12-12 06:36:34 +00:00
|
|
|
NS_ASSERTION(mCurrent, "Caller screwed up and gave us null node");
|
|
|
|
MOZ_COUNT_CTOR(nsRuleWalker);
|
|
|
|
}
|
2007-04-23 14:21:53 +00:00
|
|
|
~nsRuleWalker() { MOZ_COUNT_DTOR(nsRuleWalker); }
|
2001-10-24 00:01:09 +00:00
|
|
|
};
|
2010-04-03 01:58:27 +00:00
|
|
|
|
|
|
|
#endif /* !defined(nsRuleWalker_h_) */
|