Bug 811581 - Add a base class for all *RuleProcessorData classes. r=bz

This commit is contained in:
Cameron McCormack
2012-11-15 06:09:01 +11:00
parent f77a351d66
commit 1c716ff434
8 changed files with 66 additions and 56 deletions

View File

@@ -1256,7 +1256,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
nsresult nsresult
nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData, ElementDependentRuleProcessorData* aData,
bool* aCutOffInheritance) bool* aCutOffInheritance)
{ {
*aCutOffInheritance = false; *aCutOffInheritance = false;
@@ -1321,7 +1321,7 @@ EnumRuleProcessors(nsISupports *aKey, nsXBLBinding *aBinding, void* aClosure)
struct WalkAllRulesData { struct WalkAllRulesData {
nsIStyleRuleProcessor::EnumFunc mFunc; nsIStyleRuleProcessor::EnumFunc mFunc;
RuleProcessorData* mData; ElementDependentRuleProcessorData* mData;
}; };
static PLDHashOperator static PLDHashOperator
@@ -1338,7 +1338,7 @@ EnumWalkAllRules(nsPtrHashKey<nsIStyleRuleProcessor> *aKey, void* aClosure)
void void
nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData) ElementDependentRuleProcessorData* aData)
{ {
if (!mBindingTable.IsInitialized()) if (!mBindingTable.IsInitialized())
return; return;

View File

@@ -16,6 +16,7 @@
#include "nsTArray.h" #include "nsTArray.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
class ElementDependentRuleProcessorData;
class nsIContent; class nsIContent;
class nsIXPConnectWrappedJS; class nsIXPConnectWrappedJS;
class nsIAtom; class nsIAtom;
@@ -181,11 +182,11 @@ public:
// Style rule methods // Style rule methods
nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData, ElementDependentRuleProcessorData* aData,
bool* aCutOffInheritance); bool* aCutOffInheritance);
void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData); ElementDependentRuleProcessorData* aData);
/** /**
* Do any processing that needs to happen as a result of a change in * Do any processing that needs to happen as a result of a change in
* the characteristics of the medium, and return whether this rule * the characteristics of the medium, and return whether this rule

View File

@@ -454,7 +454,7 @@ public:
RuleHash(bool aQuirksMode); RuleHash(bool aQuirksMode);
~RuleHash(); ~RuleHash();
void AppendRule(const RuleSelectorPair &aRuleInfo); void AppendRule(const RuleSelectorPair &aRuleInfo);
void EnumerateAllRules(Element* aElement, RuleProcessorData* aData, void EnumerateAllRules(Element* aElement, ElementDependentRuleProcessorData* aData,
NodeMatchContext& aNodeMatchContext); NodeMatchContext& aNodeMatchContext);
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const; size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
@@ -684,10 +684,10 @@ void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
static inline static inline
void ContentEnumFunc(const RuleValue &value, nsCSSSelector* selector, void ContentEnumFunc(const RuleValue &value, nsCSSSelector* selector,
RuleProcessorData* data, NodeMatchContext& nodeContext, ElementDependentRuleProcessorData* data, NodeMatchContext& nodeContext,
AncestorFilter *ancestorFilter); AncestorFilter *ancestorFilter);
void RuleHash::EnumerateAllRules(Element* aElement, RuleProcessorData* aData, void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcessorData* aData,
NodeMatchContext& aNodeContext) NodeMatchContext& aNodeContext)
{ {
int32_t nameSpace = aElement->GetNameSpaceID(); int32_t nameSpace = aElement->GetNameSpaceID();
@@ -2296,7 +2296,7 @@ static bool SelectorMatchesTree(Element* aPrevElement,
static inline static inline
void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector, void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector,
RuleProcessorData* data, NodeMatchContext& nodeContext, ElementDependentRuleProcessorData* data, NodeMatchContext& nodeContext,
AncestorFilter *ancestorFilter) AncestorFilter *ancestorFilter)
{ {
if (nodeContext.mIsRelevantLink) { if (nodeContext.mIsRelevantLink) {

View File

@@ -224,17 +224,27 @@ struct NS_STACK_CLASS TreeMatchContext {
} }
}; };
// The implementation of the constructor and destructor are currently in struct NS_STACK_CLASS RuleProcessorData {
// nsCSSRuleProcessor.cpp.
struct NS_STACK_CLASS RuleProcessorData {
RuleProcessorData(nsPresContext* aPresContext, RuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aElement, nsRuleWalker* aRuleWalker)
nsRuleWalker* aRuleWalker, : mPresContext(aPresContext),
TreeMatchContext& aTreeMatchContext) mRuleWalker(aRuleWalker)
: mPresContext(aPresContext) {
NS_PRECONDITION(mPresContext, "Must have prescontext");
}
nsPresContext* const mPresContext;
nsRuleWalker* const mRuleWalker; // Used to add rules to our results.
};
struct NS_STACK_CLASS ElementDependentRuleProcessorData :
public RuleProcessorData {
ElementDependentRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aElement,
nsRuleWalker* aRuleWalker,
TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aRuleWalker)
, mElement(aElement) , mElement(aElement)
, mRuleWalker(aRuleWalker)
, mTreeMatchContext(aTreeMatchContext) , mTreeMatchContext(aTreeMatchContext)
{ {
NS_ASSERTION(aElement, "null element leaked into SelectorMatches"); NS_ASSERTION(aElement, "null element leaked into SelectorMatches");
@@ -243,80 +253,75 @@ struct NS_STACK_CLASS RuleProcessorData {
"Should be styling if and only if we have a rule walker"); "Should be styling if and only if we have a rule walker");
} }
nsPresContext* const mPresContext;
mozilla::dom::Element* const mElement; // weak ref, must not be null mozilla::dom::Element* const mElement; // weak ref, must not be null
nsRuleWalker* const mRuleWalker; // Used to add rules to our results.
TreeMatchContext& mTreeMatchContext; TreeMatchContext& mTreeMatchContext;
}; };
struct NS_STACK_CLASS ElementRuleProcessorData : public RuleProcessorData { struct NS_STACK_CLASS ElementRuleProcessorData :
public ElementDependentRuleProcessorData {
ElementRuleProcessorData(nsPresContext* aPresContext, ElementRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aElement, mozilla::dom::Element* aElement,
nsRuleWalker* aRuleWalker, nsRuleWalker* aRuleWalker,
TreeMatchContext& aTreeMatchContext) TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aElement, aRuleWalker, aTreeMatchContext) : ElementDependentRuleProcessorData(aPresContext, aElement, aRuleWalker,
aTreeMatchContext)
{ {
NS_PRECONDITION(aPresContext, "null pointer");
NS_PRECONDITION(aRuleWalker, "null pointer");
NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!"); NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!");
NS_PRECONDITION(aRuleWalker, "Must have rule walker");
} }
}; };
struct NS_STACK_CLASS PseudoElementRuleProcessorData : public RuleProcessorData { struct NS_STACK_CLASS PseudoElementRuleProcessorData :
public ElementDependentRuleProcessorData {
PseudoElementRuleProcessorData(nsPresContext* aPresContext, PseudoElementRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aParentElement, mozilla::dom::Element* aParentElement,
nsRuleWalker* aRuleWalker, nsRuleWalker* aRuleWalker,
nsCSSPseudoElements::Type aPseudoType, nsCSSPseudoElements::Type aPseudoType,
TreeMatchContext& aTreeMatchContext) TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aParentElement, aRuleWalker, : ElementDependentRuleProcessorData(aPresContext, aParentElement, aRuleWalker,
aTreeMatchContext), aTreeMatchContext),
mPseudoType(aPseudoType) mPseudoType(aPseudoType)
{ {
NS_PRECONDITION(aPresContext, "null pointer");
NS_PRECONDITION(aPseudoType < NS_PRECONDITION(aPseudoType <
nsCSSPseudoElements::ePseudo_PseudoElementCount, nsCSSPseudoElements::ePseudo_PseudoElementCount,
"null pointer"); "invalid aPseudoType value");
NS_PRECONDITION(aRuleWalker, "null pointer");
NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!"); NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!");
NS_PRECONDITION(aRuleWalker, "Must have rule walker");
} }
nsCSSPseudoElements::Type mPseudoType; nsCSSPseudoElements::Type mPseudoType;
}; };
struct NS_STACK_CLASS AnonBoxRuleProcessorData { struct NS_STACK_CLASS AnonBoxRuleProcessorData : public RuleProcessorData {
AnonBoxRuleProcessorData(nsPresContext* aPresContext, AnonBoxRuleProcessorData(nsPresContext* aPresContext,
nsIAtom* aPseudoTag, nsIAtom* aPseudoTag,
nsRuleWalker* aRuleWalker) nsRuleWalker* aRuleWalker)
: mPresContext(aPresContext), : RuleProcessorData(aPresContext, aRuleWalker),
mPseudoTag(aPseudoTag), mPseudoTag(aPseudoTag)
mRuleWalker(aRuleWalker)
{ {
NS_PRECONDITION(mPresContext, "Must have prescontext");
NS_PRECONDITION(aPseudoTag, "Must have pseudo tag"); NS_PRECONDITION(aPseudoTag, "Must have pseudo tag");
NS_PRECONDITION(aRuleWalker, "Must have rule walker"); NS_PRECONDITION(aRuleWalker, "Must have rule walker");
} }
nsPresContext* mPresContext;
nsIAtom* mPseudoTag; nsIAtom* mPseudoTag;
nsRuleWalker* mRuleWalker;
}; };
#ifdef MOZ_XUL #ifdef MOZ_XUL
struct NS_STACK_CLASS XULTreeRuleProcessorData : public RuleProcessorData { struct NS_STACK_CLASS XULTreeRuleProcessorData :
public ElementDependentRuleProcessorData {
XULTreeRuleProcessorData(nsPresContext* aPresContext, XULTreeRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aParentElement, mozilla::dom::Element* aParentElement,
nsRuleWalker* aRuleWalker, nsRuleWalker* aRuleWalker,
nsIAtom* aPseudoTag, nsIAtom* aPseudoTag,
nsICSSPseudoComparator* aComparator, nsICSSPseudoComparator* aComparator,
TreeMatchContext& aTreeMatchContext) TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aParentElement, aRuleWalker, : ElementDependentRuleProcessorData(aPresContext, aParentElement,
aTreeMatchContext), aRuleWalker, aTreeMatchContext),
mPseudoTag(aPseudoTag), mPseudoTag(aPseudoTag),
mComparator(aComparator) mComparator(aComparator)
{ {
NS_PRECONDITION(aPresContext, "null pointer");
NS_PRECONDITION(aPseudoTag, "null pointer"); NS_PRECONDITION(aPseudoTag, "null pointer");
NS_PRECONDITION(aRuleWalker, "null pointer"); NS_PRECONDITION(aRuleWalker, "Must have rule walker");
NS_PRECONDITION(aComparator, "must have a comparator"); NS_PRECONDITION(aComparator, "must have a comparator");
NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!"); NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!");
} }
@@ -326,34 +331,36 @@ struct NS_STACK_CLASS XULTreeRuleProcessorData : public RuleProcessorData {
}; };
#endif #endif
struct NS_STACK_CLASS StateRuleProcessorData : public RuleProcessorData { struct NS_STACK_CLASS StateRuleProcessorData :
public ElementDependentRuleProcessorData {
StateRuleProcessorData(nsPresContext* aPresContext, StateRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aElement, mozilla::dom::Element* aElement,
nsEventStates aStateMask, nsEventStates aStateMask,
TreeMatchContext& aTreeMatchContext) TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aElement, nullptr, aTreeMatchContext), : ElementDependentRuleProcessorData(aPresContext, aElement, nullptr,
aTreeMatchContext),
mStateMask(aStateMask) mStateMask(aStateMask)
{ {
NS_PRECONDITION(aPresContext, "null pointer");
NS_PRECONDITION(!aTreeMatchContext.mForStyling, "Not styling here!"); NS_PRECONDITION(!aTreeMatchContext.mForStyling, "Not styling here!");
} }
const nsEventStates mStateMask; // |HasStateDependentStyle| for which state(s)? const nsEventStates mStateMask; // |HasStateDependentStyle| for which state(s)?
// Constants defined in nsEventStates.h . // Constants defined in nsEventStates.h .
}; };
struct NS_STACK_CLASS AttributeRuleProcessorData : public RuleProcessorData { struct NS_STACK_CLASS AttributeRuleProcessorData :
public ElementDependentRuleProcessorData {
AttributeRuleProcessorData(nsPresContext* aPresContext, AttributeRuleProcessorData(nsPresContext* aPresContext,
mozilla::dom::Element* aElement, mozilla::dom::Element* aElement,
nsIAtom* aAttribute, nsIAtom* aAttribute,
int32_t aModType, int32_t aModType,
bool aAttrHasChanged, bool aAttrHasChanged,
TreeMatchContext& aTreeMatchContext) TreeMatchContext& aTreeMatchContext)
: RuleProcessorData(aPresContext, aElement, nullptr, aTreeMatchContext), : ElementDependentRuleProcessorData(aPresContext, aElement, nullptr,
aTreeMatchContext),
mAttribute(aAttribute), mAttribute(aAttribute),
mModType(aModType), mModType(aModType),
mAttrHasChanged(aAttrHasChanged) mAttrHasChanged(aAttrHasChanged)
{ {
NS_PRECONDITION(aPresContext, "null pointer");
NS_PRECONDITION(!aTreeMatchContext.mForStyling, "Not styling here!"); NS_PRECONDITION(!aTreeMatchContext.mForStyling, "Not styling here!");
} }
nsIAtom* mAttribute; // |HasAttributeDependentStyle| for which attribute? nsIAtom* mAttribute; // |HasAttributeDependentStyle| for which attribute?

View File

@@ -738,7 +738,7 @@ nsStyleSet::AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
// Enumerate the rules in a way that cares about the order of the rules. // Enumerate the rules in a way that cares about the order of the rules.
void void
nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
void* aData, nsIContent* aContent, RuleProcessorData* aData, nsIContent* aContent,
nsRuleWalker* aRuleWalker) nsRuleWalker* aRuleWalker)
{ {
SAMPLE_LABEL("nsStyleSet", "FileRules"); SAMPLE_LABEL("nsStyleSet", "FileRules");
@@ -786,7 +786,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
if (mBindingManager && aContent) { if (mBindingManager && aContent) {
// We can supply additional document-level sheets that should be walked. // We can supply additional document-level sheets that should be walked.
mBindingManager->WalkRules(aCollectorFunc, mBindingManager->WalkRules(aCollectorFunc,
static_cast<RuleProcessorData*>(aData), static_cast<ElementDependentRuleProcessorData*>(aData),
&cutOffInheritance); &cutOffInheritance);
} }
if (!skipUserStyles && !cutOffInheritance && if (!skipUserStyles && !cutOffInheritance &&
@@ -872,7 +872,7 @@ nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
// of the rules and doesn't walk !important-rules. // of the rules and doesn't walk !important-rules.
void void
nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc, nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData, ElementDependentRuleProcessorData* aData,
bool aWalkAllXBLStylesheets) bool aWalkAllXBLStylesheets)
{ {
if (mRuleProcessors[eAgentSheet]) if (mRuleProcessors[eAgentSheet])

View File

@@ -30,7 +30,7 @@ class nsIURI;
class nsCSSFontFaceRule; class nsCSSFontFaceRule;
class nsCSSKeyframesRule; class nsCSSKeyframesRule;
class nsRuleWalker; class nsRuleWalker;
struct RuleProcessorData; struct ElementDependentRuleProcessorData;
struct TreeMatchContext; struct TreeMatchContext;
class nsEmptyStyleRule MOZ_FINAL : public nsIStyleRule class nsEmptyStyleRule MOZ_FINAL : public nsIStyleRule
@@ -325,12 +325,13 @@ class nsStyleSet
// is the closure to pass to aCollectorFunc. If aContent is not null, // is the closure to pass to aCollectorFunc. If aContent is not null,
// aData must be a RuleProcessorData* // aData must be a RuleProcessorData*
void FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, void FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
void* aData, nsIContent* aContent, nsRuleWalker* aRuleWalker); RuleProcessorData* aData, nsIContent* aContent,
nsRuleWalker* aRuleWalker);
// Enumerate all the rules in a way that doesn't care about the order // Enumerate all the rules in a way that doesn't care about the order
// of the rules and break out if the enumeration is halted. // of the rules and break out if the enumeration is halted.
void WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc, void WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
RuleProcessorData* aData, ElementDependentRuleProcessorData* aData,
bool aWalkAllXBLStylesheets); bool aWalkAllXBLStylesheets);
already_AddRefed<nsStyleContext> already_AddRefed<nsStyleContext>

View File

@@ -631,7 +631,7 @@ nsTransitionManager::GetElementTransitions(dom::Element *aElement,
*/ */
void void
nsTransitionManager::WalkTransitionRule(RuleProcessorData* aData, nsTransitionManager::WalkTransitionRule(ElementDependentRuleProcessorData* aData,
nsCSSPseudoElements::Type aPseudoType) nsCSSPseudoElements::Type aPseudoType)
{ {
ElementTransitions *et = ElementTransitions *et =

View File

@@ -16,6 +16,7 @@ class nsStyleContext;
class nsPresContext; class nsPresContext;
class nsCSSPropertySet; class nsCSSPropertySet;
struct nsTransition; struct nsTransition;
struct ElementDependentRuleProcessorData;
/***************************************************************************** /*****************************************************************************
* Per-Element data * * Per-Element data *
@@ -162,7 +163,7 @@ private:
ElementTransitions* GetElementTransitions(mozilla::dom::Element *aElement, ElementTransitions* GetElementTransitions(mozilla::dom::Element *aElement,
nsCSSPseudoElements::Type aPseudoType, nsCSSPseudoElements::Type aPseudoType,
bool aCreateIfNeeded); bool aCreateIfNeeded);
void WalkTransitionRule(RuleProcessorData* aData, void WalkTransitionRule(ElementDependentRuleProcessorData* aData,
nsCSSPseudoElements::Type aPseudoType); nsCSSPseudoElements::Type aPseudoType);
}; };