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

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: Adding Layout Tests Created 5 years, 8 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
Index: Source/core/css/SiblingTraversalStrategies.h
diff --git a/Source/core/css/SiblingTraversalStrategies.h b/Source/core/css/SiblingTraversalStrategies.h
index 1e008dba5fda36e1c053fe4b5b43ba61e10e51af..5f1e0176bce981354f8fd4fefe37fd469553b1ba 100644
--- a/Source/core/css/SiblingTraversalStrategies.h
+++ b/Source/core/css/SiblingTraversalStrategies.h
@@ -48,15 +48,6 @@ public:
int countElementsAfter(Element&) const;
int countElementsOfTypeBefore(Element&, const QualifiedName&) const;
int countElementsOfTypeAfter(Element&, const QualifiedName&) const;
-
-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) const
@@ -93,6 +84,8 @@ inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) co
inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& element, const QualifiedName& type) const
{
+ 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) con
inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& element, const QualifiedName& type) const
{
+ 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;

Powered by Google App Engine
This is Rietveld 408576698