2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* a class that walks the lexicographic tree of rule nodes as style
|
|
|
|
* rules are matched
|
|
|
|
*/
|
|
|
|
|
2010-04-02 18:58:27 -07:00
|
|
|
#ifndef nsRuleWalker_h_
|
|
|
|
#define nsRuleWalker_h_
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleNode.h"
|
2010-04-02 18:58:27 -07:00
|
|
|
#include "nsIStyleRule.h"
|
2011-05-23 13:45:44 -07:00
|
|
|
#include "StyleRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsRuleWalker {
|
|
|
|
public:
|
2009-12-11 22:36:34 -08:00
|
|
|
nsRuleNode* CurrentNode() { return mCurrent; }
|
|
|
|
void SetCurrentNode(nsRuleNode* aNode) {
|
|
|
|
NS_ASSERTION(aNode, "Must have node here!");
|
|
|
|
mCurrent = aNode;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-02 21:53:23 -07:00
|
|
|
nsPresContext* PresContext() const { return mRoot->PresContext(); }
|
|
|
|
|
2011-05-25 13:54:30 -07:00
|
|
|
protected:
|
2011-05-23 13:45:44 -07:00
|
|
|
void DoForward(nsIStyleRule* aRule) {
|
2009-12-11 22:36:34 -08:00
|
|
|
mCurrent = mCurrent->Transition(aRule, mLevel, mImportance);
|
2011-05-23 13:45:44 -07:00
|
|
|
NS_POSTCONDITION(mCurrent, "Transition messed up");
|
|
|
|
}
|
|
|
|
|
2011-05-25 13:54:30 -07:00
|
|
|
public:
|
2011-05-23 13:45:44 -07:00
|
|
|
void Forward(nsIStyleRule* aRule) {
|
2011-05-25 13:54:30 -07:00
|
|
|
NS_PRECONDITION(!nsRefPtr<mozilla::css::StyleRule>(do_QueryObject(aRule)),
|
|
|
|
"Calling the wrong Forward() overload");
|
2011-05-23 13:45:44 -07:00
|
|
|
DoForward(aRule);
|
|
|
|
}
|
|
|
|
void Forward(mozilla::css::StyleRule* aRule) {
|
|
|
|
DoForward(aRule);
|
2009-12-11 22:36:34 -08:00
|
|
|
mCheckForImportantRules =
|
|
|
|
mCheckForImportantRules && !aRule->GetImportantRule();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-05-25 13:54:30 -07: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);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void Reset() { mCurrent = mRoot; }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AtRoot() { return mCurrent == mRoot; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetLevel(uint8_t aLevel, bool aImportance,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCheckForImportantRules) {
|
2009-12-10 14:36:02 -08:00
|
|
|
NS_ASSERTION(!aCheckForImportantRules || !aImportance,
|
|
|
|
"Shouldn't be checking for important rules while walking "
|
|
|
|
"important rules");
|
2007-05-16 14:08:51 -07:00
|
|
|
mLevel = aLevel;
|
|
|
|
mImportance = aImportance;
|
2009-12-10 14:36:02 -08:00
|
|
|
mCheckForImportantRules = aCheckForImportantRules;
|
2007-05-16 14:08:51 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t GetLevel() const { return mLevel; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetImportance() const { return mImportance; }
|
|
|
|
bool GetCheckForImportantRules() const { return mCheckForImportantRules; }
|
2007-05-16 14:08:51 -07:00
|
|
|
|
2013-03-27 19:47:25 -07:00
|
|
|
bool AuthorStyleDisabled() const { return mAuthorStyleDisabled; }
|
|
|
|
|
2010-04-02 18:58:27 -07: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
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2009-12-11 22:36:34 -08:00
|
|
|
nsRuleNode* mCurrent; // Our current position. Never null.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRuleNode* mRoot; // The root of the tree we're walking.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mLevel; // an nsStyleSet::sheetType
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mImportance;
|
|
|
|
bool mCheckForImportantRules; // If true, check for important rules as
|
2013-03-27 19:47:25 -07:00
|
|
|
// we walk and set to false if we find
|
|
|
|
// one.
|
|
|
|
bool mAuthorStyleDisabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
2013-03-27 19:47:25 -07:00
|
|
|
nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled)
|
2010-04-02 18:58:27 -07:00
|
|
|
: mCurrent(aRoot)
|
|
|
|
, mRoot(aRoot)
|
2013-03-27 19:47:25 -07:00
|
|
|
, mAuthorStyleDisabled(aAuthorStyleDisabled)
|
2010-04-02 18:58:27 -07:00
|
|
|
{
|
2009-12-11 22:36:34 -08:00
|
|
|
NS_ASSERTION(mCurrent, "Caller screwed up and gave us null node");
|
|
|
|
MOZ_COUNT_CTOR(nsRuleWalker);
|
|
|
|
}
|
2007-04-23 07:21:53 -07:00
|
|
|
~nsRuleWalker() { MOZ_COUNT_DTOR(nsRuleWalker); }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2010-04-02 18:58:27 -07:00
|
|
|
|
|
|
|
#endif /* !defined(nsRuleWalker_h_) */
|