| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class RenderScrollbar; | 40 class RenderScrollbar; |
| 41 class RenderStyle; | 41 class RenderStyle; |
| 42 | 42 |
| 43 class SelectorChecker { | 43 class SelectorChecker { |
| 44 WTF_MAKE_NONCOPYABLE(SelectorChecker); | 44 WTF_MAKE_NONCOPYABLE(SelectorChecker); |
| 45 public: | 45 public: |
| 46 enum Match { SelectorMatches, SelectorFailsLocally, SelectorFailsAllSiblings
, SelectorFailsCompletely }; | 46 enum Match { SelectorMatches, SelectorFailsLocally, SelectorFailsAllSiblings
, SelectorFailsCompletely }; |
| 47 enum VisitedMatchType { VisitedMatchDisabled, VisitedMatchEnabled }; | 47 enum VisitedMatchType { VisitedMatchDisabled, VisitedMatchEnabled }; |
| 48 enum Mode { ResolvingStyle = 0, CollectingStyleRules, CollectingCSSRules, Qu
eryingRules, SharingRules }; | 48 enum Mode { ResolvingStyle = 0, CollectingStyleRules, CollectingCSSRules, Qu
eryingRules, SharingRules }; |
| 49 explicit SelectorChecker(Document&, Mode); | 49 explicit SelectorChecker(Document&, Mode); |
| 50 enum BehaviorAtBoundary { | 50 enum ContextFlags { |
| 51 DoesNotCrossBoundary = 0, | 51 // FIXME: Revmoe DefaultBehavior. |
| 52 // FIXME: refactor to remove BoundaryBehavior (i.e. DoesNotCrossBoundary
and StaysWithinTreeScope). | 52 DefaultBehavior = 0, |
| 53 StaysWithinTreeScope = 2, | 53 ScopeContainsLastMatchedElement = 1, |
| 54 BoundaryBehaviorMask = 3, // 2bit for boundary behavior | 54 TreatShadowHostAsNormalScope = 2, |
| 55 ScopeContainsLastMatchedElement = 4, | |
| 56 ScopeIsShadowRoot = 8, | |
| 57 TreatShadowHostAsNormalScope = 16, | |
| 58 | |
| 59 ScopeIsShadowHostInPseudoHostParameter = ScopeIsShadowRoot | TreatShadow
HostAsNormalScope | |
| 60 }; | 55 }; |
| 61 | 56 |
| 62 struct SelectorCheckingContext { | 57 struct SelectorCheckingContext { |
| 63 // Initial selector constructor | 58 // Initial selector constructor |
| 64 SelectorCheckingContext(const CSSSelector& selector, Element* element, V
isitedMatchType visitedMatchType) | 59 SelectorCheckingContext(const CSSSelector& selector, Element* element, V
isitedMatchType visitedMatchType) |
| 65 : selector(&selector) | 60 : selector(&selector) |
| 66 , element(element) | 61 , element(element) |
| 67 , previousElement(0) | 62 , previousElement(0) |
| 68 , scope(0) | 63 , scope(0) |
| 69 , visitedMatchType(visitedMatchType) | 64 , visitedMatchType(visitedMatchType) |
| 70 , pseudoId(NOPSEUDO) | 65 , pseudoId(NOPSEUDO) |
| 71 , elementStyle(0) | 66 , elementStyle(0) |
| 72 , scrollbar(0) | 67 , scrollbar(0) |
| 73 , scrollbarPart(NoPart) | 68 , scrollbarPart(NoPart) |
| 74 , isSubSelector(false) | 69 , isSubSelector(false) |
| 75 , hasScrollbarPseudo(false) | 70 , hasScrollbarPseudo(false) |
| 76 , hasSelectionPseudo(false) | 71 , hasSelectionPseudo(false) |
| 77 , behaviorAtBoundary(DoesNotCrossBoundary) | 72 , contextFlags(DefaultBehavior) |
| 78 { } | 73 { } |
| 79 | 74 |
| 80 const CSSSelector* selector; | 75 const CSSSelector* selector; |
| 81 Element* element; | 76 Element* element; |
| 82 Element* previousElement; | 77 Element* previousElement; |
| 83 const ContainerNode* scope; | 78 const ContainerNode* scope; |
| 84 VisitedMatchType visitedMatchType; | 79 VisitedMatchType visitedMatchType; |
| 85 PseudoId pseudoId; | 80 PseudoId pseudoId; |
| 86 RenderStyle* elementStyle; | 81 RenderStyle* elementStyle; |
| 87 RenderScrollbar* scrollbar; | 82 RenderScrollbar* scrollbar; |
| 88 ScrollbarPart scrollbarPart; | 83 ScrollbarPart scrollbarPart; |
| 89 bool isSubSelector; | 84 bool isSubSelector; |
| 90 bool hasScrollbarPseudo; | 85 bool hasScrollbarPseudo; |
| 91 bool hasSelectionPseudo; | 86 bool hasSelectionPseudo; |
| 92 BehaviorAtBoundary behaviorAtBoundary; | 87 ContextFlags contextFlags; |
| 93 }; | 88 }; |
| 94 | 89 |
| 95 struct MatchResult { | 90 struct MatchResult { |
| 96 MatchResult() | 91 MatchResult() |
| 97 : dynamicPseudo(NOPSEUDO) | 92 : dynamicPseudo(NOPSEUDO) |
| 98 , specificity(0) { } | 93 , specificity(0) { } |
| 99 | 94 |
| 100 PseudoId dynamicPseudo; | 95 PseudoId dynamicPseudo; |
| 101 unsigned specificity; | 96 unsigned specificity; |
| 102 }; | 97 }; |
| 103 | 98 |
| 104 template<typename SiblingTraversalStrategy> | 99 template<typename SiblingTraversalStrategy> |
| 105 Match match(const SelectorCheckingContext&, const SiblingTraversalStrategy&,
MatchResult* = 0) const; | 100 Match match(const SelectorCheckingContext&, const SiblingTraversalStrategy&,
MatchResult* = 0) const; |
| 106 | 101 |
| 107 template<typename SiblingTraversalStrategy> | 102 template<typename SiblingTraversalStrategy> |
| 108 bool checkOne(const SelectorCheckingContext&, const SiblingTraversalStrategy
&, unsigned* specificity = 0) const; | 103 bool checkOne(const SelectorCheckingContext&, const SiblingTraversalStrategy
&, unsigned* specificity = 0) const; |
| 109 | 104 |
| 110 bool strictParsing() const { return m_strictParsing; } | 105 bool strictParsing() const { return m_strictParsing; } |
| 111 | 106 |
| 112 Mode mode() const { return m_mode; } | 107 Mode mode() const { return m_mode; } |
| 113 | 108 |
| 114 static bool tagMatches(const Element&, const QualifiedName&); | 109 static bool tagMatches(const Element&, const QualifiedName&); |
| 115 static bool isCommonPseudoClassSelector(const CSSSelector&); | 110 static bool isCommonPseudoClassSelector(const CSSSelector&); |
| 116 static bool matchesFocusPseudoClass(const Element&); | 111 static bool matchesFocusPseudoClass(const Element&); |
| 117 static bool checkExactAttribute(const Element&, const QualifiedName& selecto
rAttributeName, const StringImpl* value); | 112 static bool checkExactAttribute(const Element&, const QualifiedName& selecto
rAttributeName, const StringImpl* value); |
| 118 | 113 |
| 119 enum LinkMatchMask { MatchLink = 1, MatchVisited = 2, MatchAll = MatchLink |
MatchVisited }; | 114 enum LinkMatchMask { MatchLink = 1, MatchVisited = 2, MatchAll = MatchLink |
MatchVisited }; |
| 120 static unsigned determineLinkMatchType(const CSSSelector&); | 115 static unsigned determineLinkMatchType(const CSSSelector&); |
| 121 | 116 |
| 122 static bool isHostInItsShadowTree(const Element&, BehaviorAtBoundary, const
ContainerNode* scope); | 117 static bool isHostInItsShadowTree(const Element&, const ContainerNode* scope
); |
| 123 | 118 |
| 124 private: | 119 private: |
| 125 template<typename SiblingTraversalStrategy> | 120 template<typename SiblingTraversalStrategy> |
| 126 Match matchForSubSelector(const SelectorCheckingContext&, const SiblingTrave
rsalStrategy&, MatchResult*) const; | 121 Match matchForSubSelector(const SelectorCheckingContext&, const SiblingTrave
rsalStrategy&, MatchResult*) const; |
| 127 template<typename SiblingTraversalStrategy> | 122 template<typename SiblingTraversalStrategy> |
| 128 Match matchForRelation(const SelectorCheckingContext&, const SiblingTraversa
lStrategy&, MatchResult*) const; | 123 Match matchForRelation(const SelectorCheckingContext&, const SiblingTraversa
lStrategy&, MatchResult*) const; |
| 129 template<typename SiblingTraversalStrategy> | 124 template<typename SiblingTraversalStrategy> |
| 130 Match matchForShadowDistributed(const Element*, const SiblingTraversalStrate
gy&, SelectorCheckingContext& nextContext, MatchResult* = 0) const; | 125 Match matchForShadowDistributed(const Element*, const SiblingTraversalStrate
gy&, SelectorCheckingContext& nextContext, MatchResult* = 0) const; |
| 131 template<typename SiblingTraversalStrategy> | 126 template<typename SiblingTraversalStrategy> |
| 132 Match matchForPseudoShadow(const ContainerNode*, const SelectorCheckingConte
xt&, const SiblingTraversalStrategy&, MatchResult*) const; | 127 Match matchForPseudoShadow(const ContainerNode*, const SelectorCheckingConte
xt&, const SiblingTraversalStrategy&, MatchResult*) const; |
| 133 | 128 |
| 134 bool checkScrollbarPseudoClass(const SelectorCheckingContext&, Document*, co
nst CSSSelector&) const; | 129 bool checkScrollbarPseudoClass(const SelectorCheckingContext&, Document*, co
nst CSSSelector&) const; |
| 135 Element* parentElement(const SelectorCheckingContext&, bool allowToCrossBoun
dary = false) const; | |
| 136 bool scopeContainsLastMatchedElement(const SelectorCheckingContext&) const; | |
| 137 | 130 |
| 138 static bool isFrameFocused(const Element&); | 131 static bool isFrameFocused(const Element&); |
| 139 | 132 |
| 140 bool m_strictParsing; | 133 bool m_strictParsing; |
| 141 bool m_documentIsHTML; | 134 bool m_documentIsHTML; |
| 142 Mode m_mode; | 135 Mode m_mode; |
| 143 }; | 136 }; |
| 144 | 137 |
| 145 inline bool SelectorChecker::isCommonPseudoClassSelector(const CSSSelector& sele
ctor) | 138 inline bool SelectorChecker::isCommonPseudoClassSelector(const CSSSelector& sele
ctor) |
| 146 { | 139 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 170 return false; | 163 return false; |
| 171 AttributeCollection attributes = element.attributes(); | 164 AttributeCollection attributes = element.attributes(); |
| 172 AttributeCollection::const_iterator end = attributes.end(); | 165 AttributeCollection::const_iterator end = attributes.end(); |
| 173 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { | 166 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { |
| 174 if (it->matches(selectorAttributeName) && (!value || it->value().impl()
== value)) | 167 if (it->matches(selectorAttributeName) && (!value || it->value().impl()
== value)) |
| 175 return true; | 168 return true; |
| 176 } | 169 } |
| 177 return false; | 170 return false; |
| 178 } | 171 } |
| 179 | 172 |
| 180 inline bool SelectorChecker::isHostInItsShadowTree(const Element& element, Behav
iorAtBoundary behaviorAtBoundary, const ContainerNode* scope) | 173 inline bool SelectorChecker::isHostInItsShadowTree(const Element& element, const
ContainerNode* scope) |
| 181 { | 174 { |
| 182 return scope && scope->isInShadowTree() && scope->shadowHost() == element; | 175 return scope && scope->isInShadowTree() && scope->shadowHost() == element; |
| 183 } | 176 } |
| 184 | 177 |
| 185 } | 178 } |
| 186 | 179 |
| 187 #endif | 180 #endif |
| OLD | NEW |