OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NthIndexCache_h | 5 #ifndef NthIndexCache_h |
6 #define NthIndexCache_h | 6 #define NthIndexCache_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 using ParentMap = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMe mber<NthIndexData>>; | 50 using ParentMap = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMe mber<NthIndexData>>; |
51 | 51 |
52 OwnPtrWillBeMember<ParentMap> m_parentMap; | 52 OwnPtrWillBeMember<ParentMap> m_parentMap; |
53 RawPtrWillBeMember<Document> m_document; | 53 RawPtrWillBeMember<Document> m_document; |
54 uint64_t m_domTreeVersion; | 54 uint64_t m_domTreeVersion; |
55 }; | 55 }; |
56 | 56 |
57 inline unsigned NthIndexCache::NthIndexData::nthIndex(Element& element) | 57 inline unsigned NthIndexCache::NthIndexData::nthIndex(Element& element) |
58 { | 58 { |
59 if (!m_count) | 59 if (!m_count && !element.isPseudoElement()) |
60 return cacheNthIndices(element); | 60 return cacheNthIndices(element); |
61 | 61 |
62 unsigned index = 0; | 62 unsigned index = 0; |
63 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ ousSibling(*sibling), index++) { | 63 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ ousSibling(*sibling), index++) { |
esprehn
2015/04/30 01:03:52
Why go through this loop for pseudo elements? I kn
| |
64 auto it = m_elementIndexMap.find(sibling); | 64 auto it = m_elementIndexMap.find(sibling); |
65 if (it != m_elementIndexMap.end()) | 65 if (it != m_elementIndexMap.end()) |
66 return it->value + index; | 66 return it->value + index; |
67 } | 67 } |
68 return index; | 68 return index; |
69 } | 69 } |
70 | 70 |
71 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element) | 71 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element) |
72 { | 72 { |
73 unsigned index = nthIndex(element); | 73 unsigned index = nthIndex(element); |
74 return m_count - index + 1; | 74 return m_count - index + 1; |
75 } | 75 } |
76 | 76 |
77 inline unsigned NthIndexCache::nthChildIndex(Element& element) | 77 inline unsigned NthIndexCache::nthChildIndex(Element& element) |
78 { | 78 { |
79 ASSERT(element.parentNode()); | 79 ASSERT(element.parentNode()); |
80 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element); | 80 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element); |
81 } | 81 } |
82 | 82 |
83 inline unsigned NthIndexCache::nthLastChildIndex(Element& element) | 83 inline unsigned NthIndexCache::nthLastChildIndex(Element& element) |
84 { | 84 { |
85 ASSERT(element.parentNode()); | 85 ASSERT(element.parentNode()); |
86 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element); | 86 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element); |
87 } | 87 } |
88 | 88 |
89 } // namespace blink | 89 } // namespace blink |
90 | 90 |
91 #endif // NthIndexCache_h | 91 #endif // NthIndexCache_h |
OLD | NEW |