OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/dom/NthIndexCache.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 void NthIndexCache::clear() |
| 13 { |
| 14 if (m_parentMap) |
| 15 m_parentMap->clear(); |
| 16 } |
| 17 |
| 18 NthIndexCache::NthIndexData& NthIndexCache::ensureNthIndexDataFor(Node& parent) |
| 19 { |
| 20 if (!m_parentMap) |
| 21 m_parentMap = adoptPtrWillBeNoop(new ParentMap()); |
| 22 |
| 23 ParentMap::AddResult addResult = m_parentMap->add(&parent, nullptr); |
| 24 if (addResult.isNewEntry) |
| 25 addResult.storedValue->value = adoptPtrWillBeNoop(new NthIndexData()); |
| 26 |
| 27 ASSERT(addResult.storedValue->value); |
| 28 return *addResult.storedValue->value; |
| 29 } |
| 30 |
| 31 unsigned NthIndexCache::NthIndexData::cacheNthIndices(Element& element) |
| 32 { |
| 33 unsigned index = 0; |
| 34 const unsigned spread = 3; |
| 35 unsigned count = 0; |
| 36 for (Element* sibling = ElementTraversal::firstChild(*element.parentNode());
sibling; sibling = ElementTraversal::nextSibling(*sibling)) { |
| 37 if (!(++count % spread)) |
| 38 m_elementIndexMap.add(sibling, count); |
| 39 if (sibling == &element) |
| 40 index = count; |
| 41 } |
| 42 ASSERT(count && index); |
| 43 m_count = count; |
| 44 return index; |
| 45 } |
| 46 |
| 47 DEFINE_TRACE(NthIndexCache) |
| 48 { |
| 49 #if ENABLE(OILPAN) |
| 50 visitor->trace(m_parentMap); |
| 51 visitor->trace(m_document); |
| 52 #endif |
| 53 } |
| 54 |
| 55 DEFINE_TRACE(NthIndexCache::NthIndexData) |
| 56 { |
| 57 #if ENABLE(OILPAN) |
| 58 visitor->trace(m_elementIndexMap); |
| 59 #endif |
| 60 } |
| 61 |
| 62 } // namespace blink |
OLD | NEW |