Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "core/dom/CustomElementUpgradeCandidateMap.h" | 32 #include "core/dom/CustomElementUpgradeCandidateMap.h" |
| 33 | 33 |
| 34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() | 38 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() |
| 39 { | 39 { |
| 40 UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().ke ys(); | 40 UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().ke ys(); |
| 41 for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begi n().keys(); it != end; ++it) | 41 for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begi n().keys(); it != end; ++it) |
| 42 unregisterForElementDestructionNotification(*it, this); | 42 unobserve(*it); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri ptor, Element* element) | 45 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri ptor, Element* element) |
| 46 { | 46 { |
| 47 element->setCustomElementState(Element::UpgradeCandidate); | 47 element->setCustomElementState(Element::UpgradeCandidate); |
| 48 | 48 |
| 49 registerForElementDestructionNotification(element, this); | 49 observe(element); |
| 50 | 50 |
| 51 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des criptor); | 51 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des criptor); |
| 52 ASSERT(result.isNewEntry); | 52 ASSERT(result.isNewEntry); |
| 53 | 53 |
| 54 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript or); | 54 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript or); |
| 55 if (it == m_unresolvedDefinitions.end()) | 55 if (it == m_unresolvedDefinitions.end()) |
| 56 it = m_unresolvedDefinitions.add(descriptor, ElementSet()).iterator; | 56 it = m_unresolvedDefinitions.add(descriptor, ElementSet()).iterator; |
| 57 it->value.add(element); | 57 it->value.add(element); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void CustomElementUpgradeCandidateMap::remove(Element* element) | 60 void CustomElementUpgradeCandidateMap::remove(Element* element) |
| 61 { | 61 { |
| 62 unregisterForElementDestructionNotification(element, this); | 62 unobserve(element); |
| 63 | 63 |
| 64 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); | 64 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); |
| 65 ASSERT(candidate != m_upgradeCandidates.end()); | 65 ASSERT(candidate != m_upgradeCandidates.end()); |
| 66 | 66 |
| 67 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value); | 67 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value); |
| 68 ASSERT(elements != m_unresolvedDefinitions.end()); | 68 ASSERT(elements != m_unresolvedDefinitions.end()); |
| 69 elements->value.remove(element); | 69 elements->value.remove(element); |
| 70 m_upgradeCandidates.remove(candidate); | 70 m_upgradeCandidates.remove(candidate); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CustomElementUpgradeCandidateMap::moveToEnd(Element* element) | |
| 74 { | |
| 75 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); | |
| 76 ASSERT(candidate != m_upgradeCandidates.end()); | |
| 77 | |
| 78 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca ndidate->value); | |
| 79 ASSERT(elements != m_unresolvedDefinitions.end()); | |
| 80 elements->value.appendOrMoveToLast(element); | |
| 81 } | |
| 82 | |
| 73 ListHashSet<Element*> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor (const CustomElementDescriptor& descriptor) | 83 ListHashSet<Element*> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor (const CustomElementDescriptor& descriptor) |
| 74 { | 84 { |
| 75 const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descr iptor); | 85 const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descr iptor); |
| 76 | 86 |
| 77 for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) { | 87 for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) { |
| 78 unregisterForElementDestructionNotification(*candidate, this); | 88 unobserve(*candidate); |
| 79 m_upgradeCandidates.remove(*candidate); | 89 m_upgradeCandidates.remove(*candidate); |
| 80 } | 90 } |
| 81 | 91 |
| 82 return candidates; | 92 return candidates; |
| 83 } | 93 } |
| 84 | 94 |
| 95 void CustomElementUpgradeCandidateMap::elementFinishedParsingChildren(Element* e lement) | |
| 96 { | |
| 97 ElementObserverMap::iterator it = elementObservers().find(element); | |
| 98 if (it == elementObservers().end()) | |
| 99 return; | |
| 100 it->value->moveToEnd(element); | |
| 101 } | |
| 102 | |
| 85 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) | 103 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) |
| 86 { | 104 { |
| 87 DestructionObserverMap::iterator it = destructionObservers().find(element); | 105 ElementObserverMap::iterator it = elementObservers().find(element); |
|
dglazkov
2013/08/13 16:22:06
The observer terminology is much better. Though it
| |
| 88 if (it == destructionObservers().end()) | 106 if (it == elementObservers().end()) |
| 89 return; | 107 return; |
| 90 it->value->remove(element); // will also remove the destruction observer | 108 it->value->remove(element); // will also remove the destruction observer |
| 91 } | 109 } |
| 92 | 110 |
| 93 CustomElementUpgradeCandidateMap::DestructionObserverMap& CustomElementUpgradeCa ndidateMap::destructionObservers() | 111 CustomElementUpgradeCandidateMap::ElementObserverMap& CustomElementUpgradeCandid ateMap::elementObservers() |
| 94 { | 112 { |
| 95 DEFINE_STATIC_LOCAL(DestructionObserverMap, map, ()); | 113 DEFINE_STATIC_LOCAL(ElementObserverMap, map, ()); |
| 96 return map; | 114 return map; |
| 97 } | 115 } |
| 98 | 116 |
| 99 void CustomElementUpgradeCandidateMap::registerForElementDestructionNotification (Element* element, CustomElementUpgradeCandidateMap* observer) | 117 void CustomElementUpgradeCandidateMap::observe(Element* element) |
| 100 { | 118 { |
| 101 DestructionObserverMap::AddResult result = destructionObservers().add(elemen t, observer); | 119 ElementObserverMap::AddResult result = elementObservers().add(element, this) ; |
| 102 ASSERT(result.isNewEntry); | 120 ASSERT(result.isNewEntry); |
| 103 } | 121 } |
| 104 | 122 |
| 105 void CustomElementUpgradeCandidateMap::unregisterForElementDestructionNotificati on(Element* element, CustomElementUpgradeCandidateMap* observer) | 123 void CustomElementUpgradeCandidateMap::unobserve(Element* element) |
| 106 { | 124 { |
| 107 CustomElementUpgradeCandidateMap* map = destructionObservers().take(element) ; | 125 CustomElementUpgradeCandidateMap* map = elementObservers().take(element); |
| 108 ASSERT(map == observer); | 126 ASSERT(map == this); |
| 109 } | 127 } |
| 110 | 128 |
| 111 } | 129 } |
| OLD | NEW |