Bug 1180118 - Part 1: Add a method to match a single nsCSSSelector (without pseudo-elements) against an Element. r=bzbarsky
This commit is contained in:
@@ -159,6 +159,12 @@ public:
|
||||
void ToString(nsAString& aString, mozilla::CSSStyleSheet* aSheet,
|
||||
bool aAppend = false) const;
|
||||
|
||||
#ifdef DEBUG
|
||||
bool IsRestrictedSelector() const {
|
||||
return PseudoType() == nsCSSPseudoElements::ePseudo_NotPseudoElement;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void AddPseudoClassInternal(nsPseudoClassList *aPseudoClass);
|
||||
nsCSSSelector* Clone(bool aDeepNext, bool aDeepNegations) const;
|
||||
|
||||
@@ -2293,6 +2293,36 @@ static bool SelectorMatches(Element* aElement,
|
||||
|
||||
#undef STATE_CHECK
|
||||
|
||||
/* static */ bool
|
||||
nsCSSRuleProcessor::RestrictedSelectorMatches(
|
||||
Element* aElement,
|
||||
nsCSSSelector* aSelector,
|
||||
TreeMatchContext& aTreeMatchContext)
|
||||
{
|
||||
MOZ_ASSERT(aSelector->IsRestrictedSelector(),
|
||||
"aSelector must not have a pseudo-element");
|
||||
|
||||
// We match aSelector as if :visited and :link both match visited and
|
||||
// unvisited links.
|
||||
|
||||
NodeMatchContext nodeContext(EventStates(),
|
||||
nsCSSRuleProcessor::IsLink(aElement));
|
||||
if (nodeContext.mIsRelevantLink) {
|
||||
aTreeMatchContext.SetHaveRelevantLink();
|
||||
}
|
||||
aTreeMatchContext.ResetForUnvisitedMatching();
|
||||
bool matches = SelectorMatches(aElement, aSelector, nodeContext,
|
||||
aTreeMatchContext, SelectorMatchesFlags::NONE);
|
||||
if (nodeContext.mIsRelevantLink) {
|
||||
aTreeMatchContext.ResetForVisitedMatching();
|
||||
if (SelectorMatches(aElement, aSelector, nodeContext, aTreeMatchContext,
|
||||
SelectorMatchesFlags::NONE)) {
|
||||
matches = true;
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
// Right now, there are four operators:
|
||||
// ' ', the descendant combinator, is greedy
|
||||
// '~', the indirect adjacent sibling combinator, is greedy
|
||||
|
||||
@@ -112,6 +112,21 @@ public:
|
||||
*/
|
||||
static bool IsLink(mozilla::dom::Element* aElement);
|
||||
|
||||
/**
|
||||
* Returns true if the given aElement matches aSelector.
|
||||
* Like nsCSSRuleProcessor.cpp's SelectorMatches (and unlike
|
||||
* SelectorMatchesTree), this does not check an entire selector list
|
||||
* separated by combinators.
|
||||
*
|
||||
* :visited and :link will match both visited and non-visited links,
|
||||
* as if aTreeMatchContext->mVisitedHandling were eLinksVisitedOrUnvisited.
|
||||
*
|
||||
* aSelector is restricted to not containing pseudo-elements.
|
||||
*/
|
||||
static bool RestrictedSelectorMatches(mozilla::dom::Element* aElement,
|
||||
nsCSSSelector* aSelector,
|
||||
TreeMatchContext& aTreeMatchContext);
|
||||
|
||||
// nsIStyleRuleProcessor
|
||||
virtual void RulesMatching(ElementRuleProcessorData* aData) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user