Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: Source/core/css/SelectorChecker.cpp

Issue 15657003: Make a '::distributed' pseudo element the first-ever client who can accept a relative selector. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Introduce m_relationIsForShadowDistributed Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/SelectorChecker.h ('k') | Source/core/css/SelectorFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 // Disable :visited matching when we see the first link or try to match anything else than an ancestors. 133 // Disable :visited matching when we see the first link or try to match anything else than an ancestors.
134 if (!context.isSubSelector && (context.element->isLink() || (relation != CSSSelector::Descendant && relation != CSSSelector::Child))) 134 if (!context.isSubSelector && (context.element->isLink() || (relation != CSSSelector::Descendant && relation != CSSSelector::Child)))
135 nextContext.visitedMatchType = VisitedMatchDisabled; 135 nextContext.visitedMatchType = VisitedMatchDisabled;
136 136
137 nextContext.pseudoId = NOPSEUDO; 137 nextContext.pseudoId = NOPSEUDO;
138 } 138 }
139 139
140 switch (relation) { 140 switch (relation) {
141 case CSSSelector::Descendant: 141 case CSSSelector::Descendant:
142 if (context.selector->relationIsForShadowDistributed()) {
143 for (Element* element = context.element; element; element = element- >parentElement()) {
144 if (matchForShadowDistributed(element, siblingTraversalStrategy, ignoreDynamicPseudo, nextContext) == SelectorMatches)
145 return SelectorMatches;
146 }
147 return SelectorFailsCompletely;
148 }
142 nextContext.element = context.element->parentElement(); 149 nextContext.element = context.element->parentElement();
143 nextContext.isSubSelector = false; 150 nextContext.isSubSelector = false;
144 nextContext.elementStyle = 0; 151 nextContext.elementStyle = 0;
145 for (; nextContext.element; nextContext.element = nextContext.element->p arentElement()) { 152 for (; nextContext.element; nextContext.element = nextContext.element->p arentElement()) {
146 Match match = this->match(nextContext, ignoreDynamicPseudo, siblingT raversalStrategy); 153 Match match = this->match(nextContext, ignoreDynamicPseudo, siblingT raversalStrategy);
147 if (match == SelectorMatches || match == SelectorFailsCompletely) 154 if (match == SelectorMatches || match == SelectorFailsCompletely)
148 return match; 155 return match;
149 if (nextContext.element == nextContext.scope && (nextContext.behavio rAtBoundary & BoundaryBehaviorMask) != StaysWithinTreeScope) 156 if (nextContext.element == nextContext.scope && (nextContext.behavio rAtBoundary & BoundaryBehaviorMask) != StaysWithinTreeScope)
150 return SelectorFailsCompletely; 157 return SelectorFailsCompletely;
151 } 158 }
152 return SelectorFailsCompletely; 159 return SelectorFailsCompletely;
153
154 case CSSSelector::Child: 160 case CSSSelector::Child:
161 if (context.selector->relationIsForShadowDistributed())
162 return matchForShadowDistributed(context.element, siblingTraversalSt rategy, ignoreDynamicPseudo, nextContext);
155 nextContext.element = context.element->parentElement(); 163 nextContext.element = context.element->parentElement();
156 if (!nextContext.element) 164 if (!nextContext.element)
157 return SelectorFailsCompletely; 165 return SelectorFailsCompletely;
158 nextContext.isSubSelector = false; 166 nextContext.isSubSelector = false;
159 nextContext.elementStyle = 0; 167 nextContext.elementStyle = 0;
160 return match(nextContext, ignoreDynamicPseudo, siblingTraversalStrategy) ; 168 return match(nextContext, ignoreDynamicPseudo, siblingTraversalStrategy) ;
161
162 case CSSSelector::DirectAdjacent: 169 case CSSSelector::DirectAdjacent:
163 if (m_mode == ResolvingStyle) { 170 if (m_mode == ResolvingStyle) {
164 if (Element* parentElement = context.element->parentElement()) 171 if (Element* parentElement = context.element->parentElement())
165 parentElement->setChildrenAffectedByDirectAdjacentRules(); 172 parentElement->setChildrenAffectedByDirectAdjacentRules();
166 } 173 }
167 nextContext.element = context.element->previousElementSibling(); 174 nextContext.element = context.element->previousElementSibling();
168 if (!nextContext.element) 175 if (!nextContext.element)
169 return SelectorFailsAllSiblings; 176 return SelectorFailsAllSiblings;
170 nextContext.isSubSelector = false; 177 nextContext.isSubSelector = false;
171 nextContext.elementStyle = 0; 178 nextContext.elementStyle = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (context.scope && context.scope->treeScope() == context.element-> treeScope() && (context.behaviorAtBoundary & BoundaryBehaviorMask) != StaysWithi nTreeScope) 212 if (context.scope && context.scope->treeScope() == context.element-> treeScope() && (context.behaviorAtBoundary & BoundaryBehaviorMask) != StaysWithi nTreeScope)
206 return SelectorFailsCompletely; 213 return SelectorFailsCompletely;
207 Element* shadowHostNode = context.element->shadowHost(); 214 Element* shadowHostNode = context.element->shadowHost();
208 if (!shadowHostNode) 215 if (!shadowHostNode)
209 return SelectorFailsCompletely; 216 return SelectorFailsCompletely;
210 nextContext.element = shadowHostNode; 217 nextContext.element = shadowHostNode;
211 nextContext.isSubSelector = false; 218 nextContext.isSubSelector = false;
212 nextContext.elementStyle = 0; 219 nextContext.elementStyle = 0;
213 return match(nextContext, ignoreDynamicPseudo, siblingTraversalStrat egy); 220 return match(nextContext, ignoreDynamicPseudo, siblingTraversalStrat egy);
214 } 221 }
215 case CSSSelector::ShadowDistributed:
216 {
217 Vector<InsertionPoint*, 8> insertionPoints;
218 for (Element* element = context.element; element; element = element- >parentElement()) {
219 insertionPoints.clear();
220 collectInsertionPointsWhereNodeIsDistributed(element, insertionP oints);
221 for (size_t i = 0; i < insertionPoints.size(); ++i) {
222 nextContext.element = insertionPoints[i];
223 nextContext.isSubSelector = false;
224 nextContext.elementStyle = 0;
225 if (match(nextContext, ignoreDynamicPseudo, siblingTraversal Strategy) == SelectorMatches)
226 return SelectorMatches;
227 }
228 }
229 return SelectorFailsCompletely;
230 }
231 } 222 }
232 223
233 ASSERT_NOT_REACHED(); 224 ASSERT_NOT_REACHED();
234 return SelectorFailsCompletely; 225 return SelectorFailsCompletely;
235 } 226 }
236 227
228 template<typename SiblingTraversalStrategy>
229 SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Element* element, const SiblingTraversalStrategy& siblingTraversalStrategy, PseudoId& dy namicPseudo, SelectorCheckingContext& nextContext) const
230 {
231 Vector<InsertionPoint*, 8> insertionPoints;
232 collectInsertionPointsWhereNodeIsDistributed(element, insertionPoints);
233 for (size_t i = 0; i < insertionPoints.size(); ++i) {
234 nextContext.element = insertionPoints[i];
235 nextContext.isSubSelector = false;
236 nextContext.elementStyle = 0;
237 if (match(nextContext, dynamicPseudo, siblingTraversalStrategy) == Selec torMatches)
238 return SelectorMatches;
239 }
240 return SelectorFailsCompletely;
241 }
242
237 static inline bool containsHTMLSpace(const AtomicString& string) 243 static inline bool containsHTMLSpace(const AtomicString& string)
238 { 244 {
239 for (unsigned i = 0; i < string.length(); i++) 245 for (unsigned i = 0; i < string.length(); i++)
240 if (isHTMLSpace(string[i])) 246 if (isHTMLSpace(string[i]))
241 return true; 247 return true;
242 return false; 248 return false;
243 } 249 }
244 250
245 static bool attributeValueMatches(const Attribute* attributeItem, CSSSelector::M atch match, const AtomicString& selectorValue, bool caseSensitive) 251 static bool attributeValueMatches(const Attribute* attributeItem, CSSSelector::M atch match, const AtomicString& selectorValue, bool caseSensitive)
246 { 252 {
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 return element->focused() && isFrameFocused(element); 907 return element->focused() && isFrameFocused(element);
902 } 908 }
903 909
904 template 910 template
905 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, Ps eudoId&, const DOMSiblingTraversalStrategy&) const; 911 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, Ps eudoId&, const DOMSiblingTraversalStrategy&) const;
906 912
907 template 913 template
908 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, Ps eudoId&, const ShadowDOMSiblingTraversalStrategy&) const; 914 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, Ps eudoId&, const ShadowDOMSiblingTraversalStrategy&) const;
909 915
910 } 916 }
OLDNEW
« no previous file with comments | « Source/core/css/SelectorChecker.h ('k') | Source/core/css/SelectorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698