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

Unified Diff: third_party/WebKit/Source/core/dom/SelectorQuery.cpp

Issue 2767113003: Simplify some arguments inside SelectorQuery. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/SelectorQuery.cpp
diff --git a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
index 5037e303204593b63cee201bc5621043ff77aa99..4cae4ac0dc686e247054987540f3e6a6b627bbcf 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -227,15 +227,6 @@ inline bool ancestorHasClassName(ContainerNode& rootNode,
return false;
}
-// If returns true, traversalRoots has the elements that may match the selector
-// query.
-//
-// If returns false, traversalRoots has the rootNode parameter or descendants of
-// rootNode representing the subtree for which we can limit the querySelector
-// traversal.
-//
-// The travseralRoots may be empty, regardless of the returned bool value, if
-// this method finds that the selectors won't match any element.
esprehn 2017/03/23 01:09:33 This comment was ancient, from when we used to ret
sashab 2017/03/23 05:40:21 Wanna add an updated comment to explain how it wor
esprehn 2017/03/23 05:48:51 I'd prefer to do that in a separate patch.
template <typename SelectorQueryTrait>
void SelectorQuery::findTraverseRootsAndExecute(
ContainerNode& rootNode,
@@ -262,18 +253,19 @@ void SelectorQuery::findTraverseRootsAndExecute(
else if (!element || isRightmostSelector)
adjustedNode = nullptr;
if (isRightmostSelector) {
- executeForTraverseRoot<SelectorQueryTrait>(
- *m_selectors[0], adjustedNode, MatchesTraverseRoots, rootNode,
- output);
+ if (!adjustedNode)
+ return;
+ element = toElement(adjustedNode);
+ if (selectorMatches(*m_selectors[0], *element, rootNode))
+ SelectorQueryTrait::appendElement(output, *element);
sashab 2017/03/23 06:26:32 I don't really understand this part of the change,
esprehn 2017/03/23 06:31:58 The code used to pass MatchedTraverseRoot as the e
sashab 2017/03/23 23:19:05 Can you remove it from the function then? Do other
esprehn 2017/03/24 00:02:31 I did remove it from that function. There's a anot
return;
}
if (startFromParent && adjustedNode)
adjustedNode = adjustedNode->parentNode();
- executeForTraverseRoot<SelectorQueryTrait>(*m_selectors[0], adjustedNode,
- DoesNotMatchTraverseRoots,
- rootNode, output);
+ executeForTraverseRoot<SelectorQueryTrait>(adjustedNode, rootNode,
+ output);
return;
}
@@ -285,23 +277,19 @@ void SelectorQuery::findTraverseRootsAndExecute(
ClassElementList<AllElements> traverseRoots(rootNode,
selector->value());
executeForTraverseRoots<SelectorQueryTrait>(
- *m_selectors[0], traverseRoots, MatchesTraverseRoots, rootNode,
- output);
+ traverseRoots, MatchesTraverseRoots, rootNode, output);
return;
}
// Since there exists some ancestor element which has the class name, we
// need to see all children of rootNode.
if (ancestorHasClassName(rootNode, selector->value())) {
- executeForTraverseRoot<SelectorQueryTrait>(*m_selectors[0], &rootNode,
- DoesNotMatchTraverseRoots,
- rootNode, output);
+ executeForTraverseRoot<SelectorQueryTrait>(&rootNode, rootNode, output);
return;
}
ClassElementList<OnlyRoots> traverseRoots(rootNode, selector->value());
executeForTraverseRoots<SelectorQueryTrait>(
- *m_selectors[0], traverseRoots, DoesNotMatchTraverseRoots, rootNode,
- output);
+ traverseRoots, DoesNotMatchTraverseRoots, rootNode, output);
return;
}
@@ -315,25 +303,19 @@ void SelectorQuery::findTraverseRootsAndExecute(
startFromParent = false;
}
- executeForTraverseRoot<SelectorQueryTrait>(
- *m_selectors[0], &rootNode, DoesNotMatchTraverseRoots, rootNode, output);
+ executeForTraverseRoot<SelectorQueryTrait>(&rootNode, rootNode, output);
}
template <typename SelectorQueryTrait>
void SelectorQuery::executeForTraverseRoot(
- const CSSSelector& selector,
ContainerNode* traverseRoot,
- MatchTraverseRootState matchTraverseRoot,
ContainerNode& rootNode,
typename SelectorQueryTrait::OutputType& output) const {
- if (!traverseRoot)
- return;
+ DCHECK_EQ(m_selectors.size(), 1u);
- if (matchTraverseRoot) {
- if (selectorMatches(selector, toElement(*traverseRoot), rootNode))
- SelectorQueryTrait::appendElement(output, toElement(*traverseRoot));
+ if (!traverseRoot)
return;
- }
+ const CSSSelector& selector = *m_selectors[0];
for (Element& element : ElementTraversal::descendantsOf(*traverseRoot)) {
if (selectorMatches(selector, element, rootNode)) {
@@ -346,14 +328,17 @@ void SelectorQuery::executeForTraverseRoot(
template <typename SelectorQueryTrait, typename SimpleElementListType>
void SelectorQuery::executeForTraverseRoots(
- const CSSSelector& selector,
SimpleElementListType& traverseRoots,
MatchTraverseRootState matchTraverseRoots,
ContainerNode& rootNode,
typename SelectorQueryTrait::OutputType& output) const {
+ DCHECK_EQ(m_selectors.size(), 1u);
+
if (traverseRoots.isEmpty())
return;
+ const CSSSelector& selector = *m_selectors[0];
+
if (matchTraverseRoots) {
while (!traverseRoots.isEmpty()) {
Element& element = *traverseRoots.next();
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698