Chromium Code Reviews| Index: Source/core/dom/CustomElementUpgradeCandidateMap.cpp |
| diff --git a/Source/core/dom/CustomElementUpgradeCandidateMap.cpp b/Source/core/dom/CustomElementUpgradeCandidateMap.cpp |
| index c84bcb7dec56a504de7c372580cac0a3da08e967..d84c4fdfafaefdfa6d02c604291668d7d6668783 100644 |
| --- a/Source/core/dom/CustomElementUpgradeCandidateMap.cpp |
| +++ b/Source/core/dom/CustomElementUpgradeCandidateMap.cpp |
| @@ -39,14 +39,14 @@ CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() |
| { |
| UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().keys(); |
| for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begin().keys(); it != end; ++it) |
| - unregisterForElementDestructionNotification(*it, this); |
| + unobserve(*it); |
| } |
| void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descriptor, Element* element) |
| { |
| element->setCustomElementState(Element::UpgradeCandidate); |
| - registerForElementDestructionNotification(element, this); |
| + observe(element); |
| UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, descriptor); |
| ASSERT(result.isNewEntry); |
| @@ -59,7 +59,7 @@ void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri |
| void CustomElementUpgradeCandidateMap::remove(Element* element) |
| { |
| - unregisterForElementDestructionNotification(element, this); |
| + unobserve(element); |
| UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); |
| ASSERT(candidate != m_upgradeCandidates.end()); |
| @@ -70,42 +70,60 @@ void CustomElementUpgradeCandidateMap::remove(Element* element) |
| m_upgradeCandidates.remove(candidate); |
| } |
| +void CustomElementUpgradeCandidateMap::moveToEnd(Element* element) |
| +{ |
| + UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); |
| + ASSERT(candidate != m_upgradeCandidates.end()); |
| + |
| + UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value); |
| + ASSERT(elements != m_unresolvedDefinitions.end()); |
| + elements->value.appendOrMoveToLast(element); |
| +} |
| + |
| ListHashSet<Element*> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& descriptor) |
| { |
| const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descriptor); |
| for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) { |
| - unregisterForElementDestructionNotification(*candidate, this); |
| + unobserve(*candidate); |
| m_upgradeCandidates.remove(*candidate); |
| } |
| return candidates; |
| } |
| +void CustomElementUpgradeCandidateMap::elementFinishedParsingChildren(Element* element) |
| +{ |
| + ElementObserverMap::iterator it = elementObservers().find(element); |
| + if (it == elementObservers().end()) |
| + return; |
| + it->value->moveToEnd(element); |
| +} |
| + |
| void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) |
| { |
| - DestructionObserverMap::iterator it = destructionObservers().find(element); |
| - if (it == destructionObservers().end()) |
| + ElementObserverMap::iterator it = elementObservers().find(element); |
|
dglazkov
2013/08/13 16:22:06
The observer terminology is much better. Though it
|
| + if (it == elementObservers().end()) |
| return; |
| it->value->remove(element); // will also remove the destruction observer |
| } |
| -CustomElementUpgradeCandidateMap::DestructionObserverMap& CustomElementUpgradeCandidateMap::destructionObservers() |
| +CustomElementUpgradeCandidateMap::ElementObserverMap& CustomElementUpgradeCandidateMap::elementObservers() |
| { |
| - DEFINE_STATIC_LOCAL(DestructionObserverMap, map, ()); |
| + DEFINE_STATIC_LOCAL(ElementObserverMap, map, ()); |
| return map; |
| } |
| -void CustomElementUpgradeCandidateMap::registerForElementDestructionNotification(Element* element, CustomElementUpgradeCandidateMap* observer) |
| +void CustomElementUpgradeCandidateMap::observe(Element* element) |
| { |
| - DestructionObserverMap::AddResult result = destructionObservers().add(element, observer); |
| + ElementObserverMap::AddResult result = elementObservers().add(element, this); |
| ASSERT(result.isNewEntry); |
| } |
| -void CustomElementUpgradeCandidateMap::unregisterForElementDestructionNotification(Element* element, CustomElementUpgradeCandidateMap* observer) |
| +void CustomElementUpgradeCandidateMap::unobserve(Element* element) |
| { |
| - CustomElementUpgradeCandidateMap* map = destructionObservers().take(element); |
| - ASSERT(map == observer); |
| + CustomElementUpgradeCandidateMap* map = elementObservers().take(element); |
| + ASSERT(map == this); |
| } |
| } |