| 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 (element.isPseudoElement()) |
| 60 return 1; |
| 59 if (!m_count) | 61 if (!m_count) |
| 60 return cacheNthIndices(element); | 62 return cacheNthIndices(element); |
| 61 | 63 |
| 62 unsigned index = 0; | 64 unsigned index = 0; |
| 63 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ
ousSibling(*sibling), index++) { | 65 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ
ousSibling(*sibling), index++) { |
| 64 auto it = m_elementIndexMap.find(sibling); | 66 auto it = m_elementIndexMap.find(sibling); |
| 65 if (it != m_elementIndexMap.end()) | 67 if (it != m_elementIndexMap.end()) |
| 66 return it->value + index; | 68 return it->value + index; |
| 67 } | 69 } |
| 68 return index; | 70 return index; |
| 69 } | 71 } |
| 70 | 72 |
| 71 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element) | 73 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element) |
| 72 { | 74 { |
| 75 if (element.isPseudoElement()) |
| 76 return 1; |
| 73 unsigned index = nthIndex(element); | 77 unsigned index = nthIndex(element); |
| 74 return m_count - index + 1; | 78 return m_count - index + 1; |
| 75 } | 79 } |
| 76 | 80 |
| 77 inline unsigned NthIndexCache::nthChildIndex(Element& element) | 81 inline unsigned NthIndexCache::nthChildIndex(Element& element) |
| 78 { | 82 { |
| 79 ASSERT(element.parentNode()); | 83 ASSERT(element.parentNode()); |
| 80 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element); | 84 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element); |
| 81 } | 85 } |
| 82 | 86 |
| 83 inline unsigned NthIndexCache::nthLastChildIndex(Element& element) | 87 inline unsigned NthIndexCache::nthLastChildIndex(Element& element) |
| 84 { | 88 { |
| 85 ASSERT(element.parentNode()); | 89 ASSERT(element.parentNode()); |
| 86 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element); | 90 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element); |
| 87 } | 91 } |
| 88 | 92 |
| 89 } // namespace blink | 93 } // namespace blink |
| 90 | 94 |
| 91 #endif // NthIndexCache_h | 95 #endif // NthIndexCache_h |
| OLD | NEW |