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

Unified Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 1096813005: Extending the NthIndexCache to support caching for the type of index. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebasing Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/css/nth-child-and-nth-type-child-expected.html ('k') | Source/core/dom/NthIndexCache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/SiblingTraversalStrategies.h
diff --git a/Source/core/css/SiblingTraversalStrategies.h b/Source/core/css/SiblingTraversalStrategies.h
index 14c2eb6f4d566fb977cd1ad0b89a06fffe7afdfe..c6f6acbfcaf18206f1b677c0e003e3e798b1522e 100644
--- a/Source/core/css/SiblingTraversalStrategies.h
+++ b/Source/core/css/SiblingTraversalStrategies.h
@@ -48,15 +48,6 @@ public:
static int countElementsAfter(Element&);
static int countElementsOfTypeBefore(Element&, const QualifiedName&);
static int countElementsOfTypeAfter(Element&, const QualifiedName&);
-
-private:
- class HasTagName {
- public:
- explicit HasTagName(const QualifiedName& tagName) : m_tagName(tagName) { }
- bool operator() (const Element& element) const { return element.hasTagName(m_tagName); }
- private:
- const QualifiedName& m_tagName;
- };
};
inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element)
@@ -93,6 +84,8 @@ inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element)
inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& element, const QualifiedName& type)
{
+ if (NthIndexCache* nthIndexCache = element.document().nthIndexCache())
+ return nthIndexCache->nthChildIndexOfType(element, type) - 1;
int count = 0;
for (const Element* sibling = ElementTraversal::previousSibling(element, HasTagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, HasTagName(type)))
++count;
@@ -112,6 +105,9 @@ inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element)
inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& element, const QualifiedName& type)
{
+ if (NthIndexCache* nthIndexCache = element.document().nthIndexCache())
+ return nthIndexCache->nthLastChildIndexOfType(element, type) - 1;
+
int count = 0;
for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagName(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagName(type)))
++count;
« no previous file with comments | « LayoutTests/fast/css/nth-child-and-nth-type-child-expected.html ('k') | Source/core/dom/NthIndexCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698